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

Broken voronoi #119

Closed
Fil opened this issue Feb 25, 2021 · 3 comments · Fixed by #120
Closed

Broken voronoi #119

Fil opened this issue Feb 25, 2021 · 3 comments · Fixed by #120
Assignees
Labels
bug Something isn't working

Comments

@Fil
Copy link
Member

Fil commented Feb 25, 2021

Test case at mapbox/delaunator#68

@Fil Fil self-assigned this Feb 25, 2021
@mourner mourner added the bug Something isn't working label Feb 26, 2021
@Fil
Copy link
Member Author

Fil commented Mar 25, 2021

The problem comes from https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js#L43 ; if we don't add the 1e8 factor here everything is solved.

It breaks a few tests though, which I'll have to inspect more closely, in particular https://github.com/d3/d3-delaunay/blob/master/test/voronoi-test.js#L75 is problmatic since the voronoi that we test for is patently wrong (note: the strange point is a double point where only the last digit of a coordinate changes).
Capture d’écran 2021-03-26 à 00 06 24

Reference commit for that test: 4cf3466

Fil added a commit that referenced this issue Mar 26, 2021
…te triangles created by points of the hull that are almost exactly aligned.

The "circumcenter" of such a triangle is a point at the infinite, in the direction orthogonal to the hull.

It must also be "away from the center". But we can't rely on the sign of *ab*, since it's itself a difference of two products and can be of the wrong sign, leading to a ray that sometimes goes in the opposite direction.

To overcome this problem, we use the first point of the first triangle as a guide to tell us which way is "away from the center".
@plmrry
Copy link

plmrry commented May 10, 2021

I came across what I believe is the same bug:

https://observablehq.com/@plmrry/voronoi-bug

My hacky fix is to add Math.random() * 0.00001 to my collinear points 😬

@Fil
Copy link
Member Author

Fil commented May 10, 2021

Yes, thanks for the example. I've checked and branch #120 fixes it too. We just need a bit of time to publish it because it's a major version change.

mbostock added a commit that referenced this issue Jun 4, 2021
* upgrade to testing branch delaunator v5

* The issue #119 comes from the circumcenters we assign to the degenerate triangles created by points of the hull that are almost exactly aligned.

The "circumcenter" of such a triangle is a point at the infinite, in the direction orthogonal to the hull.

It must also be "away from the center". But we can't rely on the sign of *ab*, since it's itself a difference of two products and can be of the wrong sign, leading to a ray that sometimes goes in the opposite direction.

To overcome this problem, we use the first point of the first triangle as a guide to tell us which way is "away from the center".

* delaunator v5

* Minor change: Only compute bl and cl when needed. #125

* Subtle out of bounds checking need documenting

* Minor: _ClipFinit() Prevent the propagation of undefined.

* Adopt type=module

follow changes in d3-format:
* type=module
* add exports
* remove zip
* update dependencies

* readme: type=module

* Update README.md

Co-authored-by: Mike Bostock <mbostock@gmail.com>

* update README: legacy env.

* remove esm devDependency

* strictEqual, deepStrictEqual
(@aulonm)

* Update src/voronoi.js

Co-authored-by: Mike Bostock <mbostock@gmail.com>

* delaunay.renderPoints(r)

closes #130

* simpler check, more tests

* more tests

* space

* Update src/delaunay.js

Co-authored-by: Mike Bostock <mbostock@gmail.com>

* test renderPoints(context, null) gives r=2

* remove Sublime project

* update dependencies

* stricter eslint

* cleaner imports

* fix copyright

Co-authored-by: Martin <martinfrances107@hotmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
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

Successfully merging a pull request may close this issue.

3 participants