Example #1
0
        /// <summary>
        /// Performs a brute-force comparison of every segment in each
        /// <see cref="SegmentString"/>. This has n^2 performance.
        /// </summary>
        private void ComputeVertexSnaps(SegmentString e0, SegmentString e1)
        {
            ICoordinateList pts0 = e0.Coordinates;
            ICoordinateList pts1 = e1.Coordinates;

            int nCount0 = pts0.Count;
            int nCount1 = pts1.Count;

            for (int i0 = 0; i0 < nCount0 - 1; i0++)
            {
                HotPixel hotPixel = new HotPixel(pts0[i0], scaleFactor, li);
                for (int i1 = 0; i1 < nCount1 - 1; i1++)
                {
                    // don't snap a vertex to itself
                    if (e0 == e1)
                    {
                        if (i0 == i1)
                        {
                            continue;
                        }
                    }

                    bool isNodeAdded = AddSnappedNode(hotPixel, e1, i1);

                    // if a node is created for a vertex, that vertex must be noded too
                    if (isNodeAdded)
                    {
                        e0.AddIntersection(pts0[i0], i0);
                    }
                }
            }
        }
Example #2
0
            public HotPixelSnapAction(MCIndexPointSnapper pointSnapper,
                                      HotPixel hotPixel, SegmentString parentEdge, int vertexIndex)
            {
                this.enclosingInstance = pointSnapper;

                this.hotPixel    = hotPixel;
                this.parentEdge  = parentEdge;
                this.vertexIndex = vertexIndex;
            }
        /// <summary>
        /// Computes nodes introduced as a result of snapping segments
        /// to snap points (hot pixels).
        /// </summary>
        private void ComputeIntersectionSnaps(IList snapPts)
        {
            for (IEnumerator it = snapPts.GetEnumerator(); it.MoveNext();)
            {
                Coordinate snapPt   = (Coordinate)it.Current;
                HotPixel   hotPixel = new HotPixel(snapPt, scaleFactor, li);

                pointSnapper.Snap(hotPixel);
            }
        }
Example #4
0
 private void ComputeSnaps(SegmentString ss, IList snapPts)
 {
     for (IEnumerator it = snapPts.GetEnumerator(); it.MoveNext();)
     {
         Coordinate snapPt   = (Coordinate)it.Current;
         HotPixel   hotPixel = new HotPixel(snapPt, scaleFactor, li);
         for (int i = 0; i < ss.Count - 1; i++)
         {
             AddSnappedNode(hotPixel, ss, i);
         }
     }
 }
Example #5
0
        /// <summary>
        /// Snaps (nodes) all interacting segments to this hot pixel.
        /// The hot pixel may represent a vertex of an edge,
        /// in which case this routine uses the optimization
        /// of not noding the vertex itself
        ///
        /// </summary>
        /// <param name="hotPixel">the hot pixel to snap to
        /// </param>
        /// <param name="parentEdge">the edge containing the vertex, if applicable, or <code>null</code>
        /// </param>
        /// <param name="vertexIndex">the index of the vertex, if applicable, or -1
        /// </param>
        /// <returns> <see langword="true"/> if a node was added for this pixel
        /// </returns>
        public bool Snap(HotPixel hotPixel, SegmentString parentEdge, int vertexIndex)
        {
            Envelope pixelEnv = hotPixel.SafeEnvelope;

            HotPixelSnapAction hotPixelSnapAction = new HotPixelSnapAction(
                this, hotPixel, parentEdge, vertexIndex);

            index.Query(pixelEnv, new PointSnapperItemVisitor(pixelEnv,
                                                              hotPixelSnapAction, this));

            return(hotPixelSnapAction.NodeAdded);
        }
Example #6
0
        /// <summary>
        /// Adds a new node (equal to the snap pt) to the segment
        /// if the segment passes through the hot pixel
        /// </summary>
        /// <param name="hotPix">
        /// </param>
        /// <param name="segStr">
        /// </param>
        /// <param name="segIndex">
        /// </param>
        /// <returns> <see langword="true"/> if a node was added
        /// </returns>
        public static bool AddSnappedNode(HotPixel hotPix,
                                          SegmentString segStr, int segIndex)
        {
            Coordinate p0 = segStr.GetCoordinate(segIndex);
            Coordinate p1 = segStr.GetCoordinate(segIndex + 1);

            if (hotPix.Intersects(p0, p1))
            {
                segStr.AddIntersection(hotPix.Coordinate, segIndex);

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Performs a brute-force comparison of every segment in
        /// each <see cref="SegmentString"/>. This has n^2 performance.
        /// </summary>
        private void ComputeVertexSnaps(SegmentString e)
        {
            ICoordinateList pts0   = e.Coordinates;
            int             nCount = pts0.Count;

            for (int i = 0; i < nCount - 1; i++)
            {
                HotPixel hotPixel    = new HotPixel(pts0[i], scaleFactor, li);
                bool     isNodeAdded = pointSnapper.Snap(hotPixel, e, i);

                // if a node is created for a vertex, that vertex must be noded too
                if (isNodeAdded)
                {
                    e.AddIntersection(pts0[i], i);
                }
            }
        }
Example #8
0
 public bool Snap(HotPixel hotPixel)
 {
     return(Snap(hotPixel, null, -1));
 }