1 -- This file is part of Intricacy
2 -- Copyright (C) 2013 Martin Bays <mbays@sdf.org>
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.
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/.
14 import Data
.Semigroup
as Sem
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
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
)