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 ¶
- type Change
- type Grid
- func (idx *Grid) ApplyBatch(changes []Change) error
- func (idx *Grid) Query(bounds geom.Rect) []ecs.EntityID
- func (idx *Grid) QueryInto(bounds geom.Rect, ids []ecs.EntityID) []ecs.EntityID
- func (idx *Grid) QueryOverlapsInto(bounds geom.Rect, ids []ecs.EntityID) []ecs.EntityID
- func (idx *Grid) Remove(entityID ecs.EntityID)
- func (idx *Grid) Update(entityID ecs.EntityID, bounds geom.Rect) error
- type GridCell
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 ¶
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
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 ¶
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 ¶
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
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.