Source: core/math/Point.js

core/math/Point.js

  1. /**
  2. * The Point object represents a location in a two-dimensional coordinate system, where x represents
  3. * the horizontal axis and y represents the vertical axis.
  4. *
  5. * @class
  6. * @memberof PIXI
  7. */
  8. export default class Point
  9. {
  10. /**
  11. * @param {number} [x=0] - position of the point on the x axis
  12. * @param {number} [y=0] - position of the point on the y axis
  13. */
  14. constructor(x = 0, y = 0)
  15. {
  16. /**
  17. * @member {number}
  18. * @default 0
  19. */
  20. this.x = x;
  21. /**
  22. * @member {number}
  23. * @default 0
  24. */
  25. this.y = y;
  26. }
  27. /**
  28. * Creates a clone of this point
  29. *
  30. * @return {PIXI.Point} a copy of the point
  31. */
  32. clone()
  33. {
  34. return new Point(this.x, this.y);
  35. }
  36. /**
  37. * Copies x and y from the given point
  38. *
  39. * @param {PIXI.Point} p - The point to copy.
  40. */
  41. copy(p)
  42. {
  43. this.set(p.x, p.y);
  44. }
  45. /**
  46. * Returns true if the given point is equal to this point
  47. *
  48. * @param {PIXI.Point} p - The point to check
  49. * @returns {boolean} Whether the given point equal to this point
  50. */
  51. equals(p)
  52. {
  53. return (p.x === this.x) && (p.y === this.y);
  54. }
  55. /**
  56. * Sets the point to a new x and y position.
  57. * If y is omitted, both x and y will be set to x.
  58. *
  59. * @param {number} [x=0] - position of the point on the x axis
  60. * @param {number} [y=0] - position of the point on the y axis
  61. */
  62. set(x, y)
  63. {
  64. this.x = x || 0;
  65. this.y = y || ((y !== 0) ? this.x : 0);
  66. }
  67. }