Open lukehutch opened 4 years ago
I want to keep methods with (let's say) arbitrary epsilons and error recovery very low in JOML. If you try to normalize a zero vector, then you will be getting undefined (NaN) as result, because dividing zero by zero is undefined. In my opinion, this is more desirable than recovering from it in a way that may not be suitable for the client/user-application. My proposal: Leave the method as is and use isFinite to check for infinity/NaN after the normalization.
Fair argument. You should at least document all methods that can return infinity/NaN however, and suggest in the Javadoc that the user call isFinite
on the result if it might be an exceptional value.
Also some methods can set just some components of a result to infinity/NaN. For example, Quaternionf.rotationAxis
can set x
, y
and z
to infinity, but w
will always be valid. This should be documented too, because if a user just checks isFinite(q.w)
, they would miss catching the problem until it has propagated deeper into the program.
Yes, I'll document it and will add a Quaternion.isFinite() too.
Vector.isFinite()
would also be a good idea. And probably even Matrix.isFinite()
for testing all elements of a matrix.
Vector.isFinite() would also be a good idea.
I did meant that with my comment https://github.com/JOML-CI/JOML/issues/211#issuecomment-590770861 (did you open the link?)
Oh, sorry, I didn't -- I assumed that was a link to Math.isFinite(double)
without checking it.
Changes are pushed, but it seems the oss.sonatype.org endpoint to publish snapshots is currently down (504 gateway timeout in the Travis build when trying to upload the artifacts): https://travis-ci.org/JOML-CI/JOML/jobs/655543569 (also it seems the logs cannot be pulled fully, so Travis also seems to have an issue... I'll manually retrigger the job tomorrow and keep this issue open until the artifacts are published.
Oh man, I run into this all the time when attempting to publish to Sonatype. I keep filing bugs each time it happens, but they never seem to fix the underlying causes in a robust way. It's a reliably unreliable service :-) But there's no great alternative right now (I tried BinTray, and it has its own problems...)
Thanks for your work on this!
Alright, just manually retriggered the build and this one went through, so 1.9.23-SNAPSHOT is available now.
Just one thing missing... Any method that can result in NaN/infinity in any component needs to recommend in the Javadoc that the user call isFinite on the result, if there's any chance of this happening (eg. when normalizing a zero vector).
Current normalization code is as follows:
Instead division by zero should always be avoided, and the code should be something like the following to prevent division-by-zero (arguably dealing with a zero vector in the result is better from a robustness point of view than dealing with
Inf
orNaN
, since these values propagate virally):Then there should be a
Vector.isZero()
method for quickly testing if a vector is (exactly) equal to zero, so that return conditions from methods like the result ofnormalize()
can be quickly checked:There should probably also be a
Vector.isCloseToZero()
method that would replace theif (lengthSq < 1.0e-30)
test above:The constant
1.0e-30
could be smaller forfloat
vectors (maybe1.0e-12f
) -- it should be something above the precision floor, but below the probable error/noise floor for the majority of applications.