From a6c5a5469a5342dbe7d27db76dafa0bc2ef5ece8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Jan 2023 23:11:01 +0000 Subject: [PATCH] allow Vector2D scaling --- ui/src/components/rects/rectangles.ts | 5 +++++ ui/tests/unit/rectangle.spec.ts | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ui/src/components/rects/rectangles.ts b/ui/src/components/rects/rectangles.ts index 9273cc0..7b15b61 100644 --- a/ui/src/components/rects/rectangles.ts +++ b/ui/src/components/rects/rectangles.ts @@ -10,9 +10,14 @@ export class Vector2D { 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); + } } export class Rectangle { diff --git a/ui/tests/unit/rectangle.spec.ts b/ui/tests/unit/rectangle.spec.ts index 16a625c..50eec6a 100644 --- a/ui/tests/unit/rectangle.spec.ts +++ b/ui/tests/unit/rectangle.spec.ts @@ -20,6 +20,12 @@ describe("Vector2D Tests", () => { expect(v2.x).to.equal(-2); expect(v2.y).to.equal(-2); }); + + it("should scale vectors", () => { + const v2 = v.scale(3); + expect(v2.x).to.equal(3); + expect(v2.y).to.equal(6); + }); }); describe("Rectangle Tests", () => {