diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-12-02 14:16:56 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-12-02 14:16:56 -0700 |
commit | cfd970e21663c3278f6e01d356690789225b6b56 (patch) | |
tree | a868659cc8425cc47ba1cd02509b3fe80632039c /utils/point2d.ts | |
parent | 118fc144884f0d716cc03e877aa85f83d289cec8 (diff) | |
download | aoc-cfd970e21663c3278f6e01d356690789225b6b56.tar.gz aoc-cfd970e21663c3278f6e01d356690789225b6b56.zip |
2022 day 9 and add utils
Diffstat (limited to 'utils/point2d.ts')
-rw-r--r-- | utils/point2d.ts | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/utils/point2d.ts b/utils/point2d.ts new file mode 100644 index 0000000..3d07569 --- /dev/null +++ b/utils/point2d.ts @@ -0,0 +1,9 @@ +export type Vec2 = { + x: number; + y: number; +}; + +export const l2Norm = (p1: Vec2, p2: Vec2) => + Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)); + +export const isDiagAdj = (p1: Vec2, p2: Vec2) => l2Norm(p1, p2) <= Math.sqrt(2); |