Documentation
¶
Overview ¶
package hex contains discrete and real positional values for coordinates.
Index ¶
- func BoundFacing(facing int) int
- type Hex
- func (h Hex) Add(x Hex) Hex
- func (h Hex) DistanceTo(x Hex) int64
- func (h Hex) Length() int64
- func (h Hex) LineTo(x Hex) []Hex
- func (h Hex) Multiply(k int64) Hex
- func (h Hex) Neighbor(direction int) Hex
- func (h Hex) Neighbors() []Hex
- func (h Hex) Rotate(pivot Hex, direction int) Hex
- func (h Hex) S() int64
- func (h Hex) String() string
- func (h Hex) Subtract(x Hex) Hex
- func (h Hex) ToHexFractional() HexFractional
- func (h Hex) Transform(t [4][4]int64) Hex
- type HexFractional
- func (h HexFractional) Add(x HexFractional) HexFractional
- func (h HexFractional) AlmostEquals(x HexFractional) bool
- func (h HexFractional) AngleTo(x HexFractional) float64
- func (h HexFractional) DistanceTo(x HexFractional) float64
- func (h HexFractional) Length() float64
- func (h HexFractional) Multiply(k float64) HexFractional
- func (h HexFractional) Normalize() HexFractional
- func (h HexFractional) ProjectOn(x HexFractional) HexFractional
- func (h HexFractional) Rotate(center HexFractional, radians float64) HexFractional
- func (h HexFractional) S() float64
- func (h HexFractional) String() string
- func (h HexFractional) Subtract(x HexFractional) HexFractional
- func (h HexFractional) ToCartesian() (x, y float64)
- func (h HexFractional) ToHex() Hex
- type Sort
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Hex ¶
Hex is a coordinate defined axially.
[Q,R,S]
func Direction ¶
Direction returns a new hex coord offset from the origin in the given direction, which is a number from 0 to 5, inclusive. Positive Q axis is in the 0 direction. Positive R axis is in the 5 direction.
func LerpHex ¶
LerpHex finds a point between a and b weighted by t. See https://en.wikipedia.org/wiki/Linear_interpolation
func (Hex) DistanceTo ¶
DistanceTo returns the distance between two hexes.
This is the Manhattan Distance.
func (Hex) Length ¶
Length gets the length of the hex to the grid origin.
This is the Manhattan Distance.
func (Hex) LineTo ¶
LineTo returns all hexes in a line from point x to point b, inclusive. The order of elements is a line as you would expect.
func (Hex) ToHexFractional ¶
func (h Hex) ToHexFractional() HexFractional
ToHexFractional returns the fractional hex that is the center of this hex.
type HexFractional ¶
HexFractional is fractional hex coordinates in cubic coordinate system.
func Center ¶
func Center(h ...Hex) HexFractional
Center returns the hex at the center of mass of the given points.
func HexFractionalFromCartesian ¶
func HexFractionalFromCartesian(x, y float64) HexFractional
HexFractionalFromCartesian returns the hex in Cartesian Coordinates.
func LerpHexFractional ¶
func LerpHexFractional(a HexFractional, b HexFractional, t float64) HexFractional
LerpHexFractional finds a point between a and b weighted by t. See https://en.wikipedia.org/wiki/Linear_interpolation
func OriginFractional ¶
func OriginFractional() HexFractional
OriginFractional returns a new hex with origin (0,0) coordinates.
func (HexFractional) Add ¶
func (h HexFractional) Add(x HexFractional) HexFractional
Add combines two hexes.
func (HexFractional) AlmostEquals ¶
func (h HexFractional) AlmostEquals(x HexFractional) bool
AlmostEquals returns true when h and x are equal or close enough to equal for practical matters.
func (HexFractional) AngleTo ¶
func (h HexFractional) AngleTo(x HexFractional) float64
AngleTo returns the angle to x in radians. Will always return the inner (smaller) angle.
func (HexFractional) DistanceTo ¶
func (h HexFractional) DistanceTo(x HexFractional) float64
DistanceTo returns the distance between two hexes.
This is the Euclidean Distance, but NOT in orthogonal space.
func (HexFractional) Length ¶
func (h HexFractional) Length() float64
Length gets the length of the hex to the grid origin.
This is the Euclidean Distance, but NOT in orthogonal space.
func (HexFractional) Multiply ¶
func (h HexFractional) Multiply(k float64) HexFractional
Multiply scales a hex by a scalar value.
func (HexFractional) Normalize ¶
func (h HexFractional) Normalize() HexFractional
Normalize returns a vector that points in the same direction but has a length of 1.
func (HexFractional) ProjectOn ¶
func (h HexFractional) ProjectOn(x HexFractional) HexFractional
ProjectOn projects h onto x. It returns a vector parallel to x.
func (HexFractional) Rotate ¶
func (h HexFractional) Rotate(center HexFractional, radians float64) HexFractional
Rotate should move a hex about a center point counterclockwise by some number of radians.
func (HexFractional) S ¶
func (h HexFractional) S() float64
S is the implicit additional coordinate when using cubic coordinate system.
func (HexFractional) String ¶
func (h HexFractional) String() string
String converts the hex to a string.
func (HexFractional) Subtract ¶
func (h HexFractional) Subtract(x HexFractional) HexFractional
Subtract combines two hexes.
func (HexFractional) ToCartesian ¶
func (h HexFractional) ToCartesian() (x, y float64)
ToCartesian returns the hex in Cartesian Coordinates.
func (HexFractional) ToHex ¶
func (h HexFractional) ToHex() Hex
ToHex takes in fractional hex coordinates in cubic coordinates and rounds them to the nearest actual hex coordinate. This is all in normal coordinate space, not screen space.
Directories
¶
Path | Synopsis |
---|---|
package area provides constructive solid geometry-style methods for building collections of hexes.
|
package area provides constructive solid geometry-style methods for building collections of hexes. |
examples
|
|
drawhx
Module
|
|
mesh
Module
|
|
Package path has a pathfinding algorithm that operates on hexcoords.
|
Package path has a pathfinding algorithm that operates on hexcoords. |