gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
export interface IPoint {
  x: number
  y: number
}
 
export class Point implements IPoint {
  private _x: number;
 
  private _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; }
 
  public add(pt: IPoint): Point {
    return new Point(this.x + pt.x, this.y + pt.y);
  }
 
  public sub(pt: IPoint): Point {
    return new Point(this.x - pt.x, this.y - pt.y);
  }
 
  public mul(pt: IPoint): Point {
    return new Point(this.x * pt.x, this.y * pt.y);
  }
 
  public div(pt: IPoint): Point {
    return new Point(this.x / pt.x, this.y / pt.y);
  }
 
  public abs(): Point {
    return new Point(Math.abs(this.x), Math.abs(this.y));
  }
 
  public magnitude(): number {
    return Math.sqrt((this.x ** 2) + (this.y ** 2));
  }
 
  public floor(): Point {
    return new Point(Math.floor(this.x), Math.floor(this.y));
  }
}