Documentation
¶
Index ¶
- Constants
- type Grid
- func (g *Grid) Dims() (r, c int)
- func (g *Grid) Edge(u, v graph.Node) graph.Edge
- func (g *Grid) EdgeBetween(u, v graph.Node) graph.Edge
- func (g *Grid) From(u graph.Node) []graph.Node
- func (g *Grid) Has(n graph.Node) bool
- func (g *Grid) HasEdge(u, v graph.Node) bool
- func (g *Grid) NodeAt(r, c int) graph.Node
- func (g *Grid) Nodes() []graph.Node
- func (g *Grid) Render(path []graph.Node) ([]byte, error)
- func (g *Grid) RowCol(id int) (r, c int)
- func (g *Grid) Set(r, c int, open bool)
- func (g *Grid) String() string
- func (g *Grid) Weight(e graph.Edge) float64
- func (g *Grid) XY(n graph.Node) (x, y float64)
Constants ¶
const ( Closed = '*' // Closed is the closed grid node representation. Open = '.' // Open is the open grid node repesentation. )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Grid ¶
type Grid struct { // AllowDiagonal specifies whether // diagonally adjacent nodes can // be connected by an edge. AllowDiagonal bool // contains filtered or unexported fields }
Grid is a 2D grid planar undirected graph.
func NewGrid ¶
NewGrid returns an r by c grid with all positions set to the specified open state.
func NewGridFrom ¶
NewGridFrom returns a grid specified by the rows strings. All rows must be the same length and must only contain the Open or Closed characters, NewGridFrom will panic otherwise.
func (*Grid) Edge ¶
Edge returns the edge between u and v.
func (*Grid) EdgeBetween ¶
EdgeBetween returns the edge between u and v.
func (*Grid) From ¶
From returns all the nodes reachable from u.
func (*Grid) Has ¶
Has returns whether n is an open node in the grid.
func (*Grid) HasEdge ¶
HasEdge returns whether there is an edge between u and v.
func (*Grid) NodeAt ¶
NodeAt returns the node at (r, c). The returned node may be open or closed.
func (*Grid) Nodes ¶
Nodes returns all the open nodes in the grid.
func (*Grid) Render ¶
Render returns a text representation of the graph with the given path included. If the path is not a path in the grid Render returns a non-nil error and the path up to that point.
func (*Grid) RowCol ¶
RowCol returns the row and column of the id. RowCol will panic if the node id is outside the range of the grid.
func (*Grid) Set ¶
Set sets the node at position (r, c) to the specified open state.
func (*Grid) String ¶
String returns a string representation of the grid.
func (*Grid) Weight ¶
Weight returns the weight of the given edge.
Source Files
¶
- grid.go