allow Vector2D scaling

This commit is contained in:
Jörn-Michael Miehe 2023-01-24 23:11:01 +00:00
parent 42ce94f313
commit a6c5a5469a
2 changed files with 11 additions and 0 deletions

View file

@ -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 {

View file

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