UNPKG

tapspace

Version:

A zoomable user interface lib for web apps

36 lines (31 loc) 875 B
const fine = require('affineplane') const epsilon = fine.epsilon module.exports = function (distance, tolerance) { // @Distance:isAlmostEqual(distance[, tolerance]) // // Test if two distances are equal within tolerance. // The changes in basis often cause small rounding errors // due to floating point arithmetics and those // can break strict equality checks. // // Parameters: // distance // a Distance to compare with this. // tolerance // optional number on this basis. Defaults to affineplane.epsilon // // Returns: // a boolean // // Normalize if (distance.transitRaw) { distance = distance.transitRaw(this.basis) } if (typeof tolerance !== 'number') { tolerance = epsilon } else { // Ensure positive tolerance = Math.abs(tolerance) } return Math.abs(this.dist - distance) < tolerance }