gridutil

package
v0.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package gridutil provides utility functions for grid-based pathfinding. All functions work with any grid type that implements grid.Grid.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasLineOfSight

func HasLineOfSight(g grid.Grid, x1, y1, x2, y2 int) bool

HasLineOfSight reports whether two tiles can see each other — every tile on the Bresenham line between them is walkable.

func HasLineOfSightWorld

func HasLineOfSightWorld(g grid.Grid, x1, y1, x2, y2 float32) bool

HasLineOfSightWorld reports whether two world positions can see each other.

func Line

func Line(x0, y0, x1, y1 int) [][2]int

Line returns all tiles on the Bresenham line from (x0, y0) to (x1, y1), including both endpoints.

func RandomInRing

func RandomInRing(g grid.Grid, cx, cy, innerR, outerR int) (int, int, bool)

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

func RandomInRingWorld(g grid.Grid, wx, wy float32, innerR, outerR int) (float32, float32, bool)

RandomInRingWorld returns the world center of a random walkable tile with Chebyshev distance between innerR and outerR from (wx, wy).

func RandomWalkable

func RandomWalkable(g grid.Grid) (int, int, bool)

RandomWalkable returns a random walkable tile coordinate.

func RandomWalkableInRadius

func RandomWalkableInRadius(g grid.Grid, cx, cy, radius int) (int, int, bool)

RandomWalkableInRadius returns a random walkable tile within radius tiles of (cx, cy).

func RandomWalkableInRadiusWorld

func RandomWalkableInRadiusWorld(g grid.Grid, wx, wy float32, radius int) (float32, float32, bool)

RandomWalkableInRadiusWorld returns the world center of a random walkable tile within radius tiles of (wx, wy).

func RandomWalkableWorld

func RandomWalkableWorld(g grid.Grid) (float32, float32, bool)

RandomWalkableWorld returns the world center of a random walkable tile.

func TileDistance

func TileDistance(x1, y1, x2, y2 int) int

TileDistance returns the Chebyshev distance between two tiles: max(|dx|, |dy|). This is the number of steps needed for 8-directional movement.

func TilesInRadius

func TilesInRadius(cx, cy, r int) [][2]int

TilesInRadius returns all tiles within Chebyshev distance r from (cx, cy). The result includes (cx, cy) itself.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL