Various refactoring
This commit is contained in:
+13
-20
@@ -22,21 +22,6 @@ import Data.Maybe
|
||||
--import qualified Data.IntSet as IS
|
||||
--import qualified Data.Set as S
|
||||
|
||||
leftPad :: Int -> a -> [a] -> [a]
|
||||
leftPad i x xs = reverse $ take i $ reverse (take i xs) ++ repeat x
|
||||
|
||||
rightPad :: Int -> a -> [a] -> [a]
|
||||
rightPad i x xs = take i $ xs ++ repeat x
|
||||
|
||||
midPad :: Int -> a -> [a] -> [a] -> [a]
|
||||
midPad i x xs ys = xs ++ replicate j x ++ ys
|
||||
where
|
||||
j = i - (length xs + length ys)
|
||||
|
||||
midPadL :: Int -> a -> [a] -> [a] -> [a]
|
||||
midPadL i x xs ys = take j (xs ++ repeat x) ++ ys
|
||||
where
|
||||
j = i - length ys
|
||||
|
||||
{- | Implementation copied from
|
||||
- https://hackage.haskell.org/package/utility-ht-0.0.16/docs/src/Data.List.HT.Private.html#takeUntil
|
||||
@@ -428,10 +413,9 @@ nearestCrInFront p dir x w
|
||||
crInPolygon :: Creature -> [Point2] -> Bool
|
||||
crInPolygon cr = errorPointInPolygon 3 (_crPos cr)
|
||||
|
||||
--The following two functions should be unified
|
||||
{- | Transform coordinates from world position to normalised screen coordinates. -}
|
||||
worldPosToScreen :: World -> Point2 -> Point2
|
||||
worldPosToScreen w = doWindowScale . doRotate . doZoom . doTranslate
|
||||
{- | Transform coordinates from world position to screen coordinates. -}
|
||||
worldPosToScreenNorm :: World -> Point2 -> Point2
|
||||
worldPosToScreenNorm w = doWindowScale . doRotate . doZoom . doTranslate
|
||||
where
|
||||
doTranslate p = p -.- _cameraCenter w
|
||||
doZoom p = _cameraZoom w *.* p
|
||||
@@ -439,7 +423,16 @@ worldPosToScreen w = doWindowScale . doRotate . doZoom . doTranslate
|
||||
doWindowScale (V2 x y) = V2
|
||||
( x * 2 / getWindowX w)
|
||||
( y * 2 / getWindowY w)
|
||||
{- | Transform coordinates from the map position to normalised screen
|
||||
{- | Transform world coordinates to scaled screen coordinates.
|
||||
- These have to be according to the size of the window to get actual screen positions.
|
||||
- This allows for line thicknesses etc to correspond to pixel sizes.-}
|
||||
worldPosToScreen :: World -> Point2 -> Point2
|
||||
worldPosToScreen w = doRotate . doZoom . doTranslate
|
||||
where
|
||||
doTranslate p = p -.- _cameraCenter w
|
||||
doZoom p = _cameraZoom w *.* p
|
||||
doRotate p = rotateV (negate $ _cameraRot w) p
|
||||
{- | Transform coordinates from the map position to screen
|
||||
coordinates. -}
|
||||
cartePosToScreen :: World -> Point2 -> Point2
|
||||
cartePosToScreen w = doWindowScale . doRotate . doZoom . doTranslate
|
||||
|
||||
Reference in New Issue
Block a user