Documentation
¶
Index ¶
- func DecodeGridKey(key uint64) (x, y int32)
- func EncodeGridKey(x, y int32) uint64
- type Grid
- func (g *Grid[T]) CellSize() (cellWidth, cellHeight float32)
- func (g *Grid[T]) Cells() []uint64
- func (g *Grid[T]) Clear()
- func (g *Grid[T]) Contains(item T) bool
- func (g *Grid[T]) Each(region [4]float32, fn func(item T) bool)
- func (g *Grid[T]) ForEach(fn func(item T))
- func (g *Grid[T]) Insert(item T, region [4]float32, padding GridItemPadding) bool
- func (g *Grid[T]) InsertFunc(item T, region [4]float32, padding GridItemPadding, fn GridInsertionFunc[T]) bool
- func (g *Grid[T]) Query(region [4]float32) []T
- func (g *Grid[T]) QueryCells(region [4]float32) []uint64
- func (g *Grid[T]) Remove(item T)
- func (g *Grid[T]) Resize(cellWidth, cellHeight float32)
- type GridInsertionFunc
- type GridItemPadding
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeGridKey ¶
func EncodeGridKey ¶
Types ¶
type Grid ¶
type Grid[T comparable] struct { // contains filtered or unexported fields }
Grid is a simple spatial hash grid that stores items in cells based on their coordinates.
Use this for static or infrequently-updated items. It is a minimalist implementation.
func NewGrid ¶
func NewGrid[T comparable](cellWidth, cellHeight float32) *Grid[T]
func (*Grid[T]) ForEach ¶
func (g *Grid[T]) ForEach(fn func(item T))
ForEach calls the given function for each item in the grid.
func (*Grid[T]) Insert ¶
func (g *Grid[T]) Insert(item T, region [4]float32, padding GridItemPadding) bool
Insert adds an item to the grid. Returns false if the item was already present.
func (*Grid[T]) InsertFunc ¶
func (g *Grid[T]) InsertFunc(item T, region [4]float32, padding GridItemPadding, fn GridInsertionFunc[T]) bool
InsertFunc is like Insert but allows a function to determine per-cell insertion.
func (*Grid[T]) QueryCells ¶
type GridInsertionFunc ¶
type GridInsertionFunc[T comparable] func(minX, minY, maxX, maxY float32) bool
type GridItemPadding ¶
type GridItemPadding uint8
const ( NoGridPadding GridItemPadding = 0 GridCellPadding GridItemPadding = 1 )
type Set ¶
type Set[T comparable] map[T]struct{}
func NewSet ¶
func NewSet[T comparable](size ...int) Set[T]
Click to show internal directories.
Click to hide internal directories.