Documentation
¶
Index ¶
- Variables
- func NewMatrix(w, h int) [][]int
- type Grid
- type GridOption
- func WithFinder(f finder.Finder) GridOption
- func WithHexEvenStagger() GridOption
- func WithHexFlatTop() GridOption
- func WithHexSide(side int) GridOption
- func WithSmoothBresenham() GridOption
- func WithSmoothBresenhamStrict() GridOption
- func WithSmoothDense() GridOption
- func WithStaggerAxis(axis string) GridOption
- func WithStaggerEvenIndex() GridOption
- func WithTileSize(w, h int) GridOption
- type GridType
- type HexGrid
- func (g *HexGrid) Clone() finder.Grid
- func (g *HexGrid) FindNearestWalkable(wx, wy float32, maxRadius int) (int, int, bool)
- func (g *HexGrid) FindNearestWalkableWorld(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
- func (g *HexGrid) FindPath(x1, y1, x2, y2 int) [][2]int
- func (g *HexGrid) FindPathWorld(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) HasLineOfSight(x1, y1, x2, y2 int) bool
- 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) TileHeight() int
- func (g *HexGrid) TileIndex(x, y int) int
- func (g *HexGrid) TileToWorld(tx, ty int) (float32, float32)
- func (g *HexGrid) TileWidth() int
- func (g *HexGrid) TileXY(index int) (int, int)
- func (g *HexGrid) Width() int
- func (g *HexGrid) WorldToTile(wx, wy float32) (int, int)
- type OrthogonalGrid
- func (g *OrthogonalGrid) Clone() finder.Grid
- func (g *OrthogonalGrid) FindNearestWalkable(wx, wy float32, maxRadius int) (int, int, bool)
- func (g *OrthogonalGrid) FindNearestWalkableWorld(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
- func (g *OrthogonalGrid) FindPath(x1, y1, x2, y2 int) [][2]int
- func (g *OrthogonalGrid) FindPathWorld(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) HasLineOfSight(x1, y1, x2, y2 int) bool
- 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) SupportsJPSCanonicalPruning() bool
- func (g *OrthogonalGrid) TileHeight() int
- func (g *OrthogonalGrid) TileIndex(x, y int) int
- func (g *OrthogonalGrid) TileToWorld(tx, ty int) (float32, float32)
- func (g *OrthogonalGrid) TileWidth() int
- func (g *OrthogonalGrid) TileXY(index int) (int, int)
- func (g *OrthogonalGrid) Width() int
- func (g *OrthogonalGrid) WorldToTile(wx, wy float32) (int, int)
- type SVGOpts
- type SmoothMode
- type Smoother
- type StaggeredGrid
- func (g *StaggeredGrid) Clone() finder.Grid
- func (g *StaggeredGrid) FindNearestWalkable(wx, wy float32, maxRadius int) (int, int, bool)
- func (g *StaggeredGrid) FindNearestWalkableWorld(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
- func (g *StaggeredGrid) FindPath(x1, y1, x2, y2 int) [][2]int
- func (g *StaggeredGrid) FindPathWorld(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) HasLineOfSight(x1, y1, x2, y2 int) bool
- 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) TileHeight() int
- func (g *StaggeredGrid) TileIndex(x, y int) int
- func (g *StaggeredGrid) TileToWorld(tx, ty int) (float32, float32)
- func (g *StaggeredGrid) TileWidth() int
- func (g *StaggeredGrid) TileXY(index int) (int, int)
- 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 {
finder.Grid
// ObstacleCount returns the number of non-walkable tiles.
ObstacleCount() int
// TileIndex returns the flat array index for tile (x, y).
// Equivalent to y*Width + x. Panics if outside the grid.
TileIndex(x, y int) int
// TileXY returns the tile coordinates for a flat array index.
// Equivalent to (index % Width, index / Width).
TileXY(index int) (int, int)
// SetWeightAt sets the per-tile movement cost multiplier for tile (x, y).
// Weight 1.0 is the default; higher values make movement more expensive.
SetWeightAt(x, y int, weight float64)
// GetWeightAt returns the movement cost multiplier for tile (x, y).
// Returns 1.0 for tiles outside the grid.
GetWeightAt(x, y int) float64
// WorldToTile converts a world-space coordinate to tile-space.
// Results outside the grid should be checked with IsInside.
WorldToTile(wx, wy float32) (int, int)
// TileToWorld converts a tile coordinate to world-space, returning
// the centre point of the tile.
TileToWorld(tx, ty int) (float32, float32)
// IsWalkableAtWorld reports whether the tile at world position (wx, wy) is walkable.
IsWalkableAtWorld(wx, wy float32) bool
// SetWalkableAtWorld sets the walkability of the tile at world position (wx, wy).
SetWalkableAtWorld(wx, wy float32, walkable bool)
// HasLineOfSight reports whether two tiles can see each other.
// Uses the appropriate algorithm for the grid type (Bresenham for orthogonal,
// world-space dense sampling for hex and staggered).
HasLineOfSight(x1, y1, x2, y2 int) bool
// FindNearestWalkable is like FindNearestWalkableWorld but returns tile
// coordinates instead of edge-clamped world coordinates.
FindNearestWalkable(wx, wy float32, maxRadius int) (int, int, bool)
// FindNearestWalkableWorld finds the nearest walkable tile within maxRadius
// (Chebyshev distance in tiles) from world position (wx, wy).
// Returns the closest point on the edge of the nearest walkable tile, or
// (0, 0, false) if no walkable tile exists within the search radius.
FindNearestWalkableWorld(wx, wy float32, maxRadius int, edgeInset float32) (float32, float32, bool)
// Finder returns the pathfinder used by this grid.
Finder() finder.Finder
// FindPath finds a path between two tile positions.
// Result is backed by an internal buffer — valid only until the next FindPath call.
FindPath(x1, y1, x2, y2 int) [][2]int
// FindPathWorld finds a path between two world positions through the grid.
// Uses the grid's Finder. Returns the path in world coordinates.
// Result is backed by an internal buffer — valid only until the next FindPathWorld call.
FindPathWorld(wx1, wy1, wx2, wy2 float32) [][2]float32
// RenderSVG renders the grid and paths as an SVG string.
// Tiles are coloured by their Weight value with terrain legend.
// Multiple paths are drawn in different colours (1st=blue, 2nd=red dashed).
// Start/end markers are derived from the first path.
// Pass nil to use the default SVG options.
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 GridOption ¶ added in v0.8.0
type GridOption func(*gridOptions)
GridOption configures any grid type. Apply via constructor opts (NewOrthogonalGrid, etc.).
func WithFinder ¶ added in v0.8.0
func WithFinder(f finder.Finder) GridOption
WithFinder sets the pathfinding algorithm (e.g., finder.NewAStar(), finder.NewBFS()).
func WithHexEvenStagger ¶
func WithHexEvenStagger() GridOption
WithHexEvenStagger configures the hex grid to use even-row staggering.
func WithHexFlatTop ¶
func WithHexFlatTop() GridOption
WithHexFlatTop configures the hex grid for flat-top (pointy-side) orientation.
func WithHexSide ¶
func WithHexSide(side int) GridOption
WithHexSide sets the side length (in pixels) of a hex tile for world coordinate conversion.
func WithSmoothBresenham ¶ added in v0.8.0
func WithSmoothBresenham() GridOption
WithSmoothBresenham enables Bresenham line-of-sight path smoothing (orthogonal grids only).
func WithSmoothBresenhamStrict ¶ added in v0.8.0
func WithSmoothBresenhamStrict() GridOption
WithSmoothBresenhamStrict enables Bresenham smoothing with corner-cutting prevention (orthogonal grids only).
func WithSmoothDense ¶ added in v0.8.0
func WithSmoothDense() GridOption
WithSmoothDense enables world-space dense-sampling path smoothing (hex and staggered grids only).
func WithStaggerAxis ¶
func WithStaggerAxis(axis string) GridOption
WithStaggerAxis sets the stagger axis for isometric staggered grids ("x" or "y").
func WithStaggerEvenIndex ¶
func WithStaggerEvenIndex() GridOption
WithStaggerEvenIndex configures the staggered grid to use even-row indexing.
func WithTileSize ¶ added in v0.8.0
func WithTileSize(w, h int) GridOption
WithTileSize sets the tile dimensions for world coordinate conversion.
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 ¶
func NewHexGrid(matrix [][]int, opts ...GridOption) *HexGrid
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
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) FindNearestWalkableWorld ¶ added in v0.6.1
func (g *HexGrid) FindNearestWalkableWorld(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) FindPathWorld ¶ added in v0.6.1
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
func (*HexGrid) HasLineOfSight ¶ added in v0.6.1
HasLineOfSight reports whether two tiles can see each other using dense world-space sampling.
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) TileHeight ¶ added in v0.8.0
TileHeight returns the tile height in world units.
func (*HexGrid) TileToWorld ¶
TileToWorld converts hex tile coordinates to world (pixel) position (tile center).
func (*HexGrid) TileXY ¶ added in v0.7.3
TileXY returns the tile coordinates for a flat array index.
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 ...GridOption) *OrthogonalGrid
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
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) FindNearestWalkableWorld ¶ added in v0.6.1
func (g *OrthogonalGrid) FindNearestWalkableWorld(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) FindPath ¶
func (g *OrthogonalGrid) FindPath(x1, y1, x2, y2 int) [][2]int
FindPath finds a path between two tile positions. Applies smoothing if configured via WithSmoothBresenham, WithSmoothBresenhamStrict, or WithSmoothDense.
func (*OrthogonalGrid) FindPathWorld ¶ added in v0.6.1
func (g *OrthogonalGrid) FindPathWorld(wx1, wy1, wx2, wy2 float32) [][2]float32
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) HasLineOfSight ¶ added in v0.6.1
func (g *OrthogonalGrid) HasLineOfSight(x1, y1, x2, y2 int) bool
HasLineOfSight reports whether two tiles can see each other using Bresenham.
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.
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) 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) TileIndex ¶ added in v0.7.2
func (g *OrthogonalGrid) TileIndex(x, y int) int
TileIndex returns the flat array index for tile (x, y).
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) TileXY ¶ added in v0.7.3
func (g *OrthogonalGrid) TileXY(index int) (int, int)
TileXY returns the tile coordinates for a flat array index.
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 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
}
SVGOpts configures SVG rendering behavior. nil means use defaults.
type SmoothMode ¶ added in v0.8.0
type SmoothMode int
SmoothMode specifies the path smoothing algorithm.
const ( SmoothNone SmoothMode = iota // no smoothing SmoothBresenham // Bresenham line-of-sight (orthogonal) SmoothBresenhamStrict // Bresenham with corner-cutting prevention (orthogonal) SmoothDense // world-space dense sampling (hex, staggered) )
type Smoother ¶ added in v0.8.0
Smoother is a path smoothing function. It takes a tile path and returns a simplified path with fewer waypoints, typically by removing intermediate tiles that have line-of-sight to each other.
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 ...GridOption) *StaggeredGrid
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
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) FindNearestWalkableWorld ¶ added in v0.6.1
func (g *StaggeredGrid) FindNearestWalkableWorld(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) FindPath ¶
func (g *StaggeredGrid) FindPath(x1, y1, x2, y2 int) [][2]int
FindPath finds a path between two tile positions.
func (*StaggeredGrid) FindPathWorld ¶ added in v0.6.1
func (g *StaggeredGrid) FindPathWorld(wx1, wy1, wx2, wy2 float32) [][2]float32
FindPathWorld 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 call on the same grid.
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
func (*StaggeredGrid) HasLineOfSight ¶ added in v0.6.1
func (g *StaggeredGrid) HasLineOfSight(x1, y1, x2, y2 int) bool
HasLineOfSight reports whether two tiles can see each other using dense world-space sampling.
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) TileHeight ¶ added in v0.8.0
func (g *StaggeredGrid) TileHeight() int
TileHeight returns the tile height in world units.
func (*StaggeredGrid) TileIndex ¶ added in v0.7.2
func (g *StaggeredGrid) TileIndex(x, y int) int
TileIndex returns the flat array index for tile (x, y).
func (*StaggeredGrid) TileToWorld ¶
func (g *StaggeredGrid) TileToWorld(tx, ty int) (float32, float32)
TileToWorld converts tile coordinates to world position.
func (*StaggeredGrid) TileWidth ¶ added in v0.8.0
func (g *StaggeredGrid) TileWidth() int
TileWidth returns the tile width in world units.
func (*StaggeredGrid) TileXY ¶ added in v0.7.3
func (g *StaggeredGrid) TileXY(index int) (int, int)
TileXY returns the tile coordinates for a flat array index.
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.