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.

Members

Aliases

Diagonals
alias Diagonals = Flag!"Diagonals"

Whether to consider diagonals adjacent in situations dealing with the concept of adjacency.

PixelCoord
alias PixelCoord = Tuple!(float, "x", float, "y")

Represents a location in continuous 2D space.

RowColRange
alias RowColRange = typeof(span(RowCol.init, RowCol.init))

The type returned by span: a range of RowCol.

Enums

isPixelCoord
eponymoustemplate isPixelCoord(T)

True if T is a type that can represent a location in terms of pixels.

Functions

as
T as(PixelCoord pos)

Convert a PixelCoord to a user-defined (x,y) numeric pair.

manhattan
auto manhattan(RowCol a, RowCol b)

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
auto span(RowCol start, RowCol end)
auto span(RowCol start, coord_t endRow, coord_t endCol)

Enumerate all row/col pairs spanning the rectangle bounded by the corners start and end.

Structs

RowCol
struct RowCol

Represents a discrete location within the map grid.

Meta