From 967e964f453fc031816270b90d6eab38410769a3 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Fri, 9 Dec 2022 19:31:24 +0100 Subject: Extract common functions to util module --- aoc-2022-dotnet/Common/Vec2.fs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 aoc-2022-dotnet/Common/Vec2.fs (limited to 'aoc-2022-dotnet/Common/Vec2.fs') diff --git a/aoc-2022-dotnet/Common/Vec2.fs b/aoc-2022-dotnet/Common/Vec2.fs new file mode 100644 index 0000000..20b9956 --- /dev/null +++ b/aoc-2022-dotnet/Common/Vec2.fs @@ -0,0 +1,13 @@ +namespace Common + +type Vec2 = + | Vec2 of int * int + + 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 apply f (Vec2 (x, y)) = Vec2(f x, f y) + static member sign = Vec2.apply sign + static member chebyshevDist (Vec2 (x1, y1)) (Vec2 (x2, y2)) = max (abs <| x2 - x1) (abs <| y2 - y1) -- cgit v1.2.3