You shouldn't compare floats like in this method : if (mag) . Much better and crash resistant would be if ( mag > 0.0001 ) for example. I guess theres more places in Assimp that thereis such a comparason ;)
inline aiQuaterniont<TReal>& aiQuaterniont<TReal>::Normalize()
// compute the magnitude and divide through it
const TReal mag = sqrt(x*x + y*y + z*z + w*w);
if (mag) // <- HERE :)
const TReal invMag = static_cast<TReal>(1.0)/mag;
x *= invMag;
y *= invMag;
z *= invMag;
w *= invMag;
Nope, this one is fine. The inversion works as long as mag is not zero, and the check ensures this. If you'd use a non-zero epsilon in this comparision instead, you'd be making assumptions about the range of the values, which is never a good idea.
Well, technically a division could still be indeterminate for example if the numerator is super large and the denominator is super small. Luckily this can't happen for a normalize operation since the length is at least as huge as each of the components.
I therefore also think this is safe.
It's a common operation in numerical code to check, if the value is less than the machine epsilon value of the floating type. Special in bigger equations with a lot of multiplications / divisions such values can have evil effects.
But we do not work with stuff like this, so for me this is also ok.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.