delaunator-cpp icon indicating copy to clipboard operation
delaunator-cpp copied to clipboard

Add define option DELAUNATOR_SINGLE_PRECISION to allow for the use of float instead of double.

Open c0rp3n opened this issue 4 years ago • 4 comments

Add support to switch to using single precision instead of double precision floating point values in delaunator. This allows the user to define DELAUNATOR_SINGLE_PRECISION to toggle the usage of single precision floating point values.

Further had to include the header cassert in order for this to compile on MSVC 19.26.28806

Edit: ~~Added base support to the cmake file, should use a config file though for this.~~ 3 Tests currently fail when using this due too the loss of precision

Added config support for using this, the same could be done for the single header.

c0rp3n avatar Jul 08 '20 14:07 c0rp3n

Does this work OK in practice? I'm a little concerned about the tests failing.

What's the motivation for this? Do you only have a processor that doesn't single-precision floating point?

abellgithub avatar Jul 10 '20 17:07 abellgithub

So my main motivation is also allowing for the use of floats or doubles in my own library as generally dealing with ~160,000 and some of the code I intend to also use on gpu's which may have less double-fpu's than single-fpu's.

I havent seen any invalid triangulation as a result of using single precision, but my use case the points are guaranteed to be a decent distance apart.

The tests that fail are due to small rounding errors here is a copy from my machine.

E:\programming\delaunator-cpp\test\delaunator.test.cpp(29): error: Expected equality of these values:
  tri_area
    Which is: 1.1318623341473398e-16
  hull_area
    Which is: 1.1318615400539517e-16
[  FAILED  ] Delaunator.robusttiny (2 ms)
...
E:\programming\delaunator-cpp\test\delaunator.test.cpp(29): error: Expected equality of these values:
  tri_area
    Which is: 175963808
  hull_area
    Which is: 175963792
[  FAILED  ] Delaunator.robustbig (1 ms)
...
E:\programming\delaunator-cpp\test\delaunator.test.cpp(29): error: Expected equality of these values:
  tri_area
    Which is: 13.84178638458252
  hull_area
    Which is: 13.841787338256836
[  FAILED  ] Delaunator.robustmod2 (5 ms)

I also realise I didnt switch the tests to use EXPECT_FLOAT_EQ instead of EXPECT_DOUBLE_EQ so will look into whether this changes any results, so will add this to the test file too.

Edit: added what the tests where

c0rp3n avatar Jul 10 '20 19:07 c0rp3n

Sorry. I'll try to get to this shortly. I'm not convinced that it might not blow up with some cases, but I guess if a user wants to run that risk, that's on them.

abellgithub avatar Jul 16 '20 17:07 abellgithub

Just changing the types doesn't make the tests pass. I'd have to take time to look at the issues and how best to deal with them. Some tests could be skipped when using single precision, I guess. If you want to look into this, that would be great, otherwise, you'll have to wait until I have more time to investigate.

abellgithub avatar Jul 17 '20 13:07 abellgithub