msteinbeck / tinyspline

ANSI C library for NURBS, B-Splines, and Bézier curves with interfaces for C++, C#, D, Go, Java, Javascript, Lua, Octave, PHP, Python, R, and Ruby.
MIT License
1.2k stars 208 forks source link

Why a float-only implementation? #61

Closed giumas closed 8 years ago

giumas commented 8 years ago

The current implementation is float-based.

This represents a limiting factor for applications where the precision provided by float is not enough:

msteinbeck commented 8 years ago

The decision for using floats instead of double is severalfold:

GLAPI void GLAPIENTRY gluNurbsCurve (GLUnurbs* nurb, GLint knotCount, GLfloat *knots, GLint stride, GLfloat *control, GLint order, GLenum type)

that allows one to draw arbitrary splines. As you can see, the function takes GLfloat for knots and control points. Thus, I had to implement the struct tsBSpline with floats instead of doubles.

Does your code have real problems with floats that do not occur with doubles? If yes, could you please give me an example?

giumas commented 8 years ago

The first example that comes in my mind is about using geographic coordinates for the position of the control points.

msteinbeck commented 8 years ago

Do you mean latitude and longitude?

giumas commented 8 years ago

yes, the float accuracy is often not enough.

msteinbeck commented 8 years ago

If I'm correct, then there are 180 latitude and 360 longitude? That gives you about 4 well defined decimal places, for instance 150.0034. How many decimal places do you need?

giumas commented 8 years ago

http://gis.stackexchange.com/a/8674/39593

msteinbeck commented 8 years ago

http://gis.stackexchange.com/a/8674/39593

That is a really nice article. So, how many decimal places do you need?

giumas commented 8 years ago

I believe that a general GIS application supports at least the seventh decimal place.

msteinbeck commented 8 years ago

According to http://stackoverflow.com/questions/13542944/how-many-significant-digits-have-floats-and-doubles-in-java a single precision float has 6 to 9 (about 7 on average) decimal points (I'm pretty sure they have the same precision in C as in Java). I can't say if it is enough for your application but changing the interface to doubles (or using macros to give someone a choice) makes things really hard. It not only affects the C interface but also the C++, Java, Python, etc. interfaces.

giumas commented 8 years ago

I can't say if it is enough for your application but changing the interface to doubles (or using macros to give someone a choice) makes things really hard. It not only affects the C interface but also the C++, Java, Python, etc. interfaces.

I have already tweaked it using a macro. Since I only use the C library, it is relatively simple.

I usually open a ticket when I believe that a problem can be common to other users that want to use a library. Being float-based is a relevant library's feature that is not cleared stated in the README file.

msteinbeck commented 8 years ago

Being float-based is a relevant library's feature that is not cleared stated in the README file.

I will consider it when adding more text to the documentation, thanks. I think we can close this issue for now?

giumas commented 8 years ago

Of course

msteinbeck commented 8 years ago

I usually open a ticket when I believe that a problem can be common to other users that want to use a library.

Thanks for that. So far, you added some valuable changes to TinySpline.