Skip to content

Commit

Permalink
closest orthagonal distance function (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 authored Oct 4, 2024
1 parent f7d77ac commit 4b051ae
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/math/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ export class Vec2 {
static UP = new Vec2(0, -1);
static DOWN = new Vec2(0, 1);

/** Closest orthogonal direction: LEFT, RIGHT, UP, or DOWN */
toAxis(): Vec2 {
return Math.abs(this.x) > Math.abs(this.y) ?
this.x < 0 ? Vec2.LEFT : Vec2.RIGHT :
this.y < 0 ? Vec2.UP : Vec2.DOWN;
}

/** Clone the vector */
clone(): Vec2 {
return new Vec2(this.x, this.y);
Expand Down

0 comments on commit 4b051ae

Please sign in to comment.