spatial

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package spatial provides a uniform grid for broad-phase spatial queries. Grid indexes entity bounds, and callers refine its candidates with exact intersection tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change added in v0.4.0

type Change struct {
	// EntityID identifies the entity to update or remove.
	EntityID ecs.EntityID
	// Bounds is the replacement rectangle; it is ignored when Remove is true.
	Bounds geom.Rect
	// Remove removes the entity from the index instead of updating its bounds.
	Remove bool
}

Change updates or removes one entity's indexed bounds.

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

Grid indexes entity IDs by conservative axis-aligned bounds. It returns broad-phase candidates only; callers must perform any exact intersection tests themselves. Large bounds and query ranges use entry scans rather than expanding every covered cell.

func NewGrid

func NewGrid(cellSize float64) (*Grid, error)

NewGrid returns a grid whose cells have width and height cellSize in world units. cellSize must be positive and finite.

func (*Grid) ApplyBatch added in v0.4.0

func (idx *Grid) ApplyBatch(changes []Change) error

ApplyBatch applies all changes after validating the complete batch. If validation fails, the grid is unchanged. Entity IDs must be unique in the batch.

func (*Grid) Query

func (idx *Grid) Query(bounds geom.Rect) []ecs.EntityID

Query returns the unique entity IDs indexed in cells overlapped by bounds. Results are broad-phase candidates; exact intersection is not tested, and result order is unspecified.

func (*Grid) QueryInto

func (idx *Grid) QueryInto(bounds geom.Rect, ids []ecs.EntityID) []ecs.EntityID

QueryInto returns the unique entity IDs indexed in cells overlapped by bounds, reusing ids' backing array when possible. It discards the slice's previous contents. Invalid bounds produce an empty result. Results are broad-phase candidates, and their order is unspecified.

func (*Grid) QueryOverlapsInto added in v0.2.0

func (idx *Grid) QueryOverlapsInto(bounds geom.Rect, ids []ecs.EntityID) []ecs.EntityID

QueryOverlapsInto returns unique entity IDs whose indexed bounds overlap or touch bounds, reusing ids' backing array. It discards ids' previous contents. Invalid bounds produce an empty result. Order is unspecified; callers must still test the exact shapes.

func (*Grid) Remove

func (idx *Grid) Remove(entityID ecs.EntityID)

Remove deletes entityID from the index. It has no effect if the entity is not indexed.

func (*Grid) Update

func (idx *Grid) Update(entityID ecs.EntityID, bounds geom.Rect) error

Update replaces entityID's indexed bounds. Invalid bounds return an error without changing the current index for that entity.

type GridCell

type GridCell struct {
	// X is the cell's horizontal grid coordinate.
	X int
	// Y is the cell's vertical grid coordinate.
	Y int
}

GridCell identifies a cell in grid coordinates.

Jump to

Keyboard shortcuts

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