Class SwiftBVH<TKey, TVolume>
- Namespace
- SwiftCollections.Query
- Assembly
- SwiftCollections.dll
Represents a Bounding Volume Hierarchy (BVH) optimized for spatial queries.
public class SwiftBVH<TKey, TVolume> where TKey : notnull where TVolume : struct, IBoundVolume<TVolume>
Type Parameters
TKeyTVolume
- Inheritance
-
SwiftBVH<TKey, TVolume>
- Derived
- Inherited Members
Remarks
This class is not thread-safe. Concurrent access from multiple threads must be serialized externally (e.g., with a lock or by limiting access to a single thread).
Constructors
SwiftBVH(int)
Initializes a new instance of the SwiftBVH<TKey, TVolume> class with the specified capacity.
public SwiftBVH(int capacity)
Parameters
capacityint
Properties
Count
Gets the total number of leaf nodes in the BVH.
public int Count { get; }
Property Value
NodePool
Gets the underlying pool of nodes used in the BVH.
public SwiftBVHNode<TKey, TVolume>[] NodePool { get; }
Property Value
- SwiftBVHNode<TKey, TVolume>[]
Remarks
Prefer BVH APIs. Direct structural mutation must preserve tree invariants; invalid edits may fail fast.
RootNode
Gets the root node of the BVH.
public SwiftBVHNode<TKey, TVolume> RootNode { get; }
Property Value
- SwiftBVHNode<TKey, TVolume>
RootNodeIndex
Gets the index of the root node in the BVH.
public int RootNodeIndex { get; }
Property Value
Methods
Clear()
Clears the BVH, resetting all nodes, buckets, and metadata.
public void Clear()
EnsureCapacity(int)
Ensures the BVH has sufficient capacity, resizing the node pool and buckets if needed.
public void EnsureCapacity(int capacity)
Parameters
capacityint
FindEntry(TKey)
Finds the index of a node by its value in the BVH using hash buckets. Returns -1 if the value is not found.
public int FindEntry(TKey value)
Parameters
valueTKey
Returns
Insert(TKey, TVolume)
Inserts a bounding volume with an associated value into the BVH. Ensures tree balance and updates hash buckets.
public bool Insert(TKey value, TVolume bounds)
Parameters
valueTKeyboundsTVolume
Returns
Query(TVolume, ICollection<TKey>)
Queries the BVH for values whose bounding volumes intersect with the specified volume. Uses a stack-based approach for efficient traversal.
public void Query(TVolume queryBounds, ICollection<TKey> results)
Parameters
queryBoundsTVolumeresultsICollection<TKey>
Remove(TKey)
Removes a value and its associated bounding volume from the BVH. Updates tree structure and clears hash bucket entries.
public bool Remove(TKey value)
Parameters
valueTKey
Returns
UpdateEntryBounds(TKey, TVolume)
Updates the bounding volume of a node and propagates changes up the tree. Ensures consistency in parent bounds and subtree sizes.
public void UpdateEntryBounds(TKey value, TVolume newBounds)
Parameters
valueTKeynewBoundsTVolume