-
Notifications
You must be signed in to change notification settings - Fork 141
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
Issue #43 #51
Conversation
…e a majority vote) Solves #43.
Cleaner version. The fixes for voronoi will be in d3-delaunay (d3/d3-delaunay#86). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's such an awesome fix! It will probably still have some edge cases, especially considering that asymmetric orientation tests can occur within a set of points > 3 (where pairwise they're stable but inconsistent as a system), and that inCircle
tests may be unstable too. But if it makes the library more robust without affecting performance much, I'm up for it!
index.js
Outdated
@@ -379,7 +379,14 @@ function dist(ax, ay, bx, by) { | |||
} | |||
|
|||
function orient(px, py, qx, qy, rx, ry) { | |||
return (qy - py) * (rx - qx) - (qx - px) * (ry - qy) < 0; | |||
const d = cross(px, py, qx, qy, rx, ry); | |||
if (Math.abs(d) > 1e-6) return d < 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how much we could lower the 1e-6
? That may be too high for the purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all the examples I had either large numbers, or very small ones (for triangles that were definitely problematic). In those examples it looked like the small value was ~1e-11 or less, but I don't know when the precision stops being a problem.
(In any case the cost for such small triangles is just +2 area computations.)
An asymmetric (but consistent) method could be to start with the top-left point of the set — but for triangles it would be less elegant (and probably more code).
🤯 |
Did some exploration of the topic and came up with an alternative approach ("More precise" in the notebook) — @Fil check it out and let me know what you think: https://observablehq.com/@mourner/non-robust-arithmetic-as-art |
👍 I like the fact that it separates And the notebook is ⚡️ |
It may be a little slower than the voting approach because of the extra operations for bounds checking, but the advantage is that it's a proven error bound — with arbitrary ones like |
Actually somehow it looks ~15-20% faster — here are my results if you change
The tests failed at first but that turned out to be because of non-robust convex check. :) Updated to use the same formula there too and it passes now. Pushed my commit here. |
Fantastic work! 👏👏👏 |
Based on mapbox/delaunator#51 Along with the last missing test case "issue44".
* Robust orient2d checks * Add example to display triangulation in SVG * Clean up svg.rs example * Split fixture tests into separate test cases * Add test case for #10 * Copy remaining robustness tests from js repo * Add point label to svg example to easy investigations * Add grid test fixture * Add hull convex check to tests Based on mapbox/delaunator#51 Along with the last missing test case "issue44". * Remove invalid test code for connectivity
This PR contains a fix and test for #43: the idea is that the cross-product ABxAC is not stable, so we have a majority vote on the sign of ABxAC, BCxBA, CAxCB. The formula for the majority vote is symmetric, so it always gives the same answer for a given triangle. (For performance, we don't call the vote if ABxAC is not too small.)
I've also included a fix and test files for related issues with the voronoi (https://observablehq.com/d/bd8a95abd9a01c79 & https://observablehq.com/d/b219d92fae85fc9b), but as these issues only show in voronoi (ie in d3-delaunay)—the tests don't actually fail. I'm not sure what to do with this part — I don't see a way of fixing that in d3-delaunay directly though, so I've stuck it here for discussion.With these two, all the test notebooks are fixed.