From c81b40f333b2b002913d7276d4506c7d26e79ba7 Mon Sep 17 00:00:00 2001 From: DanielJDufour Date: Wed, 13 Apr 2022 00:05:04 -0400 Subject: [PATCH] shiftGeometry should return geom in addition to shifting in place --- index.js | 11 ++++++----- zonal.js | 12 +++++++----- zonal.min.js | 12 +++++++----- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index c6aafba..ba8ca0b 100644 --- a/index.js +++ b/index.js @@ -70,12 +70,13 @@ const shift = () => randSign() * Math.random() * 1e-7; const shiftRing = ring => ring.map(([x, y]) => [x + shift(), y + shift()]); const shiftPolygon = rings => rings.map(shiftRing); const shiftMultiPolygon = polygons => polygons.map(shiftPolygon); -function shiftGeometry(geometry) { - if (geometry.type === "Polygon") { - geometry.coordinates = shiftPolygon(geometry.coordinates); - } else if (geometry.type === "MultiPolygon") { - geometry.coordinates = shiftMultiPolygon(geometry.coordinates); +function shiftGeometry(geom) { + if (geom.type === "Polygon") { + geom.coordinates = shiftPolygon(geom.coordinates); + } else if (geom.type === "MultiPolygon") { + geom.coordinates = shiftMultiPolygon(geom.coordinates); } + return geom; } // assumptions diff --git a/zonal.js b/zonal.js index 37ed72c..3ee82c8 100644 --- a/zonal.js +++ b/zonal.js @@ -129,12 +129,14 @@ var shiftMultiPolygon = function shiftMultiPolygon(polygons) { return polygons.map(shiftPolygon); }; -function shiftGeometry(geometry) { - if (geometry.type === "Polygon") { - geometry.coordinates = shiftPolygon(geometry.coordinates); - } else if (geometry.type === "MultiPolygon") { - geometry.coordinates = shiftMultiPolygon(geometry.coordinates); +function shiftGeometry(geom) { + if (geom.type === "Polygon") { + geom.coordinates = shiftPolygon(geom.coordinates); + } else if (geom.type === "MultiPolygon") { + geom.coordinates = shiftMultiPolygon(geom.coordinates); } + + return geom; } // assumptions // - zones is a GeoJSON with polygons // - classes are either all polygons/multi-polygons or all points (not mix of polygons and points) diff --git a/zonal.min.js b/zonal.min.js index 4e9a9e2..7ad6014 100644 --- a/zonal.min.js +++ b/zonal.min.js @@ -5665,12 +5665,14 @@ var shiftMultiPolygon = function shiftMultiPolygon(polygons) { return polygons.map(shiftPolygon); }; -function shiftGeometry(geometry) { - if (geometry.type === "Polygon") { - geometry.coordinates = shiftPolygon(geometry.coordinates); - } else if (geometry.type === "MultiPolygon") { - geometry.coordinates = shiftMultiPolygon(geometry.coordinates); +function shiftGeometry(geom) { + if (geom.type === "Polygon") { + geom.coordinates = shiftPolygon(geom.coordinates); + } else if (geom.type === "MultiPolygon") { + geom.coordinates = shiftMultiPolygon(geom.coordinates); } + + return geom; } // assumptions // - zones is a GeoJSON with polygons // - classes are either all polygons/multi-polygons or all points (not mix of polygons and points)