private static bool IsSnapped(Coordinate v, Coordinate p0, Coordinate p1)
 {
     if (v.Equals2D(p0)) return true;
     if (v.Equals2D(p1)) return true;
     var seg = new LineSegment(p0, p1);
     var dist = seg.Distance(v);
     if (dist < SnapTolerance / 2.05) return false;
     return true;
 }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputPt"></param>
        /// <param name="minIndex"></param>
        /// <returns></returns>
        private double IndexOfFromStart(Coordinate inputPt, double minIndex)
        {
            var minDistance = Double.MaxValue;

            var ptMeasure = minIndex;
            var segmentStartMeasure = 0.0;

            var seg = new LineSegment();
            var it = new LinearIterator(_linearGeom);

            while (it.HasNext())
            {
                if (!it.IsEndOfLine)
                {
                    seg.P0 = it.SegmentStart;
                    seg.P1 = it.SegmentEnd;
                    var segDistance = seg.Distance(inputPt);
                    var segMeasureToPt = SegmentNearestMeasure(seg, inputPt, segmentStartMeasure);
                    if (segDistance < minDistance
                        && segMeasureToPt > minIndex)
                    {
                        ptMeasure = segMeasureToPt;
                        minDistance = segDistance;
                    }
                    segmentStartMeasure += seg.Length;
                }
                it.Next();
            }
            return ptMeasure;
        }
 private int FindFurthestPoint(Coordinate[] pts, int i, int j, double[] maxDistance)
 {
     LineSegment seg = new LineSegment();
     seg.P0 = pts[i];
     seg.P1 = pts[j];
     double maxDist = -1.0;
     int maxIndex = i;
     for (int k = i + 1; k < j; k++)
     {
         Coordinate midPt = pts[k];
         double distance = seg.Distance(midPt);
         if (distance > maxDist)
         {
             maxDist = distance;
             maxIndex = k;
         }
     }
     maxDistance[0] = maxDist;
     return maxIndex;
 }
        private LinearLocation IndexOfFromStart(Coordinate inputPt, LinearLocation minIndex)
        {
            var minDistance = Double.MaxValue;
            var minComponentIndex = 0;
            var minSegmentIndex = 0;
            var minFrac = -1.0;

            var seg = new LineSegment();
            for (var it = new LinearIterator(_linearGeom);
                 it.HasNext(); it.Next())
            {
                if (!it.IsEndOfLine)
                {
                    seg.P0 = it.SegmentStart;
                    seg.P1 = it.SegmentEnd;
                    var segDistance = seg.Distance(inputPt);
                    var segFrac = seg.SegmentFraction(inputPt);

                    var candidateComponentIndex = it.ComponentIndex;
                    var candidateSegmentIndex = it.VertexIndex;
                    if (segDistance < minDistance)
                    {
                        // ensure after minLocation, if any
                        if (minIndex == null ||
                            minIndex.CompareLocationValues(candidateComponentIndex, candidateSegmentIndex, segFrac) < 0)
                        {
                            // otherwise, save this as new minimum
                            minComponentIndex = candidateComponentIndex;
                            minSegmentIndex = candidateSegmentIndex;
                            minFrac = segFrac;
                            minDistance = segDistance;
                        }
                    }
                }
            }

            if (minDistance == Double.MaxValue)
            {
                // no minimum was found past minLocation, so return it
                return new LinearLocation(minIndex);
            }
            // otherwise, return computed location
            var loc = new LinearLocation(minComponentIndex, minSegmentIndex, minFrac);
            return loc;
        }