| | | 1 | | namespace SwiftCollections.Query |
| | | 2 | | { |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a node in a Bounding Volume Hierarchy (BVH). |
| | | 5 | | /// Stores spatial data and maintains hierarchical relationships. |
| | | 6 | | /// </summary> |
| | | 7 | | public struct SwiftBVHNode<T> |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Gets or sets the value stored in the node. |
| | | 11 | | /// </summary> |
| | 377139 | 12 | | public T Value { get; set; } |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets or sets the bounding volume of the node. |
| | | 16 | | /// </summary> |
| | 1982998 | 17 | | public IBoundVolume Bounds { get; set; } |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets or sets the index of the parent node. |
| | | 21 | | /// </summary> |
| | 326611 | 22 | | public int ParentIndex { get; set; } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Determines if the node has a parent. |
| | | 26 | | /// </summary> |
| | 3639 | 27 | | public bool HasParent => ParentIndex != -1; |
| | | 28 | | |
| | 196515 | 29 | | public int MyIndex { get; set; } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets or sets the index of the left child node. |
| | | 33 | | /// </summary> |
| | 1649908 | 34 | | public int LeftChildIndex { get; set; } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Determines if the node has a left child. |
| | | 38 | | /// </summary> |
| | 676488 | 39 | | public bool HasLeftChild => LeftChildIndex != -1; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets or sets the index of the right child node. |
| | | 43 | | /// </summary> |
| | 1749398 | 44 | | public int RightChildIndex { get; set; } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Determines if the node has a right child. |
| | | 48 | | /// </summary> |
| | 691337 | 49 | | public bool HasRightChild => RightChildIndex != -1; |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Determines if the node has any children. |
| | | 53 | | /// </summary> |
| | 19186 | 54 | | public bool HasChildren => HasLeftChild || HasRightChild; |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Gets or sets a value indicating whether this node is a leaf node. |
| | | 58 | | /// </summary> |
| | 740033 | 59 | | public bool IsLeaf { get; set; } |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Tracks the number of nodes in the subtree rooted at this node. |
| | | 63 | | /// </summary> |
| | 1770795 | 64 | | public int SubtreeSize { get; set; } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Determines whether or not this node has been allocated from the pool or is a pooled instance |
| | | 68 | | /// </summary> |
| | 2564381 | 69 | | public bool IsAllocated { get; set; } |
| | | 70 | | |
| | | 71 | | /// <summary> |
| | | 72 | | /// Provides a custom default instance of <see cref="SwiftBVHNode{T}"/>. |
| | | 73 | | /// </summary> |
| | 2829 | 74 | | public static SwiftBVHNode<T> Default => new SwiftBVHNode<T> |
| | 2829 | 75 | | { |
| | 2829 | 76 | | Value = default, |
| | 2829 | 77 | | Bounds = default, |
| | 2829 | 78 | | ParentIndex = -1, |
| | 2829 | 79 | | LeftChildIndex = -1, |
| | 2829 | 80 | | RightChildIndex = -1, |
| | 2829 | 81 | | SubtreeSize = 0, |
| | 2829 | 82 | | IsLeaf = false, |
| | 2829 | 83 | | IsAllocated = false |
| | 2829 | 84 | | }; |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Resets the node to its default state. |
| | | 88 | | /// Clears all references and metadata. |
| | | 89 | | /// </summary> |
| | | 90 | | public void Reset() |
| | 139010 | 91 | | { |
| | 139010 | 92 | | Value = default; |
| | 139010 | 93 | | Bounds = default; |
| | 139010 | 94 | | IsLeaf = false; |
| | 139010 | 95 | | ParentIndex = -1; |
| | 139010 | 96 | | MyIndex = -1; |
| | 139010 | 97 | | LeftChildIndex = -1; |
| | 139010 | 98 | | RightChildIndex = -1; |
| | 139010 | 99 | | SubtreeSize = 0; |
| | 139010 | 100 | | IsAllocated = false; |
| | 139010 | 101 | | } |
| | | 102 | | } |
| | | 103 | | } |