Documentation
¶
Overview ¶
Package gridutil provides utility functions for grid-based pathfinding. All functions work with any grid type that satisfies the minimal interfaces defined here (GridLOS, GridWorld). No grid/finder package imports needed.
Index ¶
- func BresenhamLine(x0, y0, x1, y1 int) [][2]int
- func CompressPath(path [][2]int) [][2]int
- func HasLineOfSightBresenham(g GridLOS, x1, y1, x2, y2 int) bool
- func HasLineOfSightDense(g GridWorld, x1, y1, x2, y2 int) bool
- func RandomInRing(g GridLOS, cx, cy, innerR, outerR int) (int, int, bool)
- func RandomInRingWorld(g GridWorld, wx, wy float32, innerR, outerR int) (float32, float32, bool)
- func RandomWalkable(g GridLOS) (int, int, bool)
- func RandomWalkableInRadius(g GridLOS, cx, cy, radius int) (int, int, bool)
- func RandomWalkableInRadiusWorld(g GridWorld, wx, wy float32, radius int) (float32, float32, bool)
- func RandomWalkableWorld(g GridWorld) (float32, float32, bool)
- func SmoothenBresenham(g GridLOS, path [][2]int) [][2]int
- func SmoothenBresenhamStrict(g GridLOS, path [][2]int) [][2]int
- func SmoothenDense(g GridWorld, path [][2]int) [][2]int
- func TileDistance(x1, y1, x2, y2 int) int
- func TilesInRadius(cx, cy, r int) [][2]int
- type GridLOS
- type GridWorld
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BresenhamLine ¶ added in v0.8.0
BresenhamLine returns all tiles on the Bresenham line from (x0, y0) to (x1, y1), including both endpoints.
func CompressPath ¶ added in v0.8.0
CompressPath removes collinear waypoints from a tile path without any line-of-sight checking. Only points where the direction changes are kept. This is guaranteed to never cut corners since it only removes truly redundant waypoints. Writes the result in-place over the input buffer.
func HasLineOfSightBresenham ¶ added in v0.8.0
HasLineOfSightBresenham reports whether two tiles can see each other — every tile on the Bresenham line between them is walkable. Only suitable for orthogonal grids. For hex and staggered grids, use HasLineOfSightDense instead.
func HasLineOfSightDense ¶ added in v0.8.0
HasLineOfSightDense reports whether two tiles can see each other using world-space sub-tile sampling. Suitable for all grid types. For orthogonal grids, HasLineOfSightBresenham is more efficient.
func RandomInRing ¶
RandomInRing returns a random walkable tile with Chebyshev distance between innerR and outerR from (cx, cy).
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 SmoothenBresenham ¶ added in v0.8.0
SmoothenBresenham removes unnecessary waypoints from a tile path using Bresenham line-of-sight (greedy string-pulling). Only suitable for orthogonal grids. For hex and staggered grids, use SmoothenDense instead. Writes the result in-place over the input buffer (the finder's cached pathBuf).
func SmoothenBresenhamStrict ¶ added in v0.8.0
SmoothenBresenhamStrict is like SmoothenBresenham but also checks corner cells at each diagonal step, preventing the smoothed path from cutting through the corner of a blocked tile. Only suitable for orthogonal grids.
func SmoothenDense ¶ added in v0.8.0
SmoothenDense removes unnecessary waypoints from a tile path using world-space line-of-sight sampling. Suitable for all grid types. Writes the result in-place over the input buffer.
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).
Types ¶
type GridLOS ¶ added in v0.8.0
GridLOS is the interface for tile-space operations (LOS, smoothing). All grid types (*OrthogonalGrid, *HexGrid, *StaggeredGrid) satisfy it.
type GridWorld ¶ added in v0.8.0
type GridWorld interface {
GridLOS
TileToWorld(tx, ty int) (float32, float32)
WorldToTile(wx, wy float32) (int, int)
TileWidth() int
TileHeight() int
}
GridWorld extends GridLOS with world coordinate conversion. Needed by SmoothenPathDense and other world-space utilities.