Пример #1
0
        /// <summary>
        /// Computes the distance to another facet sequence
        /// </summary>
        /// <param name="facetSeq">The other facet sequence</param>
        /// <returns>The distance between this and <paramref name="facetSeq"/>.</returns>
        public double Distance(FacetSequence facetSeq)
        {
            bool isPoint      = IsPoint;
            bool isPointOther = facetSeq.IsPoint;

            if (isPoint && isPointOther)
            {
                _pts.GetCoordinate(_start, _pt);
                facetSeq._pts.GetCoordinate(facetSeq._start, _seqPt);
                return(_pt.Distance(_seqPt));
            }

            if (isPoint)
            {
                _pts.GetCoordinate(_start, _pt);
                return(ComputePointLineDistance(_pt, facetSeq));
            }

            if (isPointOther)
            {
                facetSeq._pts.GetCoordinate(facetSeq._start, _seqPt);
                return(ComputePointLineDistance(_seqPt, this));
            }

            return(ComputeLineLineDistance(facetSeq));
        }
Пример #2
0
        //// temporary Coordinates to materialize points from the CoordinateSequence
        //private readonly Coordinate _p0 = new Coordinate();
        //private readonly Coordinate _p1 = new Coordinate();
        //private readonly Coordinate _q0 = new Coordinate();
        //private readonly Coordinate _q1 = new Coordinate();

        private double ComputeLineLineDistance(FacetSequence facetSeq)
        {
            // both linear - compute minimum segment-segment distance
            var minDistance = Double.MaxValue;

            var p0 = new Coordinate();
            var p1 = new Coordinate();
            var q0 = new Coordinate();
            var q1 = new Coordinate();

            for (int i = _start; i < _end - 1; i++)
            {
                for (int j = facetSeq._start; j < facetSeq._end - 1; j++)
                {
                    _pts.GetCoordinate(i, p0);
                    _pts.GetCoordinate(i + 1, p1);
                    facetSeq._pts.GetCoordinate(j, q0);
                    facetSeq._pts.GetCoordinate(j + 1, q1);

                    double dist = DistanceComputer.SegmentToSegment(p0, p1, q0, q1);
                    if (dist == 0.0)
                    {
                        return(0.0);
                    }
                    if (dist < minDistance)
                    {
                        minDistance = dist;
                    }
                }
            }
            return(minDistance);
        }
        private static void AddFacetSequences(ICoordinateSequence pts, List <FacetSequence> sections)
        {
            int i    = 0;
            int size = pts.Count;

            while (i <= size - 1)
            {
                int end = i + FacetSequenceSize + 1;
                // if only one point remains after this section, include it in this
                // section
                if (end >= size - 1)
                {
                    end = size;
                }
                var sect = new FacetSequence(pts, i, end);
                sections.Add(sect);
                i = i + FacetSequenceSize;
            }
        }
Пример #4
0
        private static double ComputePointLineDistance(Coordinate pt, FacetSequence facetSeq)
        {
            var minDistance = Double.MaxValue;

            var q0 = new Coordinate();
            var q1 = new Coordinate();

            for (var i = facetSeq._start; i < facetSeq._end - 1; i++)
            {
                facetSeq._pts.GetCoordinate(i, q0);
                facetSeq._pts.GetCoordinate(i + 1, q1);
                var dist = DistanceComputer.PointToSegment(pt, q0, q1);
                if (dist == 0.0)
                {
                    return(0.0);
                }
                if (dist < minDistance)
                {
                    minDistance = dist;
                }
            }
            return(minDistance);
        }