Safe Haskell | None |
---|
Basic operations on 2D points represented as linear offsets.
- type Point = Int
- toPoint :: X -> PointXY -> Point
- showPoint :: X -> Point -> Text
- origin :: Point
- chessDist :: X -> Point -> Point -> Int
- adjacent :: X -> Point -> Point -> Bool
- vicinity :: X -> Y -> Point -> [Point]
- vicinityCardinal :: X -> Y -> Point -> [Point]
- inside :: X -> Point -> Area -> Bool
- displacementXYZ :: X -> Point -> Point -> VectorXY
- bla :: X -> Y -> Int -> Point -> Point -> Maybe [Point]
Documentation
The type of locations on the 2D level map, heavily optimized.
We represent the (level map on the) screen as a linear framebuffer,
where Point
is an Int
offset counted from the first cell.
We do bounds check for the X size whenever we convert between
representations and each subsequent
array access performs another check, effectively for Y size.
After dungeon is generated (using PointXY
, not Point
),
and converted to the Point
representation, points are used
mainly as keys and not constructed often, so the performance will improve
due to smaller save files, the use of IntMap
and cheaper array indexing,
including cheaper bounds checks.
We don't define Point
as a newtype to avoid the trouble
with using EnumMap
in place of IntMap
, etc.
chessDist :: X -> Point -> Point -> IntSource
The distance between two points in the chessboard metric.
adjacent :: X -> Point -> Point -> BoolSource
Checks whether two points are adjacent on the map (horizontally, vertically or diagonally).
vicinity :: X -> Y -> Point -> [Point]Source
Returns the 8, or less, surrounding locations of a given location.
vicinityCardinal :: X -> Y -> Point -> [Point]Source
Returns the 4, or less, surrounding locations in cardinal directions from a given location.