Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            if (_currNode == null)
            {
                _currNode     = _nextNode;
                _currSegIndex = _currNode.SegmentIndex;
                ReadNextNode();
                return(true);
            }

            // check for trying to read too far
            if (_nextNode == null)
            {
                return(false);
            }

            if (_nextNode.SegmentIndex == _currNode.SegmentIndex)
            {
                _currNode     = _nextNode;
                _currSegIndex = _currNode.SegmentIndex;
                ReadNextNode();
                return(true);
            }

            if (_nextNode.SegmentIndex > _currNode.SegmentIndex)
            {
            }
            return(false);
        }
Ejemplo n.º 2
0
        private void AddEdgeCoordinates(SegmentNode ei0, SegmentNode ei1,
                                        CoordinateList coordList)
        {
            var npts = ei1.SegmentIndex - ei0.SegmentIndex + 2;

            var lastSegStartPt = _edge.GetCoordinate(ei1.SegmentIndex);
            // if the last intersection point is not equal to the its segment start pt,
            // add it to the points list as well.
            // (This check is needed because the distance metric is not totally reliable!)
            // The check for point equality is 2D only - Z values are ignored
            var useIntPt1 = ei1.IsInterior || !ei1.Coord.Equals2D(lastSegStartPt);

            if (!useIntPt1)
            {
                npts--;
            }

            var ipt = 0;

            coordList.Add(new Coordinate(ei0.Coord), false);
            for (var i = ei0.SegmentIndex + 1; i <= ei1.SegmentIndex; i++)
            {
                coordList.Add(_edge.GetCoordinate(i));
            }
            if (useIntPt1)
            {
                coordList.Add(new Coordinate(ei1.Coord));
            }
        }
Ejemplo n.º 3
0
        /*
         * /// <summary>
         * /// Checks the correctness of the set of split edges corresponding to this edge.
         * /// </summary>
         * /// <param name="splitEdges"></param>
         * private void CheckSplitEdgesCorrectness(IList<ISegmentString> splitEdges)
         * {
         *  var edgePts = _edge.Coordinates;
         *
         *  // check that first and last points of split edges are same as endpoints of edge
         *  var split0 = (ISegmentString) splitEdges[0];
         *  var pt0 = split0.Coordinates[0];
         *  if (!pt0.Equals2D(edgePts[0]))
         *      throw new Exception("bad split edge start point at " + pt0);
         *
         *  var splitn = (ISegmentString)splitEdges[splitEdges.Count - 1];
         *  var splitnPts = splitn.Coordinates;
         *  var ptn = splitnPts[splitnPts.Length - 1];
         *  if (!ptn.Equals2D(edgePts[edgePts.Length - 1]))
         *      throw new Exception("bad split edge end point at " + ptn);
         * }
         */

        /// <summary>
        ///  Create a new "split edge" with the section of points between
        /// (and including) the two intersections.
        /// The label for the new edge is the same as the label for the parent edge.
        /// </summary>
        /// <param name="ei0"></param>
        /// <param name="ei1"></param>
        /// <returns></returns>
        ISegmentString CreateSplitEdge(SegmentNode ei0, SegmentNode ei1)
        {
            var npts = ei1.SegmentIndex - ei0.SegmentIndex + 2;

            var lastSegStartPt = _edge.GetCoordinate(ei1.SegmentIndex);
            // if the last intersection point is not equal to the its segment start pt, add it to the points list as well.
            // (This check is needed because the distance metric is not totally reliable!)
            // The check for point equality is 2D only - Z values are ignored
            var useIntPt1 = ei1.IsInterior || !ei1.Coord.Equals2D(lastSegStartPt);

            if (!useIntPt1)
            {
                npts--;
            }

            var pts = new Coordinate[npts];
            var ipt = 0;

            pts[ipt++] = new Coordinate(ei0.Coord);
            for (var i = ei0.SegmentIndex + 1; i <= ei1.SegmentIndex; i++)
            {
                pts[ipt++] = _edge.GetCoordinate(i);
            }
            if (useIntPt1)
            {
                pts[ipt] = new Coordinate(ei1.Coord);
            }

            return(new NodedSegmentString(pts, _edge.Context));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Extracts the points for a split edge running between two nodes.
        /// The extracted points should contain no duplicate points.
        /// There should always be at least two points extracted
        /// (which will be the given nodes).
        /// </summary>
        /// <param name="ei0">The start node of the split edge</param>
        /// <param name="ei1">The end node of the split edge</param>
        /// <returns>The points for the split edge</returns>
        private Coordinate[] CreateSplitEdgePts(SegmentNode ei0, SegmentNode ei1)
        {
            //Debug.WriteLine("\nCreateSplitEdge"); Debug.print(ei0); Debug.print(ei1);

            int npts = ei1.SegmentIndex - ei0.SegmentIndex + 2;

            var lastSegStartPt = _edge.GetCoordinate(ei1.SegmentIndex);
            // if the last intersection point is not equal to the its segment start pt, add it to the points list as well.
            // (This check is needed because the distance metric is not totally reliable!)
            // The check for point equality is 2D only - Z values are ignored
            bool useIntPt1 = ei1.IsInterior || !ei1.Coord.Equals2D(lastSegStartPt);

            if (!useIntPt1)
            {
                npts--;
            }

            var pts = new Coordinate[npts];
            int ipt = 0;

            pts[ipt++] = ei0.Coord.Copy();
            for (int i = ei0.SegmentIndex + 1; i <= ei1.SegmentIndex; i++)
            {
                pts[ipt++] = _edge.GetCoordinate(i);
            }
            if (useIntPt1)
            {
                pts[ipt] = ei1.Coord.Copy();
            }

            return(pts);
        }
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 private void ReadNextNode()
 {
     if (_nodeIt.MoveNext())
     {
         _nextNode = (SegmentNode)_nodeIt.Current;
     }
     else
     {
         _nextNode = null;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds an intersection into the list, if it isn't already there.
        /// The input segmentIndex and dist are expected to be normalized.
        /// </summary>
        /// <param name="intPt"></param>
        /// <param name="segmentIndex"></param>
        /// <returns>The SegmentIntersection found or added.</returns>
        public SegmentNode Add(Coordinate intPt, int segmentIndex)
        {
            var    eiNew = new SegmentNode(_edge, intPt, segmentIndex, _edge.GetSegmentOctant(segmentIndex));
            object eiObj;

            if (_nodeMap.TryGetValue(eiNew, out eiObj))
            {
                var ei = (SegmentNode)eiObj;
                // debugging sanity check
                Assert.IsTrue(ei.Coord.Equals2D(intPt), "Found equal nodes with different coordinates");
                return(ei);
            }
            // node does not exist, so create it
            _nodeMap.Add(eiNew, eiNew);
            return(eiNew);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ei0"></param>
        /// <param name="ei1"></param>
        /// <param name="collapsedVertexIndex"></param>
        /// <returns></returns>
        private static bool FindCollapseIndex(SegmentNode ei0, SegmentNode ei1, int[] collapsedVertexIndex)
        {
            // only looking for equal nodes
            if (!ei0.Coord.Equals2D(ei1.Coord))
            {
                return(false);
            }
            var numVerticesBetween = ei1.SegmentIndex - ei0.SegmentIndex;

            if (!ei1.IsInterior)
            {
                numVerticesBetween--;
            }
            // if there is a single vertex between the two equal nodes, this is a collapse
            if (numVerticesBetween == 1)
            {
                collapsedVertexIndex[0] = ei0.SegmentIndex + 1;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 8
0
        /*
         * /// <summary>
         * /// Checks the correctness of the set of split edges corresponding to this edge.
         * /// </summary>
         * /// <param name="splitEdges"></param>
         * private void CheckSplitEdgesCorrectness(IList<ISegmentString> splitEdges)
         * {
         *  var edgePts = _edge.Coordinates;
         *
         *  // check that first and last points of split edges are same as endpoints of edge
         *  var split0 = (ISegmentString) splitEdges[0];
         *  var pt0 = split0.Coordinates[0];
         *  if (!pt0.Equals2D(edgePts[0]))
         *      throw new Exception("bad split edge start point at " + pt0);
         *
         *  var splitn = (ISegmentString)splitEdges[splitEdges.Count - 1];
         *  var splitnPts = splitn.Coordinates;
         *  var ptn = splitnPts[splitnPts.Length - 1];
         *  if (!ptn.Equals2D(edgePts[edgePts.Length - 1]))
         *      throw new Exception("bad split edge end point at " + ptn);
         * }
         */

        /// <summary>
        ///  Create a new "split edge" with the section of points between
        /// (and including) the two intersections.
        /// The label for the new edge is the same as the label for the parent edge.
        /// </summary>
        /// <param name="ei0"></param>
        /// <param name="ei1"></param>
        /// <returns></returns>
        private ISegmentString CreateSplitEdge(SegmentNode ei0, SegmentNode ei1)
        {
            var pts = CreateSplitEdgePts(ei0, ei1);

            return(new NodedSegmentString(pts, _edge.Context));
        }
Ejemplo n.º 9
0
 public LineNode(SegmentNode node, Location locForward, Location locBackward)
 {
     _node = node;
     _location[Forward] = locForward;
     _location[Backward] = locBackward;
 }