// Should only be called by segmentCompare private bool CompareSweepEvent(SweepEvent e1, SweepEvent e2) { if (e1.p.x > e2.p.x) // Different x coordinate { return(true); } if (e2.p.x > e1.p.x) // Different x coordinate { return(false); } if (e1.p != e2.p) // Different points, but same x coordinate. The event with lower y coordinate is processed first { return(e1.p.y > e2.p.y); } if (e1.isLeft != e2.isLeft) // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first { return(e1.isLeft); } // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first return(e1.isAbove(e2.otherSE.p)); }
private bool SegmentCompare(SweepEvent e1, SweepEvent e2) { if (e1.Equals(e2)) { return(false); } if (signedArea(e1.p, e1.otherSE.p, e2.p) != 0 || signedArea(e1.p, e1.otherSE.p, e2.otherSE.p) != 0) { // Segments are not collinear // If they share their left endpoint use the right endpoint to sort if (Point.EqualsBoth(e1.p, e2.p)) { return(e1.isBelow(e2.otherSE.p)); } if (CompareSweepEvent(e1, e2)) { return(e2.isAbove(e1.p)); } return(e1.isBelow(e2.p)); } if (Point.EqualsBoth(e1.p, e2.p)) // Segments colinear { return(false); } return(CompareSweepEvent(e1, e2)); }
// Should only be called by segmentCompare private bool CompareSweepEvent(SweepEvent e1, SweepEvent e2) { if (e1.p.x > e2.p.x) // Different x coordinate return true; if (e2.p.x > e1.p.x) // Different x coordinate return false; if (e1.p != e2.p) // Different points, but same x coordinate. The event with lower y coordinate is processed first return e1.p.y > e2.p.y; if (e1.isLeft != e2.isLeft) // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first return e1.isLeft; // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first return e1.isAbove (e2.otherSE.p); }
private bool SegmentCompare(SweepEvent e1, SweepEvent e2) { if (e1.Equals(e2)) return false; if (signedArea (e1.p, e1.otherSE.p, e2.p) != 0 || signedArea (e1.p, e1.otherSE.p, e2.otherSE.p) != 0) { // Segments are not collinear // If they share their left endpoint use the right endpoint to sort if (Point.EqualsBoth(e1.p, e2.p)) return e1.isBelow (e2.otherSE.p); if (CompareSweepEvent (e1, e2)) return e2.isAbove (e1.p); return e1.isBelow (e2.p); } if (Point.EqualsBoth(e1.p, e2.p)) // Segments colinear return false; return CompareSweepEvent (e1, e2); }
bool Sec(SweepEvent e1, SweepEvent e2) { // Different x coordinate if (e1.p.x - e2.p.x > Point.PRECISION || e1.p.x - e2.p.x < -Point.PRECISION) { return(e1.p.x > e2.p.x); } // Same x coordinate. The event with lower y coordinate is processed first if (e1.p.y - e2.p.y > Point.PRECISION || e1.p.y - e2.p.y < -Point.PRECISION) { return(e1.p.y > e2.p.y); } // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first if (e1.isLeft != e2.isLeft) { return(e1.isLeft); } // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first return(e1.isAbove(e2.otherSE.p)); }
// The ordering is reversed because push and pop are faster. int CompareSweepEvent(SweepEvent e1, SweepEvent e2) { if (e1.Equals(e2)) { return(0); } if (e1.p.x - e2.p.x > Point.PRECISION) // Different x coordinate { return(-1); } if (e1.p.x - e2.p.x < -Point.PRECISION) // Different x coordinate { return(1); } if (e1.p.y - e2.p.y > Point.PRECISION) // Different points, but same x coordinate. The event with lower y coordinate is processed first { return(-1); } if (e1.p.y - e2.p.y < -Point.PRECISION) // Different points, but same x coordinate. The event with lower y coordinate is processed first { return(1); } if (e1.isLeft != e2.isLeft) // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first { return((e1.isLeft) ? -1 : 1); } // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first bool isAbove = e1.isAbove(e2.otherSE.p); return(isAbove ? -1 : 1); }
bool Sec(SweepEvent e1, SweepEvent e2) { // Different x coordinate if ( e1.p.x - e2.p.x > Point.PRECISION || e1.p.x - e2.p.x < -Point.PRECISION ) { return e1.p.x > e2.p.x; } // Same x coordinate. The event with lower y coordinate is processed first if ( e1.p.y - e2.p.y > Point.PRECISION || e1.p.y - e2.p.y < -Point.PRECISION) { return e1.p.y > e2.p.y; } // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first if (e1.isLeft != e2.isLeft) { return e1.isLeft; } // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first return e1.isAbove(e2.otherSE.p); }
// The ordering is reversed because push and pop are faster. int CompareSweepEvent(SweepEvent e1, SweepEvent e2) { if (e1.Equals(e2)) return 0; if (e1.p.x - e2.p.x > Point.PRECISION) // Different x coordinate return -1; if (e1.p.x - e2.p.x < -Point.PRECISION) // Different x coordinate return 1; if ( e1.p.y - e2.p.y > Point.PRECISION) // Different points, but same x coordinate. The event with lower y coordinate is processed first return -1; if ( e1.p.y - e2.p.y < -Point.PRECISION ) // Different points, but same x coordinate. The event with lower y coordinate is processed first return 1; if (e1.isLeft != e2.isLeft) // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first return (e1.isLeft) ? -1 : 1; // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first bool isAbove = e1.isAbove (e2.otherSE.p); return isAbove ? -1 : 1; }