/// <summary> /// Compare two sweep events. /// </summary> /// <param name="e1"></param> /// <param name="e2"></param> /// <returns>True when e1 should be placed before e2, i.e. e1 should be handled after e2</returns> public static int CompareTo(SweepEvent e1, SweepEvent e2) { if (e1.Point.x > e2.Point.x) // Different x-coordinate { return(1); } if (e1.Point.x < e2.Point.x) // Different x-coordinate { return(-1); } if (!e1.Point.y.Equals(e2.Point.y) ) // Different points, but same x-coordinate. The event with lower y-coordinate is processed first { return(e1.Point.y > e2.Point.y ? 1 : -1); } if (e1.IsStart != e2.IsStart ) // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first. { return(e1.IsStart ? 1 : -1); } // Same point, but events are left endpoints or both are right endpoints. if (MathUtil.SignedArea(e1.Point, e1.OtherEvent.Point, e2.OtherEvent.Point) != 0) { // Not collinear return (e1.Above(e2.OtherEvent.Point) ? 1 : -1); // The event associated to the bottom segment is processed first } // Collinear return(e1.PolygonType > e2.PolygonType ? 1 : -1); }