Comparing two vectors

Well, you can use Vector3.equals() if you want to check for equality. However, if you need more flexibility because of floating point inaccuracies, you can monkey-path Vector3 with your own equals method like so:

equals( v, epsilon = Number.EPSILON ) {

    return ( ( Math.abs( v.x - this.x ) < epsilon ) && ( Math.abs( v.y - this.y ) < epsilon ) && ( Math.abs( v.z - this.z ) < epsilon ) );

}
5 Likes