| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Game.LambdaHack.Common.Vector
Contents
Description
Basic operations on bounded 2D vectors, with an efficient, but not 1-1
and not monotonic Enum instance.
Synopsis
- data Vector = Vector {}
- isUnit :: Vector -> Bool
- isDiagonal :: Vector -> Bool
- neg :: Vector -> Vector
- chessDistVector :: Vector -> Int
- euclidDistSqVector :: Vector -> Vector -> Int
- moves :: [Vector]
- movesCardinal :: [Vector]
- movesDiagonal :: [Vector]
- compassText :: Vector -> Text
- vicinity :: X -> Y -> Point -> [Point]
- vicinityUnsafe :: Point -> [Point]
- vicinityCardinal :: X -> Y -> Point -> [Point]
- vicinityCardinalUnsafe :: Point -> [Point]
- squareUnsafeSet :: Point -> EnumSet Point
- shift :: Point -> Vector -> Point
- shiftBounded :: X -> Y -> Point -> Vector -> Point
- trajectoryToPath :: Point -> [Vector] -> [Point]
- trajectoryToPathBounded :: X -> Y -> Point -> [Vector] -> [Point]
- vectorToFrom :: Point -> Point -> Vector
- computeTrajectory :: Int -> Int -> Int -> [Point] -> ([Vector], (Speed, Int))
- type RadianAngle = Double
- rotate :: RadianAngle -> Vector -> Vector
- towards :: Point -> Point -> Vector
- maxVectorDim :: Int
- _moveTexts :: [Text]
- longMoveTexts :: [Text]
- normalize :: Double -> Double -> Vector
- normalizeVector :: Vector -> Vector
- pathToTrajectory :: [Point] -> [Vector]
Documentation
2D vectors in cartesian representation. Coordinates grow to the right and down, so that the (1, 1) vector points to the bottom-right corner of the screen.
Instances
| Enum Vector # | |
Defined in Game.LambdaHack.Common.Vector | |
| Eq Vector # | |
| Ord Vector # | |
| Read Vector # | |
| Show Vector # | |
| Generic Vector # | |
| Binary Vector # | |
| NFData Vector # | |
Defined in Game.LambdaHack.Common.Vector | |
| type Rep Vector # | |
Defined in Game.LambdaHack.Common.Vector type Rep Vector = D1 (MetaData "Vector" "Game.LambdaHack.Common.Vector" "LambdaHack-0.8.3.0-1hn0NFDS4ux6qD3ggO7yse" False) (C1 (MetaCons "Vector" PrefixI True) (S1 (MetaSel (Just "vx") NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 X) :*: S1 (MetaSel (Just "vy") NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 Y))) | |
isDiagonal :: Vector -> Bool #
Checks whether a unit vector is a diagonal direction, as opposed to cardinal. If the vector is not unit, it checks that the vector is not horizontal nor vertical.
chessDistVector :: Vector -> Int #
The lenght of a vector in the chessboard metric, where diagonal moves cost 1.
euclidDistSqVector :: Vector -> Vector -> Int #
Squared euclidean distance between two vectors.
Vectors of all unit moves in the chessboard metric, clockwise, starting north-west.
movesCardinal :: [Vector] #
Vectors of all cardinal direction unit moves, clockwise, starting north.
movesDiagonal :: [Vector] #
Vectors of all diagonal direction unit moves, clockwise, starting north.
compassText :: Vector -> Text #
All (8 at most) closest neighbours of a point within an area.
vicinityUnsafe :: Point -> [Point] #
All (4 at most) cardinal direction neighbours of a point within an area.
vicinityCardinalUnsafe :: Point -> [Point] #
squareUnsafeSet :: Point -> EnumSet Point #
shiftBounded :: X -> Y -> Point -> Vector -> Point #
Translate a point by a vector, but only if the result fits in an area.
trajectoryToPath :: Point -> [Vector] -> [Point] #
A list of points that a list of vectors leads to.
trajectoryToPathBounded :: X -> Y -> Point -> [Vector] -> [Point] #
A list of points that a list of vectors leads to, bounded by level size.
vectorToFrom :: Point -> Point -> Vector #
The vector between the second point and the first. We have
shift pos1 (pos2 `vectorToFrom` pos1) == pos2
The arguments are in the same order as in the underlying scalar subtraction.
type RadianAngle = Double #
rotate :: RadianAngle -> Vector -> Vector #
Rotate a vector by the given angle (expressed in radians) counterclockwise and return a unit vector approximately in the resulting direction.
towards :: Point -> Point -> Vector #
Given two distinct positions, determine the direction (a unit vector) in which one should move from the first in order to get closer to the second. Ignores obstacles. Of several equally good directions (in the chessboard metric) it picks one of those that visually (in the euclidean metric) maximally align with the vector between the two points.
Internal operations
maxVectorDim :: Int #
Maximal supported vector X and Y coordinates.
_moveTexts :: [Text] #
Currently unused.
longMoveTexts :: [Text] #
normalize :: Double -> Double -> Vector #
Given a vector of arbitrary non-zero length, produce a unit vector that points in the same direction (in the chessboard metric). Of several equally good directions it picks one of those that visually (in the euclidean metric) maximally align with the original vector.
normalizeVector :: Vector -> Vector #
pathToTrajectory :: [Point] -> [Vector] #
A list of vectors between a list of points.