Пример #1
0
Segment* Segment::prev1(SegmentTypes types) const
      {
      for (Segment* s = prev1(); s; s = s->prev1()) {
            if (s->subtype() & types)
                  return s;
            }
      return 0;
      }
Пример #2
0
static void remove(int i) {
    int prevIndex = prev1(i);
    int nextIndex = next1(i);

    if (prevIndex == 0) {
        /* at head */
        avail = nextIndex;
    } else {
        /* in the middle */
        next(prevIndex,nextIndex);
    }
    if (nextIndex != 0) {
        prev(nextIndex,prevIndex);
    }
}
Пример #3
0
void splitAreas(QList<Geometry*> *firstHalf, QList<Geometry*> *secondHalf, QList<Geometry*> all) {
    int length1 = 1;
    int length2 = all.length()-1;
    int splitIdx = 0; //last index included in the first half of objs

    QList<Geometry*> prev1(all.mid(0,length1));
    QList<Geometry*> prev2(all.mid(1,all.length()-1));

    float prevArea1 = calcAreas(prev1);
    float prevArea2 = calcAreas(prev2);

    for (int i = 0; i < all.length(); i++) {
        length1++; //add one to firstHalf list of objs
        length2--; //remove one from secondHalf list
        QList<Geometry*> temp1(all.mid(0, length1));
        QList<Geometry*> temp2(all.mid(splitIdx, length2));

        float area1 = calcAreas(temp1);
        float area2 = calcAreas(temp2);
        if (area1 > area2) { //when area of first is finally greater than area 2
            //check if the previous split was better balanced:

            float prevDifference = glm::abs(prevArea2 - prevArea1);
            float newDifference = glm::abs(area1 - area2);
            if (prevDifference > newDifference) { //they are NOW more evenly split
                prev1 = temp1;
                prev2 = temp2;
            } else { //they were previously more evenly split
                //current prev1 and prev2 contain ideal split
                break; //dont replace the return value with the new lists
            }
        }else {
            //they havent been replaced, make prev=curr area calcs
            prevArea1 = area1;
            prevArea2 = area2;
        }
    }
    *firstHalf = prev1;
    *secondHalf = prev2;

}