Safe Haskell | None |
---|
Basic operations on 2D vectors represented in an efficient, but not unique, way.
- data Vector = Vector {}
- isUnit :: Vector -> Bool
- isDiagonal :: Vector -> Bool
- neg :: Vector -> Vector
- chessDistVector :: Vector -> Int
- euclidDistSqVector :: Vector -> Vector -> Int
- moves :: [Vector]
- compassText :: Vector -> Text
- vicinity :: X -> Y -> Point -> [Point]
- vicinityCardinal :: X -> Y -> Point -> [Point]
- shift :: Point -> Vector -> Point
- shiftBounded :: X -> Y -> Point -> Vector -> Point
- trajectoryToPath :: Point -> [Vector] -> [Point]
- displacement :: Point -> Point -> Vector
- pathToTrajectory :: [Point] -> [Vector]
- type RadianAngle = Double
- rotate :: RadianAngle -> Vector -> Vector
- towards :: Point -> Point -> Vector
- data BfsDistance
- data MoveLegal
- apartBfs :: BfsDistance
- fillBfs :: (Point -> Point -> MoveLegal) -> (Point -> Point -> Bool) -> Point -> Array BfsDistance -> Array BfsDistance
- findPathBfs :: (Point -> Point -> MoveLegal) -> (Point -> Point -> Bool) -> Point -> Point -> Int -> Array BfsDistance -> Maybe [Point]
- accessBfs :: Array BfsDistance -> Point -> Maybe Int
- posAimsPos :: Array BfsDistance -> Point -> Point -> Bool
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.
isDiagonal :: Vector -> BoolSource
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 -> IntSource
The lenght of a vector in the chessboard metric, where diagonal moves cost 1.
euclidDistSqVector :: Vector -> Vector -> IntSource
Squared euclidean distance between two vectors.
Vectors of all unit moves in the chessboard metric, clockwise, starting north-west.
compassText :: Vector -> TextSource
All (8 at most) closest neighbours of a point within an area.
All (4 at most) cardinal direction neighbours of a point within an area.
shiftBounded :: X -> Y -> Point -> Vector -> PointSource
Translate a point by a vector, but only if the result fits in an area.
trajectoryToPath :: Point -> [Vector] -> [Point]Source
A list of points that a list of vectors leads to.
displacement :: Point -> Point -> VectorSource
A vector from a point to another. We have
shift pos1 (displacement pos1 pos2) == pos2
pathToTrajectory :: [Point] -> [Vector]Source
A list of vectors between a list of points.
type RadianAngle = DoubleSource
rotate :: RadianAngle -> Vector -> VectorSource
Rotate a vector by the given angle (expressed in radians) counterclockwise and return a unit vector approximately in the resulting direction.
towards :: Point -> Point -> VectorSource
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.
data BfsDistance Source
findPathBfs :: (Point -> Point -> MoveLegal) -> (Point -> Point -> Bool) -> Point -> Point -> Int -> Array BfsDistance -> Maybe [Point]Source
Find a path, without the source position, with the smallest length.
The eps
coefficient determines which direction (or the closest
directions available) that path should prefer, where 0 means north-west
and 1 means north.
posAimsPos :: Array BfsDistance -> Point -> Point -> BoolSource