index.js
function ifIsectAddToOutput(ring0, edge0, ring1, edge1) {
    var start0 = coord[ring0][edge0];
    var end0 = coord[ring0][edge0+1];
    var start1 = coord[ring1][edge1];
    var end1 = coord[ring1][edge1+1];

    var isect = intersect(start0, end0, start1, end1);

    if (isect == null) return; // discard parallels and coincidence
    frac0, frac1;
    if (end0[0] != start0[0]) {
      var frac0 = (isect[0]-start0[0])/(end0[0]-start0[0]);
    } else {
      var frac0 = (isect[1]-start0[1])/(end0[1]-start0[1]);
    };
    if (end1[0] != start1[0]) {
      var frac1 = (isect[0]-start1[0])/(end1[0]-start1[0]);
    } else {
      var frac1 = (isect[1]-start1[1])/(end1[1]-start1[1]);
    };

    // There are roughly three cases we need to deal with.
    // 1. If at least one of the fracs lies outside [0,1], there is no intersection.
    if (isOutside(frac0) || isOutside(frac1)) {
      return; // require segment intersection
    }

    // 2. If both are either exactly 0 or exactly 1, this is not an intersection but just
    // two edge segments sharing a common vertex.
    if (isBoundaryCase(frac0) && isBoundaryCase(frac1)){
      if(! options.reportVertexOnVertex) return;
    }

    // 3. If only one of the fractions is exactly 0 or 1, this is
    // a vertex-on-edge situation.
    if (isBoundaryCase(frac0) || isBoundaryCase(frac1)){
      if(! options.reportVertexOnEdge) return;
    }

    var key = isect;
    var unique = !seen[key];
    if (unique) {
      seen[key] = true;
    }

    if (filterFn) {
      output.push(filterFn(isect, ring0, edge0, start0, end0, frac0, ring1, edge1, start1, end1, frac1, unique));
    } else {
      output.push(isect);
    }
  }
function ifIsectAddToOutput(ring0, edge0, ring1, edge1) {
    var start0 = coord[ring0][edge0];
    var end0 = coord[ring0][edge0+1];
    var start1 = coord[ring1][edge1];
    var end1 = coord[ring1][edge1+1];

    var isect = intersect(start0, end0, start1, end1);

    if (isect == null) return; // discard parallels and coincidence
    frac0, frac1;
    if (end0[0] != start0[0]) {
      var frac0 = (isect[0]-start0[0])/(end0[0]-start0[0]);
    } else {
      var frac0 = (isect[1]-start0[1])/(end0[1]-start0[1]);
    };
    if (end1[0] != start1[0]) {
      var frac1 = (isect[0]-start1[0])/(end1[0]-start1[0]);
    } else {
      var frac1 = (isect[1]-start1[1])/(end1[1]-start1[1]);
    };

    // There are roughly three cases we need to deal with.
    // 1. If at least one of the fracs lies outside [0,1], there is no intersection.
    if (isOutside(frac0) || isOutside(frac1)) {
      return; // require segment intersection
    }

    // 2. If both are either exactly 0 or exactly 1, this is not an intersection but just
    // two edge segments sharing a common vertex.
    if (isBoundaryCase(frac0) && isBoundaryCase(frac1)){
      if(! options.reportVertexOnVertex) return;
    }

    // 3. If only one of the fractions is exactly 0 or 1, this is
    // a vertex-on-edge situation.
    if (isBoundaryCase(frac0) || isBoundaryCase(frac1)){
      if(! options.reportVertexOnEdge) return;
    }

    var key = isect;
    var unique = !seen[key];
    if (unique) {
      seen[key] = true;
    }

    if (filterFn) {
      output.push(filterFn(isect, ring0, edge0, start0, end0, frac0, ring1, edge1, start1, end1, frac1, unique));
    } else {
      output.push(isect);
    }
  }
function ifIsectAddToOutput ( ring0 , edge0 , ring1 , edge1 ) { var start0 = coord [ ring0 ] [ edge0 ] ; var end0 = coord [ ring0 ] [ edge0 + 1 ] ; var start1 = coord [ ring1 ] [ edge1 ] ; var end1 = coord [ ring1 ] [ edge1 + 1 ] ; var isect = intersect ( start0 , end0 , start1 , end1 ) ; if ( isect == null ) return ; // discard parallels and coincidence frac0 , frac1 ; if ( end0 [ 0 ] != start0 [ 0 ] ) { var frac0 = ( isect [ 0 ] - start0 [ 0 ] ) / ( end0 [ 0 ] - start0 [ 0 ] ) ; } else { var frac0 = ( isect [ 1 ] - start0 [ 1 ] ) / ( end0 [ 1 ] - start0 [ 1 ] ) ; } ; if ( end1 [ 0 ] != start1 [ 0 ] ) { var frac1 = ( isect [ 0 ] - start1 [ 0 ] ) / ( end1 [ 0 ] - start1 [ 0 ] ) ; } else { var frac1 = ( isect [ 1 ] - start1 [ 1 ] ) / ( end1 [ 1 ] - start1 [ 1 ] ) ; } ; // There are roughly three cases we need to deal with. // 1. If at least one of the fracs lies outside [0,1], there is no intersection. if ( isOutside ( frac0 ) || isOutside ( frac1 ) ) { return ; // require segment intersection } // 2. If both are either exactly 0 or exactly 1, this is not an intersection but just // two edge segments sharing a common vertex. if ( isBoundaryCase ( frac0 ) && isBoundaryCase ( frac1 ) ) { if ( ! options . reportVertexOnVertex ) return ; } // 3. If only one of the fractions is exactly 0 or 1, this is // a vertex-on-edge situation. if ( isBoundaryCase ( frac0 ) || isBoundaryCase ( frac1 ) ) { if ( ! options . reportVertexOnEdge ) return ; } var key = isect ; var unique = ! seen [ key ] ; if ( unique ) { seen [ key ] = true ; } if ( filterFn ) { output . push ( filterFn ( isect , ring0 , edge0 , start0 , end0 , frac0 , ring1 , edge1 , start1 , end1 , frac1 , unique ) ) ; } else { output . push ( isect ) ; } }
Function to check if two edges intersect and add the intersection to the output
Function to check if two edges intersect and add the intersection to the output