Class ScyllaLooseQuadtree<T>
Typed payload wrapper around ScyllaLooseQuadtree that associates an arbitrary
managed payload of type T with each integer item ID.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaLooseQuadtree<T> : IScyllaCollection, IDisposable
Type Parameters
| Name | Description |
|---|---|
| T | The payload type stored alongside each spatial item. May be any reference or value type.
Payloads are stored in a managed Dictionary<TKey, TValue> keyed by item ID, so
|
Remarks
Architecture: Spatial indexing (item IDs, bounding boxes, node structure) is delegated entirely to the inner ScyllaLooseQuadtree. The managed dictionary provides O(1) average-case payload lookup by ID after queries return candidate IDs.
Query workflow: Query methods return item IDs in the provided result list. Callers then call TryGetPayload(int, out T) for each ID to retrieve the associated payload.
IScyllaCollection contract: This type intentionally does not implement IScyllaCollection<T> because the quadtree’s primary API is ID+bounds-based, not element-based enqueue/dequeue semantics.
Disposal: Call Dispose() to release the inner tree’s native containers. The managed payload dictionary is cleared but does not require explicit disposal.
Constructors
ScyllaLooseQuadtree(ScyllaAABB2, int, int, float, Allocator, int)
Creates a new typed loose quadtree that stores both spatial data and a managed payload per item.
Declaration
public ScyllaLooseQuadtree(ScyllaAABB2 rootBounds, int maxDepth, int maxItemsPerNode, float looseness, Allocator allocator, int initialItemCapacity = 64)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaAABB2 | rootBounds | Tight root bounds of the tree. See ScyllaLooseQuadtree(ScyllaAABB2, int, int, float, Allocator, int) for full parameter semantics. |
| int | maxDepth | Maximum subdivision depth. |
| int | maxItemsPerNode | Maximum items per node before subdivision. |
| float | looseness | Looseness factor (must be finite and >= 1.0). |
| Allocator | allocator | Native memory allocator for internal node and item containers. |
| int | initialItemCapacity | Initial capacity for both the native item map and the managed payload dictionary. Defaults to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
| ArgumentOutOfRangeException | Thrown when any numeric parameter is out of its valid range. |
Properties
Capabilities
Capability flags supported by this collection instance.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities |
Count
Number of items currently stored.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Convenience property indicating whether the tree contains no items.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SyncRoot
Synchronization root for externally coordinating operations with this collection.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object |
ThreadSafety
Declares the thread-safety guarantees provided by this collection instance.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety |
Tree
Gets the underlying untyped ScyllaLooseQuadtree for direct access to spatial queries and 3D projection overloads not exposed by this typed wrapper.
Declaration
public ScyllaLooseQuadtree Tree { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaLooseQuadtree | The inner ScyllaLooseQuadtree instance that performs all spatial indexing. |
Methods
Add(int, T, ScyllaAABB2)
Adds a new item to the tree with its spatial bounds and an associated payload.
Declaration
public void Add(int itemID, T payload, ScyllaAABB2 bounds)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | Unique integer ID for the item. Must not already be registered. |
| T | payload | Payload to associate with |
| ScyllaAABB2 | bounds | 2D bounding box for the item. Must be within the root loose bounds. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
| InvalidOperationException | Thrown when |
| ObjectDisposedException | Thrown when the underlying tree has been disposed. |
Clear()
Removes all items from the tree and clears the managed payload dictionary. After this call, Count is zero and all previously registered IDs are invalid.
Declaration
public void Clear()
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown when the underlying tree has been disposed. |
Dispose()
Disposes the underlying ScyllaLooseQuadtree (releasing its native containers) and clears the managed payload dictionary.
Declaration
public void Dispose()
Remarks
The managed dictionary does not hold unmanaged memory, so only the native tree needs explicit disposal. After this call, any further use of this instance is undefined behavior.
QueryOverlap(ScyllaAABB2, NativeList<int>)
Overlap query: appends the IDs of all items whose bounding boxes intersect query.
Call TryGetPayload(int, out T) for each returned ID to retrieve the associated payload.
Declaration
public void QueryOverlap(ScyllaAABB2 query, NativeList<int> results)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaAABB2 | query | 2D query region. Items are returned when their bounds overlap this region. |
| NativeList<int> | results | Output list to which matching IDs are appended. Not cleared before appending. |
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown when the underlying tree has been disposed. |
QueryRadius(float2, float, NativeList<int>)
Radius query: appends the IDs of all items whose bounding boxes are within radius
of center. Call TryGetPayload(int, out T) for each returned ID to retrieve
the associated payload.
Declaration
public void QueryRadius(float2 center, float radius, NativeList<int> results)
Parameters
| Type | Name | Description |
|---|---|---|
| float2 | center | 2D center of the search circle. |
| float | radius | Search radius. Negative values cause the query to be skipped. |
| NativeList<int> | results | Output list to which matching IDs are appended. Not cleared before appending. |
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown when the underlying tree has been disposed. |
Remove(int)
Removes the item with the specified ID from both the spatial tree and the payload dictionary.
Declaration
public bool Remove(int itemID)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item to remove. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown when the underlying tree has been disposed. |
Remove(int, out T)
Removes the item with the specified ID from both the spatial tree and the payload dictionary, returning the associated payload via an out parameter.
Declaration
public bool Remove(int itemID, out T payload)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item to remove. |
| T | payload | Set to the payload associated with |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown when the underlying tree has been disposed. |
TryGetPayload(int, out T)
Attempts to retrieve the payload associated with the specified item ID.
Declaration
public bool TryGetPayload(int itemID, out T payload)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item whose payload is requested. |
| T | payload | Set to the associated payload when the method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Update(int, ScyllaAABB2)
Updates the 2D bounding box of an existing item without changing its payload. The item is reinserted into a different node if it has moved outside its current node's loose bounds.
Declaration
public bool Update(int itemID, ScyllaAABB2 newBounds)
Parameters
| Type | Name | Description |
|---|---|---|
| int | itemID | ID of the item to update. Must be currently registered. |
| ScyllaAABB2 | newBounds | The item's updated 2D bounding box. Must be within the root loose bounds. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | Thrown when the underlying tree has been disposed. |