module BishBosh.Cartesian.Ordinate(
yLength,
yMin,
yMax,
yBounds,
yRange,
toIx,
fromIx,
firstRank,
lastRank,
pawnsFirstRank,
enPassantRank,
reflect,
translate,
maybeTranslate,
inBounds
) where
import qualified BishBosh.Cartesian.Abscissa as Cartesian.Abscissa
import qualified BishBosh.Colour.LogicalColour as Colour.LogicalColour
import qualified BishBosh.Property.Opposable as Property.Opposable
import qualified BishBosh.Type.Length as Type.Length
import qualified Control.Exception
yLength :: Type.Length.Y
yLength :: Y
yLength = Y -> Y
forall a b. (Integral a, Num b) => a -> b
fromIntegral Y
Cartesian.Abscissa.xLength
yBounds :: (Type.Length.Y, Type.Length.Y)
yMin, yMax :: Type.Length.Y
yBounds :: (Y, Y)
yBounds@(Y
yMin, Y
yMax) = (Y
0, Y
yMin Y -> Y -> Y
forall a. Num a => a -> a -> a
+ Y -> Y
forall a. Enum a => a -> a
pred Y
yLength)
yRange :: [Type.Length.Y]
yRange :: [Y]
yRange = (Y -> Y -> [Y]) -> (Y, Y) -> [Y]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Y -> Y -> [Y]
forall a. Enum a => a -> a -> [a]
enumFromTo (Y, Y)
yBounds
toIx :: Type.Length.Y -> Int
{-# INLINE toIx #-}
toIx :: Y -> Y
toIx = Y -> Y
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Y -> Y) -> (Y -> Y) -> Y -> Y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Y -> Y -> Y
forall a. Num a => a -> a -> a
subtract Y
yMin
fromIx :: Int -> Type.Length.Y
{-# INLINE fromIx #-}
fromIx :: Y -> Y
fromIx = (Y -> Y -> Y
forall a. Num a => a -> a -> a
+ Y
yMin) (Y -> Y) -> (Y -> Y) -> Y -> Y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Y -> Y
forall a b. (Integral a, Num b) => a -> b
fromIntegral
firstRank :: Colour.LogicalColour.LogicalColour -> Type.Length.Y
firstRank :: LogicalColour -> Y
firstRank LogicalColour
Colour.LogicalColour.Black = Y
yMax
firstRank LogicalColour
_ = Y
yMin
lastRank :: Colour.LogicalColour.LogicalColour -> Type.Length.Y
lastRank :: LogicalColour -> Y
lastRank = LogicalColour -> Y
firstRank (LogicalColour -> Y)
-> (LogicalColour -> LogicalColour) -> LogicalColour -> Y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicalColour -> LogicalColour
forall a. Opposable a => a -> a
Property.Opposable.getOpposite
pawnsFirstRank :: Colour.LogicalColour.LogicalColour -> Type.Length.Y
{-# INLINE pawnsFirstRank #-}
pawnsFirstRank :: LogicalColour -> Y
pawnsFirstRank LogicalColour
Colour.LogicalColour.Black = Y -> Y
forall a. Enum a => a -> a
pred Y
yMax
pawnsFirstRank LogicalColour
_ = Y -> Y
forall a. Enum a => a -> a
succ Y
yMin
enPassantRank :: Colour.LogicalColour.LogicalColour -> Type.Length.Y
{-# INLINE enPassantRank #-}
enPassantRank :: LogicalColour -> Y
enPassantRank LogicalColour
Colour.LogicalColour.Black = Y -> Y
fromIx Y
3
enPassantRank LogicalColour
_ = Y -> Y
fromIx Y
4
reflect :: Type.Length.Y -> Type.Length.Y
reflect :: Y -> Y
reflect = (
Y -> Y -> Y
forall a. Num a => a -> a -> a
+ (Y
2 Y -> Y -> Y
forall a. Num a => a -> a -> a
* Y
yMin Y -> Y -> Y
forall a. Num a => a -> a -> a
+ Y -> Y
forall a. Enum a => a -> a
pred Y
yLength)
) (Y -> Y) -> (Y -> Y) -> Y -> Y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Y -> Y
forall a. Num a => a -> a
negate
inBounds :: Type.Length.Y -> Bool
{-# INLINE inBounds #-}
inBounds :: Y -> Bool
inBounds Y
y = Y
y Y -> Y -> Bool
forall a. Ord a => a -> a -> Bool
>= Y
yMin Bool -> Bool -> Bool
&& Y
y Y -> Y -> Bool
forall a. Ord a => a -> a -> Bool
<= Y
yMax
translate :: (Type.Length.Y -> Type.Length.Y) -> Type.Length.Y -> Type.Length.Y
translate :: (Y -> Y) -> Y -> Y
translate Y -> Y
transformation = (\Y
y -> Bool -> Y -> Y
forall a. (?callStack::CallStack) => Bool -> a -> a
Control.Exception.assert (Y -> Bool
inBounds Y
y) Y
y) (Y -> Y) -> (Y -> Y) -> Y -> Y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Y -> Y
transformation
maybeTranslate :: (Type.Length.Y -> Type.Length.Y) -> Type.Length.Y -> Maybe Type.Length.Y
maybeTranslate :: (Y -> Y) -> Y -> Maybe Y
maybeTranslate Y -> Y
transformation = (
\Y
y -> if Y -> Bool
inBounds Y
y
then Y -> Maybe Y
forall a. a -> Maybe a
Just Y
y
else Maybe Y
forall a. Maybe a
Nothing
) (Y -> Maybe Y) -> (Y -> Y) -> Y -> Maybe Y
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Y -> Y
transformation