/// <summary>
 /// Initializes a new instance of the <see cref="HotPixelSnapAction"/> class.
 /// </summary>
 /// <param name="hotPixel"></param>
 /// <param name="parentEdge"></param>
 /// <param name="vertexIndex"></param>
 public HotPixelSnapAction(HotPixel hotPixel, SegmentString parentEdge, int vertexIndex)
 {
     this.hotPixel = hotPixel;
     this.parentEdge = parentEdge;
     this.vertexIndex = vertexIndex;
 }
 /// <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 <c>null</c>.</param>
 /// <param name="vertexIndex"></param>
 /// <returns><c>true</c> if a node was added for this pixel.</returns>
 public bool Snap(HotPixel hotPixel, SegmentString parentEdge, int vertexIndex)
 {
     Envelope pixelEnv = hotPixel.GetSafeEnvelope();
     HotPixelSnapAction hotPixelSnapAction = new HotPixelSnapAction(hotPixel, parentEdge, vertexIndex);
     index.Query(pixelEnv, new QueryVisitor(pixelEnv, hotPixelSnapAction));
     return hotPixelSnapAction.IsNodeAdded;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="hotPixel"></param>
 /// <returns></returns>
 public bool Snap(HotPixel hotPixel)
 {
     return Snap(hotPixel, null, -1);
 }
        /// <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></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>
 /// <param name="e0"></param>
 /// <param name="e1"></param>
 private void ComputeVertexSnaps(SegmentString e0, SegmentString e1)
 {
     IList<Coordinate> pts0 = e0.Coordinates;
     IList<Coordinate> pts1 = e1.Coordinates;
     for (int i0 = 0; i0 < pts0.Count - 1; i0++)
     {
         HotPixel hotPixel = new HotPixel(pts0[i0], _scaleFactor, _li);
         for (int i1 = 0; i1 < pts1.Count - 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);                    
         }
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ss"></param>
 /// <param name="snapPts"></param>
 private void ComputeSnaps(SegmentString ss, IList snapPts)
 {
     foreach(object objo in snapPts)
     {
         Coordinate snapPt = (Coordinate)objo;
         HotPixel hotPixel = new HotPixel(snapPt, _scaleFactor, _li);
         for(int i = 0; i < ss.Count - 1; i++)
             AddSnappedNode(hotPixel, ss, i);
     }
 }
 /// <summary>
 /// Performs a brute-force comparison of every segment in each <see cref="SegmentString" />.
 /// This has n^2 performance.
 /// </summary>
 /// <param name="e"></param>
 private void ComputeVertexSnaps(SegmentString e)
 {
     IList<Coordinate> pts0 = e.Coordinates;
     for(int i = 0; i < pts0.Count - 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);
     }
 }
 /// <summary>
 /// Computes nodes introduced as a result of snapping segments to snap points (hot pixels).
 /// </summary>
 /// <param name="snapPts"></param>
 private void ComputeIntersectionSnaps(IList snapPts)
 {
     foreach(object obj in snapPts)
     {
         Coordinate snapPt = (Coordinate)obj;
         HotPixel hotPixel = new HotPixel(snapPt, _scaleFactor, _li);
         _pointSnapper.Snap(hotPixel);
     }
 }