@turf/tesselate
Advanced tools
Comparing version 6.2.0-alpha.2 to 6.2.0-alpha.3
@@ -19,59 +19,62 @@ import earcut from 'earcut'; | ||
function tesselate(poly) { | ||
if (!poly.geometry || (poly.geometry.type !== 'Polygon' && poly.geometry.type !== 'MultiPolygon')) { | ||
throw new Error('input must be a Polygon or MultiPolygon'); | ||
} | ||
if ( | ||
!poly.geometry || | ||
(poly.geometry.type !== "Polygon" && poly.geometry.type !== "MultiPolygon") | ||
) { | ||
throw new Error("input must be a Polygon or MultiPolygon"); | ||
} | ||
var fc = {type: 'FeatureCollection', features: []}; | ||
var fc = { type: "FeatureCollection", features: [] }; | ||
if (poly.geometry.type === 'Polygon') { | ||
fc.features = processPolygon(poly.geometry.coordinates); | ||
} else { | ||
poly.geometry.coordinates.forEach(function (coordinates) { | ||
fc.features = fc.features.concat(processPolygon(coordinates)); | ||
}); | ||
} | ||
if (poly.geometry.type === "Polygon") { | ||
fc.features = processPolygon(poly.geometry.coordinates); | ||
} else { | ||
poly.geometry.coordinates.forEach(function (coordinates) { | ||
fc.features = fc.features.concat(processPolygon(coordinates)); | ||
}); | ||
} | ||
return fc; | ||
return fc; | ||
} | ||
function processPolygon(coordinates) { | ||
var data = flattenCoords(coordinates); | ||
var dim = 2; | ||
var result = earcut(data.vertices, data.holes, dim); | ||
var data = flattenCoords(coordinates); | ||
var dim = 2; | ||
var result = earcut(data.vertices, data.holes, dim); | ||
var features = []; | ||
var vertices = []; | ||
var features = []; | ||
var vertices = []; | ||
result.forEach(function (vert, i) { | ||
var index = result[i]; | ||
vertices.push([data.vertices[index * dim], data.vertices[index * dim + 1]]); | ||
}); | ||
result.forEach(function (vert, i) { | ||
var index = result[i]; | ||
vertices.push([data.vertices[index * dim], data.vertices[index * dim + 1]]); | ||
}); | ||
for (var i = 0; i < vertices.length; i += 3) { | ||
var coords = vertices.slice(i, i + 3); | ||
coords.push(vertices[i]); | ||
features.push(polygon([coords])); | ||
} | ||
for (var i = 0; i < vertices.length; i += 3) { | ||
var coords = vertices.slice(i, i + 3); | ||
coords.push(vertices[i]); | ||
features.push(polygon([coords])); | ||
} | ||
return features; | ||
return features; | ||
} | ||
function flattenCoords(data) { | ||
var dim = data[0][0].length, | ||
result = {vertices: [], holes: [], dimensions: dim}, | ||
holeIndex = 0; | ||
var dim = data[0][0].length, | ||
result = { vertices: [], holes: [], dimensions: dim }, | ||
holeIndex = 0; | ||
for (var i = 0; i < data.length; i++) { | ||
for (var j = 0; j < data[i].length; j++) { | ||
for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]); | ||
} | ||
if (i > 0) { | ||
holeIndex += data[i - 1].length; | ||
result.holes.push(holeIndex); | ||
} | ||
for (var i = 0; i < data.length; i++) { | ||
for (var j = 0; j < data[i].length; j++) { | ||
for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]); | ||
} | ||
if (i > 0) { | ||
holeIndex += data[i - 1].length; | ||
result.holes.push(holeIndex); | ||
} | ||
} | ||
return result; | ||
return result; | ||
} | ||
export default tesselate; |
@@ -23,60 +23,62 @@ 'use strict'; | ||
function tesselate(poly) { | ||
if (!poly.geometry || (poly.geometry.type !== 'Polygon' && poly.geometry.type !== 'MultiPolygon')) { | ||
throw new Error('input must be a Polygon or MultiPolygon'); | ||
} | ||
if ( | ||
!poly.geometry || | ||
(poly.geometry.type !== "Polygon" && poly.geometry.type !== "MultiPolygon") | ||
) { | ||
throw new Error("input must be a Polygon or MultiPolygon"); | ||
} | ||
var fc = {type: 'FeatureCollection', features: []}; | ||
var fc = { type: "FeatureCollection", features: [] }; | ||
if (poly.geometry.type === 'Polygon') { | ||
fc.features = processPolygon(poly.geometry.coordinates); | ||
} else { | ||
poly.geometry.coordinates.forEach(function (coordinates) { | ||
fc.features = fc.features.concat(processPolygon(coordinates)); | ||
}); | ||
} | ||
if (poly.geometry.type === "Polygon") { | ||
fc.features = processPolygon(poly.geometry.coordinates); | ||
} else { | ||
poly.geometry.coordinates.forEach(function (coordinates) { | ||
fc.features = fc.features.concat(processPolygon(coordinates)); | ||
}); | ||
} | ||
return fc; | ||
return fc; | ||
} | ||
function processPolygon(coordinates) { | ||
var data = flattenCoords(coordinates); | ||
var dim = 2; | ||
var result = earcut(data.vertices, data.holes, dim); | ||
var data = flattenCoords(coordinates); | ||
var dim = 2; | ||
var result = earcut(data.vertices, data.holes, dim); | ||
var features = []; | ||
var vertices = []; | ||
var features = []; | ||
var vertices = []; | ||
result.forEach(function (vert, i) { | ||
var index = result[i]; | ||
vertices.push([data.vertices[index * dim], data.vertices[index * dim + 1]]); | ||
}); | ||
result.forEach(function (vert, i) { | ||
var index = result[i]; | ||
vertices.push([data.vertices[index * dim], data.vertices[index * dim + 1]]); | ||
}); | ||
for (var i = 0; i < vertices.length; i += 3) { | ||
var coords = vertices.slice(i, i + 3); | ||
coords.push(vertices[i]); | ||
features.push(helpers.polygon([coords])); | ||
} | ||
for (var i = 0; i < vertices.length; i += 3) { | ||
var coords = vertices.slice(i, i + 3); | ||
coords.push(vertices[i]); | ||
features.push(helpers.polygon([coords])); | ||
} | ||
return features; | ||
return features; | ||
} | ||
function flattenCoords(data) { | ||
var dim = data[0][0].length, | ||
result = {vertices: [], holes: [], dimensions: dim}, | ||
holeIndex = 0; | ||
var dim = data[0][0].length, | ||
result = { vertices: [], holes: [], dimensions: dim }, | ||
holeIndex = 0; | ||
for (var i = 0; i < data.length; i++) { | ||
for (var j = 0; j < data[i].length; j++) { | ||
for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]); | ||
} | ||
if (i > 0) { | ||
holeIndex += data[i - 1].length; | ||
result.holes.push(holeIndex); | ||
} | ||
for (var i = 0; i < data.length; i++) { | ||
for (var j = 0; j < data[i].length; j++) { | ||
for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]); | ||
} | ||
if (i > 0) { | ||
holeIndex += data[i - 1].length; | ||
result.holes.push(holeIndex); | ||
} | ||
} | ||
return result; | ||
return result; | ||
} | ||
module.exports = tesselate; | ||
module.exports.default = tesselate; |
@@ -1,2 +0,2 @@ | ||
import { Feature, FeatureCollection, Polygon } from '@turf/helpers' | ||
import { Feature, FeatureCollection, Polygon } from "@turf/helpers"; | ||
@@ -3,0 +3,0 @@ /** |
{ | ||
"name": "@turf/tesselate", | ||
"version": "6.2.0-alpha.2", | ||
"version": "6.2.0-alpha.3", | ||
"description": "turf tesselate module", | ||
@@ -34,2 +34,6 @@ "author": "Turf Authors", | ||
"module": "dist/es/index.js", | ||
"exports": { | ||
"import": "./dist/es/index.js", | ||
"require": "./dist/js/index.js" | ||
}, | ||
"types": "index.d.ts", | ||
@@ -42,8 +46,7 @@ "sideEffects": false, | ||
"scripts": { | ||
"bench": "npm-run-all prepare bench:run", | ||
"bench:run": "node bench.js", | ||
"bench": "node -r esm bench.js", | ||
"build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json", | ||
"docs": "node ../../scripts/generate-readmes", | ||
"posttest": "node -r esm ../../scripts/validate-es5-dependencies.js", | ||
"prepare": "rollup -c ../../rollup.config.js", | ||
"test": "npm-run-all prepare test:*", | ||
"test": "npm-run-all test:*", | ||
"test:tape": "node -r esm test.js" | ||
@@ -58,6 +61,6 @@ }, | ||
"dependencies": { | ||
"@turf/helpers": "^6.2.0-alpha.2", | ||
"@turf/helpers": "^6.2.0-alpha.3", | ||
"earcut": "^2.0.0" | ||
}, | ||
"gitHead": "23d5cb91d77e0c1e2e903a2252f525797f1d0d09" | ||
"gitHead": "dce9edfc705352e8cb9e0083c9330ba0e8d77409" | ||
} |
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
9
268
13406
Updated@turf/helpers@^6.2.0-alpha.3