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", () => {