2024-10-26 14:24:38 +01:00
|
|
|
export default class Vec2 {
|
2023-11-02 08:31:43 +00:00
|
|
|
public x:number;
|
|
|
|
public y:number;
|
|
|
|
|
|
|
|
public constructor(x?:Vec2 | number, y?:number) {
|
|
|
|
if (typeof(x) === "number" && typeof(y) === "number") {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
} else if (typeof(x) === "number" && typeof(y) !== "number") {
|
|
|
|
this.x = x;
|
|
|
|
this.y = x;
|
|
|
|
} else if (x instanceof Vec2) {
|
|
|
|
this.x = x.x;
|
|
|
|
this.y = x.y;
|
|
|
|
} else {
|
|
|
|
this.x = this.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 10:56:28 +00:00
|
|
|
public get isZero() {
|
|
|
|
return this.x === 0 && this.y === 0;
|
|
|
|
}
|
|
|
|
|
2023-11-02 08:31:43 +00:00
|
|
|
public set(x?:Vec2 | number, y?:number) {
|
|
|
|
if (x instanceof Vec2) {
|
|
|
|
this.x = x.x;
|
|
|
|
this.y = x.y;
|
|
|
|
} else if (typeof(x) === "number" && typeof(y) === "number") {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
} else {
|
|
|
|
this.x = this.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|