modeling/src/maths/vec3/snap.js

  1. /**
  2. * Snaps the coordinates of the given vector to the given epsilon.
  3. *
  4. * @param {vec3} out - receiving vector
  5. * @param {vec3} vector - vector to snap
  6. * @param {Number} epsilon - epsilon of precision, less than 0
  7. * @returns {vec3} out
  8. * @alias module:modeling/maths/vec3.snap
  9. */
  10. const snap = (out, vector, epsilon) => {
  11. out[0] = Math.round(vector[0] / epsilon) * epsilon + 0
  12. out[1] = Math.round(vector[1] / epsilon) * epsilon + 0
  13. out[2] = Math.round(vector[2] / epsilon) * epsilon + 0
  14. return out
  15. }
  16. module.exports = snap