summaryrefslogtreecommitdiff
path: root/packages/web/src/math/Coord.ts
blob: db7ee6d67d605531487fdca022852375180c72ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/** A coord on a grid whose origin is in the top left. */
export default class Coord {
  private readonly _x: number;
  private readonly _y: number;

  constructor(x: number, y: number) {
    this._x = x;
    this._y = y;
  }

  get x(): number {
    return this._x;
  }

  get y(): number {
    return this._y;
  }

  /** Get the squared distance of this point from the origin. */
  squaredDistanceFromOrigin(): number {
    return this._x * this._x + this._y * this._y;
  }
}