{-# Language ImportQualifiedPost, DeriveGeneric #-}
module Advent.Coord3 where
data Coord3 = C3 !Int !Int !Int deriving (Coord3 -> Coord3 -> Bool
(Coord3 -> Coord3 -> Bool)
-> (Coord3 -> Coord3 -> Bool) -> Eq Coord3
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Coord3 -> Coord3 -> Bool
$c/= :: Coord3 -> Coord3 -> Bool
== :: Coord3 -> Coord3 -> Bool
$c== :: Coord3 -> Coord3 -> Bool
Eq, Eq Coord3
Eq Coord3
-> (Coord3 -> Coord3 -> Ordering)
-> (Coord3 -> Coord3 -> Bool)
-> (Coord3 -> Coord3 -> Bool)
-> (Coord3 -> Coord3 -> Bool)
-> (Coord3 -> Coord3 -> Bool)
-> (Coord3 -> Coord3 -> Coord3)
-> (Coord3 -> Coord3 -> Coord3)
-> Ord Coord3
Coord3 -> Coord3 -> Bool
Coord3 -> Coord3 -> Ordering
Coord3 -> Coord3 -> Coord3
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Coord3 -> Coord3 -> Coord3
$cmin :: Coord3 -> Coord3 -> Coord3
max :: Coord3 -> Coord3 -> Coord3
$cmax :: Coord3 -> Coord3 -> Coord3
>= :: Coord3 -> Coord3 -> Bool
$c>= :: Coord3 -> Coord3 -> Bool
> :: Coord3 -> Coord3 -> Bool
$c> :: Coord3 -> Coord3 -> Bool
<= :: Coord3 -> Coord3 -> Bool
$c<= :: Coord3 -> Coord3 -> Bool
< :: Coord3 -> Coord3 -> Bool
$c< :: Coord3 -> Coord3 -> Bool
compare :: Coord3 -> Coord3 -> Ordering
$ccompare :: Coord3 -> Coord3 -> Ordering
Ord, Int -> Coord3 -> ShowS
[Coord3] -> ShowS
Coord3 -> String
(Int -> Coord3 -> ShowS)
-> (Coord3 -> String) -> ([Coord3] -> ShowS) -> Show Coord3
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Coord3] -> ShowS
$cshowList :: [Coord3] -> ShowS
show :: Coord3 -> String
$cshow :: Coord3 -> String
showsPrec :: Int -> Coord3 -> ShowS
$cshowsPrec :: Int -> Coord3 -> ShowS
Show)
origin :: Coord3
origin :: Coord3
origin = Int -> Int -> Int -> Coord3
C3 Int
0 Int
0 Int
0
manhattan :: Coord3 -> Coord3 -> Int
manhattan :: Coord3 -> Coord3 -> Int
manhattan (C3 Int
x1 Int
y1 Int
z1) (C3 Int
x2 Int
y2 Int
z2) = Int -> Int
forall a. Num a => a -> a
abs (Int
x1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
x2) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int
forall a. Num a => a -> a
abs (Int
y1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
y2) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int
forall a. Num a => a -> a
abs (Int
z1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
z2)
diff :: Coord3 -> Coord3 -> Coord3
diff :: Coord3 -> Coord3 -> Coord3
diff (C3 Int
x Int
y Int
z) (C3 Int
x' Int
y' Int
z') = Int -> Int -> Int -> Coord3
C3 (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
x') (Int
yInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
y') (Int
zInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
z')
add :: Coord3 -> Coord3 -> Coord3
add :: Coord3 -> Coord3 -> Coord3
add (C3 Int
x Int
y Int
z) (C3 Int
x' Int
y' Int
z') = Int -> Int -> Int -> Coord3
C3 (Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
x') (Int
yInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y') (Int
zInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
z')