diff options
| author | uakci <git@uakci.space> | 2024-04-13 13:48:55 +0000 |
|---|---|---|
| committer | uakci <git@uakci.space> | 2024-04-13 13:48:55 +0000 |
| commit | 7d14ee03e9fdad3736f14748115ad5a55c0dcd53 (patch) | |
| tree | d9cf89e7bfa9b82a7551197cfb4a853c7826313a /src/V2.ts | |
| download | runicity-7d14ee03e9fdad3736f14748115ad5a55c0dcd53.tar.gz runicity-7d14ee03e9fdad3736f14748115ad5a55c0dcd53.zip | |
Diffstat (limited to 'src/V2.ts')
| -rw-r--r-- | src/V2.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/V2.ts b/src/V2.ts new file mode 100644 index 0000000..5ef60b3 --- /dev/null +++ b/src/V2.ts @@ -0,0 +1,38 @@ +export default class V2 { + readonly x: number; + readonly y: number; + + constructor(x: number, y: number) { + this.x = x; + this.y = y; + } + + static get zero() { + return new V2(0, 0); + } + + toString() { + return `(${this.x}, ${this.y})`; + } + + *[Symbol.iterator]() { + yield this.x; + yield this.y; + } + + scale(factor: number) { + return new V2(this.x * factor, this.y * factor); + } + + get neg() { + return this.scale(-1); + } + + add(other: V2) { + return new V2(this.x + other.x, this.y + other.y); + } + + sub(other: V2) { + return this.add(other.neg); + } +} |
