예제 #1
0
파일: Simplify.cs 프로젝트: fel88/GeomPad
        public static void simplifyDPStep(NFP points, int first, int last, double?sqTolerance, NFP simplified)
        {
            var maxSqDist = sqTolerance;
            var index     = -1;
            var marked    = false;

            for (var i = first + 1; i < last; i++)
            {
                var sqDist = getSqSegDist(points[i], points[first], points[last]);

                if (sqDist > maxSqDist)
                {
                    index     = i;
                    maxSqDist = sqDist;
                }
            }


            if (maxSqDist > sqTolerance || marked)
            {
                if (index - first > 1)
                {
                    simplifyDPStep(points, first, index, sqTolerance, simplified);
                }
                simplified.push(points[index]);
                if (last - index > 1)
                {
                    simplifyDPStep(points, index, last, sqTolerance, simplified);
                }
            }
        }
예제 #2
0
파일: Simplify.cs 프로젝트: fel88/GeomPad
        // simplification using Ramer-Douglas-Peucker algorithm
        public static NFP simplifyDouglasPeucker(NFP points, double?sqTolerance)
        {
            var last = points.Length - 1;

            var simplified = new NFP();

            simplified.AddPoint(points[0]);
            simplifyDPStep(points, 0, last, sqTolerance, simplified);
            simplified.push(points[last]);

            return(simplified);
        }