INT32 BOCTX::EVENT::Compare(const EVENT &a, const EVENT &b) { assert(INT20_MIN <= a.x and a.x <= INT20_MAX); assert(INT20_MIN <= a.y and a.y <= INT20_MAX); assert(INT20_MIN <= b.x and b.x <= INT20_MAX); assert(INT20_MIN <= b.y and b.y <= INT20_MAX); if (a.x != b.x) return a.x - b.x; TYPE aType = a.GetType(); TYPE bType = b.GetType(); int asx, asy, bsx, bsy; if (aType == X) asx = a.GetSignX(), asy = a.GetSignY(); else asx = asy = 0; if (bType == X) bsx = b.GetSignX(), bsy = b.GetSignY(); else bsx = bsy = 0; if (asx != bsx) return asx - bsx; if (a.y != b.y) return a.y - b.y; if (asy != bsy) return asy - bsy; if (aType != bType) return aType - bType; return a.id - b.id; } // EVENT::Compare
void BOCTX::HandleEvent(EVENT & event) { switch (event.GetType()) { case EVENT::E: { SEGM2 * sn = event.e.s->n; SEGM2 * sp = event.e.s->p; // untie segment m_S.erase(SEGM_LIST::iterator(event.e.s)); CheckForCross(sp, sn); } break; case EVENT::S: InsMainList(event.s.s); CheckForCross(event.s.s, event.s.s->n); CheckForCross(event.s.s->p, event.s.s); break; case EVENT::X: { if (event.c.s0->n != event.c.s1) return; // ignore crossing event in case of non-adjacent segments SEGM_LIST::iterator s0(event.c.s0), s1(event.c.s1); // swap segments assert(s0->n == &*s1 and s1->p == &*s0); // untie s0 m_S.erase(s1); m_S.insert(s0, *s1); CheckForCross(s1->p, &*s1); CheckForCross(&*s0, s0->n); } break; } } // BOCTX::HandleEvent