feat: Vector.angle
This commit is contained in:
parent
c6e14e5eb8
commit
3566640678
|
@ -255,6 +255,10 @@ export function toDirection4(vector) {
|
|||
}
|
||||
}
|
||||
|
||||
export function angle(v) {
|
||||
return Math.atan2(v[1], v[0]);
|
||||
}
|
||||
|
||||
// Convert a vector to an 8-direction. An 8-direction is:
|
||||
//
|
||||
// * 0: Up
|
||||
|
@ -274,7 +278,7 @@ export function toDirection4(vector) {
|
|||
export function toDirection8(v) {
|
||||
v = hypotenuse(v);
|
||||
// Orient radians.
|
||||
let rad = (TWO_PI + Math.atan2(v[1], v[0])) % TWO_PI;
|
||||
let rad = (TWO_PI + angle(v)) % TWO_PI;
|
||||
rad = (rad + HALF_PI) % TWO_PI;
|
||||
// Truncate.
|
||||
rad = Math.floor(rad * 100000) / 100000;
|
||||
|
|
Loading…
Reference in New Issue
Block a user