class Vector {
constructor(x, y) {
this.x = x;
this.y = y;
}
distance(other) {
let dx = this.x - other.x;
let dy = this.y - other.y;
return Math.hypot(dx, dy);
}
add(other) {
if (other instanceof Vector)
return new Vector(this.x + other.x, this.y + other.y);
else return new Vector(this.x + other, this.y + other);
}
sub(other) {
if (other instanceof Vector)
return new Vector(this.x - other.x, this.y - other.y);
else return new Vector(this.x - other, this.y - other);
}
mul(other) {
if (other instanceof Vector)
return new Vector(this.x * other.x, this.y * other.y);
else return new Vector(this.x * other, this.y * other);
}
div(other) {
if (other instanceof Vector)
return new Vector(this.x / other.x, this.y / other.y);
else return new Vector(this.x / other, this.y / other);
}
dot(other) {
return this.x * other.x + this.y * other.y;
}
get length() {
return Math.sqrt(this.dot(this));
}
get norm() {
return this.div(this.length);
}
normalize() {}
}