Documentation ¶
Index ¶
- Constants
- Variables
- type Direction
- type Edge
- type Item
- type Node
- type Path
- func (p *Path) Neighbors(nodeX int, nodeY int) (neighbors []*Edge)
- func (p *Path) NewNode(ix int, iy int, isCollider bool, cost float64)
- func (p *Path) Node(x int, y int) *Node
- func (p *Path) Path(startX int, startY int, endX int, endY int) (path []*Edge, err error)
- func (p *Path) Route(startX, startY, endX, endY int) ([]*Edge, error)
- type PriorityQueue
- type Rectangle
- type Vector
- func (v *Vector) Add(nv *Vector) *Vector
- func (v *Vector) Angle() float64
- func (v *Vector) Copy() *Vector
- func (v *Vector) Cross(nv *Vector) float64
- func (v *Vector) Dot(nv *Vector) float64
- func (v *Vector) Equal(nv *Vector) bool
- func (v *Vector) Len() float64
- func (v *Vector) Lerp(a *Vector, b *Vector, t float64) *Vector
- func (v *Vector) Map(f func(float64) float64) *Vector
- func (v *Vector) Normal() *Vector
- func (v *Vector) Project(nv *Vector) *Vector
- func (v *Vector) Rotated(angle float64) *Vector
- func (v *Vector) Scaled(s float64) *Vector
- func (v *Vector) ScaledXY(nv *Vector) *Vector
- func (v *Vector) String() string
- func (v *Vector) Sub(nv *Vector) *Vector
- func (v *Vector) Unit() *Vector
- func (v *Vector) XY() (x, y float64)
Constants ¶
const ( // Up is a direction Up = Direction(0) // Right is a direction Right = Direction(1) // Down is a direction Down = Direction(2) // Left is a direction Left = Direction(3) )
Variables ¶
var ( // ErrNoNodesLoaded is returned when a path is called before any nodes are set ErrNoNodesLoaded = fmt.Errorf("no nodes are loaded") // ErrRouteNotFound is returned when all options are exhausted ErrRouteNotFound = fmt.Errorf("route not found") )
var ZV = &Vector{0, 0}
ZV is a zero vector
Functions ¶
This section is empty.
Types ¶
type Item ¶ added in v0.0.9
type Item struct {
// contains filtered or unexported fields
}
Item represents a node item
type Node ¶ added in v0.0.9
Node represents an element in the grid
type Path ¶ added in v0.0.9
type Path struct {
// contains filtered or unexported fields
}
Path represents a navigation mesh
type PriorityQueue ¶ added in v0.0.9
type PriorityQueue []*Item
PriorityQueue is an array of items
func (PriorityQueue) Len ¶ added in v0.0.9
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶ added in v0.0.9
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶ added in v0.0.9
func (pq *PriorityQueue) Pop() interface{}
Pop removes an item from a queue
func (*PriorityQueue) Push ¶ added in v0.0.9
func (pq *PriorityQueue) Push(x interface{})
Push add an item to a queue
func (PriorityQueue) Swap ¶ added in v0.0.9
func (pq PriorityQueue) Swap(i, j int)
type Rectangle ¶
type Rectangle struct {
Min, Max Vector
}
Rectangle is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two points, Min and Max.
The invariant should hold, that Max's components are greater or equal than Min's components respectively.
func RectImageCopy ¶
RectImageCopy converts an image rectangle to model rect
type Vector ¶
type Vector struct {
X, Y float64
}
Vector is a 2D vector type with X and Y coordinates
func NewVectorFromPoint ¶
NewVectorFromPoint converts an image point to a vector
func (*Vector) Angle ¶
Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].
func (*Vector) Lerp ¶
Lerp returns a linear interpolation between vector a and b.
This function basically returns a point along the line between a and b and t chooses which one. If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will return the appropriate point between a and b and so on.
func (*Vector) Map ¶
Map applies the function f to both x and y components of the vector u and returns the modified vector.
u := pixel.V(10.5, -1.5) v := nv.Map(math.Floor) // v is Vector(10, -2), both components of u floored
func (*Vector) Normal ¶
Normal returns a vector normal to nv. Equivalent to nv.Rotated(math.Pi / 2), but faster.
func (*Vector) Project ¶
Project returns a projection (or component) of vector u in the direction of vector v.
Behaviour is undefined if v is a zero vector.