tiny vector perf improvements
This commit is contained in:
parent
3607ce237a
commit
b850fc9704
|
|
@ -57,7 +57,7 @@ export class Vector {
|
||||||
* @returns {number} The magnitude of the vector
|
* @returns {number} The magnitude of the vector
|
||||||
*/
|
*/
|
||||||
static mag(v: Point): number {
|
static mag(v: Point): number {
|
||||||
return hypot(v.x, v.y);
|
return Math.sqrt(v.x * v.x + v.y * v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -80,7 +80,9 @@ export class Vector {
|
||||||
* @returns {number} The distance between the points
|
* @returns {number} The distance between the points
|
||||||
*/
|
*/
|
||||||
static distance(a: Point, b: Point): number {
|
static distance(a: Point, b: Point): number {
|
||||||
return hypot(a.x - b.x, a.y - b.y);
|
const dx = a.x - b.x;
|
||||||
|
const dy = a.y - b.y;
|
||||||
|
return Math.sqrt(dx * dx + dy * dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -179,4 +181,13 @@ export class Vector {
|
||||||
y: point.y - origin.y,
|
y: point.y - origin.y,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the squared magnitude of a vector
|
||||||
|
* @param {Point} v - The vector
|
||||||
|
* @returns {number} The squared magnitude of the vector
|
||||||
|
*/
|
||||||
|
static magSquared(v: Point): number {
|
||||||
|
return v.x * v.x + v.y * v.y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue