Vector3.js 785 B

12345678910111213141516171819202122232425262728293031323334353637
  1. module.exports = class Vector3 {
  2. /**
  3. * A 3D vector
  4. *
  5. * @param {number} x The X value of this vector
  6. * @param {number} y The Y value of this vector
  7. * @param {number} z The Z value of this vector
  8. */
  9. constructor(x, y, z) {
  10. this.x = x;
  11. this.y = y;
  12. this.z = z;
  13. }
  14. /**
  15. * Add another vector to this one
  16. *
  17. * @param {Vector3} operand The vector to add to this one
  18. * @returns {void}
  19. */
  20. add(operand) {
  21. this.x += operand.x;
  22. this.y += operand.y;
  23. this.z += operand.z;
  24. }
  25. /**
  26. * Flip the sign of all properties of the vector
  27. *
  28. * @returns {void}
  29. */
  30. negate() {
  31. this.x = -this.x;
  32. this.y = -this.y;
  33. this.z = -this.z;
  34. }
  35. };