Orasund/pixelengine/5.0.3

NOTE: the latest version is 6.2.0

Grid.Position

DEPRECATED! Got moved to its separate package.

This module contains two ways of representing a point on a grid: Position and Coord. Positions are meant to be stored, and coordinates are meant to to calculations with.

Position

type alias Position =
( Int, Int )

A Position is a comparable representation for 2D Coordinates.

You should store your coordinates in this type.

move : Int -> Direction -> Position -> Position

moves a Point some amount of steps in a direction. This is the most used way how to change a position.

add : Coord -> Position -> Position

Apply Coordinates to a position to get the relative position.

move amount direction == add (fromDirection direction |> scaleby amount)
coordsTo : Position -> Position -> Coord

Returns the difference between two positions.

difference p1 p2 == p1 <------- p2

Vector

type alias Coord =
{ x : Int
, y : Int
}

Coord is a non-comparable representation for 2D Coordinates.

Use this type for your calculations.

converts a Direction into a Vector with length 1.

converts any Vector into its nearest Direction value.

fromValue (0,0) == Right fromValue (1,1) == Down fromValue (-1,1) == Down fromValue (1,-1) == Up fromValue (-1,-1) == Up

distance : Position -> Position -> Float

Gets the distance between to points. (The length of the difference)

distance == vectorTo >> length
scaleBy : Int -> Coord -> Coord

Scales Coordnates. Coordnates obtained by fromDirection have size 1.

fromDirection angle |> scaleBy l |> length == l
length : Coord -> Float

Returns the length of the coordinate (distance to (0,0)