Liking cljdoc? Tell your friends :D

fastmath.grid

Grid calculation functions.

Convert 2d coordinates into various grid coordinates and back.

Terms used:

  • cell type - grid cell shape: square, triangular, hexagonal, rhomboidal
  • coords - 2d euclidean coordinates (x,y)
  • cell - cell coordinates (q,r)
  • anchor - cell position in 2d euclidean space
  • corners - shape vertices
  • size - size of the cell.

Grids

Each grid is defined by cell type and size. Optionally you can provide translating vector.

Each cell has it's own coordinates, mostly axial based (only square has offset).

For hexagonal cell size is a radius from midpoint to corner. For the rest it is the size of the side.

Cell types are:

  • :square
  • :shifted-square
  • :triangle
  • :rhombus
  • :flat-hex - flat topped
  • :pointy-hex - pointy topped

Notes

  • Hexagonal grids are based on https://www.redblobgames.com/grids/hexagons/
  • Only hexagonal cells have anchor at the center. For the rest the anchor is at the top left vertex.
    • Anchors for triangular grids are shared between two cells: even and odd q coordinate. Even q is pointy topped, odd q is flat topped.
Grid calculation functions.

Convert 2d coordinates into various grid coordinates and back.

Terms used:

* cell type - grid cell shape: square, triangular, hexagonal, rhomboidal
* coords - 2d euclidean coordinates (x,y)
* cell - cell coordinates (q,r)
* anchor - cell position in 2d euclidean space
* corners - shape vertices
* size - size of the cell.

### Grids

Each grid is defined by cell type and size. Optionally you can provide translating vector.

Each cell has it's own coordinates, mostly axial based (only square has offset).

For hexagonal cell size is a radius from midpoint to corner. For the rest it is the size of the side.

Cell types are:

* `:square`
* `:shifted-square`
* `:triangle`
* `:rhombus`
* `:flat-hex` - flat topped
* `:pointy-hex` - pointy topped

### Notes

* Hexagonal grids are based on https://www.redblobgames.com/grids/hexagons/
* Only hexagonal cells have anchor at the center. For the rest the anchor is at the top left vertex.
    * Anchors for triangular grids are shared between two cells: even and odd `q` coordinate. Even `q` is pointy topped, odd `q` is flat topped.
raw docstring

cell->anchorclj

(cell->anchor g cell)

Converts cell coordinates to anchor coordinates.

Converts cell coordinates to anchor coordinates.
sourceraw docstring

cell->midclj

(cell->mid g cell)

Converts cell coordinates to mid point

Converts cell coordinates to mid point
sourceraw docstring

cell-namesclj

source

coords->anchorclj

(coords->anchor g coords)

Converts 2d coordinates to cell anchor.

Converts 2d coordinates to cell anchor.
sourceraw docstring

coords->cellclj

(coords->cell g coords)

Converts 2d space coordinates to cell coordinates.

Converts 2d space coordinates to cell coordinates.
sourceraw docstring

coords->midclj

(coords->mid g coords)

Converts 2d space into cell midpoint.

Converts 2d space into cell midpoint.
sourceraw docstring

cornersclj

(corners g coords)
(corners g coords scale)

Returns list of cell vertices for given 2d space coordinates.

Returns list of cell vertices for given 2d space coordinates.
sourceraw docstring

flat-hex-cornersclj

Function which returns vertices for flat topped hexagon for given size and coordinates.

Function which returns vertices for flat topped hexagon for given size and coordinates.
sourceraw docstring

gridclj

(grid)
(grid type)
(grid type size)
(grid type size sx sy)

Create grid for given type, size and optional translating vector.

Create grid for given type, size and optional translating vector.
sourceraw docstring

grid-typeclj

(grid-type g)

Returns type of the cell.

Returns type of the cell.
sourceraw docstring

pointy-hex-cornersclj

Function which returns vertices for pointy topped hexagon for given size and coordinates.

Function which returns vertices for pointy topped hexagon for given size and coordinates.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close