| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace SwiftCollections.Query; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Controls node subdivision behavior for <see cref="SwiftOctree{TKey, TVolume}"/>. |
| | | 7 | | /// </summary> |
| | | 8 | | public readonly struct SwiftOctreeOptions : IEquatable<SwiftOctreeOptions> |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Initializes a new instance of the <see cref="SwiftOctreeOptions"/> struct. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="maxDepth">The maximum child depth allowed below the root node.</param> |
| | | 14 | | /// <param name="nodeCapacity">The maximum number of entries a node should hold before attempting to split.</param> |
| | | 15 | | public SwiftOctreeOptions(int maxDepth, int nodeCapacity) |
| | 44 | 16 | | : this(maxDepth, nodeCapacity, true) { } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="SwiftOctreeOptions"/> struct. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="maxDepth">The maximum child depth allowed below the root node.</param> |
| | | 22 | | /// <param name="nodeCapacity">The maximum number of entries a node should hold before attempting to split.</param> |
| | | 23 | | /// <param name="enableMergeOnRemove">Whether empty child regions should collapse back into their parent after remov |
| | | 24 | | public SwiftOctreeOptions(int maxDepth, int nodeCapacity, bool enableMergeOnRemove) |
| | | 25 | | { |
| | 29 | 26 | | if (maxDepth < 0) |
| | 1 | 27 | | throw new ArgumentOutOfRangeException(nameof(maxDepth), maxDepth, "Maximum depth must be zero or greater."); |
| | | 28 | | |
| | 28 | 29 | | if (nodeCapacity <= 0) |
| | 1 | 30 | | throw new ArgumentOutOfRangeException(nameof(nodeCapacity), nodeCapacity, "Node capacity must be greater tha |
| | | 31 | | |
| | 27 | 32 | | MaxDepth = maxDepth; |
| | 27 | 33 | | NodeCapacity = nodeCapacity; |
| | 27 | 34 | | EnableMergeOnRemove = enableMergeOnRemove; |
| | 27 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the maximum child depth allowed below the root node. |
| | | 39 | | /// </summary> |
| | 79 | 40 | | public int MaxDepth { get; } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets the preferred number of entries per node before subdivision is attempted. |
| | | 44 | | /// </summary> |
| | 230 | 45 | | public int NodeCapacity { get; } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Gets a value indicating whether nodes should merge after removals leave sparse children. |
| | | 49 | | /// </summary> |
| | 15 | 50 | | public bool EnableMergeOnRemove { get; } |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | public bool Equals(SwiftOctreeOptions other) |
| | | 54 | | { |
| | 7 | 55 | | return MaxDepth == other.MaxDepth && |
| | 7 | 56 | | NodeCapacity == other.NodeCapacity && |
| | 7 | 57 | | EnableMergeOnRemove == other.EnableMergeOnRemove; |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <inheritdoc /> |
| | 2 | 61 | | public override bool Equals(object? obj) => obj is SwiftOctreeOptions other && Equals(other); |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Determines whether two SwiftOctreeOptions instances are equal. |
| | | 65 | | /// </summary> |
| | 2 | 66 | | public static bool operator ==(SwiftOctreeOptions left, SwiftOctreeOptions right) => left.Equals(right); |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Determines whether two SwiftOctreeOptions instances are not equal. |
| | | 70 | | /// </summary> |
| | 1 | 71 | | public static bool operator !=(SwiftOctreeOptions left, SwiftOctreeOptions right) => !(left == right); |
| | | 72 | | |
| | | 73 | | /// <inheritdoc /> |
| | 2 | 74 | | public override int GetHashCode() => HashCode.Combine(MaxDepth, NodeCapacity, EnableMergeOnRemove); |
| | | 75 | | } |