hextille v0.1.0 Hextille.Offset View Source

Hexagon module that represents hexagon tiles using offset coordinates. Instead of names x, y this module uses names col and row.

Coordinates in q-offset system represent hexagons in pointy top orientation, r-offset in flat top orientation.

By default this module uses even-r and even-q offset coordinates, but the offset can be optionally specified.

This module should only be used to display coordinates as offset coordinates. All math should be done by using cube coordinates.

Link to this section Summary

Functions

Converts Cube in cube coordinates to flat top q-offset coordinates

Converts Offset in flat top q-offset coordinates to Cube

Converts hexagon in Cube coordinates to pointy top r-offset coordinates

Converts Offset in pointy top r-offset coordinates to Cube

Link to this section Functions

Link to this function qoffset_from_cube(h, offset \\ 0) View Source

Converts Cube in cube coordinates to flat top q-offset coordinates.

Examples:

iex> h = %Cube{q: 3, r: 4, s: -7} iex> Offset.qoffset_from_cube(h) %Offset{col: 3, row: 5} iex> Offset.qoffset_from_cube(h, 0) %Offset{col: 3, row: 5} iex> Offset.qoffset_from_cube(h, 1) %Offset{col: 3, row: 6}

Link to this function qoffset_to_cube(h, offset \\ 0) View Source

Converts Offset in flat top q-offset coordinates to Cube.

Examples:

iex> a = %Offset{col: 3, row: 5} iex> b = %Offset{col: 3, row: 6} iex> Offset.qoffset_to_cube(a) %Cube{q: 3, r: 4, s: -7} iex> Offset.qoffset_to_cube(a, 0) %Cube{q: 3, r: 4, s: -7} iex> Offset.qoffset_to_cube(b, 1) %Cube{q: 3, r: 4, s: -7}

Link to this function roffset_from_cube(h, offset \\ 0) View Source

Converts hexagon in Cube coordinates to pointy top r-offset coordinates.

Examples:

iex> h = %Cube{q: 4, r: 3, s: -7} iex> Offset.roffset_from_cube(h) %Offset{col: 5, row: 3} iex> Offset.roffset_from_cube(h, 0) %Offset{col: 5, row: 3} iex> Offset.roffset_from_cube(h, 1) %Offset{col: 6, row: 3}

Link to this function roffset_to_cube(h, offset \\ 0) View Source

Converts Offset in pointy top r-offset coordinates to Cube.

Examples:

iex> a = %Offset{col: 5, row: 3} iex> b = %Offset{col: 6, row: 3} iex> Offset.roffset_to_cube(a) %Cube{q: 4, r: 3, s: -7} iex> Offset.roffset_to_cube(a, 0) %Cube{q: 4, r: 3, s: -7} iex> Offset.roffset_to_cube(b, 1) %Cube{q: 4, r: 3, s: -7}