internal

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewGrid(r, c int, open bool) *Grid

NewGrid returns an r by c grid with all positions set to the specified open state.

func NewGridFrom

func NewGridFrom(rows ...string) *Grid

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) Dims

func (g *Grid) Dims() (r, c int)

Dims returns the dimensions of the grid.

func (*Grid) Edge

func (g *Grid) Edge(u, v graph.Node) graph.Edge

Edge returns the edge between u and v.

func (*Grid) EdgeBetween

func (g *Grid) EdgeBetween(u, v graph.Node) graph.Edge

EdgeBetween returns the edge between u and v.

func (*Grid) From

func (g *Grid) From(u graph.Node) []graph.Node

From returns all the nodes reachable from u.

func (*Grid) Has

func (g *Grid) Has(n graph.Node) bool

Has returns whether n is an open node in the grid.

func (*Grid) HasEdge

func (g *Grid) HasEdge(u, v graph.Node) bool

HasEdge returns whether there is an edge between u and v.

func (*Grid) NodeAt

func (g *Grid) NodeAt(r, c int) graph.Node

NodeAt returns the node at (r, c). The returned node may be open or closed.

func (*Grid) Nodes

func (g *Grid) Nodes() []graph.Node

Nodes returns all the open nodes in the grid.

func (*Grid) Render

func (g *Grid) Render(path []graph.Node) ([]byte, error)

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

func (g *Grid) RowCol(id int) (r, c int)

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

func (g *Grid) Set(r, c int, open bool)

Set sets the node at position (r, c) to the specified open state.

func (*Grid) String

func (g *Grid) String() string

String returns a string representation of the grid.

func (*Grid) Weight

func (g *Grid) Weight(e graph.Edge) float64

Weight returns the weight of the given edge.

func (*Grid) XY

func (g *Grid) XY(n graph.Node) (x, y float64)

XY returns the cartesian coordinates of n. If n is not a node in the grid, (NaN, NaN) is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL