turf-convex
Advanced tools
Comparing version 0.1.0 to 0.1.1
60
index.js
@@ -1,30 +0,46 @@ | ||
// 1. run tin on points | ||
// 2. merge the tin | ||
//var topojson = require('') | ||
var t = {} | ||
t.tin = require('turf-tin') | ||
t.merge = require('turf-merge') | ||
t.buffer = require('turf-buffer') | ||
// http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain#JavaScript | ||
module.exports = function(points, done){ | ||
var tinPolys = t.tin(points, null), | ||
mergePolys; | ||
module.exports = function(fc){ | ||
var points = fc.features.map(function(point){ | ||
return point.geometry.coordinates | ||
}) | ||
done = done || function () {}; | ||
points.sort(function(a, b) { | ||
return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0] | ||
}) | ||
if (tinPolys instanceof Error) { | ||
done(tinPolys); | ||
return tinPolys; | ||
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.push(points[i]) | ||
} | ||
//mergePolys = t.merge(t.buffer(tinPolys, .05, 'miles')); | ||
mergePolys = t.merge(tinPolys); | ||
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.push(points[i]) | ||
} | ||
if (mergePolys instanceof Error) { | ||
done(mergePolys); | ||
} else { | ||
done(null, mergePolys); | ||
upper.pop() | ||
lower.pop() | ||
var coords = lower.concat(upper) | ||
coords.push(coords[0]) | ||
return { | ||
type:'Feature', | ||
properties: {}, | ||
geometry: { | ||
type:'Polygon', | ||
coordinates: [ | ||
coords | ||
] | ||
} | ||
} | ||
} | ||
return mergePolys; | ||
} | ||
function cross(o, a, b) { | ||
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) | ||
} |
{ | ||
"name": "turf-convex", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "", | ||
@@ -30,7 +30,3 @@ "main": "index.js", | ||
}, | ||
"dependencies": { | ||
"turf-tin": "0.0.2", | ||
"turf-buffer": "0.1.0", | ||
"turf-merge": "0.0.2" | ||
} | ||
"dependencies": {} | ||
} |
@@ -6,3 +6,3 @@ var convex = require('../'), | ||
var REGEN = false; | ||
var REGEN = true; | ||
@@ -9,0 +9,0 @@ test('intersect', function(t){ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
0
53
13309
- Removedturf-buffer@0.1.0
- Removedturf-merge@0.0.2
- Removedturf-tin@0.0.2
- Removedclone@0.1.19(transitive)
- Removedjavascript.util@0.10.1(transitive)
- Removedjsts@0.13.4(transitive)
- Removedminimist@0.2.4(transitive)
- Removedturf-buffer@0.1.0(transitive)
- Removedturf-combine@0.1.0(transitive)
- Removedturf-distance@0.1.5(transitive)
- Removedturf-featurecollection@0.1.0(transitive)
- Removedturf-merge@0.0.2(transitive)
- Removedturf-nearest@0.1.3(transitive)
- Removedturf-point@0.1.6(transitive)
- Removedturf-polygon@0.1.1(transitive)
- Removedturf-tin@0.0.2(transitive)
- Removedturf-union@0.0.0(transitive)