summaryrefslogtreecommitdiff
path: root/utils/point2d.ts
diff options
context:
space:
mode:
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);