Module dtiled.coords

This module helps handle coordinate systems within a map.

When dealing with a grid, do you ever forget whether the row or column is the first index?

Me too.

For this reason, all functions dealing with grid coordinates take a RowCol argument. This makes it abundantly clear that the map is indexed in row-major order. Furthormore, it prevents confusion between **grid** coordinates and **pixel** coordinates.

A 'pixel' coordinate refers to an (x,y) location in 'pixel' space. The units used by 'pixel' coords are the same as used in MapData tilewidth and tileheight.

Within dtiled, pixel locations are represented by a PixelCoord. However, you may already be using a game library that provides some 'Vector' implementation used to represent positions. You can pass any such type to dtiled functions expecting a pixel coordinate so long as it satisfies isPixelCoord.

Functions

Name Description
as Convert a PixelCoord to a user-defined (x,y) numeric pair.
manhattan Return the manhattan distance between two tile coordinates. For two coordinates a and b, this is defined as abs(a.row - b.row) + abs(a.col - b.col)
span Enumerate all row/col pairs spanning the rectangle bounded by the corners start and end.

Structs

Name Description
RowCol Represents a discrete location within the map grid.

Enum values

Name Type Description
isPixelCoord True if T is a type that can represent a location in terms of pixels.

Aliases

Name Type Description
Diagonals std.typecons.Flag!("Diagonals") Whether to consider diagonals adjacent in situations dealing with the concept of adjacency.
PixelCoord std.typecons.Tuple!(float,"x",float,"y") Represents a location in continuous 2D space.

Authors

Copyright

License