Vector3.js 826 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 {Vector3} A new Vector3
  29. */
  30. negate() {
  31. return new Vector3(
  32. -this.x,
  33. -this.y,
  34. -this.z,
  35. );
  36. }
  37. };