39 lines
530 B
JavaScript
39 lines
530 B
JavaScript
export class Vec2 {
|
|
constructor(x, y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
addTo(o) {
|
|
this.x += o.x;
|
|
this.y += o.y;
|
|
}
|
|
|
|
isInside(lt, rb) {
|
|
return this.x >= lt.x && this.x < rb.x && this.y >= lt.y && this.y < rb.y;
|
|
}
|
|
|
|
clone() {
|
|
return new Vec2(this.x, this.y);
|
|
}
|
|
|
|
equals(o) {
|
|
return this.x == o.x && this.y == o.y;
|
|
}
|
|
|
|
match(x, y) {
|
|
return this.x == x && this.y == y;
|
|
}
|
|
|
|
toString() {
|
|
return `(${this.x}, ${this.y})`;
|
|
}
|
|
|
|
static fromRaw(o) {
|
|
return new Vec2(o.x, o.y);
|
|
}
|
|
|
|
static zero = new Vec2(0, 0);
|
|
};
|
|
|