LambdaHack-0.11.0.1: A game engine library for tactical squad ASCII roguelike dungeon crawlers

Safe Haskell | None
Language | Haskell2010

Game.LambdaHack.Common.Vector

Contents

- Internal operations

Description

Basic operations on bounded 2D vectors, with an efficient, but not 1-1 and not monotonic `Enum` instance.

Synopsis

- data Vector = Vector {
  - vx :: X
  - vy :: Y
  }
- type VectorI = Int
- isUnit :: Vector -> Bool
- neg :: Vector -> Vector
- chessDistVector :: Vector -> Int
- euclidDistSqVector :: Vector -> Vector -> Int
- moves :: [Vector]
- movesCardinal :: [Vector]
- movesCardinalI :: [VectorI]
- movesDiagonal :: [Vector]
- movesDiagonalI :: [VectorI]
- compassText :: Vector -> Text
- vicinityBounded :: 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
- longMoveTexts :: [Text]
- movesSquare :: [VectorI]
- pathToTrajectory :: [Point] -> [Vector]
- normalize :: Double -> Double -> Vector
- normalizeVector :: Vector -> Vector

# Documentation

data Vector Source #

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.

Constructors

Vector |

Fields

- vx :: X
- vy :: Y

#### Instances

Instances details

Binary Vector Source # |
Instance details Defined in Game.LambdaHack.Common.Vector Methods put :: Vector -> Put Source # get :: Get Vector Source # putList :: [Vector] -> Put Source #
NFData Vector Source # |
Instance details Defined in Game.LambdaHack.Common.Vector Methods rnf :: Vector -> () Source #
Enum Vector Source # |

Instance details

Defined in Game.LambdaHack.Common.Vector

Methods

succ :: Vector -> Vector Source #

pred :: Vector -> Vector Source #

toEnum :: Int -> Vector Source #

fromEnum :: Vector -> Int Source #

enumFrom :: Vector -> [Vector] Source #

enumFromThen :: Vector -> Vector -> [Vector] Source #

enumFromTo :: Vector -> Vector -> [Vector] Source #

enumFromThenTo :: Vector -> Vector -> Vector -> [Vector] Source #

Generic Vector Source # |

Instance details

Defined in Game.LambdaHack.Common.Vector

Associated Types

type Rep Vector |

Instance details

Defined in Game.LambdaHack.Common.Vector

type Rep Vector = D1 ('MetaData "Vector" "Game.LambdaHack.Common.Vector" "LambdaHack-0.11.0.1-BLuOaw8nuizISmzkanqI8h" 'False) (C1 ('MetaCons "Vector" 'PrefixI 'True) (S1 ('MetaSel ('Just "vx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 X) :*: S1 ('MetaSel ('Just "vy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Y)))

Methods

from :: Vector -> Rep Vector x Source #

to :: Rep Vector x -> Vector Source #

Read Vector Source # |
Instance details Defined in Game.LambdaHack.Common.Vector Methods readsPrec :: Int -> ReadS Vector Source # readList :: ReadS [Vector] Source # readPrec :: ReadPrec Vector Source # readListPrec :: ReadPrec [Vector] Source #
Show Vector Source # |
Instance details Defined in Game.LambdaHack.Common.Vector Methods showsPrec :: Int -> Vector -> ShowS Source # show :: Vector -> String Source # showList :: [Vector] -> ShowS Source #
Eq Vector Source # |
Instance details Defined in Game.LambdaHack.Common.Vector Methods (==) :: Vector -> Vector -> Bool Source # (/=) :: Vector -> Vector -> Bool Source #
Ord Vector Source # |
Instance details Defined in Game.LambdaHack.Common.Vector Methods compare :: Vector -> Vector -> Ordering Source # (<) :: Vector -> Vector -> Bool Source # (<=) :: Vector -> Vector -> Bool Source # (>) :: Vector -> Vector -> Bool Source # (>=) :: Vector -> Vector -> Bool Source # max :: Vector -> Vector -> Vector Source # min :: Vector -> Vector -> Vector Source #
type Rep Vector Source # |

Instance details

Defined in Game.LambdaHack.Common.Vector

type Rep Vector = D1 ('MetaData "Vector" "Game.LambdaHack.Common.Vector" "LambdaHack-0.11.0.1-BLuOaw8nuizISmzkanqI8h" 'False) (C1 ('MetaCons "Vector" 'PrefixI 'True) (S1 ('MetaSel ('Just "vx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 X) :*: S1 ('MetaSel ('Just "vy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Y)))

type VectorI = Int Source #

Enumeration representation of `Vector`.

isUnit :: Vector -> Bool Source #

Tells if a vector has length 1 in the chessboard metric.

neg :: Vector -> Vector Source #

Reverse an arbirary vector.

chessDistVector :: Vector -> Int Source #

The lenght of a vector in the chessboard metric, where diagonal moves cost 1.

euclidDistSqVector :: Vector -> Vector -> Int Source #

Squared euclidean distance between two vectors.

moves :: [Vector] Source #

Vectors of all unit moves in the chessboard metric, clockwise, starting north-west.

movesCardinal :: [Vector] Source #

Vectors of all cardinal direction unit moves, clockwise, starting north.

movesCardinalI :: [VectorI] Source #

movesDiagonal :: [Vector] Source #

Vectors of all diagonal direction unit moves, clockwise, starting north.

movesDiagonalI :: [VectorI] Source #

compassText :: Vector -> Text Source #

vicinityBounded Source #

Arguments

:: X |
-> Y | limit the search to this area
-> Point | position to find neighbours of
-> [Point] |

All (8 at most) closest neighbours of a point within an area.

vicinityUnsafe :: Point -> [Point] Source #

vicinityCardinal Source #

Arguments

:: X |
-> Y | limit the search to this area
-> Point | position to find neighbours of
-> [Point] |

All (4 at most) cardinal direction neighbours of a point within an area.

vicinityCardinalUnsafe :: Point -> [Point] Source #

squareUnsafeSet :: Point -> EnumSet Point Source #

shift :: Point -> Vector -> Point Source #

Translate a point by a vector.

shiftBounded :: X -> Y -> Point -> Vector -> Point Source #

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.

trajectoryToPathBounded :: X -> Y -> Point -> [Vector] -> [Point] Source #

A list of points that a list of vectors leads to, bounded by level size.

vectorToFrom :: Point -> Point -> Vector Source #

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.

computeTrajectory :: Int -> Int -> Int -> [Point] -> ([Vector], (Speed, Int)) Source #

type RadianAngle = Double Source #

rotate :: RadianAngle -> Vector -> Vector Source #

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 Source #

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

longMoveTexts :: [Text] Source #

movesSquare :: [VectorI] Source #

pathToTrajectory :: [Point] -> [Vector] Source #

A list of vectors between a list of points.

normalize :: Double -> Double -> Vector Source #

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 Source #