Header menu logo Mibo

Grid2DSpatial Module

Nested modules

Modules Description

Internal

Internal helpers for A* pathfinding. Not intended for direct use.

Functions and values

Function or value Description

distanceChebyshev x1 y1 x2 y2

Full Usage: distanceChebyshev x1 y1 x2 y2

Parameters:
    x1 : ^a
    y1 : ^c
    x2 : ^b
    y2 : ^d

Returns: int
Modifiers: inline
Type parameters: ^a, ^b, ^c, ^d

Chebyshev distance: cost of moving in 8 directions (diagonal = 1).

x1 : ^a
y1 : ^c
x2 : ^b
y2 : ^d
Returns: int

distanceEuclidean x1 y1 x2 y2

Full Usage: distanceEuclidean x1 y1 x2 y2

Parameters:
    x1 : ^a
    y1 : ^d
    x2 : ^b
    y2 : ^e

Returns: float32
Modifiers: inline
Type parameters: ^a, ^b, ^c, ^d, ^e, ^f

Euclidean distance (straight-line).

x1 : ^a
y1 : ^d
x2 : ^b
y2 : ^e
Returns: float32

distanceManhattan x1 y1 x2 y2

Full Usage: distanceManhattan x1 y1 x2 y2

Parameters:
    x1 : ^a
    y1 : ^f
    x2 : ^b
    y2 : ^e

Returns: int
Modifiers: inline
Type parameters: ^a, ^b, ^c, ^d, ^e, ^f

Manhattan distance: cost of moving in 4 directions.

x1 : ^a
y1 : ^f
x2 : ^b
y2 : ^e
Returns: int

findPath startX startY goalX goalY isPassable costFn grid

Full Usage: findPath startX startY goalX goalY isPassable costFn grid

Parameters:
    startX : int
    startY : int
    goalX : int
    goalY : int
    isPassable : int -> int -> bool
    costFn : int -> int -> int -> int -> float32
    grid : CellGrid2D<'T>

Returns: (int * int)[] voption
Modifiers: inline
Type parameters: 'T

A* pathfinding on a square grid. Returns the shortest path from (startX, startY) to (goalX, goalY) as an array of coordinates, or ValueNone if no path exists. `isPassable` returns true for cells that can be walked through. `costFn` returns the movement cost between two adjacent cells.

startX : int
startY : int
goalX : int
goalY : int
isPassable : int -> int -> bool
costFn : int -> int -> int -> int -> float32
grid : CellGrid2D<'T>
Returns: (int * int)[] voption

floodFill x y predicate grid

Full Usage: floodFill x y predicate grid

Parameters:
    x : int
    y : int
    predicate : int -> int -> bool
    grid : CellGrid2D<'T>

Returns: (int * int)[]
Modifiers: inline
Type parameters: 'T

Flood fill from (x, y) using BFS. Returns all reachable cells for which `predicate` returns true. Does not cross cells where predicate is false.

x : int
y : int
predicate : int -> int -> bool
grid : CellGrid2D<'T>
Returns: (int * int)[]

inRange x y range grid

Full Usage: inRange x y range grid

Parameters:
    x : int32
    y : int32
    range : int
    grid : CellGrid2D<'T>

Returns: (int * int)[]
Modifiers: inline
Type parameters: 'T

Returns all grid cells within Chebyshev distance `range` of (x, y). Includes the origin cell when range >= 0.

x : int32
y : int32
range : int
grid : CellGrid2D<'T>
Returns: (int * int)[]

lineOfSight x1 y1 x2 y2 isBlocked grid

Full Usage: lineOfSight x1 y1 x2 y2 isBlocked grid

Parameters:
    x1 : int
    y1 : int
    x2 : int
    y2 : int
    isBlocked : int -> int -> bool
    grid : CellGrid2D<'T>

Returns: bool
Modifiers: inline
Type parameters: 'T

Returns true if a straight line from (x1,y1) to (x2,y2) is clear of blocked cells. Uses Bresenham's algorithm. The start cell is not checked; the goal cell IS checked (a blocked goal means LOS is false).

x1 : int
y1 : int
x2 : int
y2 : int
isBlocked : int -> int -> bool
grid : CellGrid2D<'T>
Returns: bool

lineOfSightCells x1 y1 x2 y2 isBlocked grid

Full Usage: lineOfSightCells x1 y1 x2 y2 isBlocked grid

Parameters:
    x1 : int
    y1 : int
    x2 : int
    y2 : int
    isBlocked : int -> int -> bool
    grid : CellGrid2D<'T>

Returns: (int * int)[]
Modifiers: inline
Type parameters: 'T

Returns the visible cells along a line from (x1,y1) toward (x2,y2), stopping at the first blocked cell. The start cell is included if not blocked.

x1 : int
y1 : int
x2 : int
y2 : int
isBlocked : int -> int -> bool
grid : CellGrid2D<'T>
Returns: (int * int)[]

neighbors4 x y grid

Full Usage: neighbors4 x y grid

Parameters:
Returns: (int * int)[]
Modifiers: inline
Type parameters: 'T

Returns the 4 cardinal (N/S/E/W) neighbors of (x, y), filtered to grid bounds.

x : int
y : int
grid : CellGrid2D<'T>
Returns: (int * int)[]

neighbors8 x y grid

Full Usage: neighbors8 x y grid

Parameters:
Returns: (int * int)[]
Modifiers: inline
Type parameters: 'T

Returns the 8 surrounding neighbors (cardinal + diagonal), filtered to grid bounds.

x : int32
y : int32
grid : CellGrid2D<'T>
Returns: (int * int)[]

worldToCell worldPos grid

Full Usage: worldToCell worldPos grid

Parameters:
Returns: (int * int) voption
Modifiers: inline
Type parameters: 'T

Converts a world position to the nearest grid cell coordinates. Returns ValueNone if the position is outside the grid.

worldPos : Vector2
grid : CellGrid2D<'T>
Returns: (int * int) voption

Type something to start searching.