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

polygon clipping errors #30

Closed
Fil opened this issue May 15, 2019 · 15 comments
Closed

polygon clipping errors #30

Fil opened this issue May 15, 2019 · 15 comments

Comments

@Fil
Copy link
Member

Fil commented May 15, 2019


while these first two could be solved by clipping to the sphere, the last one shows we still sometimes have inversions:

(reported by @mootari @ https://imgur.com/a/Km2wK6m)

@mootari
Copy link

mootari commented May 15, 2019

Can you reproduce the inversion from the screenshot alone? Or would it help if I tried to create a reduced test case?

@Fil
Copy link
Member Author

Fil commented May 15, 2019

It's just a question of fiddling with the mouse and then printing projection.rotate()…

A bad case:

projection = d3.geoAirocean().rotate([88, -37.8, -73.2])

https://observablehq.com/d/7c5b4f1ff5a76024

@Fil
Copy link
Member Author

Fil commented May 15, 2019

And

projection.rotate([-70.2, -47, -121.6])

creates an inversion of land and ocean

@mootari
Copy link

mootari commented May 15, 2019

Another inversion: https://observablehq.com/d/303582dda96b0649

@mootari
Copy link

mootari commented May 15, 2019

I've updated the notebook to only show the offending polygon (and added the ability to step through all polygons).

@Fil
Copy link
Member Author

Fil commented May 15, 2019 via email

@Fil
Copy link
Member Author

Fil commented May 16, 2019

I've fixed the problematic point in https://unpkg.com/visionscarto-world-atlas@0.0.6/
(see visionscarto/world-atlas@590dbeb), and it fixes the inversion problem.

Fil added a commit that referenced this issue May 18, 2019
@Fil
Copy link
Member Author

Fil commented May 18, 2019

Looks like I finally nailed that bug. There is a case where we would rejoin with a line if the segment's first and last points were coincident. But the test for coincidence used a very tolerant pointEqual, and two points seperated by 1e-6 were considered equal, and they were rejoined directly, creating this "bleeding". Fixed at a08a09e

Test here: https://observablehq.com/d/7c5b4f1ff5a76024

(EDIT - Dec. 2019: the bug is still here — looks like I forgot to merge the change)

@Fil
Copy link
Member Author

Fil commented May 18, 2019

We still get some inversions on the example, but I'm having a hard time isolating them.

@mootari
Copy link

mootari commented May 18, 2019

What's your process and intuition to narrow them down?

@Fil
Copy link
Member Author

Fil commented May 19, 2019

To find the problematic rotations I have no method, I just rotate the airocean globe until I see a flash of black (if such a thing exists). If I'm lucky to find one, I can just type projection.rotate() in a cell to read the values.

To find the faulty code, my method in this case is a bit like what you did in the notebook: I remove as much "matter" as I can from the polygons, and try to get to (ideally) a faulty triangle or a polygon with very few edges.

Then I write two test cases in node, one with the faulty rotation, the other with a different rotation, which is ideally very close to the faulty one, but does not break.

After that, I start to edit the src code, adding console.warn() where I suspect there might be a difference, and run the two test cases side by side. The numbers change a bit, but I'm looking for places where the structure is different. In the case of a08a09e, I ended up at this specific line of code, and saw that the pointEqual test was suddenly saying true and triggered the bug.

@mootari
Copy link

mootari commented May 19, 2019

What assumptions can be made about the inversions so far? E.g.:

  • Are they limited to certain types of projections?
  • Are they guaranteed to be caused only by a faulty geometry? What kind of faults (e.g. overlaps/intersections)?
  • Will the inversion only be triggered by lines that get cropped by the projection's sphere?

@Fil
Copy link
Member Author

Fil commented May 19, 2019 via email

@mootari
Copy link

mootari commented May 19, 2019

Not sure if related or relevant: compareIntersection appears to apply some fuzz via epsilon.

Related issue: #3

Fil added a commit that referenced this issue Dec 28, 2019
Fil added a commit that referenced this issue Dec 28, 2019
@Fil
Copy link
Member Author

Fil commented Dec 28, 2019

Closing for now, as bleeding issues are solved. If we can find an inversion we'll open a new issue.

@Fil Fil closed this as completed Dec 28, 2019
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