src/data/GeometryUtils.js
function simplifyDouglasPeucker(points, sqTolerance) {

            var len = points.length;
            var MarkerArray = typeof Uint8Array !== 'undefined' ? Uint8Array
                    : Array;
            var markers = new MarkerArray(len);
            var first = 0;
            var last = len - 1;
            var stack = [];
            var newPoints = [];
            var i;
            var maxSqDist;
            var sqDist;
            var index;

            markers[first] = markers[last] = 1;

            while (last) {

                maxSqDist = 0;

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

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

                if (maxSqDist > sqTolerance) {
                    markers[index] = 1;
                    stack.push(first, index, index, last);
                }

                last = stack.pop();
                first = stack.pop();
            }

            for (i = 0; i < len; i++) {
                if (markers[i])
                    newPoints.push(points[i]);
            }

            return newPoints;
        }
function simplifyDouglasPeucker(points, sqTolerance) {

            var len = points.length;
            var MarkerArray = typeof Uint8Array !== 'undefined' ? Uint8Array
                    : Array;
            var markers = new MarkerArray(len);
            var first = 0;
            var last = len - 1;
            var stack = [];
            var newPoints = [];
            var i;
            var maxSqDist;
            var sqDist;
            var index;

            markers[first] = markers[last] = 1;

            while (last) {

                maxSqDist = 0;

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

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

                if (maxSqDist > sqTolerance) {
                    markers[index] = 1;
                    stack.push(first, index, index, last);
                }

                last = stack.pop();
                first = stack.pop();
            }

            for (i = 0; i < len; i++) {
                if (markers[i])
                    newPoints.push(points[i]);
            }

            return newPoints;
        }
function simplifyDouglasPeucker ( points , sqTolerance ) { var len = points . length ; var MarkerArray = typeof Uint8Array !== 'undefined' ? Uint8Array : Array ; var markers = new MarkerArray ( len ) ; var first = 0 ; var last = len - 1 ; var stack = [ ] ; var newPoints = [ ] ; var i ; var maxSqDist ; var sqDist ; var index ; markers [ first ] = markers [ last ] = 1 ; while ( last ) { maxSqDist = 0 ; for ( i = first + 1 ; i < last ; i ++ ) { sqDist = getSqSegDist ( points [ i ] , points [ first ] , points [ last ] ) ; if ( sqDist > maxSqDist ) { index = i ; maxSqDist = sqDist ; } } if ( maxSqDist > sqTolerance ) { markers [ index ] = 1 ; stack . push ( first , index , index , last ) ; } last = stack . pop ( ) ; first = stack . pop ( ) ; } for ( i = 0 ; i < len ; i ++ ) { if ( markers [ i ] ) newPoints . push ( points [ i ] ) ; } return newPoints ; }
simplification using optimized Douglas-Peucker algorithm with recursion elimination
simplification using optimized Douglas - Peucker algorithm with recursion elimination