Documentation ¶
Index ¶
- func Axial(x, y, z float64) (float64, float64)
- func AxialRound(c, r float64) (float64, float64)
- func AxialRoundInt(c, r float64) (int, int)
- func Cube(c, r float64) (float64, float64, float64)
- func CubeRound(x, y, z float64) (float64, float64, float64)
- func CubeRoundInt(x, y, z float64) (int, int, int)
- type Grid
- type HexGrid
- func (grid *HexGrid) Get(c, r int) (data interface{}, ok bool)
- func (grid *HexGrid) Map() map[Loc]interface{}
- func (grid *HexGrid) Set(c, r int, data interface{})
- func (grid *HexGrid) Tile(c, r float64) (int, int)
- func (grid *HexGrid) ToGrid(x, y float64) (float64, float64)
- func (grid *HexGrid) ToWorld(c, r float64) (float64, float64)
- func (grid *HexGrid) Vertices(c, r int) (verts []mgl64.Vec2)
- type HexagonOrientation
- type Loc
- type SquareGrid
- func (grid *SquareGrid) Get(c, r int) (data interface{}, ok bool)
- func (grid *SquareGrid) Map() map[Loc]interface{}
- func (grid *SquareGrid) Set(c, r int, data interface{})
- func (grid *SquareGrid) Tile(c, r float64) (int, int)
- func (grid *SquareGrid) ToGrid(x, y float64) (float64, float64)
- func (grid *SquareGrid) ToWorld(c, r float64) (float64, float64)
- func (grid *SquareGrid) Vertices(c, r int) (verts []mgl64.Vec2)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AxialRound ¶
AxialRound rounds fractional axial coordinates to the center of the hexagon they're in.
First converts coords to cube, uses CubeRound(), then converts back.
func AxialRoundInt ¶
AxialRoundInt does the same as AxialRound() but converts to int for you.
Types ¶
type Grid ¶
type Grid interface { ToWorld(c, r float64) (float64, float64) ToGrid(x, y float64) (float64, float64) Vertices(c, r int) []mgl64.Vec2 Get(c, r int) (interface{}, bool) Set(c, r int, data interface{}) Map() map[Loc]interface{} Tile(c, r float64) (int, int) // converts fractional grid coords to the integer location of the grid unit }
Grid is an interface for 2D polygon grids, such as a hexagonal or square grid.
type HexGrid ¶
type HexGrid struct { Circumradius float64 Inradius float64 Orientation HexagonOrientation Data map[Loc]interface{} // contains filtered or unexported fields }
HexGrid represents a grid of regular hexagons of either the "flat topped" or "pointy topped" variety.
Arbitrary user data can be associated with a particular hexagon by using the 'Data' map. The grid is indexed by "columns" and "rows" using the "axial" style coordinates described by https://www.redblobgames.com/grids/hexagons/#coordinates-axial. However, this grid follows the normal Y-orientation (+y = up) instead of the inverted one in the link
func NewHexGrid ¶
func NewHexGrid(circumradius float64, orientation HexagonOrientation) *HexGrid
NewHexGrid creates the data structure to represent a hexagonal grid in either flat-topped or pointy-topped regular hexagons.
func (*HexGrid) Get ¶
Get returns the data at axial coordinates (c,r) and a boolean indicating whether or not data existed at that location. Really it's just a convenience method for accessing the Data member.
func (*HexGrid) Set ¶
Set sets the data at axial coordinates (c,r). Really it's just a convenience method for accessing the Data member. If data is nil, the map value at (c,r) is deleted.
func (*HexGrid) Tile ¶
Tile returns the axial coords (column and row) of the hexagon containing the given fractional grid coordinates.
type HexagonOrientation ¶
type HexagonOrientation int
HexagonOrientation describes if a hexagon is flat topped or pointy topped.
const ( FlatTop HexagonOrientation = iota PointyTop HexagonOrientation = iota )
constants for the 2 types of hexagon orientations
type Loc ¶
type Loc [2]int
Loc is a [2]int representing the (column, row) of a hexagonal grid tile's center.
type SquareGrid ¶
type SquareGrid struct { SideLength float64 Circumradius float64 Inradius float64 Orientation float64 Data map[Loc]interface{} // contains filtered or unexported fields }
SquareGrid represents a grid of squares.
func NewSquareGrid ¶
func NewSquareGrid(sideLength, angleRadians float64) *SquareGrid
NewSquareGrid creates the data structure to represent a square grid. The squares of the grid can be rotated counterclockwise by angleRadians.
func (*SquareGrid) Get ¶
func (grid *SquareGrid) Get(c, r int) (data interface{}, ok bool)
Get returns the data at the grid coordinate (c,r) and a boolean indicating whether or not the data existed at that location.
func (*SquareGrid) Map ¶
func (grid *SquareGrid) Map() map[Loc]interface{}
Map gets access to the grid's data, for use in "range" etc.
func (*SquareGrid) Set ¶
func (grid *SquareGrid) Set(c, r int, data interface{})
Set sets the data at the grid coordinates (c,r). If data is nil, the value at (c,r) is deleted.
func (*SquareGrid) Tile ¶
func (grid *SquareGrid) Tile(c, r float64) (int, int)
Tile returns the grid coords (column and row) of the square containing the given fractional grid coordinates.
func (*SquareGrid) ToGrid ¶
func (grid *SquareGrid) ToGrid(x, y float64) (float64, float64)
ToGrid converts world (screen) coordinates to grid coordinates.