-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vectors): migrate direction(), normalLeft/Right2() from geom pkg
- Loading branch information
1 parent
862ed08
commit 07d5f8f
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ReadonlyVec, Vec } from "./api"; | ||
import { normalize } from "./normalize"; | ||
import { sub } from "./sub"; | ||
|
||
/** | ||
* Computes direction vector `a` -> `b`, normalized to length `n` | ||
* (default 1). | ||
* | ||
* @param a | ||
* @param b | ||
* @param n | ||
*/ | ||
export const direction = | ||
(out: Vec, a: ReadonlyVec, b: ReadonlyVec, n = 1) => | ||
normalize(null, sub(out || a, b, a), n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ReadonlyVec, Vec } from "./api"; | ||
import { direction } from "./direction"; | ||
import { perpendicularLeft2, perpendicularRight2 } from "./perpendicular"; | ||
|
||
/** | ||
* Computes 2D normal by rotating direction vector `a` -> `b`, 90 deg | ||
* counterclockwise, normalized to length `n` (default: 1). If `out` is | ||
* null, creates new vector. | ||
* | ||
* @param out | ||
* @param a | ||
* @param b | ||
* @param n | ||
*/ | ||
export const normalLeft2 = | ||
(out: Vec, a: ReadonlyVec, b: ReadonlyVec, n = 1) => | ||
perpendicularLeft2(null, direction(out || [], a, b, n)); | ||
|
||
/** | ||
* Computes 2D normal by rotating direction vector `a` -> `b`, 90 deg | ||
* clockwise, normalized to length `n` (default: 1). If `out` is null, | ||
* creates new vector. | ||
* | ||
* @param out | ||
* @param a | ||
* @param b | ||
* @param n | ||
*/ | ||
export const normalRight2 = | ||
(out: Vec, a: ReadonlyVec, b: ReadonlyVec, n = 1) => | ||
perpendicularRight2(null, direction(out || [], a, b, n)); |