/// <summary> /// Initializes a new instance of the <see cref="EventQueue" /> class. /// </summary> /// <param name="source">The source coordinates representing multiple line strings.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public EventQueue(IEnumerable <IList <Coordinate> > source) { // source: http://geomalgorithms.com/a09-_intersect-3.html if (source == null) { throw new ArgumentNullException("source", "The source is null."); } _comparer = new CoordinateComparer(); _eventHeap = new EventHeap(); Int32 index = 0, compare; foreach (IList <Coordinate> coordinateList in source) { if (coordinateList == null || coordinateList.Count < 2) { continue; } for (Int32 i = 0; i < coordinateList.Count - 1; i++) { EndPointEvent firstEvent = new EndPointEvent { Edge = index, Vertex = coordinateList[i] }; EndPointEvent secondEvent = new EndPointEvent { Edge = index, Vertex = coordinateList[i + 1] }; compare = _comparer.Compare(coordinateList[i], coordinateList[i + 1]); if (compare == 0) { continue; } if (compare < 0) { firstEvent.Type = EventType.Left; secondEvent.Type = EventType.Right; } else { firstEvent.Type = EventType.Right; secondEvent.Type = EventType.Left; } _eventHeap.Insert(firstEvent); _eventHeap.Insert(secondEvent); index++; } index++; } }
/// <summary> /// Adds an intersection event to the queue. /// </summary> /// <param name="intersectionEvent">The intersection event.</param> /// <exception cref="System.ArgumentNullException">The intersection event is null.</exception> public void Add(IntersectionEvent intersectionEvent) { if (intersectionEvent == null) { throw new ArgumentNullException("intersectionEvent", "The intersection event is null."); } _eventHeap.Insert(intersectionEvent); }