@turf/polygon-smooth
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -0,3 +1,3 @@ | ||
import { multiPolygon, polygon, featureCollection } from '@turf/helpers'; | ||
import { geomEach, coordEach } from '@turf/meta'; | ||
import { multiPolygon, polygon, featureCollection } from '@turf/helpers'; | ||
@@ -11,3 +11,3 @@ /** | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.iterations=1] THe number of times to smooth the polygon. A higher value means a smoother polygon. | ||
* @param {string} [options.iterations=1] The number of times to smooth the polygon. A higher value means a smoother polygon. | ||
* @returns {FeatureCollection<Polygon>} FeatureCollection containing the smoothed polygon/poylgons | ||
@@ -23,2 +23,3 @@ * @example | ||
function polygonSmooth(inputPolys, options) { | ||
options = options || {}; | ||
var outPolys = []; | ||
@@ -38,3 +39,3 @@ // Optional parameters | ||
for (var i = 0; i < iterations; i++) { | ||
tempOutput = [[]]; | ||
tempOutput = []; | ||
poly = geom; | ||
@@ -50,3 +51,3 @@ if (i > 0) poly = polygon(outCoords).geometry; | ||
for (var y = 0; y < iterations; y++) { | ||
tempOutput = [[[]]]; | ||
tempOutput = []; | ||
poly = geom; | ||
@@ -72,4 +73,4 @@ if (y > 0) poly = multiPolygon(outCoords).geometry; | ||
function processPolygon(poly, tempOutput) { | ||
var prevGeomIndex = 0; | ||
var subtractCoordIndex = 0; | ||
var previousCoord = null; | ||
var previousGeometryIndex = null; | ||
@@ -85,23 +86,22 @@ coordEach( | ||
) { | ||
if (geometryIndex > prevGeomIndex) { | ||
prevGeomIndex = geometryIndex; | ||
subtractCoordIndex = coordIndex; | ||
if (previousGeometryIndex !== geometryIndex) { | ||
tempOutput.push([]); | ||
} else { | ||
var p0x = previousCoord[0]; | ||
var p0y = previousCoord[1]; | ||
var p1x = currentCoord[0]; | ||
var p1y = currentCoord[1]; | ||
tempOutput[geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
} | ||
var realCoordIndex = coordIndex - subtractCoordIndex; | ||
var p1 = poly.coordinates[geometryIndex][realCoordIndex + 1]; | ||
var p0x = currentCoord[0]; | ||
var p0y = currentCoord[1]; | ||
var p1x = p1[0]; | ||
var p1y = p1[1]; | ||
tempOutput[geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
previousCoord = currentCoord; | ||
previousGeometryIndex = geometryIndex; | ||
}, | ||
true | ||
false | ||
); | ||
@@ -119,5 +119,5 @@ tempOutput.forEach(function (ring) { | ||
function processMultiPolygon(poly, tempOutput) { | ||
var prevGeomIndex = 0; | ||
var subtractCoordIndex = 0; | ||
var prevMultiIndex = 0; | ||
var previousCoord = null; | ||
var previousMultiFeatureIndex = null; | ||
var previousGeometryIndex = null; | ||
@@ -133,31 +133,26 @@ coordEach( | ||
) { | ||
if (multiFeatureIndex > prevMultiIndex) { | ||
prevMultiIndex = multiFeatureIndex; | ||
subtractCoordIndex = coordIndex; | ||
if (previousMultiFeatureIndex !== multiFeatureIndex) { | ||
tempOutput.push([[]]); | ||
} | ||
if (geometryIndex > prevGeomIndex) { | ||
prevGeomIndex = geometryIndex; | ||
subtractCoordIndex = coordIndex; | ||
} else if (previousGeometryIndex !== geometryIndex) { | ||
tempOutput[multiFeatureIndex].push([]); | ||
} else { | ||
var p0x = previousCoord[0]; | ||
var p0y = previousCoord[1]; | ||
var p1x = currentCoord[0]; | ||
var p1y = currentCoord[1]; | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
} | ||
var realCoordIndex = coordIndex - subtractCoordIndex; | ||
var p1 = | ||
poly.coordinates[multiFeatureIndex][geometryIndex][realCoordIndex + 1]; | ||
var p0x = currentCoord[0]; | ||
var p0y = currentCoord[1]; | ||
var p1x = p1[0]; | ||
var p1y = p1[1]; | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
previousCoord = currentCoord; | ||
previousMultiFeatureIndex = multiFeatureIndex; | ||
previousGeometryIndex = geometryIndex; | ||
}, | ||
true | ||
false | ||
); | ||
tempOutput.forEach(function (poly) { | ||
@@ -164,0 +159,0 @@ poly.forEach(function (ring) { |
'use strict'; | ||
var helpers = require('@turf/helpers'); | ||
var meta = require('@turf/meta'); | ||
var helpers = require('@turf/helpers'); | ||
@@ -13,3 +13,3 @@ /** | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.iterations=1] THe number of times to smooth the polygon. A higher value means a smoother polygon. | ||
* @param {string} [options.iterations=1] The number of times to smooth the polygon. A higher value means a smoother polygon. | ||
* @returns {FeatureCollection<Polygon>} FeatureCollection containing the smoothed polygon/poylgons | ||
@@ -25,2 +25,3 @@ * @example | ||
function polygonSmooth(inputPolys, options) { | ||
options = options || {}; | ||
var outPolys = []; | ||
@@ -40,3 +41,3 @@ // Optional parameters | ||
for (var i = 0; i < iterations; i++) { | ||
tempOutput = [[]]; | ||
tempOutput = []; | ||
poly = geom; | ||
@@ -52,3 +53,3 @@ if (i > 0) poly = helpers.polygon(outCoords).geometry; | ||
for (var y = 0; y < iterations; y++) { | ||
tempOutput = [[[]]]; | ||
tempOutput = []; | ||
poly = geom; | ||
@@ -74,4 +75,4 @@ if (y > 0) poly = helpers.multiPolygon(outCoords).geometry; | ||
function processPolygon(poly, tempOutput) { | ||
var prevGeomIndex = 0; | ||
var subtractCoordIndex = 0; | ||
var previousCoord = null; | ||
var previousGeometryIndex = null; | ||
@@ -87,23 +88,22 @@ meta.coordEach( | ||
) { | ||
if (geometryIndex > prevGeomIndex) { | ||
prevGeomIndex = geometryIndex; | ||
subtractCoordIndex = coordIndex; | ||
if (previousGeometryIndex !== geometryIndex) { | ||
tempOutput.push([]); | ||
} else { | ||
var p0x = previousCoord[0]; | ||
var p0y = previousCoord[1]; | ||
var p1x = currentCoord[0]; | ||
var p1y = currentCoord[1]; | ||
tempOutput[geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
} | ||
var realCoordIndex = coordIndex - subtractCoordIndex; | ||
var p1 = poly.coordinates[geometryIndex][realCoordIndex + 1]; | ||
var p0x = currentCoord[0]; | ||
var p0y = currentCoord[1]; | ||
var p1x = p1[0]; | ||
var p1y = p1[1]; | ||
tempOutput[geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
previousCoord = currentCoord; | ||
previousGeometryIndex = geometryIndex; | ||
}, | ||
true | ||
false | ||
); | ||
@@ -121,5 +121,5 @@ tempOutput.forEach(function (ring) { | ||
function processMultiPolygon(poly, tempOutput) { | ||
var prevGeomIndex = 0; | ||
var subtractCoordIndex = 0; | ||
var prevMultiIndex = 0; | ||
var previousCoord = null; | ||
var previousMultiFeatureIndex = null; | ||
var previousGeometryIndex = null; | ||
@@ -135,31 +135,26 @@ meta.coordEach( | ||
) { | ||
if (multiFeatureIndex > prevMultiIndex) { | ||
prevMultiIndex = multiFeatureIndex; | ||
subtractCoordIndex = coordIndex; | ||
if (previousMultiFeatureIndex !== multiFeatureIndex) { | ||
tempOutput.push([[]]); | ||
} | ||
if (geometryIndex > prevGeomIndex) { | ||
prevGeomIndex = geometryIndex; | ||
subtractCoordIndex = coordIndex; | ||
} else if (previousGeometryIndex !== geometryIndex) { | ||
tempOutput[multiFeatureIndex].push([]); | ||
} else { | ||
var p0x = previousCoord[0]; | ||
var p0y = previousCoord[1]; | ||
var p1x = currentCoord[0]; | ||
var p1y = currentCoord[1]; | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
} | ||
var realCoordIndex = coordIndex - subtractCoordIndex; | ||
var p1 = | ||
poly.coordinates[multiFeatureIndex][geometryIndex][realCoordIndex + 1]; | ||
var p0x = currentCoord[0]; | ||
var p0y = currentCoord[1]; | ||
var p1x = p1[0]; | ||
var p1y = p1[1]; | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.75 * p0x + 0.25 * p1x, | ||
0.75 * p0y + 0.25 * p1y, | ||
]); | ||
tempOutput[multiFeatureIndex][geometryIndex].push([ | ||
0.25 * p0x + 0.75 * p1x, | ||
0.25 * p0y + 0.75 * p1y, | ||
]); | ||
previousCoord = currentCoord; | ||
previousMultiFeatureIndex = multiFeatureIndex; | ||
previousGeometryIndex = geometryIndex; | ||
}, | ||
true | ||
false | ||
); | ||
tempOutput.forEach(function (poly) { | ||
@@ -166,0 +161,0 @@ poly.forEach(function (ring) { |
@@ -1,7 +0,2 @@ | ||
import { | ||
Feature, | ||
FeatureCollection, | ||
Polygon, | ||
MultiPolygon, | ||
} from "@turf/helpers"; | ||
import { Feature, FeatureCollection, Polygon, MultiPolygon } from "geojson"; | ||
@@ -8,0 +3,0 @@ /** |
{ | ||
"name": "@turf/polygon-smooth", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf polygon smooth module", | ||
@@ -48,3 +48,3 @@ "author": "Turf Authors", | ||
"test:tape": "node -r esm test.js", | ||
"test:types": "tsc --esModuleInterop --noEmit types.ts" | ||
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts" | ||
}, | ||
@@ -61,6 +61,6 @@ "devDependencies": { | ||
"dependencies": { | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/meta": "^6.5.0" | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/meta": "^7.0.0-alpha.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -10,10 +10,11 @@ # @turf/polygon-smooth | ||
**Parameters** | ||
### Parameters | ||
- `inputPolys` **([FeatureCollection][4] \| [Feature][5]<([Polygon][6] \| [MultiPolygon][7])>)** (Multi)Polygon(s) to smooth | ||
- `options` **[Object][8]** Optional parameters (optional, default `{}`) | ||
- `options.iterations` **[string][9]** THe number of times to smooth the polygon. A higher value means a smoother polygon. (optional, default `1`) | ||
* `inputPolys` **([FeatureCollection][4] | [Feature][5]<([Polygon][6] | [MultiPolygon][7])>)** (Multi)Polygon(s) to smooth | ||
* `options` **[Object][8]** Optional parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.iterations` **[string][9]** The number of times to smooth the polygon. A higher value means a smoother polygon. (optional, default `1`) | ||
### Examples | ||
```javascript | ||
@@ -28,3 +29,3 @@ var polygon = turf.polygon([[[11, 0], [22, 4], [31, 0], [31, 11], [21, 15], [11, 11], [11, 0]]]); | ||
Returns **[FeatureCollection][4]<[Polygon][6]>** FeatureCollection containing the smoothed polygon/poylgons | ||
Returns **[FeatureCollection][4]<[Polygon][6]>** FeatureCollection containing the smoothed polygon/poylgons | ||
@@ -31,0 +32,0 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.6 |
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
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
72
14617
310
1
+ Added@turf/helpers@7.1.0(transitive)
+ Added@turf/meta@7.1.0(transitive)
+ Added@types/geojson@7946.0.15(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/meta@6.5.0(transitive)
Updated@turf/helpers@^7.0.0-alpha.0
Updated@turf/meta@^7.0.0-alpha.0