Documentation ¶
Overview ¶
Package hex contains geometry of hexagonal world.
Index ¶
- Constants
- Variables
- func AreaAtDistance(r int) int
- func CompareSlices(a, b []Hex) bool
- func InverseDirection(d int) int
- func NormalizeDirection(d int) int
- func PrettyDirection(d int) string
- func RingLenAtDistance(r int) int
- type Hex
- func (h Hex) Add(t Hex) Hex
- func (h Hex) Array() [2]int
- func (h Hex) Direction(t Hex, sign LineSign) int
- func (h Hex) Distance(t Hex) int
- func (h Hex) Equal(t Hex) bool
- func (h Hex) Len() int
- func (h Hex) Line(t Hex, sign LineSign) (res []Hex)
- func (h Hex) Mul(k int) Hex
- func (h Hex) Neighbor(d int) Hex
- func (h Hex) NeighborsAtDistance(d int, res []Hex)
- func (h Hex) Q() int
- func (h Hex) R() int
- func (h Hex) RingAtDistance(d int, res []Hex)
- func (h Hex) S() int
- func (h Hex) String() string
- func (h Hex) Sub(t Hex) Hex
- func (h Hex) Title() string
- type LineSign
Constants ¶
const (
// DirectionCount is const to be used for arrays and calculations.
DirectionCount = 6
)
Variables ¶
var ( ZE = Hex{0, 0, 0} EE = Hex{1, 0, -1} NE = Hex{1, -1, 0} NW = Hex{0, -1, 1} WW = Hex{-1, 0, 1} SW = Hex{-1, 1, 0} SE = Hex{0, 1, -1} )
Directions.
Functions ¶
func AreaAtDistance ¶
AreaAtDistance returns amount of all hexes limited by ring at specified distance including center hex and ring.
func CompareSlices ¶
CompareSlices returns true if slices a and b have equal length and elements at same positions.
func InverseDirection ¶
InverseDirection returns inverter direction for specified.
func NormalizeDirection ¶
NormalizeDirection returns normalized value direction for specified.
func PrettyDirection ¶
PrettyDirection returns pretty representation of direction.
func RingLenAtDistance ¶
RingLenAtDistance returns length of ring at specified distance.
Types ¶
type Hex ¶
type Hex struct {
// contains filtered or unexported fields
}
Hex is coordinates at Hexagonal Grid.
func NewWithArray ¶
NewWithArray returns new Hex object represented as array.
func (Hex) NeighborsAtDistance ¶
NeighborsAtDistance returns all neighbors Hex of h on distance d.
func (Hex) RingAtDistance ¶
RingAtDistance returns ring.
type LineSign ¶ added in v1.1.0
type LineSign float64
LineSign is alias for float64 to determine it from other real values.
Line signs. LSPlus means counterclockwise path with ray connecting start hex with end one being traced on edge. LSMinus means clockwise path with ray connecting start hex with end one being traced on edge. LSZero means that there are no such ray or unknown direction.