Exemple #1
0
        /**
         * Uses a heuristic to reduce the number of points scanned
         * to compute the hull.
         * The heuristic is to find a polygon guaranteed to
         * be in (or on) the hull, and eliminate all points inside it.
         * A quadrilateral defined by the extremal points
         * in the four orthogonal directions
         * can be used, but even more inclusive is
         * to use an octilateral defined by the points in the 8 cardinal directions.
         * <p>
         * Note that even if the method used to determine the polygon vertices
         * is not 100% robust, this does not affect the robustness of the convex hull.
         *
         * @param pts
         * @return
         */
        private ICoordinateList Reduce(ICoordinateList inputPts)
        {
            ICoordinateList polyPts = ComputeOctRing(inputPts);

            // unable to compute interior polygon for some reason
            if (polyPts == null)
            {
                return(inputPts);
            }

            // add points defining polygon
            ICoordinateList reducedSet = new CoordinateCollection();
            int             nCount     = polyPts.Count;

            for (int i = 0; i < nCount; i++)
            {
                if (!reducedSet.Contains(polyPts[i]))
                {
                    reducedSet.Add(polyPts[i]);
                }
            }

            // Add all unique points not in the interior poly.
            // CGAlgorithms.isPointInRing is not defined for points actually on the ring,
            // but this doesn't matter since the points of the interior polygon
            // are forced to be in the reduced set.
            nCount = inputPts.Count;

            for (int i = 0; i < nCount; i++)
            {
                if (!CGAlgorithms.IsPointInRing(inputPts[i], polyPts))
                {
                    reducedSet.Add(inputPts[i]);
                }
            }

            return(reducedSet);
        }
 public bool IsInside(Coordinate pt)
 {
     return(CGAlgorithms.IsPointInRing(pt, pts));
 }