Documentation
¶
Overview ¶
Package gridutil provides utility functions for grid-based pathfinding. All functions work with any grid type that implements grid.Grid.
Index ¶
- func HasLineOfSight(g grid.Grid, x1, y1, x2, y2 int) bool
- func HasLineOfSightWorld(g grid.Grid, x1, y1, x2, y2 float32) bool
- func Line(x0, y0, x1, y1 int) [][2]int
- func RandomInRing(g grid.Grid, cx, cy, innerR, outerR int) (int, int, bool)
- func RandomInRingWorld(g grid.Grid, wx, wy float32, innerR, outerR int) (float32, float32, bool)
- func RandomWalkable(g grid.Grid) (int, int, bool)
- func RandomWalkableInRadius(g grid.Grid, cx, cy, radius int) (int, int, bool)
- func RandomWalkableInRadiusWorld(g grid.Grid, wx, wy float32, radius int) (float32, float32, bool)
- func RandomWalkableWorld(g grid.Grid) (float32, float32, bool)
- func TileDistance(x1, y1, x2, y2 int) int
- func TilesInRadius(cx, cy, r int) [][2]int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasLineOfSight ¶
HasLineOfSight reports whether two tiles can see each other — every tile on the Bresenham line between them is walkable.
func HasLineOfSightWorld ¶
HasLineOfSightWorld reports whether two world positions can see each other.
func Line ¶
Line returns all tiles on the Bresenham line from (x0, y0) to (x1, y1), including both endpoints.
func RandomInRing ¶
RandomInRing returns a random walkable tile with Chebyshev distance between innerR and outerR from (cx, cy). The inner exclusion zone is useful for spawning units around a point without landing on the spot.
func RandomInRingWorld ¶
RandomInRingWorld returns the world center of a random walkable tile with Chebyshev distance between innerR and outerR from (wx, wy).
func RandomWalkable ¶
RandomWalkable returns a random walkable tile coordinate.
func RandomWalkableInRadius ¶
RandomWalkableInRadius returns a random walkable tile within radius tiles of (cx, cy).
func RandomWalkableInRadiusWorld ¶
RandomWalkableInRadiusWorld returns the world center of a random walkable tile within radius tiles of (wx, wy).
func RandomWalkableWorld ¶
RandomWalkableWorld returns the world center of a random walkable tile.
func TileDistance ¶
TileDistance returns the Chebyshev distance between two tiles: max(|dx|, |dy|). This is the number of steps needed for 8-directional movement.
func TilesInRadius ¶
TilesInRadius returns all tiles within Chebyshev distance r from (cx, cy). The result includes (cx, cy) itself.
Types ¶
This section is empty.