Documentation
¶
Index ¶
- Variables
- func NewMatrix(w, h int) [][]int
- type Grid
- type GridType
- type HexGrid
- func (g *HexGrid) Clone() finder.Grid
- func (g *HexGrid) FindNearestWalkable(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
- func (g *HexGrid) FindNearestWalkableTile(wx, wy float32, maxRadius int) (int, int, bool)
- func (g *HexGrid) FindPath(wx1, wy1, wx2, wy2 float32) [][2]float32
- func (g *HexGrid) FindSmoothPath(wx1, wy1, wx2, wy2 float32) [][2]float32
- func (g *HexGrid) Finder() finder.Finder
- func (g *HexGrid) GetNeighbors(node *finder.Node, _ finder.DiagonalMovement, buffer []*finder.Node) []*finder.Node
- func (g *HexGrid) GetNodeAt(x, y int) *finder.Node
- func (g *HexGrid) GetWeightAt(x, y int) float64
- func (g *HexGrid) Height() int
- func (g *HexGrid) IsInside(x, y int) bool
- func (g *HexGrid) IsWalkableAt(x, y int) bool
- func (g *HexGrid) IsWalkableAtWorld(wx, wy float32) bool
- func (g *HexGrid) ObstacleCount() int
- func (g *HexGrid) RenderSVG(cfg *SVGOpts, paths ...[][2]int) string
- func (g *HexGrid) SetWalkableAt(x, y int, walkable bool)
- func (g *HexGrid) SetWalkableAtWorld(wx, wy float32, walkable bool)
- func (g *HexGrid) SetWeightAt(x, y int, weight float64)
- func (g *HexGrid) SmoothenTilePath(path [][2]int) [][2]int
- func (g *HexGrid) TileToWorld(tx, ty int) (float32, float32)
- func (g *HexGrid) Width() int
- func (g *HexGrid) WorldToTile(wx, wy float32) (int, int)
- type HexOption
- type OrthogonalGrid
- func (g *OrthogonalGrid) Clone() finder.Grid
- func (g *OrthogonalGrid) FindNearestWalkable(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
- func (g *OrthogonalGrid) FindNearestWalkableTile(wx, wy float32, maxRadius int) (int, int, bool)
- func (g *OrthogonalGrid) FindPath(wx1, wy1, wx2, wy2 float32) [][2]float32
- func (g *OrthogonalGrid) FindSmoothPath(wx1, wy1, wx2, wy2 float32) [][2]float32
- func (g *OrthogonalGrid) Finder() finder.Finder
- func (g *OrthogonalGrid) GetNeighbors(node *finder.Node, diagonal finder.DiagonalMovement, buffer []*finder.Node) []*finder.Node
- func (g *OrthogonalGrid) GetNodeAt(x, y int) *finder.Node
- func (g *OrthogonalGrid) GetWeightAt(x, y int) float64
- func (g *OrthogonalGrid) Height() int
- func (g *OrthogonalGrid) IsInside(x, y int) bool
- func (g *OrthogonalGrid) IsWalkableAt(x, y int) bool
- func (g *OrthogonalGrid) IsWalkableAtWorld(wx, wy float32) bool
- func (g *OrthogonalGrid) ObstacleCount() int
- func (g *OrthogonalGrid) RenderSVG(cfg *SVGOpts, paths ...[][2]int) string
- func (g *OrthogonalGrid) SetWalkableAt(x, y int, walkable bool)
- func (g *OrthogonalGrid) SetWalkableAtWorld(wx, wy float32, walkable bool)
- func (g *OrthogonalGrid) SetWeightAt(x, y int, weight float64)
- func (g *OrthogonalGrid) SmoothenTilePath(path [][2]int) [][2]int
- func (g *OrthogonalGrid) SupportsJPSCanonicalPruning() bool
- func (g *OrthogonalGrid) TileHeight() int
- func (g *OrthogonalGrid) TileToWorld(tx, ty int) (float32, float32)
- func (g *OrthogonalGrid) TileWidth() int
- func (g *OrthogonalGrid) Width() int
- func (g *OrthogonalGrid) WorldToTile(wx, wy float32) (int, int)
- type OrthogonalOption
- type SVGOpts
- type StaggerOption
- type StaggeredGrid
- func (g *StaggeredGrid) Clone() finder.Grid
- func (g *StaggeredGrid) FindNearestWalkable(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
- func (g *StaggeredGrid) FindNearestWalkableTile(wx, wy float32, maxRadius int) (int, int, bool)
- func (g *StaggeredGrid) FindPath(wx1, wy1, wx2, wy2 float32) [][2]float32
- func (g *StaggeredGrid) FindSmoothPath(wx1, wy1, wx2, wy2 float32) [][2]float32
- func (g *StaggeredGrid) Finder() finder.Finder
- func (g *StaggeredGrid) GetNeighbors(node *finder.Node, diagonal finder.DiagonalMovement, buffer []*finder.Node) []*finder.Node
- func (g *StaggeredGrid) GetNodeAt(x, y int) *finder.Node
- func (g *StaggeredGrid) GetWeightAt(x, y int) float64
- func (g *StaggeredGrid) Height() int
- func (g *StaggeredGrid) IsInside(x, y int) bool
- func (g *StaggeredGrid) IsWalkableAt(x, y int) bool
- func (g *StaggeredGrid) IsWalkableAtWorld(wx, wy float32) bool
- func (g *StaggeredGrid) ObstacleCount() int
- func (g *StaggeredGrid) RenderSVG(cfg *SVGOpts, paths ...[][2]int) string
- func (g *StaggeredGrid) SetWalkableAt(x, y int, walkable bool)
- func (g *StaggeredGrid) SetWalkableAtWorld(wx, wy float32, walkable bool)
- func (g *StaggeredGrid) SetWeightAt(x, y int, weight float64)
- func (g *StaggeredGrid) SmoothenTilePath(path [][2]int) [][2]int
- func (g *StaggeredGrid) TileToWorld(tx, ty int) (float32, float32)
- func (g *StaggeredGrid) Width() int
- func (g *StaggeredGrid) WorldToTile(wx, wy float32) (int, int)
Constants ¶
This section is empty.
Variables ¶
var DefaultSVGOpts = &SVGOpts{ WeightColors: [][2]string{ {"0.3", "#bbdefb"}, {"1.0", "#c8e6c9"}, {"2.0", "#fff9c4"}, {"5.0", "#ffcc80"}, {"+Inf", "#ef5350"}, }, LegendEntries: [][2]string{ {"#bbdefb", "Road ≤0.3"}, {"#c8e6c9", "Grass ≤1.0"}, {"#fff9c4", "Sand ≤2.0"}, {"#ffcc80", "Swamp ≤5.0"}, {"#ef5350", ">5.0 Extreme"}, {"#555555", "Wall"}, }, }
DefaultSVGOpts is the default SVG rendering config, used when nil is passed.
Functions ¶
Types ¶
type Grid ¶ added in v0.3.0
type Grid interface {
// Tile coordinate queries
Width() int
Height() int
IsInside(x, y int) bool
IsWalkableAt(x, y int) bool
SetWalkableAt(x, y int, walkable bool)
GetNodeAt(x, y int) *finder.Node
ObstacleCount() int
// Tile weight support
SetWeightAt(x, y int, weight float64)
GetWeightAt(x, y int) float64
// World coordinate conversion
WorldToTile(wx, wy float32) (int, int)
TileToWorld(tx, ty int) (float32, float32)
IsWalkableAtWorld(wx, wy float32) bool
SetWalkableAtWorld(wx, wy float32, walkable bool)
// Nearest walkable search
FindNearestWalkable(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
FindNearestWalkableTile(wx, wy float32, maxRadius int) (int, int, bool)
// Pathfinding
Finder() finder.Finder
FindPath(wx1, wy1, wx2, wy2 float32) [][2]float32
FindSmoothPath(wx1, wy1, wx2, wy2 float32) [][2]float32
SmoothenTilePath(path [][2]int) [][2]int
// Rendering
RenderSVG(cfg *SVGOpts, paths ...[][2]int) string
}
Grid defines the interface that all grid types implement. It focuses on grid-consumer operations: coordinate conversion, walkability queries, pathfinding, and rendering. This is separate from finder.Grid, which only exposes what pathfinding algorithms need.
type HexGrid ¶
type HexGrid struct {
// contains filtered or unexported fields
}
HexGrid is a hexagonal grid using axial coordinates (X, Y). Supports both flat-top (stagger on X) and pointy-top (stagger on Y) layouts, matching Tiled's "hexagonal" orientation.
Derived layout parameters (sideOffX/Y, colW, rowH) are precomputed in NewHexGrid to avoid per-call overhead.
func NewHexGrid ¶
NewHexGrid creates a HexGrid from a walkability matrix (0=walkable, non-zero=obstacle). Default tile size is 64×64 pixels. Default finder is AStarFinder.
func (*HexGrid) Clone ¶
Clone returns a deep copy of the hex grid, including a copy of all nodes with parent references cleared. The clone shares the finder and precomputed layout parameters but owns its own node slice.
func (*HexGrid) FindNearestWalkable ¶ added in v0.3.0
func (g *HexGrid) FindNearestWalkable(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
FindNearestWalkable finds the nearest walkable tile within maxRadius (tile rings) from the given world position (wx, wy). See Grid.FindNearestWalkable for details.
func (*HexGrid) FindNearestWalkableTile ¶ added in v0.3.0
FindNearestWalkableTile finds the nearest walkable tile within maxRadius (tile rings) from the given world position (wx, wy). Returns the tile coordinates and true if found; returns (0, 0, false) if no walkable tile exists within the search radius.
func (*HexGrid) FindPath ¶
FindPath finds a path between two world positions through the hex grid. The returned [][2]float32 is backed by an internal buffer and is only valid until the next FindPath/FindSmoothPath call on the same grid.
func (*HexGrid) FindSmoothPath ¶
FindSmoothPath finds a path between two world positions and smooths it. Same buffer contract as FindPath.
func (*HexGrid) GetNeighbors ¶
func (g *HexGrid) GetNeighbors(node *finder.Node, _ finder.DiagonalMovement, buffer []*finder.Node) []*finder.Node
GetNeighbors returns the 6 hex neighbors. Diagonal parameter is ignored because hex grids have no separate diagonal concept — all 6 are cardinal moves.
func (*HexGrid) GetNodeAt ¶
GetNodeAt returns the node at the given tile coordinates. The coordinates must be inside the grid; the caller should check IsInside first.
func (*HexGrid) GetWeightAt ¶ added in v0.5.0
GetWeightAt returns the movement cost multiplier for the tile at (x, y).
func (*HexGrid) IsInside ¶
IsInside reports whether the given tile coordinates are within the grid bounds.
func (*HexGrid) IsWalkableAt ¶
IsWalkableAt reports whether the tile at the given coordinates is walkable. Coordinates outside the grid bounds are considered not walkable.
func (*HexGrid) IsWalkableAtWorld ¶
IsWalkableAtWorld checks walkability at a world position.
func (*HexGrid) ObstacleCount ¶ added in v0.3.0
ObstacleCount returns the number of non-walkable tiles in the grid.
func (*HexGrid) SetWalkableAt ¶
SetWalkableAt sets the walkability of the tile at the given coordinates.
func (*HexGrid) SetWalkableAtWorld ¶
SetWalkableAtWorld sets walkability at a world position.
func (*HexGrid) SetWeightAt ¶ added in v0.5.0
SetWeightAt sets the movement cost multiplier for the tile at (x, y).
func (*HexGrid) SmoothenTilePath ¶
SmoothenTilePath smooths a tile-coordinate hex path by removing unnecessary waypoints. Writes the smoothed result in-place over the input (finder's cached pathBuf).
func (*HexGrid) TileToWorld ¶
TileToWorld converts hex tile coordinates to world (pixel) position (tile center).
type HexOption ¶
type HexOption func(*HexGrid)
HexOption configures a HexGrid.
func WithHexEvenStagger ¶
func WithHexEvenStagger() HexOption
WithHexEvenStagger configures even-index stagger offset. Default is odd-index.
func WithHexFinder ¶
WithHexFinder sets the pathfinder and returns the grid.
func WithHexFlatTop ¶
func WithHexFlatTop() HexOption
WithHexFlatTop configures flat-top hexagons (stagger on X axis). Default is pointy-top.
func WithHexSide ¶
WithHexSide sets the hex side length in pixels.
func WithHexTileSize ¶
WithHexTileSize sets the pixel dimensions of the hex tile.
type OrthogonalGrid ¶
type OrthogonalGrid struct {
// contains filtered or unexported fields
}
OrthogonalGrid is a standard rectangular grid. Coordinates are in tile space. World-space helpers convert using tileW/tileH.
func NewOrthogonalGrid ¶
func NewOrthogonalGrid(matrix [][]int, opts ...OrthogonalOption) *OrthogonalGrid
NewOrthogonalGrid creates an OrthogonalGrid from a matrix (0=walkable, non-zero=obstacle). Default tile size is 1×1 world unit. Default finder is AStarFinder.
func (*OrthogonalGrid) Clone ¶
func (g *OrthogonalGrid) Clone() finder.Grid
Clone creates a deep copy of the grid. The returned grid has its own node slice; each node is copied, but the parent pointer is cleared. The finder reference and tile dimensions are shared from the original.
func (*OrthogonalGrid) FindNearestWalkable ¶ added in v0.3.0
func (g *OrthogonalGrid) FindNearestWalkable(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
FindNearestWalkable finds the nearest walkable tile within maxRadius (tile rings) from the given world position (wx, wy). See the method doc on Grid for details.
func (*OrthogonalGrid) FindNearestWalkableTile ¶ added in v0.3.0
FindNearestWalkableTile finds the nearest walkable tile within maxRadius (tile rings) from the given world position (wx, wy). Returns the tile coordinates and true if found; returns (0, 0, false) if no walkable tile exists within the search radius.
func (*OrthogonalGrid) FindPath ¶
func (g *OrthogonalGrid) FindPath(wx1, wy1, wx2, wy2 float32) [][2]float32
FindPath finds a path between two world positions through the grid. The returned [][2]float32 is backed by an internal buffer and is only valid until the next FindPath/FindSmoothPath call on the same grid. Automatically smooths the path via SmoothenTilePath when smoothing is enabled (default). Disable with WithGridSmoothing(false) when using a finder that already does its own smoothing, such as WaypointFinder.
func (*OrthogonalGrid) FindSmoothPath ¶
func (g *OrthogonalGrid) FindSmoothPath(wx1, wy1, wx2, wy2 float32) [][2]float32
FindSmoothPath finds a path between two world positions and smooths it. Same buffer contract as FindPath.
func (*OrthogonalGrid) Finder ¶
func (g *OrthogonalGrid) Finder() finder.Finder
Finder returns the pathfinder associated with this grid.
func (*OrthogonalGrid) GetNeighbors ¶
func (g *OrthogonalGrid) GetNeighbors(node *finder.Node, diagonal finder.DiagonalMovement, buffer []*finder.Node) []*finder.Node
GetNeighbors returns the walkable neighbors of the given node. The diagonal parameter controls which diagonal moves are permitted. The result is written into the provided buffer slice (which is resliced to zero and reused), so the caller must not hold references past the next call.
func (*OrthogonalGrid) GetNodeAt ¶
func (g *OrthogonalGrid) GetNodeAt(x, y int) *finder.Node
GetNodeAt returns the node at tile coordinate (x, y). The caller must ensure the coordinate is inside the grid (see IsInside); otherwise the method panics.
func (*OrthogonalGrid) GetWeightAt ¶ added in v0.5.0
func (g *OrthogonalGrid) GetWeightAt(x, y int) float64
GetWeightAt returns the movement cost multiplier for the tile at (x, y). Returns the default weight (1.0) for tiles outside the grid.
func (*OrthogonalGrid) Height ¶
func (g *OrthogonalGrid) Height() int
Height returns the number of tiles vertically in the grid.
func (*OrthogonalGrid) IsInside ¶
func (g *OrthogonalGrid) IsInside(x, y int) bool
IsInside reports whether the tile coordinate (x, y) is within the grid bounds.
func (*OrthogonalGrid) IsWalkableAt ¶
func (g *OrthogonalGrid) IsWalkableAt(x, y int) bool
IsWalkableAt reports whether the tile at (x, y) is walkable. Coordinates outside the grid are reported as not walkable.
func (*OrthogonalGrid) IsWalkableAtWorld ¶
func (g *OrthogonalGrid) IsWalkableAtWorld(wx, wy float32) bool
IsWalkableAtWorld reports whether the tile at the given world-space coordinate is walkable. The coordinate is converted to tile-space via WorldToTile before checking.
func (*OrthogonalGrid) ObstacleCount ¶ added in v0.3.0
func (g *OrthogonalGrid) ObstacleCount() int
ObstacleCount returns the number of non-walkable tiles in the grid.
func (*OrthogonalGrid) RenderSVG ¶
func (g *OrthogonalGrid) RenderSVG(cfg *SVGOpts, paths ...[][2]int) string
RenderSVG renders the grid with weight-colored tiles and one or more paths. Each path in paths is drawn in a different color. The first path uses the default blue; additional paths cycle through red, green, and purple. Walkable tiles are colored by their Weight field:
weight=1.0 (default): light green weight<1.0 (road): light blue weight>1.0 (swamp): yellow → orange gradient
Blocked tiles are shown in dark gray with a hatch pattern.
func (*OrthogonalGrid) SetWalkableAt ¶
func (g *OrthogonalGrid) SetWalkableAt(x, y int, walkable bool)
SetWalkableAt sets the walkability of the tile at (x, y). The caller must ensure the coordinate is inside the grid; otherwise the method panics.
func (*OrthogonalGrid) SetWalkableAtWorld ¶
func (g *OrthogonalGrid) SetWalkableAtWorld(wx, wy float32, walkable bool)
SetWalkableAtWorld sets the walkability of the tile at the given world-space coordinate. The coordinate is converted to tile-space via WorldToTile before applying the change.
func (*OrthogonalGrid) SetWeightAt ¶ added in v0.5.0
func (g *OrthogonalGrid) SetWeightAt(x, y int, weight float64)
SetWeightAt sets the movement cost multiplier for the tile at (x, y). A weight of 1.0 is the default; higher values make the tile more costly to traverse. Panics if (x, y) is outside the grid.
func (*OrthogonalGrid) SmoothenTilePath ¶
func (g *OrthogonalGrid) SmoothenTilePath(path [][2]int) [][2]int
SmoothenTilePath smooths a tile-coordinate path by removing unnecessary waypoints. Writes the result in-place over the input buffer (which is the finder's cached pathBuf), so the smoothed path reuses the same allocation.
func (*OrthogonalGrid) SupportsJPSCanonicalPruning ¶
func (g *OrthogonalGrid) SupportsJPSCanonicalPruning() bool
SupportsJPSCanonicalPruning returns true — orthogonal grids have axis-aligned topology and support the standard JPS pruning rules.
func (*OrthogonalGrid) TileHeight ¶
func (g *OrthogonalGrid) TileHeight() int
TileHeight returns the world-space height of a single tile.
func (*OrthogonalGrid) TileToWorld ¶
func (g *OrthogonalGrid) TileToWorld(tx, ty int) (float32, float32)
TileToWorld converts a tile-space coordinate to world-space, returning the center point of the tile (offset by half the tile dimensions).
func (*OrthogonalGrid) TileWidth ¶
func (g *OrthogonalGrid) TileWidth() int
TileWidth returns the world-space width of a single tile.
func (*OrthogonalGrid) Width ¶
func (g *OrthogonalGrid) Width() int
Width returns the number of tiles horizontally in the grid.
func (*OrthogonalGrid) WorldToTile ¶
func (g *OrthogonalGrid) WorldToTile(wx, wy float32) (int, int)
WorldToTile converts a world-space coordinate to a tile-space coordinate. The conversion uses integer truncation; results outside the grid should be checked with IsInside before use.
type OrthogonalOption ¶
type OrthogonalOption func(*OrthogonalGrid)
OrthogonalOption configures an OrthogonalGrid.
func WithOrthogonalFinder ¶
func WithOrthogonalFinder(f finder.Finder) OrthogonalOption
WithOrthogonalFinder sets the pathfinder associated with this grid.
func WithOrthogonalTileSize ¶
func WithOrthogonalTileSize(w, h int) OrthogonalOption
WithOrthogonalTileSize sets the tile dimensions for world coordinate conversion.
type SVGOpts ¶ added in v0.5.0
type SVGOpts struct {
// WeightColors maps weight thresholds to tile fill colors.
// Each entry is (threshold, color). Applied in order: weight <= threshold → color.
// The last entry with a threshold of +Inf catches everything above the second-last.
// The second-to-last entry with a threshold of +Inf catches exactly the last threshold.
// Example:
// {{"0.3", "#bbdefb"}, {"1.0", "#c8e6c9"}, {"2.0", "#fff9c4"}, {"5.0", "#ffcc80"}, {"+Inf", "#ef5350"}}
// Set to nil for defaults: road(0.3)→blue, grass(1.0)→green, sand(2.0)→yellow,
// swamp(5.0)→orange, >5.0→red.
WeightColors [][2]string
// LegendEntries overrides the legend labels. Each entry is (color_hex, label).
// If nil, labels are auto-generated from WeightColors as "≤threshold".
LegendEntries [][2]string
}
Grid defines the interface that all grid types implement. It focuses on grid-consumer operations: coordinate conversion, walkability queries, pathfinding, and rendering. This is separate from finder.Grid, which only exposes what pathfinding algorithms need. SVGOpts configures SVG rendering behavior. nil means use defaults.
type StaggerOption ¶
type StaggerOption func(*StaggeredGrid)
StaggerOption configures a StaggeredGrid.
func WithStaggerAxis ¶
func WithStaggerAxis(axis string) StaggerOption
WithStaggerAxis sets the stagger axis ("x" or "y"). Default is "y".
func WithStaggerEvenIndex ¶
func WithStaggerEvenIndex() StaggerOption
WithStaggerEvenIndex configures even-index stagger offset. Default is odd-index.
func WithStaggerFinder ¶
func WithStaggerFinder(f finder.Finder) StaggerOption
WithStaggerFinder sets the pathfinder and returns the grid.
func WithStaggerTileSize ¶
func WithStaggerTileSize(w, h int) StaggerOption
WithStaggerTileSize sets the pixel dimensions of the staggered tile.
type StaggeredGrid ¶
type StaggeredGrid struct {
// contains filtered or unexported fields
}
StaggeredGrid is a 45-degree isometric/staggered grid (diamond-shaped tiles). It mirrors Tiled's "staggered" orientation, using the HexagonalRenderer math but overrides screenToTileCoords with a 4-corner detection + 45° rotation (exactly as Tiled's StaggeredRenderer does).
func NewStaggeredGrid ¶
func NewStaggeredGrid(matrix [][]int, opts ...StaggerOption) *StaggeredGrid
NewStaggeredGrid creates a StaggeredGrid from a matrix (0=walkable, non-zero=obstacle). Default tile size is 64x64. Default stagger axis is "y" (odd rows shift right). Default finder is AStarFinder.
func (*StaggeredGrid) Clone ¶
func (g *StaggeredGrid) Clone() finder.Grid
Clone returns a deep copy of the staggered grid with independent node data.
func (*StaggeredGrid) FindNearestWalkable ¶ added in v0.3.0
func (g *StaggeredGrid) FindNearestWalkable(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
FindNearestWalkable finds the nearest walkable tile within maxRadius (tile rings) from the given world position (wx, wy). See Grid.FindNearestWalkable for details.
func (*StaggeredGrid) FindNearestWalkableTile ¶ added in v0.3.0
FindNearestWalkableTile finds the nearest walkable tile within maxRadius (tile rings) from the given world position (wx, wy). Returns the tile coordinates and true if found; returns (0, 0, false) if no walkable tile exists within the search radius.
func (*StaggeredGrid) FindPath ¶
func (g *StaggeredGrid) FindPath(wx1, wy1, wx2, wy2 float32) [][2]float32
FindPath finds a path between two world positions through the staggered grid. The returned [][2]float32 is backed by an internal buffer and is only valid until the next FindPath/FindSmoothPath call on the same grid.
func (*StaggeredGrid) FindSmoothPath ¶
func (g *StaggeredGrid) FindSmoothPath(wx1, wy1, wx2, wy2 float32) [][2]float32
FindSmoothPath finds a path between two world positions and smooths it. Same buffer contract as FindPath.
func (*StaggeredGrid) Finder ¶
func (g *StaggeredGrid) Finder() finder.Finder
Finder returns the pathfinder associated with this grid.
func (*StaggeredGrid) GetNeighbors ¶
func (g *StaggeredGrid) GetNeighbors(node *finder.Node, diagonal finder.DiagonalMovement, buffer []*finder.Node) []*finder.Node
GetNeighbors returns neighbors for a node on a staggered isometric grid, respecting the diagonal movement rule. The result is written into the provided buffer.
func (*StaggeredGrid) GetNodeAt ¶
func (g *StaggeredGrid) GetNodeAt(x, y int) *finder.Node
GetNodeAt returns the node at the given tile coordinates.
func (*StaggeredGrid) GetWeightAt ¶ added in v0.5.0
func (g *StaggeredGrid) GetWeightAt(x, y int) float64
GetWeightAt returns the movement cost multiplier for the tile at (x, y).
func (*StaggeredGrid) Height ¶
func (g *StaggeredGrid) Height() int
Height returns the number of tiles vertically in the staggered grid.
func (*StaggeredGrid) IsInside ¶
func (g *StaggeredGrid) IsInside(x, y int) bool
IsInside checks whether the tile coordinates (x, y) are within the grid bounds.
func (*StaggeredGrid) IsWalkableAt ¶
func (g *StaggeredGrid) IsWalkableAt(x, y int) bool
IsWalkableAt returns whether the tile at (x, y) is walkable (no obstacle).
func (*StaggeredGrid) IsWalkableAtWorld ¶
func (g *StaggeredGrid) IsWalkableAtWorld(wx, wy float32) bool
IsWalkableAtWorld checks walkability at a world position.
func (*StaggeredGrid) ObstacleCount ¶ added in v0.3.0
func (g *StaggeredGrid) ObstacleCount() int
ObstacleCount returns the number of non-walkable tiles in the grid.
func (*StaggeredGrid) RenderSVG ¶
func (g *StaggeredGrid) RenderSVG(cfg *SVGOpts, paths ...[][2]int) string
RenderSVG renders the staggered grid with weight-colored tiles and paths.
func (*StaggeredGrid) SetWalkableAt ¶
func (g *StaggeredGrid) SetWalkableAt(x, y int, walkable bool)
SetWalkableAt sets the walkability of the tile at (x, y).
func (*StaggeredGrid) SetWalkableAtWorld ¶
func (g *StaggeredGrid) SetWalkableAtWorld(wx, wy float32, walkable bool)
SetWalkableAtWorld sets walkability at a world position.
func (*StaggeredGrid) SetWeightAt ¶ added in v0.5.0
func (g *StaggeredGrid) SetWeightAt(x, y int, weight float64)
SetWeightAt sets the movement cost multiplier for the tile at (x, y).
func (*StaggeredGrid) SmoothenTilePath ¶
func (g *StaggeredGrid) SmoothenTilePath(path [][2]int) [][2]int
SmoothenTilePath smooths a tile-coordinate staggered path by removing unnecessary waypoints. Writes the smoothed result in-place over the input (finder's cached pathBuf).
func (*StaggeredGrid) TileToWorld ¶
func (g *StaggeredGrid) TileToWorld(tx, ty int) (float32, float32)
TileToWorld converts tile coordinates to world position.
func (*StaggeredGrid) Width ¶
func (g *StaggeredGrid) Width() int
Width returns the number of tiles horizontally in the staggered grid.
func (*StaggeredGrid) WorldToTile ¶
func (g *StaggeredGrid) WorldToTile(wx, wy float32) (int, int)
WorldToTile converts world coordinates to staggered tile coordinates. Mirrors Tiled's StaggeredRenderer::screenToTileCoords.