src/index.js
function polygonIsSimple(polygon){
    var path = polygon, i;
    // Check
    for(i=0; i<path.length-1; i++){
        for(var j=0; j<i-1; j++){
            if(lineSegmentsIntersect(path[i], path[i+1], path[j], path[j+1] )){
                return false;
            }
        }
    }

    // Check the segment between the last and the first point to all others
    for(i=1; i<path.length-2; i++){
        if(lineSegmentsIntersect(path[0], path[path.length-1], path[i], path[i+1] )){
            return false;
        }
    }

    return true;
}
function polygonIsSimple(polygon){
    var path = polygon, i;
    // Check
    for(i=0; i<path.length-1; i++){
        for(var j=0; j<i-1; j++){
            if(lineSegmentsIntersect(path[i], path[i+1], path[j], path[j+1] )){
                return false;
            }
        }
    }

    // Check the segment between the last and the first point to all others
    for(i=1; i<path.length-2; i++){
        if(lineSegmentsIntersect(path[0], path[path.length-1], path[i], path[i+1] )){
            return false;
        }
    }

    return true;
}
function polygonIsSimple ( polygon ) { var path = polygon , i ; // Check for ( i = 0 ; i < path . length - 1 ; i ++ ) { for ( var j = 0 ; j < i - 1 ; j ++ ) { if ( lineSegmentsIntersect ( path [ i ] , path [ i + 1 ] , path [ j ] , path [ j + 1 ] ) ) { return false ; } } } // Check the segment between the last and the first point to all others for ( i = 1 ; i < path . length - 2 ; i ++ ) { if ( lineSegmentsIntersect ( path [ 0 ] , path [ path . length - 1 ] , path [ i ] , path [ i + 1 ] ) ) { return false ; } } return true ; }
Checks that the line segments of this polygon do not intersect each other.
@method isSimple
@param  {Array} path An array of vertices e.g. [[0,0],[0,1],...]
@return {Boolean}
@todo Should it check all segments with all others?
Checks that the line segments of this polygon do not intersect each other .