20 lines
574 B
JavaScript
20 lines
574 B
JavaScript
module.exports = equals
|
|
|
|
var EPSILON = require('./epsilon')
|
|
|
|
/**
|
|
* Returns whether or not the vectors have approximately the same elements in the same position.
|
|
*
|
|
* @param {vec2} a The first vector.
|
|
* @param {vec2} b The second vector.
|
|
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
*/
|
|
function equals(a, b) {
|
|
var a0 = a[0]
|
|
var a1 = a[1]
|
|
var b0 = b[0]
|
|
var b1 = b[1]
|
|
return (Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
|
|
Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)))
|
|
}
|