more informative Declare error when no placed locks
[intricacy.git] / CVec.hs
blob0b6d366378a7d34eb520bec8dafff5b9656dc3b6
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 Hex
14 import Data.Monoid
16 data CVec = CVec { cy, cx :: Int }
17 deriving (Eq, Ord, Show)
18 instance Monoid CVec where
19 mempty = CVec 0 0
20 mappend (CVec y x) (CVec y' x') = CVec (y+y') (x+x')
21 instance Grp CVec where
22 neg (CVec y x) = CVec (-y) (-x)
23 type CCoord = PHS CVec
25 hexVec2CVec :: HexVec -> CVec
26 hexVec2CVec (HexVec x y z) = CVec (-y) (x-z)
27 cVec2HexVec :: CVec -> HexVec
28 cVec2HexVec (CVec y x) = HexVec ((x+y)`div`2) (-y) ((y-x)`div`2)
30 truncateCVec :: CVec -> CVec
31 truncateCVec (CVec x y) = CVec (max 0 x) (max 0 y)