aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-09 20:30:12 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-09 20:30:12 +0100
commit3c444c7e3300ea7df5dcc8811e216ff552136fa9 (patch)
tree80aa089d178f80e12c940ab441d507c24711f6eb /aoc-2022-dotnet
parent967e964f453fc031816270b90d6eab38410769a3 (diff)
downloadgleam_aoc2020-3c444c7e3300ea7df5dcc8811e216ff552136fa9.tar.gz
gleam_aoc2020-3c444c7e3300ea7df5dcc8811e216ff552136fa9.zip
Add Vec2 functions which might be useful in the coming days
Diffstat (limited to 'aoc-2022-dotnet')
-rw-r--r--aoc-2022-dotnet/Common/Vec2.fs14
1 files changed, 10 insertions, 4 deletions
diff --git a/aoc-2022-dotnet/Common/Vec2.fs b/aoc-2022-dotnet/Common/Vec2.fs
index 20b9956..bbe3ef2 100644
--- a/aoc-2022-dotnet/Common/Vec2.fs
+++ b/aoc-2022-dotnet/Common/Vec2.fs
@@ -5,9 +5,15 @@ type Vec2 =
static member zero = Vec2(0, 0)
- static member (+)(Vec2 (x1, y1), Vec2 (x2, y2)) = Vec2(x1 + x2, y1 + y2)
- static member (-)(Vec2 (x1, y1), Vec2 (x2, y2)) = Vec2(x1 - x2, y1 - y2)
+ static member inline (~-) = Vec2.map (~-)
+ static member inline (+)(Vec2 (x1, y1), Vec2 (x2, y2)) = Vec2(x1 + x2, y1 + y2)
+ static member inline (-)(v1, v2) = v1 + Vec2.op_UnaryNegation (v2)
+ static member inline (*)(v1, k) = Vec2.map ((*) k) v1
+ static member inline dot (Vec2 (x1, y1)) (Vec2 (x2, y2)) = x1 * x2 + y1 * y2
+ static member inline cross (Vec2 (x1, y1)) (Vec2 (x2, y2)) = x1 * y2 - y1 * x2
- static member apply f (Vec2 (x, y)) = Vec2(f x, f y)
- static member sign = Vec2.apply sign
+ static member map f (Vec2 (x, y)) = Vec2(f x, f y)
+ static member inline sign = Vec2.map sign
+ static member inline lengthSquared(Vec2 (x, y)) = x * x + y * y
+ static member mahattanDist (Vec2 (x1, y1)) (Vec2 (x2, y2)) = abs (x2 - x1) + abs (y2 - y1)
static member chebyshevDist (Vec2 (x1, y1)) (Vec2 (x2, y2)) = max (abs <| x2 - x1) (abs <| y2 - y1)