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

Some contour polygon is reverse. #52

Open
stoneshell opened this issue Nov 13, 2020 · 5 comments
Open

Some contour polygon is reverse. #52

stoneshell opened this issue Nov 13, 2020 · 5 comments
Labels
bug Something isn’t working

Comments

@stoneshell
Copy link

I'm using d3-contour to draw beautiful chart recently. Most of the time it's fine.
But in this case: https://observablehq.com/@choukou/untitled
In hundreds of polygons, one is special
截屏2020-11-13 下午12 46 50
It's counterclockwise. That cause the whole screen green.
Would you give me some help?

@Fil
Copy link
Member

Fil commented Nov 13, 2020

It seems that you are computing the contours on the spherical coordinates, then project the resulting polygons. But this creates issues with the holes. If you changed the order of operations (first project, then compute the contours), it would work. I'm sending you a suggestion.

See also https://observablehq.com/@d3/cloud-contours and https://observablehq.com/@fil/netcdf

@Fil Fil closed this as completed Nov 13, 2020
@stoneshell
Copy link
Author

It seems that you are computing the contours on the spherical coordinates, then project the resulting polygons. But this creates issues with the holes. If you changed the order of operations (first project, then compute the contours), it would work. I'm sending you a suggestion.

See also https://observablehq.com/@d3/cloud-contours and https://observablehq.com/@fil/netcdf

Thanks very much for your speedy and professional advice, I'm reading your code now, may get back to you if any further help needed.

Wish you a nice weekend ahead.

@stoneshell
Copy link
Author

In the data source(contours.json), masked area(land) is set -1e20.
When I change -1e20 to -999, the chart becomes perfect.
I don't know why this value affect the contour polygons.

@Fil
Copy link
Member

Fil commented Nov 16, 2020

Ah, true:

contours = d3.contours()
                  .size([data.width, data.height])
                  .thresholds(thresholds)(varData.values.map(d => Math.max(-1e13, d)))

is correct, but with 1e-14 it's broken:

contours = d3.contours()
                  .size([data.width, data.height])
                  .thresholds(thresholds)(varData.values.map(d => Math.max(-1e14, d)))

@Fil Fil reopened this Nov 16, 2020
@mbostock mbostock added the bug Something isn’t working label Jun 28, 2022
@mbostock
Copy link
Member

I suspect that this is related to numerical instability and I think it’s unlikely that we would implement a fully robust algorithm. Maybe we can at least guarantee consistency with d3.polygonArea though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Development

No branches or pull requests

3 participants