turf-convex
Advanced tools
Comparing version 0.1.1 to 1.0.0
32
index.js
@@ -5,29 +5,29 @@ // http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain#JavaScript | ||
var points = fc.features.map(function(point){ | ||
return point.geometry.coordinates | ||
}) | ||
return point.geometry.coordinates; | ||
}); | ||
points.sort(function(a, b) { | ||
return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0] | ||
}) | ||
return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]; | ||
}); | ||
var lower = [] | ||
var lower = []; | ||
for (var i = 0; i < points.length; i++) { | ||
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], points[i]) <= 0) { | ||
lower.pop() | ||
lower.pop(); | ||
} | ||
lower.push(points[i]) | ||
lower.push(points[i]); | ||
} | ||
var upper = [] | ||
var upper = []; | ||
for (var i = points.length - 1; i >= 0; i--) { | ||
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], points[i]) <= 0) { | ||
upper.pop() | ||
upper.pop(); | ||
} | ||
upper.push(points[i]) | ||
upper.push(points[i]); | ||
} | ||
upper.pop() | ||
lower.pop() | ||
var coords = lower.concat(upper) | ||
coords.push(coords[0]) | ||
upper.pop(); | ||
lower.pop(); | ||
var coords = lower.concat(upper); | ||
coords.push(coords[0]); | ||
return { | ||
@@ -42,7 +42,7 @@ type:'Feature', | ||
} | ||
} | ||
}; | ||
} | ||
function cross(o, a, b) { | ||
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) | ||
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]); | ||
} |
{ | ||
"name": "turf-convex", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "", | ||
@@ -27,6 +27,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"glob": "~4.0.3", | ||
"tape": "~2.13.3" | ||
"benchmark": "^1.0.0", | ||
"glob": "~4.3.1", | ||
"tape": "~3.0.3" | ||
}, | ||
"dependencies": {} | ||
} |
var convex = require('../'), | ||
test = require('tape'), | ||
glob = require('glob'), | ||
fs = require('fs') | ||
fs = require('fs'); | ||
@@ -6,0 +6,0 @@ var REGEN = true; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13770
13
67
0
3
2