assets/rdp2.js
// this is the implementation with perpendicular Distance
this is the implementation with perpendicular Distance
this is the implementation with perpendicular Distance
function RDPppd(points,epsilon){
    var firstPoint=points[0];
    var lastPoint=points[points.length-1];
    if (points.length<3){
        return points;
    }
    var index=-1;
    var dist=0;
    for (var i=1;i<points.length-1;i++){
        var cDist=findPerpendicularDistance(points[i],firstPoint,lastPoint);
        if (cDist>dist){
            dist=cDist;
            index=i;
        }
    }
    if (dist>epsilon){
        var l1=points.slice(0, index+1);
        var l2=points.slice(index);
        var r1=RDPppd(l1,epsilon);
        var r2=RDPppd(l2,epsilon);
        var rs=r1.slice(0,r1.length-1).concat(r2);
        return rs;
    }else{
        return [firstPoint,lastPoint];
    }
}
function RDPppd ( points , epsilon ) { var firstPoint = points [ 0 ] ; var lastPoint = points [ points . length - 1 ] ; if ( points . length < 3 ) { return points ; } var index = - 1 ; var dist = 0 ; for ( var i = 1 ; i < points . length - 1 ; i ++ ) { var cDist = findPerpendicularDistance ( points [ i ] , firstPoint , lastPoint ) ; if ( cDist > dist ) { dist = cDist ; index = i ; } } if ( dist > epsilon ) { var l1 = points . slice ( 0 , index + 1 ) ; var l2 = points . slice ( index ) ; var r1 = RDPppd ( l1 , epsilon ) ; var r2 = RDPppd ( l2 , epsilon ) ; var rs = r1 . slice ( 0 , r1 . length - 1 ) . concat ( r2 ) ; return rs ; } else { return [ firstPoint , lastPoint ] ; } }
this is the implementation with perpendicular Distance
this is the implementation with perpendicular Distance
// iterate // concat r2 to r1 minus the end/startpoint that will be the same