geojson-polygon-self-intersections
Advanced tools
Comparing version 1.1.1 to 1.1.2
53
index.js
@@ -6,3 +6,3 @@ // Find self-intersections in geojson polygon (possibly with interior rings) | ||
if (feature.geometry.type != "Polygon") throw new Error("The input feature must be a Polygon"); | ||
if (!useSpatialIndex) useSpatialIndex = 1; | ||
if (useSpatialIndex == undefined) useSpatialIndex = 1; | ||
@@ -59,4 +59,13 @@ var coord = feature.geometry.coordinates; | ||
if (isect == null) return; // discard parallels and coincidence | ||
var frac0 = (isect[0]-start0[0])/(end0[0]-start0[0]); | ||
var frac1 = (isect[0]-start1[0])/(end1[0]-start1[0]); | ||
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]); | ||
}; | ||
if (frac0 >= 1 || frac0 <= 0 || frac1 >= 1 || frac1 <= 0) return; // require segment intersection | ||
@@ -118,23 +127,23 @@ | ||
function equalArrays(array1, array2) { | ||
// if the other array is a falsy value, return | ||
if (!array1 || !array2) | ||
return false; | ||
// if the other array is a falsy value, return | ||
if (!array1 || !array2) | ||
return false; | ||
// compare lengths - can save a lot of time | ||
if (array1.length != array2.length) | ||
return false; | ||
// compare lengths - can save a lot of time | ||
if (array1.length != array2.length) | ||
return false; | ||
for (var i = 0, l=array1.length; i < l; i++) { | ||
// Check if we have nested arrays | ||
if (array1[i] instanceof Array && array2[i] instanceof Array) { | ||
// recurse into the nested arrays | ||
if (!equalArrays(array1[i],array2[i])) | ||
return false; | ||
} | ||
else if (array1[i] != array2[i]) { | ||
// Warning - two different object instances will never be equal: {x:20} != {x:20} | ||
return false; | ||
} | ||
} | ||
return true; | ||
for (var i = 0, l=array1.length; i < l; i++) { | ||
// Check if we have nested arrays | ||
if (array1[i] instanceof Array && array2[i] instanceof Array) { | ||
// recurse into the nested arrays | ||
if (!equalArrays(array1[i],array2[i])) | ||
return false; | ||
} | ||
else if (array1[i] != array2[i]) { | ||
// Warning - two different object instances will never be equal: {x:20} != {x:20} | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
{ | ||
"name": "geojson-polygon-self-intersections", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
9542
127