Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong centroid calculation #1539

Closed
raviqqe opened this issue Nov 30, 2018 · 3 comments · Fixed by #1894
Closed

Wrong centroid calculation #1539

raviqqe opened this issue Nov 30, 2018 · 3 comments · Fixed by #1894
Assignees

Comments

@raviqqe
Copy link

raviqqe commented Nov 30, 2018

import { centroid, polygon } from "@turf/turf";

console.log(centroid(polygon([[[-1, -1], [1, -1], [1, 1], [-1, 1], [-1, -1]]])));

The result should be a point at (0, 0) but is actually (-0.2, -0.2). The algorithm is using the enclosing point twice.

@rowanwins
Copy link
Member

Great pickup thanks @raviqqe

I'll get a fix for this within the v7 branch and add a test.

@vomc
Copy link

vomc commented Jul 29, 2019

This is probably in development, but I just made a Fiddle using 7.0.0-alpha.1 and the centroid still seems off: https://jsfiddle.net/9z37srjb/3/

@rowanwins
Copy link
Member

Yeah the change hasn't been released yet @vomc , it was added after the 7.0.0-alpha.1 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants