compilation fixes
[intricacy.git] / CVec.hs
blobab2ec99ad25d0b43a03f919932d927323e9a7dc7
1 -- This file is part of Intricacy
2 -- Copyright (C) 2013 Martin Bays <mbays@sdf.org>
3 --
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
7 --
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
11 module CVec where
13 import Data.Monoid
14 import Data.Semigroup as Sem
15 import Hex
17 data CVec = CVec { cy, cx :: Int }
18 deriving (Eq, Ord, Show)
19 instance Sem.Semigroup CVec where
20 (CVec y x) <> (CVec y' x') = CVec (y+y') (x+x')
21 instance Monoid CVec where
22 mempty = CVec 0 0
23 mappend = (Sem.<>)
24 instance Grp CVec where
25 neg (CVec y x) = CVec (-y) (-x)
26 type CCoord = PHS CVec
28 hexVec2CVec :: HexVec -> CVec
29 hexVec2CVec (HexVec x y z) = CVec (-y) (x-z)
30 cVec2HexVec :: CVec -> HexVec
31 cVec2HexVec (CVec y x) = HexVec ((x+y)`div`2) (-y) ((y-x)`div`2)
33 truncateCVec :: CVec -> CVec
34 truncateCVec (CVec x y) = CVec (max 0 x) (max 0 y)