Documentation ¶
Overview ¶
Package paths3D is a simple library written in Go made to handle 3D pathfinding. All you need to do is generate a Grid, specify which cells aren't walkable and what height the cells are, optionally change the cost on specific cells, and finally get a path from one cell to another. For a simple guide, take a look at how-to.md in the github repo: https://github.com/Simzahn001/paths3D
Index ¶
- type Cell
- type Grid
- func (m *Grid) AddHeightMap(profile map[rune]int)
- func (m *Grid) AllCells() []*Cell
- func (m *Grid) CellsByCost(cost float64) []*Cell
- func (m *Grid) CellsByHeightLevel(heightLevel int) []*Cell
- func (m *Grid) CellsByRune(char rune) []*Cell
- func (m *Grid) CellsByWalkable(walkable bool) []*Cell
- func (m *Grid) DataAsRuneArrays() [][]rune
- func (m *Grid) DataAsStringArray() []string
- func (m *Grid) DataToString() string
- func (m *Grid) Get(x, y int) *Cell
- func (m *Grid) GetAverageHeight() float64
- func (m *Grid) GetHeightLevels() []int
- func (m *Grid) GetMaxHeight() int
- func (m *Grid) GetMinHeight() int
- func (m *Grid) GetPath(startX, startY, endX, endY float64, stepHeight, dropHeight int, ...) *Path
- func (m *Grid) GetPathFromCells(start, dest *Cell, stepHeight, dropHeight int, ...) *Path
- func (m *Grid) GetPathFromSettings(settings PathSettings) *Path
- func (m *Grid) Height() int
- func (m *Grid) SetCost(char rune, cost float64)
- func (m *Grid) SetHeightLevel(char rune, heightLevel int)
- func (m *Grid) SetWalkable(char rune, walkable bool)
- func (m *Grid) Visualise() (visualisation []string, error error)
- func (m *Grid) VisualisePath(path *Path) []string
- func (m *Grid) Width() int
- type Node
- type Path
- func (p *Path) Advance()
- func (p *Path) Current() *Cell
- func (p *Path) Get(index int) *Cell
- func (p *Path) Index(cell *Cell) int
- func (p *Path) IsAtEnd() bool
- func (p *Path) IsAtStart() bool
- func (p *Path) Length() int
- func (p *Path) Next() *Cell
- func (p *Path) Prev() *Cell
- func (p *Path) Restart()
- func (p *Path) Reverse()
- func (p *Path) Same(otherPath *Path) bool
- func (p *Path) SetIndex(index int)
- func (p *Path) TotalCost() float64
- type PathSettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cell ¶
A Cell represents a point on a Grid map. It has an X and Y value for the position, a Cost, which influences which Cells are ideal for paths, Walkable, which indicates if the tile can be walked on or should be avoided, a Rune, which indicates which rune character the Cell is represented by, and a HeightLevel (default: 0), which represents the height of this cell.
type Grid ¶
type Grid struct {
Data [][]*Cell
}
Grid represents a "map" composed of individual Cells at each point in the map. Data is a 2D array of Cells. CellWidth and CellHeight indicate the size of Cells for Cell Position <-> World Position translation.
func NewGridFromRuneArrays ¶
NewGridFromRuneArrays creates a Grid map from a 2D array of runes. Each individual Rune becomes a Cell in the resulting Grid.
func NewGridFromStringArrays ¶
NewGridFromStringArrays creates a Grid map from a 1D array of strings. Each string becomes a row of Cells, each with one rune as its character.
func (*Grid) AddHeightMap ¶
AddHeightMap adds a height to the grid via a key-value map. All runes, the map contains, do have an assigned height. This height is applied to ALL cells with this rune. After the execution of this method, letters aren't bound to the height; they are no pointers. If you change a letter, the height will stay the same. Keep in mind, that cell runes are case-sensitive.
func (*Grid) AllCells ¶
AllCells returns a single slice of pointers to all Cells contained in the Grid's 2D Data array.
func (*Grid) CellsByCost ¶
CellsByCost returns a slice of pointers to Cells that all have the Cost value provided.
func (*Grid) CellsByHeightLevel ¶
CellsByHeightLevel returns a slice of pointers to Cells that all have the height level provided.
func (*Grid) CellsByRune ¶
CellsByRune returns a slice of pointers to Cells that all have the character provided.
func (*Grid) CellsByWalkable ¶
CellsByWalkable returns a slice of pointers to Cells that all have the Cost value provided.
func (*Grid) DataAsRuneArrays ¶
DataAsRuneArrays returns a 2D array of runes for each Cell in the Grid. The first axis is the Y axis.
func (*Grid) DataAsStringArray ¶
DataAsStringArray returns a 2D array of runes for each Cell in the Grid. The first axis is the Y axis.
func (*Grid) DataToString ¶
DataToString returns a string, used to easily identify the Grid map.
func (*Grid) GetAverageHeight ¶
GetAverageHeight returns the average height over all the Grid. Use math.Round to get an int
func (*Grid) GetHeightLevels ¶
GetHeightLevels returns a list of all different height levels. use len() on the returned slice to get the amount of different height levels
func (*Grid) GetMaxHeight ¶
GetMaxHeight returns the maximum height of the whole Grid
func (*Grid) GetMinHeight ¶
GetMinHeight returns the minimum height of the whole Grid
func (*Grid) GetPath ¶
func (m *Grid) GetPath(startX, startY, endX, endY float64, stepHeight, dropHeight int, diagonals, wallsBlockDiagonals bool) *Path
GetPath returns a Path, from the starting cell's X and Y to the ending cell's X and Y. diagonals controls whether moving diagonally is acceptable when creating the Path. wallsBlockDiagonals indicates whether to allow diagonal movement "through" walls that are positioned diagonally. This is essentially just a smoother way to get a Path from GetPathFromCells().
func (*Grid) GetPathFromCells ¶
func (m *Grid) GetPathFromCells(start, dest *Cell, stepHeight, dropHeight int, diagonals, wallsBlockDiagonals bool) *Path
GetPathFromCells returns a Path, from the starting Cell to the destination Cell. diagonals controls whether moving diagonally is acceptable when creating the Path. wallsBlockDiagonals indicates whether to allow diagonal movement "through" walls that are positioned diagonally. If stepHeight and/or dropHeight are negative, they will not be used in the calculation -> infinite drop and/or step height
func (*Grid) GetPathFromSettings ¶
func (m *Grid) GetPathFromSettings(settings PathSettings) *Path
GetPathFromSettings returns a Path, from the starting Cell to the ending Cell. The starting and ending Cells as well as the other parameters (stepHeight, dropHeight, diagonals, wallsBlockDiagonals) are read from the passed PathSettings object.
func (*Grid) SetCost ¶
SetCost sets the movement cost across all cells in the Grid with the specified rune.
func (*Grid) SetHeightLevel ¶
SetHeightLevel sets the height level for all cells in the Grid with the specified rune.
func (*Grid) SetWalkable ¶
SetWalkable sets walkability across all cells in the Grid with the specified rune.
func (*Grid) Visualise ¶
Visualise return a string visualisation of the grid's cell heights. Not walkable blocks are represented by a blank space. An error is returned if there are more than 26 height levels. The heightmap is filled though, but every layer after the 26th is still visualised with the letter 'z'
func (*Grid) VisualisePath ¶
type Node ¶
Node represents the node a path, it contains the cell it represents. Also contains other information such as the parent and the cost.
type Path ¶
A Path is a struct that represents a path, or sequence of Cells from point A to point B. The Cells list is the list of Cells contained in the Path, and the CurrentIndex value represents the current step on the Path. Using Path.Next() and Path.Prev() advances and walks back the Path by one step.
func (*Path) Get ¶
Get returns the Cell of the specified index in the Path. If the index is outside of the length of the Path, it returns -1.
func (*Path) Index ¶
Index returns the index of the specified Cell in the Path. If the Cell isn't contained in the Path, it returns -1.
func (*Path) IsAtStart ¶
IsAtStart returns if the Path's current index is 0, the first Cell in the Path.
func (*Path) Next ¶
Next returns the next cell in the path. If the Path is at the end, Next() returns nil.
func (*Path) Prev ¶
Prev returns the previous cell in the path. If the Path is at the start, Prev() returns nil.
func (*Path) Restart ¶
func (p *Path) Restart()
Restart restarts the Path, so that calling path.Current() will now return the first Cell in the Path.
func (*Path) Same ¶
Same returns if the Path shares the exact same cells as the other specified Path.
type PathSettings ¶
type PathSettings struct {
// contains filtered or unexported fields
}
PathSettings represents the settings used when finding a path. See Grid.GetPath for more information on each setting. Create a path with Grid.GetPathFromSettings.
func NewDefaultPathSettings ¶
func NewDefaultPathSettings(startCell, endCell *Cell) *PathSettings
NewDefaultPathSettings returns a new PathSettings struct with default values.
Default values:
- StepHeight: 1
- DropHeight: 1
- Diagonals: true
- WallBlocksDiagonals: true