| | | 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<TKey, TVolume> |
| | | 8 | | where TVolume : struct, IBoundVolume<TVolume> |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Gets or sets the value stored in the node. |
| | | 12 | | /// </summary> |
| | 117451 | 13 | | public TKey Value { get; set; } |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Gets or sets the bounding volume of the node. |
| | | 17 | | /// </summary> |
| | 931244 | 18 | | public TVolume Bounds { get; set; } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets or sets the index of the parent node. |
| | | 22 | | /// </summary> |
| | 134513 | 23 | | public int ParentIndex { get; set; } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Determines if the node has a parent. |
| | | 27 | | /// </summary> |
| | 0 | 28 | | public readonly bool HasParent => ParentIndex != -1; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets the index value associated with this instance. |
| | | 32 | | /// </summary> |
| | 88412 | 33 | | public int MyIndex { get; set; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets or sets the index of the left child node. |
| | | 37 | | /// </summary> |
| | 663568 | 38 | | public int LeftChildIndex { get; set; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Determines if the node has a left child. |
| | | 42 | | /// </summary> |
| | 10516 | 43 | | public readonly bool HasLeftChild => LeftChildIndex != -1; |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets or sets the index of the right child node. |
| | | 47 | | /// </summary> |
| | 659880 | 48 | | public int RightChildIndex { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Determines if the node has a right child. |
| | | 52 | | /// </summary> |
| | 10516 | 53 | | public readonly bool HasRightChild => RightChildIndex != -1; |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Determines if the node has any children. |
| | | 57 | | /// </summary> |
| | 0 | 58 | | public readonly bool HasChildren => HasLeftChild || HasRightChild; |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets or sets a value indicating whether this node is a leaf node. |
| | | 62 | | /// </summary> |
| | 284173 | 63 | | public bool IsLeaf { get; set; } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Tracks the number of nodes in the subtree rooted at this node. |
| | | 67 | | /// </summary> |
| | 809463 | 68 | | public int SubtreeSize { get; set; } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Determines whether or not this node has been allocated from the pool or is a pooled instance |
| | | 72 | | /// </summary> |
| | 1095991 | 73 | | public bool IsAllocated { get; set; } |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Provides a custom default instance of <see cref="SwiftBVHNode{TKey, TVolume}"/>. |
| | | 77 | | /// </summary> |
| | 4 | 78 | | public static SwiftBVHNode<TKey, TVolume> Default => new() |
| | 4 | 79 | | { |
| | 4 | 80 | | Value = default!, |
| | 4 | 81 | | Bounds = default, |
| | 4 | 82 | | ParentIndex = -1, |
| | 4 | 83 | | LeftChildIndex = -1, |
| | 4 | 84 | | RightChildIndex = -1, |
| | 4 | 85 | | SubtreeSize = 0, |
| | 4 | 86 | | IsLeaf = false, |
| | 4 | 87 | | IsAllocated = false |
| | 4 | 88 | | }; |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Resets the node to its default state. |
| | | 92 | | /// Clears all references and metadata. |
| | | 93 | | /// </summary> |
| | | 94 | | public void Reset() |
| | | 95 | | { |
| | 61982 | 96 | | Value = default!; |
| | 61982 | 97 | | Bounds = default; |
| | 61982 | 98 | | IsLeaf = false; |
| | 61982 | 99 | | ParentIndex = -1; |
| | 61982 | 100 | | MyIndex = -1; |
| | 61982 | 101 | | LeftChildIndex = -1; |
| | 61982 | 102 | | RightChildIndex = -1; |
| | 61982 | 103 | | SubtreeSize = 0; |
| | 61982 | 104 | | IsAllocated = false; |
| | 61982 | 105 | | } |
| | | 106 | | } |