Skip to content

Commit

Permalink
shiftGeometry should return geom in addition to shifting in place
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Apr 13, 2022
1 parent aaddebf commit c81b40f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions zonal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions zonal.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c81b40f

Please sign in to comment.