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

d3.geoCentroid sometimes returns the wrong result? #81

Closed
mbostock opened this issue Feb 14, 2017 · 7 comments
Closed

d3.geoCentroid sometimes returns the wrong result? #81

mbostock opened this issue Feb 14, 2017 · 7 comments

Comments

@mbostock
Copy link
Member

https://bl.ocks.org/mbostock/c62c0d706d1f046f84c0f0cf698bc0a9

Moved from d3/d3#1883. /cc @Fil

@mbostock
Copy link
Member Author

mbostock commented Feb 14, 2017

Support for area-weighted polygon centroids was added in D3 3.2. Related d3/d3@492215a d3/d3#1011 d3/d3#1286. Interestingly, the prior behavior is more accurate for this input.

@Fil
Copy link
Member

Fil commented Feb 14, 2017

in function centroidRingPoint(lambda, phi) { if I change v = m && -acos(u) / m, // area weight to v = -1 the blue dot ends up on the red dot.

@Fil
Copy link
Member

Fil commented Feb 14, 2017

if I apply this patch then some tests fail, but by not much — moreover, the failing tests are weird:

# the centroid of a spherical square touching the antimeridian
not ok 124 should be in delta 0.000001
  ---
    operator: inDelta
    expected: |-
      [ -179.5, 4.987448 ]
    actual: |-
      [ -179.50000000000028, 4.999810580369795 ]
    at: Test.tape.Test.inDelta (/Users/fil/Sites/d3/d3-geo/test/inDelta.js:5:8)
  ...

the actual result (with v=-1) looks much closer to what I understand to be the centroid of said "circle" (which doesn't look circular at all).

(Looks like we're not testing features but non-regression.)

@mbostock
Copy link
Member Author

I dunno, sorry.

@Fil
Copy link
Member

Fil commented Feb 18, 2017

@mbostock
Copy link
Member Author

Released in 1.4.2.

@Fil
Copy link
Member

Fil commented Feb 19, 2017

I took the time to write this up so that the next person who wants to understand the code might spend less time on it. (In any case it wasn't time wasted.)
https://bl.ocks.org/Fil/608b3ca94a008f2ae01c6273fafb25e7

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

No branches or pull requests

2 participants