But the q1.angleTo(q2) === 0 is always false.
The result of q1.angleTo(q2) is a very very small number, so I think it because of the number’s precision.
so, (x*x+...+w*w) is 0.999…9, although it should be 1.
Generally, to safeguard against similar problems, avoid using == with floating point numbers that are results of calculations. Instead, check whether the numbers are close enough.
It was discussed at GitHub to add an additional epsilon parameter to certain math methods (e.g. equals()) but the main issue is agreeing on an appropriate default value. A typical candidate is Number.EPSILON however it does not work in all use cases since it might be too small. A higher value is also hard to pinpoint since you don’t want to pick a too large one. Epsilon values are mainly app specific so try to solve the issue like shown below:
if (q1.angleTo(q2) < Number.EPSILON ) {
If Number.EPSILON doesn’t work, pick whatever epsilon works for you.