Documentation
¶
Index ¶
- Constants
- Variables
- func DirectionToProto(d HexDir) pb.Direction
- func HexCircumference(r int) int
- func IsFullyConnected(s *HexSet) bool
- type AStarParams
- type AStarResult
- type AngularInterval
- type GeoCoord
- func (g GeoCoord) Add(g2 GeoCoord) GeoCoord
- func (g GeoCoord) Angle() float64
- func (c GeoCoord) Cross(v GeoCoord) float64
- func (g GeoCoord) DistanceTo(g2 GeoCoord) float64
- func (g GeoCoord) Length() float64
- func (c GeoCoord) Normalized() GeoCoord
- func (c GeoCoord) Scaled(s float64) GeoCoord
- func (g GeoCoord) SquareLength() float64
- func (p GeoCoord) String() string
- func (g GeoCoord) Sub(g2 GeoCoord) GeoCoord
- type HexCoord
- func BreadthFirstSearch(start HexCoord, isSteppable func(HexCoord, HexCoord) bool, ...) ([]HexCoord, error)
- func BreadthFirstSearchFromMultiple(frontierSet *HexSet, isSteppable func(HexCoord, HexCoord) bool, ...) ([]HexCoord, error)
- func DepthFirstSearch(start HexCoord, isSteppable func(HexCoord, HexCoord) bool, ...) ([]HexCoord, error)
- func HexCircle(r int) []HexCoord
- func HexDisk(r int) []HexCoord
- func HexFromProto(p *pb.HexCoord) (HexCoord, error)
- func NewHex(x, y int) HexCoord
- func NewHexPolar(r, step int) HexCoord
- func RandomHexOnCircle(r *rand.Rand, radius int) HexCoord
- func RayIntersection(start, delta HexCoord, set *HexSet) (HexCoord, error)
- func TryNewHex(x, y int) (HexCoord, error)
- func (c *HexCoord) AbsX() int
- func (c *HexCoord) AbsY() int
- func (c *HexCoord) AddDelta(d HexCoord) HexCoord
- func (c *HexCoord) AddMultDelta(m int, d HexCoord) HexCoord
- func (c HexCoord) CalculateFov(cone AngularInterval, maxR int, obstruct func(HexCoord) bool, ...)
- func (c HexCoord) ContainsRay(dx, dy float64) bool
- func (c HexCoord) ExtremeAngles() AngularInterval
- func (c HexCoord) Geo() GeoCoord
- func (c HexCoord) IsZero() bool
- func (a HexCoord) Less(b HexCoord) bool
- func (c HexCoord) Minus(p HexCoord) HexCoord
- func (c *HexCoord) Move(ds ...HexDir) HexCoord
- func (c HexCoord) Negation() HexCoord
- func (c *HexCoord) Neighbours() []HexCoord
- func (c *HexCoord) NeighboursSet() *HexSet
- func (c *HexCoord) Radius() int
- func (c HexCoord) String() string
- func (c HexCoord) ToProto() *pb.HexCoord
- func (c HexCoord) Vertex(i int) GeoCoord
- type HexDir
- type HexSet
- func FindConnectedComponent(start HexCoord, isContained func(HexCoord) bool) (*HexSet, error)
- func HexSetFromProto(p *pb.HexSet) (*HexSet, error)
- func HexSetWithHolesFilled(s *HexSet) *HexSet
- func NewHexSet() *HexSet
- func NewHexSetAround(p HexCoord, r int) *HexSet
- func NewHexSetSingleton(p HexCoord) *HexSet
- func (h *HexSet) Add(x HexCoord)
- func (h *HexSet) AddHex(i, j int)
- func (h *HexSet) Clone() *HexSet
- func (h *HexSet) Contains(x HexCoord) bool
- func (h *HexSet) ContainsHex(i, j int) bool
- func (h *HexSet) ContainsSet(xs *HexSet) bool
- func (h *HexSet) Difference(x *HexSet) *HexSet
- func (h *HexSet) Each(f func(HexCoord))
- func (h *HexSet) Enumerate() []HexCoord
- func (h *HexSet) Except(p HexCoord) *HexSet
- func (h *HexSet) Expand(n int)
- func (h *HexSet) ExpandFiltered(n int, f func(HexCoord) bool)
- func (h *HexSet) Expanded(n int) *HexSet
- func (h *HexSet) Filter(f func(HexCoord) bool)
- func (h *HexSet) Filtered(f func(HexCoord) bool) *HexSet
- func (s *HexSet) Freeze()
- func (c *HexSet) GeoDistanceHeuristic() func(HexCoord) float64
- func (s *HexSet) GoRepr() string
- func (h *HexSet) InPlaceUnion(x *HexSet)
- func (h *HexSet) Intersection(x *HexSet) *HexSet
- func (h *HexSet) Intersects(x *HexSet) bool
- func (h *HexSet) IntersectsWithOffset(x *HexSet, offset HexCoord) bool
- func (h *HexSet) MaxRadius() int
- func (s *HexSet) OuterBorder() *HexSet
- func (h *HexSet) PickArbitrary() (HexCoord, error)
- func (c *HexSet) Predicate() func(HexCoord) bool
- func (h *HexSet) Random() (HexCoord, error)
- func (h *HexSet) RandomFrom(r *rand.Rand) (HexCoord, error)
- func (h *HexSet) Remove(x HexCoord)
- func (h *HexSet) RemoveHex(i, j int)
- func (h *HexSet) Size() int
- func (h *HexSet) ToList() []HexCoord
- func (h *HexSet) ToOrderedList() []HexCoord
- func (c *HexSet) ToProto() *pb.HexSet
- func (h *HexSet) Union(x *HexSet) *HexSet
Constants ¶
Variables ¶
var ( // FullAngularInterval is the AngularInterval that contains all angles. FullAngularInterval = AngularInterval{Full: true} // EmptyAngularInterval is the AngularInterval that contains no angles. EmptyAngularInterval = AngularInterval{Empty: true} )
var ( OrderedDirections = []HexDir{ North, Northwest, Southwest, South, Southeast, Northeast, } OrthogonalCCW = map[HexDir]HexDir{ North: Southwest, Northwest: South, Southwest: Southeast, South: Northeast, Southeast: North, Northeast: Northwest, } Directions = map[HexDir]HexCoord{ North: HexCoord{0, 2}, Northwest: HexCoord{-1, 1}, Southwest: HexCoord{-1, -1}, South: HexCoord{0, -2}, Southeast: HexCoord{1, -1}, Northeast: HexCoord{1, 1}, } Origin = HexCoord{0, 0} )
Functions ¶
func DirectionToProto ¶
DirectionToProto converts a HexDir to a pb.Direction.
func HexCircumference ¶
HexCircumference computes the circumference (in number of cells) of a hex "circle" of radius r, where with the degenerate case of r=0 representing a single cell.
func IsFullyConnected ¶
IsFullyConnected checks whether a HexSet is fully connected.
Types ¶
type AStarParams ¶
type AStarParams struct {
Start *HexSet
IsGoal func(HexCoord) bool
Cost func(HexCoord, HexCoord) (float64, bool)
Heuristic func(HexCoord) float64
MaxCost float64
}
AStarParams provides parameters for an A* search.
type AStarResult ¶
AStarResult represents the result of an A* search.
type AngularInterval ¶
AngularInterval is a connected interval of angles.
func NewAngularInterval ¶
func NewAngularInterval(a0, a1 float64) AngularInterval
NewAngularInterval constructs a new angular interval -- neither empty nor full.
func NewAngularSextant ¶
func NewAngularSextant(section HexDir) AngularInterval
NewAngularSextant computes an AngularInterval corresponding to a given sextant (i.e. 60-degree section of the plane corresponding to the hex directions outwards from the origin).
func (AngularInterval) Contains ¶
func (n AngularInterval) Contains(a float64) bool
Contains tests whether another AngularInterval is contained in this one.
func (AngularInterval) Intersection ¶
func (n AngularInterval) Intersection(x AngularInterval) AngularInterval
Intersection computes the intersection of two AngularIntervals.
func (AngularInterval) Size ¶
func (n AngularInterval) Size() float64
Size returns the size (in radians) of an angular interval.
func (AngularInterval) String ¶
func (n AngularInterval) String() string
String returns a human-readable string form of an AngularInterval.
type GeoCoord ¶
type GeoCoord struct {
X, Y float64
}
GeoCoord is a geometric coordinate (a general coordinate on the 2D plane, not restricted to the hex grid).
func NewGeoPolar ¶
NewGeoPolar creates a GeoCoord, specified with polar coordinates.
func (GeoCoord) DistanceTo ¶
DistanceTo computes the distance between two GeoCoords.
func (GeoCoord) Normalized ¶
Normalized produces a new GeoCoord that is a normalized version of the old one.
func (GeoCoord) SquareLength ¶
SquareLength computes the squared length of a GeoCoord (the squared distance from the origin).
type HexCoord ¶
type HexCoord struct {
X, Y int
}
HexCoord is a coordinate on a hex grid. (X,Y) is a valid hex coordinate if and only if X and Y are of equal parity.
func BreadthFirstSearch ¶
func BreadthFirstSearch(start HexCoord, isSteppable func(HexCoord, HexCoord) bool, isGoal func(HexCoord) bool) ([]HexCoord, error)
BreadthFirstSearch runs a breadth-first search through a hex grid. The hex grid is specified through the two functions "isSteppable" (which determines whether a step from one coordinate to another is legal) and "isGoal" (which determines whether the goal has been reached).
func BreadthFirstSearchFromMultiple ¶
func BreadthFirstSearchFromMultiple(frontierSet *HexSet, isSteppable func(HexCoord, HexCoord) bool, isGoal func(HexCoord) bool) ([]HexCoord, error)
BreadthFirstSearchFromMultiple performs a breadth-first search (like BreadthFirstSearch), except starting from multiple coordinates at once.
func DepthFirstSearch ¶
func DepthFirstSearch(start HexCoord, isSteppable func(HexCoord, HexCoord) bool, isGoal func(HexCoord) bool) ([]HexCoord, error)
DepthFirstSearch performs a depth-first search on a hex grid. Like BreadthFirstSearch, the hex grid is specified through callback functions "isSteppable" and "isGoal".
func HexFromProto ¶
HexFromProto converts a proto to a HexCoord.
func NewHexPolar ¶
NewHexPolar computes a HexCoord using integral polar coordinates.
func RandomHexOnCircle ¶
RandomHexOnCircle returns a random hex on a "hex circle".
func RayIntersection ¶
RayIntersection finds the first intersection of a ray (where the direction is cell-aligned) with a HexSet. An error is returned if no intersection exists.
func TryNewHex ¶
TryNewHex creates a new HexCoord, returning an error if the two integers do not specify a valid coordinate (i.e. are not of equal parity).
func (*HexCoord) AddMultDelta ¶
AddMultDelta adds a multiple of a HexCoord; i.e. c + m * d.
func (HexCoord) CalculateFov ¶
func (c HexCoord) CalculateFov(cone AngularInterval, maxR int, obstruct func(HexCoord) bool, addLight func(HexCoord, AngularInterval))
CalculateFov calculates shadowcasting field-of-view from the origin. FOV may be restricted by angle or by radius (use -1) to not restrict by radius. Obstructions are specified through the "obstruct" callback. Output happens with the "addLight" callback which adds light to a certain HexCoord. Note that addLight can be called multiple times for one HexCoord.
func (HexCoord) ContainsRay ¶
ContainsRay tests whether the hex would intersect a given ray from the origin.
func (HexCoord) ExtremeAngles ¶
func (c HexCoord) ExtremeAngles() AngularInterval
ExtremeAngles computes the AngularInterval of this hexagon seen from the origin.
func (*HexCoord) Move ¶
Move computes a HexCoord that results after taking an number of steps from an initial HexCoord.
func (*HexCoord) Neighbours ¶
Neighbours computes a slice of the HexCoord's immediate neighbours.
func (*HexCoord) NeighboursSet ¶
NeighboursSet computes the HexSet of a HexCoord's immediate neighbours.
type HexDir ¶
type HexDir int32
HexDir represents one of the six directions on a hex grid.
func DirectionFromProto ¶
DirectionFromProto converts a pb.Direction to a HexDir.
type HexSet ¶
type HexSet struct {
// contains filtered or unexported fields
}
HexSet is a set of HexCoords.
func FindConnectedComponent ¶
FindConnectedComponent determines, given a representative coordinate and a membership-test function, the connected component of the representative.
func HexSetFromProto ¶
HexSetFromProto converts a pb.HexSet proto to a HexSet.
func HexSetWithHolesFilled ¶
HexSetWithHolesFilled returns a HexSet with any internal holes filled.
func NewHexSetAround ¶
NewHexSetAround creates a new HexSet containing one HexCoord and all HexCoords within a certain radius of it.
func NewHexSetSingleton ¶
NewHexSetSingleton creates a new HexSet containing a single HexCoord.
func (*HexSet) AddHex ¶
RemoveHex adds a certain HexCoord (specified explicitly with integers) to the HexSet.
func (*HexSet) ContainsHex ¶
ContainsHex checks whether a certain HexCoord (specified explicitly with integers) is in the HexSet.
func (*HexSet) ContainsSet ¶
ContainsSet checks whether a HexSet contains an entire other set.
func (*HexSet) Difference ¶
Difference removes all elements in another HexSet from this HexSet.
func (*HexSet) Except ¶
Except computes a new HexSet that is like this one, except not containing a certain HexCoord.
func (*HexSet) ExpandFiltered ¶
ExpandFiltered expands the HexSet n steps outwards; except not proceeding into any hex p where f(p) return false.
func (*HexSet) Expanded ¶
Expanded computes a new HexSet that is like the old one, except expanded by n steps.
func (*HexSet) Filtered ¶
Filtered computes a new HexSet that is like the old one, except only containing HexCoords p where f(p) returns true.
func (*HexSet) GeoDistanceHeuristic ¶
GeoDistanceHeuristic returns a function f(x) that, given a HexCoord x, computes the minimum geometric distance to any point p in the HexSet.
func (*HexSet) GoRepr ¶
GoRepr returns an explicit Go representation of the HexSet (code that would produce it).
func (*HexSet) InPlaceUnion ¶
InPlaceUnion mutates the HexSet to take the union with another.
func (*HexSet) Intersection ¶
Intersection computes the intersection of two HexSets.
func (*HexSet) Intersects ¶
Intersects checks whether two HexSets intersect.
func (*HexSet) IntersectsWithOffset ¶
IntersectsWithOffset checks whether a HexSet intersects with the result of mapping over another by (+offset), i.e. adding a certain HexCoord delta to each element.
func (*HexSet) MaxRadius ¶
MaxRadius returns an upper bound on the radius of the HexCoords in the set.
func (*HexSet) OuterBorder ¶
OuterBorder computes the outer border of the HexSet.
func (*HexSet) PickArbitrary ¶
PickArbitrary picks an arbitrary HexCoord from a HexSet.
func (*HexSet) Predicate ¶
Predicate converts the HexSet to a callback that checks for HexCoord membership in the set.
func (*HexSet) RandomFrom ¶
RandomFrom selects a random HexCoord from a HexSet, using a specified rand.Rand.
func (*HexSet) RemoveHex ¶
RemoveHex removes a certain HexCoord (specified explicitly with integers) from the HexSet.
func (*HexSet) ToOrderedList ¶
ToOrderedList converts a HexSet to an ordered list of HexCoords.