refactor
This commit is contained in:
@@ -38,9 +38,14 @@ export default class Vec2d implements Point {
|
||||
|
||||
normalize(): Vec2d {
|
||||
const len = this.length();
|
||||
if (len === 0) return new Vec2d(0, 0); // avoid division by zero
|
||||
return new Vec2d(this.x / len, this.y / len);
|
||||
}
|
||||
|
||||
neg(): Vec2d {
|
||||
return new Vec2d(-this.x, -this.y);
|
||||
}
|
||||
|
||||
scale(scalar: number): Vec2d {
|
||||
return new Vec2d(this.x * scalar, this.y * scalar);
|
||||
}
|
||||
@@ -61,6 +66,10 @@ export default class Vec2d implements Point {
|
||||
return this.sub(other).length();
|
||||
}
|
||||
|
||||
dot(other: Vec2d): number {
|
||||
return this.x * other.x + this.y * other.y;
|
||||
}
|
||||
|
||||
lerp(other: Vec2d, t: number): Vec2d {
|
||||
// (1-t)*A + B*t
|
||||
return this.scale(1 - t).add(other.scale(t));
|
||||
|
||||
Reference in New Issue
Block a user