mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 08:13:01 +00:00
27 lines
630 B
TypeScript
27 lines
630 B
TypeScript
export class Vector2D {
|
|
public readonly x: number;
|
|
public readonly y: number;
|
|
|
|
constructor();
|
|
constructor(x: number, y: number);
|
|
constructor(x = 0, y = 0) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
public plus(other: Vector2D): Vector2D {
|
|
return new Vector2D(this.x + other.x, this.y + other.y);
|
|
}
|
|
|
|
public minus(other: Vector2D): Vector2D {
|
|
return new Vector2D(this.x - other.x, this.y - other.y);
|
|
}
|
|
|
|
public scale(other: number): Vector2D {
|
|
return new Vector2D(this.x * other, this.y * other);
|
|
}
|
|
|
|
public equals(other: Vector2D): boolean {
|
|
return this.x === other.x && this.y === other.y;
|
|
}
|
|
}
|