Safe Haskell | None |
---|
Basic operations on 2D vectors represented in an efficient, but not unique, way.
- data Vector
- toVector :: X -> VectorXY -> Vector
- shift :: Point -> Vector -> Point
- shiftBounded :: X -> Area -> Point -> Vector -> Point
- moves :: X -> [Vector]
- movesWidth :: [X -> Vector]
- isUnit :: X -> Vector -> Bool
- euclidDistSq :: X -> Vector -> Vector -> Int
- diagonal :: X -> Vector -> Bool
- neg :: Vector -> Vector
- towards :: X -> Point -> Point -> Vector
- displacement :: Point -> Point -> Vector
- displacePath :: [Point] -> [Vector]
- shiftPath :: Point -> [Vector] -> [Point]
Documentation
2D vectors represented as offsets in the linear framebuffer
indexed by Point
.
A newtype is used to prevent mixing up the type with Point
itself.
Note that the offset representations of a vector is usually not unique.
E.g., for vectors of length 1 in the chessboard metric, used to denote
geographical directions, the representations are pairwise distinct
if and only if the level width and height are at least 3.
shift :: Point -> Vector -> PointSource
Translate a point by a vector.
Particularly simple and fast implementation in the linear representation.
shiftBounded :: X -> Area -> Point -> Vector -> PointSource
Translate a point by a vector, but only if the result fits in an area.
movesWidth :: [X -> Vector]Source
Vectors of all unit moves, clockwise, starting north-west, parameterized by level width.
euclidDistSq :: X -> Vector -> Vector -> IntSource
Squared euclidean distance between two unit vectors.
diagonal :: X -> Vector -> BoolSource
Checks whether a unit vector is a diagonal direction, as opposed to cardinal.
towards :: X -> Point -> Point -> VectorSource
Given two distinct locations, 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..
displacement :: Point -> Point -> VectorSource
A vector from a point to another. We have
shift loc1 (displacement loc1 loc2) == loc2
Particularly simple and fast implementation in the linear representation.
displacePath :: [Point] -> [Vector]Source
A list of vectors between a list of points.