/// <summary> /// Insert an EdgeEnd into the map, and clear the edgeList cache, /// since the list of edges has now changed. /// </summary> /// <param name="e"></param> /// <param name="obj"></param> protected void InsertEdgeEnd(EdgeEnd e, object obj) { // Diego Guidi says: i have inserted this line because if i try to add an object already present // in the list, a System.ArgumentException was thrown. if (_edgeMap.Contains(e)) return; _edgeMap.Add(e, obj); _edgeList = null; // edge list has changed - clear the cache }
/// <summary> /// Insert a EdgeEnd in order in the list. /// If there is an existing EdgeStubBundle which is parallel, the EdgeEnd is /// added to the bundle. Otherwise, a new EdgeEndBundle is created /// to contain the EdgeEnd. /// </summary> /// <param name="e"></param> public override void Insert(EdgeEnd e) { EdgeEndBundle eb = (EdgeEndBundle) EdgeMap[e]; if (eb == null) { eb = new EdgeEndBundle(e); InsertEdgeEnd(e, eb); } else eb.Insert(e); }
/// <summary> /// Create a StubEdge for the edge after the intersection eiCurr. /// The next intersection is provided /// in case it is the endpoint for the stub edge. /// Otherwise, the next point from the parent edge will be the endpoint. /// eiCurr will always be an EdgeIntersection, but eiNext may be null. /// </summary> /// <param name="edge"></param> /// <param name="l"></param> /// <param name="eiCurr"></param> /// <param name="eiNext"></param> public virtual void CreateEdgeEndForNext(Edge edge, IList l, EdgeIntersection eiCurr, EdgeIntersection eiNext) { int iNext = eiCurr.SegmentIndex + 1; // if there is no next edge there is nothing to do if (iNext >= edge.NumPoints && eiNext == null) return; Coordinate pNext = edge.GetCoordinate(iNext); // if the next intersection is in the same segment as the current, use it as the endpoint if (eiNext != null && eiNext.SegmentIndex == eiCurr.SegmentIndex) pNext = eiNext.Coordinate; EdgeEnd e = new EdgeEnd(edge, eiCurr.Coordinate, pNext, new Label(edge.Label)); l.Add(e); }
/// <summary> /// Create a EdgeStub for the edge before the intersection eiCurr. /// The previous intersection is provided /// in case it is the endpoint for the stub edge. /// Otherwise, the previous point from the parent edge will be the endpoint. /// eiCurr will always be an EdgeIntersection, but eiPrev may be null. /// </summary> /// <param name="edge"></param> /// <param name="l"></param> /// <param name="eiCurr"></param> /// <param name="eiPrev"></param> public virtual void CreateEdgeEndForPrev(Edge edge, IList l, EdgeIntersection eiCurr, EdgeIntersection eiPrev) { int iPrev = eiCurr.SegmentIndex; if (eiCurr.Distance == 0.0) { // if at the start of the edge there is no previous edge if (iPrev == 0) return; iPrev--; } Coordinate pPrev = edge.GetCoordinate(iPrev); // if prev intersection is past the previous vertex, use it instead if (eiPrev != null && eiPrev.SegmentIndex >= iPrev) pPrev = eiPrev.Coordinate; Label label = new Label(edge.Label); // since edgeStub is oriented opposite to it's parent edge, have to flip sides for edge label label.Flip(); EdgeEnd e = new EdgeEnd(edge, eiCurr.Coordinate, pPrev, label); l.Add(e); }
/// <summary> /// Insert a directed edge in the list. /// </summary> /// <param name="ee"></param> public override void Insert(EdgeEnd ee) { DirectedEdge de = (DirectedEdge) ee; InsertEdgeEnd(de, de); }
/// <summary> /// Implements the total order relation: /// a has a greater angle with the positive x-axis than b. /// Using the obvious algorithm of simply computing the angle is not robust, /// since the angle calculation is obviously susceptible to roundoff. /// A robust algorithm is: /// - first compare the quadrant. If the quadrants /// are different, it it trivial to determine which vector is "greater". /// - if the vectors lie in the same quadrant, the computeOrientation function /// can be used to decide the relative orientation of the vectors. /// </summary> /// <param name="e"></param> public virtual int CompareDirection(EdgeEnd e) { if (dx == e.dx && dy == e.dy) return 0; // if the rays are in different quadrants, determining the ordering is trivial if (quadrant > e.quadrant) return 1; if (quadrant < e.quadrant) return -1; // vectors are in the same quadrant - check relative orientation of direction vectors // this is > e if it is CCW of e return CGAlgorithms.ComputeOrientation(e.p0, e.p1, p1); }
/// <summary> /// Adds a node for the start point of this EdgeEnd /// (if one does not already exist in this map). /// Adds the EdgeEnd to the (possibly new) node. /// </summary> /// <param name="e"></param> public virtual void Add(EdgeEnd e) { Coordinate p = e.Coordinate; Node n = AddNode(p); n.Add(e); }
/// <summary> /// /// </summary> /// <param name="e"></param> public virtual void Insert(EdgeEnd e) { // Assert: start point is the same // Assert: direction is the same edgeEnds.Add(e); }
/// <summary> /// /// </summary> /// <param name="e"></param> public EdgeEndBundle(EdgeEnd e) : base(e.Edge, e.Coordinate, e.DirectedCoordinate, new Label(e.Label)) { Insert(e); }
/// <summary> /// Adds a new EdgeEnd to the planar graph /// </summary> /// <param name="e">The EdgeEnd to add</param> public virtual void Add(EdgeEnd e) { _nodes.Add(e); _edgeEndList.Add(e); }
/// <summary> /// /// </summary> /// <param name="de"></param> /// <param name="i"></param> /// <returns></returns> private static Positions GetRightmostSideOfSegment(EdgeEnd de, int i) { Edge e = de.Edge; IList<Coordinate> coord = e.Coordinates; if (i < 0 || i + 1 >= coord.Count) return Positions.Parallel; if (coord[i].Y == coord[i + 1].Y) return Positions.Parallel; Positions pos = Positions.Left; if (coord[i].Y < coord[i + 1].Y) pos = Positions.Right; return pos; }
/// <summary> /// Insert a EdgeEnd into this EdgeEndStar. /// </summary> /// <param name="e"></param> abstract public void Insert(EdgeEnd e);
/// <summary> /// /// </summary> /// <param name="eSearch"></param> /// <returns></returns> public virtual int FindIndex(EdgeEnd eSearch) { GetEnumerator(); // force edgelist to be computed for (int i = 0; i < _edgeList.Count; i++ ) { EdgeEnd e = (EdgeEnd)_edgeList[i]; if (e == eSearch) return i; } return -1; }
/// <summary> /// /// </summary> /// <param name="ee"></param> /// <returns></returns> public virtual EdgeEnd GetNextCw(EdgeEnd ee) { InitializeEdges(); int i = _edgeList.IndexOf(ee); int iNextCw = i - 1; if (i == 0) iNextCw = _edgeList.Count - 1; return (EdgeEnd)_edgeList[iNextCw]; }
/// <summary> /// Add the edge to the list of edges at this node. /// </summary> /// <param name="e"></param> public virtual void Add(EdgeEnd e) { // Assert: start pt of e is equal to node point _edges.Insert(e); e.Node = this; }