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

Increase Delaunator orient function robustness #479

Conversation

MFraters
Copy link
Member

@MFraters MFraters commented Apr 7, 2023

I found a corner case where in debug mode where the Delaunator orient function return a different result depending on whether it is in debug or release mode. This causes issues in the release mode, which is basically wrong. The issue comes down to that (qy - py) * (rx - qx) - (qx - px) * (ry - qy) is exactly zero in debug mode (so (qy - py) * (rx - qx) - (qx - px) * (ry - qy) < 0.0 is false) and the release mode is slightly less accurate and results in -3.48086e-21, which then returns true.

The solution I have gone for here is to check if the value is smaller that -epsilon. I guess it is not a perfect solution, but it seems to solve the problem.

For reference, these are the values of (qy - py) * (rx - qx) - (qx - px) * (ry - qy) and the results for debug mode left and release mode right.
(0.80218-0.793353) * (-1.78205 - -1.7908) - (-1.7908 - -1.79954) * (0.811008 - 0.80218) = 0 | (0.80218-0.793353) * (-1.78205 - -1.7908) - (-1.7908 - -1.79954) * (0.811008 - 0.80218) = -3.48086e-21

Playing with some of the flag could potentially help, but I just want it to be more robust, which this pull request achieves.

@github-actions
Copy link

github-actions bot commented Apr 7, 2023

Benchmark Main Feature Difference (99.9% CI)
Slab interpolation simple none 1.433 ± 0.036 (s=320) 1.436 ± 0.037 (s=310) -0.5% .. +0.9%
Slab interpolation curved simple none 1.201 ± 0.003 (s=370) 1.201 ± 0.003 (s=382) -0.0% .. +0.1%
Spherical slab interpolation simple none 1.497 ± 0.004 (s=296) 1.496 ± 0.005 (s=308) -0.1% .. +0.0%
Slab interpolation simple curved CMS 1.375 ± 0.002 (s=340) 1.375 ± 0.002 (s=317) -0.1% .. +0.0%
Spherical slab interpolation simple CMS 2.362 ± 0.005 (s=180) 2.361 ± 0.004 (s=204) -0.1% .. +0.0%
Spherical fault interpolation simple none 1.527 ± 0.005 (s=289) 1.526 ± 0.006 (s=303) -0.1% .. +0.1%
Cartesian min max surface 3.423 ± 0.033 (s=138) 3.419 ± 0.021 (s=128) -0.4% .. +0.2%
Spherical min max surface 9.672 ± 0.147 (s=50) 9.581 ± 0.132 (s=46) -1.9% .. +0.1%

@MFraters MFraters force-pushed the fix_delaunator_orient_small_zero_bug branch from cb95ebd to f340a90 Compare April 7, 2023 23:21
@codecov
Copy link

codecov bot commented Apr 7, 2023

Codecov Report

Merging #479 (c3753b2) into main (d41db79) will not change coverage.
The diff coverage is n/a.

❗ Current head c3753b2 differs from pull request most recent head 6ce66d1. Consider uploading reports for the commit 6ce66d1 to get more accurate results

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #479   +/-   ##
=======================================
  Coverage   90.85%   90.85%           
=======================================
  Files          91       91           
  Lines        6406     6406           
=======================================
  Hits         5820     5820           
  Misses        586      586           

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d41db79...6ce66d1. Read the comment docs.

@MFraters MFraters force-pushed the fix_delaunator_orient_small_zero_bug branch from f340a90 to 6ce66d1 Compare April 13, 2023 21:18
@MFraters MFraters merged commit 87411f9 into GeodynamicWorldBuilder:main Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant