mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-12-23 21:22:59 +00:00
allow Vector2D scaling
This commit is contained in:
parent
42ce94f313
commit
a6c5a5469a
2 changed files with 11 additions and 0 deletions
|
@ -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 {
|
||||
|
|
|
@ -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", () => {
|
||||
|
|
Loading…
Reference in a new issue