Exemple #1
0
        /// <summary>
        /// Given the specified test point, this checks each segment, and will
        /// return the closest point on the specified segment.
        /// </summary>
        /// <param name="testPoint">The point to test.</param>
        /// <returns></returns>
        public override Coordinate ClosestPoint(Coordinate testPoint)
        {
            // For a point outside the polygon, it must be closer to the shell than
            // any holes.
            if (Intersects(new Point(testPoint)) == false)
            {
                return(_shell.ClosestPoint(testPoint));
            }

            Coordinate closest = _shell.ClosestPoint(testPoint);
            double     dist    = testPoint.Distance(closest);

            foreach (ILinearRing ring in Holes)
            {
                Coordinate temp     = ring.ClosestPoint(testPoint);
                double     tempDist = testPoint.Distance(temp);
                if (tempDist >= dist)
                {
                    continue;
                }
                dist    = tempDist;
                closest = temp;
            }
            return(closest);
        }