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