Module sark_grids::world_grid[][src]

Expand description

A utility for translating between grid points and world space.

You can specify a world position, size, and pivot for the grid when creating it. These will affect the grid’s bounds and tile points.

Example Grids

A 3x3 Pivot::Center grid:

|-1,-1| 0, 1| 1, 1|
|-1, 0| 0, 0| 1, 0|
|-1,-1| 0,-1| 1,-1|

A 3x3 Pivot::BottomLeft grid:

| 0, 2| 1, 2| 2, 2|
| 0, 1| 1, 1| 2, 1|
| 0, 0| 1, 0| 2, 0|

A 3x3 Pivot::TopRight grid:

|-3,-1|-2,-1|-1,-1|
|-3,-2|-2,-2|-1,-2|
|-3,-3|-2,-3|-1,-3|

Types of Points

The api has several different “types” of positions that can be referenced:

  • World Position: The world offset of the grid.
  • Grid Position: The local position of the grid’s tiles. It’s range is based on the grid’s pivot.
  • Index: The 1d index of a tile. Goes from 0 to width * height - 1.
  • 2d Index: The 2d index of a tile in the grid. Goes from [0,0] to [width-1,height-1].
  • Tile Position: The bottom-left point on a tile in the grid.
  • Tile Center: The center of a tile in the grid.

Structs

A sized grid with a custom pivot for translating between aligned grid points and world space.