public void AddEvents(LineSegment segment, List <IntersectionSweepEvent> events) { Vector2 point1 = segment.Point1; Vector2 point2 = segment.Point2; var ev1 = new IntersectionSweepEvent(point1, false, false, segment, null as IntersectionSweepEvent); var ev2 = new IntersectionSweepEvent(point2, false, false, segment, ev1); ev1.OtherEvent = ev2; if (point1.Equals(point2)) { return; } if (ev1.CompareTo(ev2) < 1) { ev1.IsStart = true; ev2.IsEnd = true; } else { ev1.IsEnd = true; ev2.IsStart = true; } events.Add(ev1); events.Add(ev2); }
public int CompareTo(IntersectionStatusItem other) { if (Equals(other)) { return(0); } IntersectionSweepEvent ev = SweepEvent; IntersectionSweepEvent otherEv = other.SweepEvent; if (ev.Equals(otherEv)) { return(0); } if (MathUtil.SignedArea(ev.Point, ev.OtherEvent.Point, otherEv.Point) != 0 || MathUtil.SignedArea(ev.Point, ev.OtherEvent.Point, otherEv.OtherEvent.Point) != 0) { if (ev.Point.Equals(otherEv.Point)) { return(ev.Below(otherEv.OtherEvent.Point) ? -1 : 1); } if (ev.Point.x.Equals(otherEv.Point.x)) { return(ev.Point.y < otherEv.Point.y ? -1 : 1); } if (ev.CompareTo(otherEv) == 1) { return(!otherEv.Below(ev.Point) ? -1 : 1); } return(ev.Below(otherEv.Point) ? -1 : 1); } if (ev.Point.Equals(otherEv.Point) && ev.OtherEvent.Point.Equals(otherEv.OtherEvent.Point)) { return(0); } return(ev.CompareTo(otherEv) == 1 ? 1 : -1); }