{-# LANGUAGE PatternSynonyms #-}
module Swarm.Game.World.Coords (
Coords (..),
locToCoords,
coordsToLoc,
BoundsRectangle,
)
where
import Control.Lens (Rewrapped, Wrapped)
import Data.Array.IArray (Ix)
import Data.Int (Int32)
import GHC.Generics (Generic)
import Swarm.Game.Location (Location, pattern Location)
newtype Coords = Coords {Coords -> (Int32, Int32)
unCoords :: (Int32, Int32)}
deriving (Coords -> Coords -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Coords -> Coords -> Bool
$c/= :: Coords -> Coords -> Bool
== :: Coords -> Coords -> Bool
$c== :: Coords -> Coords -> Bool
Eq, Eq Coords
Coords -> Coords -> Bool
Coords -> Coords -> Ordering
Coords -> Coords -> Coords
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 :: Coords -> Coords -> Coords
$cmin :: Coords -> Coords -> Coords
max :: Coords -> Coords -> Coords
$cmax :: Coords -> Coords -> Coords
>= :: Coords -> Coords -> Bool
$c>= :: Coords -> Coords -> Bool
> :: Coords -> Coords -> Bool
$c> :: Coords -> Coords -> Bool
<= :: Coords -> Coords -> Bool
$c<= :: Coords -> Coords -> Bool
< :: Coords -> Coords -> Bool
$c< :: Coords -> Coords -> Bool
compare :: Coords -> Coords -> Ordering
$ccompare :: Coords -> Coords -> Ordering
Ord, Int -> Coords -> ShowS
[Coords] -> ShowS
Coords -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Coords] -> ShowS
$cshowList :: [Coords] -> ShowS
show :: Coords -> String
$cshow :: Coords -> String
showsPrec :: Int -> Coords -> ShowS
$cshowsPrec :: Int -> Coords -> ShowS
Show, Ord Coords
(Coords, Coords) -> Int
(Coords, Coords) -> [Coords]
(Coords, Coords) -> Coords -> Bool
(Coords, Coords) -> Coords -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
unsafeRangeSize :: (Coords, Coords) -> Int
$cunsafeRangeSize :: (Coords, Coords) -> Int
rangeSize :: (Coords, Coords) -> Int
$crangeSize :: (Coords, Coords) -> Int
inRange :: (Coords, Coords) -> Coords -> Bool
$cinRange :: (Coords, Coords) -> Coords -> Bool
unsafeIndex :: (Coords, Coords) -> Coords -> Int
$cunsafeIndex :: (Coords, Coords) -> Coords -> Int
index :: (Coords, Coords) -> Coords -> Int
$cindex :: (Coords, Coords) -> Coords -> Int
range :: (Coords, Coords) -> [Coords]
$crange :: (Coords, Coords) -> [Coords]
Ix, forall x. Rep Coords x -> Coords
forall x. Coords -> Rep Coords x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Coords x -> Coords
$cfrom :: forall x. Coords -> Rep Coords x
Generic)
instance Rewrapped Coords t
instance Wrapped Coords
locToCoords :: Location -> Coords
locToCoords :: Location -> Coords
locToCoords (Location Int32
x Int32
y) = (Int32, Int32) -> Coords
Coords (-Int32
y, Int32
x)
coordsToLoc :: Coords -> Location
coordsToLoc :: Coords -> Location
coordsToLoc (Coords (Int32
r, Int32
c)) = Int32 -> Int32 -> Location
Location Int32
c (-Int32
r)
type BoundsRectangle = (Coords, Coords)