Table of Contents

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

TKey
TVolume
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

capacity int

Properties

Count

Gets the total number of leaf nodes in the BVH.

public int Count { get; }

Property Value

int

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

int

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

capacity int

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

value TKey

Returns

int

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

value TKey
bounds TVolume

Returns

bool

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

queryBounds TVolume
results ICollection<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

value TKey

Returns

bool

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

value TKey
newBounds TVolume