hex

package
v0.0.0-...-af8dc49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2019 License: Unlicense Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Axial

func Axial(x, y, z float64) (float64, float64)

Axial converts cube coordinates to axial coordinates.

func AxialRound

func AxialRound(c, r float64) (float64, float64)

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

func AxialRoundInt(c, r float64) (int, int)

AxialRoundInt does the same as AxialRound() but converts to int for you.

func Cube

func Cube(c, r float64) (float64, float64, float64)

Cube converts axial coordinates to cube coordinates.

func CubeRound

func CubeRound(x, y, z float64) (float64, float64, float64)

CubeRound rounds fractional cube coordinats to the center of the hexagon they're in.

func CubeRoundInt

func CubeRoundInt(x, y, z float64) (int, int, int)

CubeRoundInt does the same as CubeRound() 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

func (grid *HexGrid) Get(c, r int) (data interface{}, ok bool)

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) Map

func (grid *HexGrid) Map() map[Loc]interface{}

Map gets access to the grid's data, for use in "range", etc.

func (*HexGrid) Set

func (grid *HexGrid) Set(c, r int, data interface{})

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

func (grid *HexGrid) Tile(c, r float64) (int, int)

Tile returns the axial coords (column and row) of the hexagon containing the given fractional grid coordinates.

func (*HexGrid) ToGrid

func (grid *HexGrid) ToGrid(x, y float64) (float64, float64)

ToGrid converts world coordinates to axial grid coordinates.

func (*HexGrid) ToWorld

func (grid *HexGrid) ToWorld(c, r float64) (float64, float64)

ToWorld converts axial grid coordinates to world/carteasian coordinates.

func (*HexGrid) Vertices

func (grid *HexGrid) Vertices(c, r int) (verts []mgl64.Vec2)

Vertices gets the 6 vertices (corners) of the hexagon at (c,r) in world coordinates, starting on the right and going in a counter-clockwise direction.

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.

func (Loc) C

func (l Loc) C() int

C gets the column coordinate of Loc.

func (Loc) CR

func (l Loc) CR() (int, int)

CR gets the column and row coordinates of Loc.

func (Loc) R

func (l Loc) R() int

R gets the row coordinate of Loc.

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.

func (*SquareGrid) ToWorld

func (grid *SquareGrid) ToWorld(c, r float64) (float64, float64)

ToWorld converts grid coordinates to world (screen) coordinates.

func (*SquareGrid) Vertices

func (grid *SquareGrid) Vertices(c, r int) (verts []mgl64.Vec2)

Verticies gets the 4 vertices of the square at (c,r) in world coordinates, starting in the "top right" and going counter-clockwise.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL