module Game.LambdaHack.Common.VectorXY
( VectorXY(..), shiftXY, movesXY, movesCardinalXY
, chessDistXY, euclidDistSqXY, negXY, vicinityXY, vicinityCardinalXY
) where
import Data.Binary
import Game.LambdaHack.Common.PointXY
newtype VectorXY = VectorXY (X, Y)
deriving (Eq, Ord, Show, Read, Binary)
shiftXY :: PointXY -> VectorXY -> PointXY
shiftXY (PointXY (x0, y0)) (VectorXY (x1, y1)) = PointXY (x0 + x1, y0 + y1)
movesXY :: [VectorXY]
movesXY =
map VectorXY
[(1, 1), (0, 1), (1, 1), (1, 0), (1, 1), (0, 1), (1, 1), (1, 0)]
movesCardinalXY :: [VectorXY]
movesCardinalXY = map VectorXY [(0, 1), (1, 0), (0, 1), (1, 0)]
chessDistXY :: VectorXY -> Int
chessDistXY (VectorXY (x, y)) = max (abs x) (abs y)
euclidDistSqXY :: VectorXY -> Int
euclidDistSqXY (VectorXY (x, y)) = x * x + y * y
negXY :: VectorXY -> VectorXY
negXY (VectorXY (x, y)) = VectorXY (x, y)
vicinityXY :: (X, Y, X, Y)
-> PointXY
-> [PointXY]
vicinityXY area xy =
[ res | dxy <- movesXY, let res = shiftXY xy dxy, insideXY res area ]
vicinityCardinalXY :: (X, Y, X, Y)
-> PointXY
-> [PointXY]
vicinityCardinalXY area xy =
[ res
| dxy <- movesCardinalXY, let res = shiftXY xy dxy, insideXY res area ]