4 ms·
I can't stop precision loss in all cases, but I do my darnedest to avoid loss when it causes false positives, especially for stuff like intersect detection code
by tidwall 3y ago
I can't stop precision loss in all cases, but I do my darnedest to avoid loss when it causes false positives, especially for stuff like intersect detection code. For example the collinear [1] function looks really big for a seemingly simple operation, but there are extra checks built in for precision loss and in the cases of compiler associate math issues (like a user borking a build with -ffast-math).
I'm sure it's not all perfect but I feel pretty good about it overall. It certainly helps that much of the logic derived from the Tile38 [2] project, which has 8 years of use in production. I ported many of the tests too, which make me warm and fuzzy every time they pass.
[1] https://github.com/tidwall/tg/blob/v0.1.0/tg.c#L389 https://github.com/tidwall/tg/blob/v0.1.0/tg.c#L389
[2] https://github.com/tidwall/tile38 https://github.com/tidwall/tile38
- fastneutron 3y agoYou might consider Shewchuk’s methods for robust geometric computations: https://www.cs.cmu.edu/~quake/robust.html https://www.cs.cmu.edu/~quake/robust.html There are more modern implementations available on GitHub, but I’ve found it to be fairly easy to integrate into C-family projects without much modification.