Skip to content

Commit

Permalink
Resolve #1539 where incorrect centroid is calculated for polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
Rowan Winsemius authored and Rowan Winsemius committed Dec 4, 2018
1 parent fd08414 commit 2a64511
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/centroid/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function centroid(geojson, options) {
xSum += coord[0];
ySum += coord[1];
len++;
});
}, true);
return point([xSum / len, ySum / len], options.properties);
}

Expand Down
8 changes: 8 additions & 0 deletions src/centroid/test/in/polygon2.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-1, -1], [1, -1], [1, 1], [-1, 1], [-1, -1]]]
}
}
4 changes: 2 additions & 2 deletions src/centroid/test/out/imbalanced-polygon.geojson
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"geometry": {
"type": "Point",
"coordinates": [
4.851914405822754,
45.78098812633097
4.851791984156558,
45.78143055383553
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/centroid/test/out/polygon.geojson
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"geometry": {
"type": "Point",
"coordinates": [
4.839177131652832,
45.76256007199914
4.841194152832031,
45.75807143030368
]
}
},
Expand Down
49 changes: 49 additions & 0 deletions src/centroid/test/out/polygon2.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"marker-symbol": "circle"
},
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-1,
-1
],
[
1,
-1
],
[
1,
1
],
[
-1,
1
],
[
-1,
-1
]
]
]
}
}
]
}

0 comments on commit 2a64511

Please sign in to comment.