Esempio n. 1
0
//! Non-const since copy is an alias
//! Derived from QhullSet::value
QhullPoint QhullPointSet::
value(int idx, QhullPoint &defaultValue) const
{
    // Avoid call to qh_setsize() and assert in elementPointer()
    void **n= reinterpret_cast<void **>(&SETelem_(getSetT(), idx));
    coordT **n2= reinterpret_cast<coordT **>(n);
    if(idx>=0 && n<endPointer()){
        return QhullPoint(dimension(), *n2);
    }else{
        return defaultValue;
    }
}//value
Esempio n. 2
0
void testSetlastEtc(int numInts, int *intarray, int checkEvery)
{
    setT *ints= NULL;
    setT *ints2= NULL;
    int i,j,prepend;

    qh_fprintf(stderr, 8020, "\n\nTesting qh_setlast, qh_setnew_delnthsorted, qh_setunique, and qh_setzero 0..%d. Test", numInts-1);
    for(j=0; j<numInts; j++){
        if(log_i(ints, "j", j, numInts, checkEvery)){
            for(i= qh_setsize(ints); i<j; i++){  /* Test i<j to test the empty set */
                if(!qh_setunique(&ints, intarray+i)){
                    qh_fprintf(stderr, 6340, "qh_setunique: not able to append next element %d\n", i);
                    error_count++;
                }
                if(checkEvery==1){
                    checkSetContents("qh_setunique", ints, i+1, 0, -1, -1);
                }
                if(qh_setunique(&ints, intarray+i)){
                    qh_fprintf(stderr, 6341, "qh_setunique: appended next element twice %d\n", i);
                    error_count++;
                }
                if(qh_setunique(&ints, intarray+i/2)){
                    qh_fprintf(stderr, 6346, "qh_setunique: appended middle element twice %d/2\n", i);
                    error_count++;
                }
            }
            checkSetContents("qh_setunique 2", ints, j, 0, -1, -1);
            if(j==0 && NULL!=qh_setlast(ints)){
                qh_fprintf(stderr, 6339, "qh_setlast: returned last element of empty set\n");
                error_count++;
            }
            if(j>0){
                if(intarray+j-1!=qh_setlast(ints)){
                    qh_fprintf(stderr, 6338, "qh_setlast: wrong last element\n");
                    error_count++;
                }
                prepend= (j<100 ? j/4 : 0);
                ints2= qh_setnew_delnthsorted(ints, qh_setsize(ints), j/2, prepend);
                if(qh_setsize(ints2)!=j+prepend-1){
                    qh_fprintf(stderr, 6345, "qh_setnew_delnthsorted: Expecting %d elements, got %d\n", j+prepend-1, qh_setsize(ints2));
                    error_count++;
                }
                /* Define prepended elements.  Otherwise qh_setdelnthsorted may fail */
                for(i= 0; i<prepend; i++){
                    void **p= &SETelem_(ints2, i);
                    *p= intarray+0;
                }
                for(i= 0; i<prepend; i++){
                    qh_setdelnthsorted(ints2, 0);  /* delete undefined prefix */
                }
                checkSetContents("qh_setnew_delnthsorted", ints2, j-1, 0, j/2+1, -1);
                if(j>2){
                    qh_setzero(ints2, j/2, j-1);  /* max size may be j-1 */
                    if(qh_setsize(ints2)!=j-1){
                        qh_fprintf(stderr, 6342, "qh_setzero: Expecting %d elements, got %d\n", j, qh_setsize(ints2));
                        error_count++;
                    }
                    qh_setcompact(ints2);
                    checkSetContents("qh_setzero", ints2, j/2, 0, -1, -1);
                }
            }
            qh_setfree(&ints2);
        }
    }
    qh_setfreelong(&ints);
    if(ints){
        qh_setfree(&ints); /* Was quick memory */
    }
}/*testSetlastEtc*/