summaryrefslogtreecommitdiff
path: root/utils/point2d.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-12-02 14:16:56 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-12-02 14:16:56 -0700
commitcfd970e21663c3278f6e01d356690789225b6b56 (patch)
treea868659cc8425cc47ba1cd02509b3fe80632039c /utils/point2d.ts
parent118fc144884f0d716cc03e877aa85f83d289cec8 (diff)
downloadaoc-cfd970e21663c3278f6e01d356690789225b6b56.tar.gz
aoc-cfd970e21663c3278f6e01d356690789225b6b56.zip
2022 day 9 and add utils
Diffstat (limited to 'utils/point2d.ts')
-rw-r--r--utils/point2d.ts9
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);