Moon.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const Vector3 = require("./Vector3");
  2. module.exports = class Moon {
  3. /**
  4. * @param {Vector3} position The starting position of the moon
  5. */
  6. constructor(position) {
  7. /**
  8. * The position of the moon in space
  9. */
  10. this.position = position;
  11. /**
  12. * The position of the moon at the time of creation
  13. *
  14. * This is a silly trick to get a clean copy of the Vector, but it works.
  15. *
  16. * @private
  17. */
  18. this._initialPosition = position.negate().negate();
  19. /**
  20. * The current velocity of the moon
  21. */
  22. this.velocity = new Vector3(0, 0, 0);
  23. }
  24. /**
  25. * Check whether or not the moon has returned to its initial position
  26. *
  27. * @returns {bool} True if the current position is the same as the initial position and if the velocity is zero
  28. */
  29. hasReachedInitialState() {
  30. return (
  31. this._initialPosition.x == this.position.x
  32. && this._initialPosition.y == this.position.y
  33. && this._initialPosition.z == this.position.z
  34. ) && (
  35. this.velocity.x == 0
  36. && this.velocity.y == 0
  37. && this.velocity.z == 0
  38. );
  39. }
  40. };