public void Add(Edge edge) { OnAddEdgeEvent(edge); LinkedListNode <PointChain> current = openPolygons.First; while (current != null) { LinkedListNode <PointChain> next = current.Next; PointChain currentChain = current.Value; if (currentChain.LinkSegment(edge)) { if (currentChain.IsClosed()) { closedPolygons.AddLast(currentChain); openPolygons.Remove(current); } else { LinkedListNode <PointChain> innerCurrent = current.Next; while (innerCurrent != null) { LinkedListNode <PointChain> innerNext = innerCurrent.Next; if (currentChain.LinkPointChain(innerCurrent.Value)) { openPolygons.Remove(innerCurrent); break; } innerCurrent = innerNext; } } return; } current = next; } openPolygons.AddLast(new PointChain(edge)); }
public bool LinkPointChain(PointChain chain) { if (chain.points.First() == points.Last()) { chain.points.RemoveFirst(); points.AppendRange(chain.points); return(true); } if (chain.points.Last() == points.First()) { points.RemoveFirst(); points.PrependRange(chain.points); return(true); } if (chain.points.First() == points.First()) { points.RemoveFirst(); chain.points.ReverseOrder(); points.PrependRange(chain.points); return(true); } if (chain.points.Last() == points.Last()) { points.RemoveLast(); chain.points.ReverseOrder(); points.AppendRange(chain.points); return(true); } return(false); }
public void Add(Segment s) { // j iterates through the openPolygon chains. for (int j=0; j<openPolygons.Count; j++) { PointChain chain = openPolygons [j]; if (!chain.LinkSegment (s)) continue; if (chain.closed) { if (chain.pointList.Count == 2) { // We tried linking the same segment (but flipped end and start) to // a chain. (i.e. chain was <p0, p1>, we tried linking Segment(p1, p0) // so the chain was closed illegally. chain.closed = false; return; } closedPolygons.Add (chain); openPolygons.RemoveAt (j); return; } int k = openPolygons.Count; for (int i=j+1; i<k; i++) { // Try to connect this open link to the rest of the chains. // We won't be able to connect this to any of the chains preceding this one // because we know that linkSegment failed on those. if (chain.LinkPointChain (openPolygons [i])) { openPolygons.RemoveAt (i); return; } } return; } PointChain newChain = new PointChain (s); openPolygons.Add (newChain); }