Class SwiftSpatialHash<TKey, TVolume>
- Namespace
- SwiftCollections.Query
- Assembly
- SwiftCollections.dll
Represents a mutable spatial hash that indexes keyed bounding volumes into deterministic integer grid cells.
public class SwiftSpatialHash<TKey, TVolume> where TKey : notnull where TVolume : struct, IBoundVolume<TVolume>
Type Parameters
TKeyThe key used to identify each stored entry.
TVolumeThe volume type used for broad-phase registration and queries.
- Inheritance
-
SwiftSpatialHash<TKey, TVolume>
- Derived
- Inherited Members
Constructors
SwiftSpatialHash(int, ISpatialHashCellMapper<TVolume>)
Initializes a new instance of the SwiftSpatialHash<TKey, TVolume> class.
public SwiftSpatialHash(int capacity, ISpatialHashCellMapper<TVolume> cellMapper)
Parameters
capacityintThe initial entry capacity.
cellMapperISpatialHashCellMapper<TVolume>The mapper that projects volumes into deterministic cell coordinates.
SwiftSpatialHash(int, ISpatialHashCellMapper<TVolume>, SwiftSpatialHashOptions)
Initializes a new instance of the SwiftSpatialHash<TKey, TVolume> class.
public SwiftSpatialHash(int capacity, ISpatialHashCellMapper<TVolume> cellMapper, SwiftSpatialHashOptions options)
Parameters
capacityintThe initial entry capacity.
cellMapperISpatialHashCellMapper<TVolume>The mapper that projects volumes into deterministic cell coordinates.
optionsSwiftSpatialHashOptionsSpatial hash query options.
Properties
Count
Gets the number of active entries stored in the spatial hash.
public int Count { get; }
Property Value
Options
Gets the options used by this spatial hash.
public SwiftSpatialHashOptions Options { get; }
Property Value
Methods
Clear()
Removes all entries and cell registrations from the spatial hash.
public void Clear()
CollectCellCandidates(SwiftSpatialHashCellIndex, ICollection<TKey>)
Collects every entry registered in one already-mapped spatial cell.
protected void CollectCellCandidates(SwiftSpatialHashCellIndex cell, ICollection<TKey> results)
Parameters
cellSwiftSpatialHashCellIndexresultsICollection<TKey>
Contains(TKey)
Determines whether the spatial hash contains the specified key.
public bool Contains(TKey key)
Parameters
keyTKey
Returns
EnsureCapacity(int)
Ensures the spatial hash can store the specified number of entries without growing its entry storage.
public void EnsureCapacity(int capacity)
Parameters
capacityint
Insert(TKey, TVolume)
Inserts a new entry or replaces the bounds of an existing key.
public bool Insert(TKey key, TVolume bounds)
Parameters
keyTKeyThe entry key.
boundsTVolumeThe entry bounds.
Returns
- bool
truewhen a new key was added;falsewhen an existing key was replaced.
Query(TVolume, ICollection<TKey>)
Queries the spatial hash and returns only entries whose bounds intersect the supplied query volume.
public void Query(TVolume queryBounds, ICollection<TKey> results)
Parameters
queryBoundsTVolumeresultsICollection<TKey>
QueryNeighborhood(TVolume, ICollection<TKey>)
Queries the spatial hash using the supplied query volume plus the configured neighborhood padding.
public void QueryNeighborhood(TVolume queryBounds, ICollection<TKey> results)
Parameters
queryBoundsTVolumeresultsICollection<TKey>
Remove(TKey)
Removes an entry from the spatial hash.
public bool Remove(TKey key)
Parameters
keyTKeyThe entry key.
Returns
- bool
truewhen the key existed and was removed; otherwise,false.
TryGetBounds(TKey, out TVolume)
Attempts to retrieve the bounds registered for the supplied key.
public bool TryGetBounds(TKey key, out TVolume bounds)
Parameters
keyTKeyboundsTVolume
Returns
UpdateEntryBounds(TKey, TVolume)
Updates the bounds for an existing entry.
public bool UpdateEntryBounds(TKey key, TVolume newBounds)
Parameters
keyTKeyThe entry key.
newBoundsTVolumeThe replacement bounds.
Returns
- bool
truewhen the key existed; otherwise,false.