jsfiddle/OpenLayers.debug.js
function(points, firstPoint, lastPoint, tolerance){
                var maxDistance = 0;
                var indexFarthest = 0;
    
                for (var index = firstPoint, distance; index < lastPoint; index++) {
                    distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]);
                    if (distance > maxDistance) {
                        maxDistance = distance;
                        indexFarthest = index;
                    }
                }
    
                if (maxDistance > tolerance && indexFarthest != firstPoint) {
                    //Add the largest point that exceeds the tolerance
                    pointIndexsToKeep.push(indexFarthest);
                    douglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance);
                    douglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance);
                }
            }
function(points, firstPoint, lastPoint, tolerance){
                var maxDistance = 0;
                var indexFarthest = 0;
    
                for (var index = firstPoint, distance; index < lastPoint; index++) {
                    distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]);
                    if (distance > maxDistance) {
                        maxDistance = distance;
                        indexFarthest = index;
                    }
                }
    
                if (maxDistance > tolerance && indexFarthest != firstPoint) {
                    //Add the largest point that exceeds the tolerance
                    pointIndexsToKeep.push(indexFarthest);
                    douglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance);
                    douglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance);
                }
            }
function ( points , firstPoint , lastPoint , tolerance ) { var maxDistance = 0 ; var indexFarthest = 0 ; for ( var index = firstPoint , distance ; index < lastPoint ; index ++ ) { distance = perpendicularDistance ( points [ firstPoint ] , points [ lastPoint ] , points [ index ] ) ; if ( distance > maxDistance ) { maxDistance = distance ; indexFarthest = index ; } } if ( maxDistance > tolerance && indexFarthest != firstPoint ) { //Add the largest point that exceeds the tolerance pointIndexsToKeep . push ( indexFarthest ) ; douglasPeuckerReduction ( points , firstPoint , indexFarthest , tolerance ) ; douglasPeuckerReduction ( points , indexFarthest , lastPoint , tolerance ) ; } }
Private function doing the Douglas-Peucker reduction
Private function doing the Douglas - Peucker reduction