Documentation
¶
Overview ¶
Package hexgrid provides various utilities to handle regular hexagons math This is a GO implementation of the algorithms described at http://www.redblobgames.com/grids/hexagons/implementation.html
Index ¶
- Constants
- Variables
- type Direction
- type FractionalHex
- type Hex
- func (h Hex) Add(o Hex) Hex
- func (h Hex) Distance(o Hex) int
- func (h Hex) FieldOfView(candidates []Hex, blocking []Hex) []Hex
- func (h Hex) HasLineOfSight(target Hex, blocking []Hex) bool
- func (h Hex) Length() int
- func (h Hex) LineDraw(o Hex) []Hex
- func (h Hex) Neighbor(direction Direction) Hex
- func (h Hex) Neighbors() []Hex
- func (h Hex) Range(r int) []Hex
- func (h Hex) Scale(k int) Hex
- func (h Hex) String() string
- func (h Hex) Subtract(o Hex) Hex
- type Layout
- type Point
Constants ¶
const ( DirectionSE = iota DirectionNE DirectionN DirectionNW DirectionSW DirectionS )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Direction ¶
type Direction int
Direction represents a one-step move in some direction. The direction names assumes a flat-top layout.
type FractionalHex ¶
fractionHex provides a more precise representation for hexagons when precision is required. It's also represented in Cube Coordinates
func NewFractionalHex ¶
func NewFractionalHex(q, r float64) FractionalHex
func PixelToHex ¶
func PixelToHex(l Layout, p Point) FractionalHex
PixelToHex returns the corresponding hexagon axial coordinates for a given pixel on a certain Layout
func (FractionalHex) Round ¶
func (h FractionalHex) Round() Hex
Rounds a FractionalHex to a Regular Hex
type Hex ¶
type Hex struct {
Q, R, S int
}
Hex describes a regular hexagon with Cube Coordinates (although the S coordinate is computed on the constructor) It's also easy to reference them as axial (trapezoidal coordinates):
For additional reference on these coordinate systems: http://www.redblobgames.com/grids/hexagons/#coordinates
func RectangleGrid ¶
Returns the set of hexagons that form a rectangle with the specified width and height
func (Hex) FieldOfView ¶
Returns the list of hexagons that are visible from the hexagon
func (Hex) HasLineOfSight ¶
Determines if a given hexagon is visible from the hexagon, taking into consideration a set of blocking hexagons
func (Hex) LineDraw ¶
Returns the slice of hexagons that exist on a line that goes from the hexagon to another TODO: Name doesn't seem to fit
func (Hex) Neighbor ¶
Returns the neighbor hexagon at a certain direction TODO: Not sure if I like this approach
type Point ¶
func HexCornerOffset ¶
func HexToPixel ¶
HexToPixel returns the center pixel for a given hexagon an a certain Layout
func HexagonCorners ¶
Gets the corners of the hexagon for the given Layout, starting at the E vertex and proceeding in a CCW order