| | | 1 | | //======================================================================= |
| | | 2 | | // GridConfigurationKey.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 FixedMathSharp; |
| | | 9 | | using GridForge.Grids.Topology; |
| | | 10 | | using SwiftCollections.Utility; |
| | | 11 | | using System; |
| | | 12 | | |
| | | 13 | | namespace GridForge.Configuration; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Exact identity key for a grid's snapped bounds and topology. |
| | | 17 | | /// </summary> |
| | | 18 | | public readonly struct GridConfigurationKey : IEquatable<GridConfigurationKey> |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// The minimum snapped bounds of the grid. |
| | | 22 | | /// </summary> |
| | | 23 | | public readonly Vector3d BoundsMin; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// The maximum snapped bounds of the grid. |
| | | 27 | | /// </summary> |
| | | 28 | | public readonly Vector3d BoundsMax; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// The grid topology used by these bounds. |
| | | 32 | | /// </summary> |
| | | 33 | | public readonly GridTopologyKind TopologyKind; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// The topology metrics used by these bounds. |
| | | 37 | | /// </summary> |
| | | 38 | | public readonly GridTopologyMetrics TopologyMetrics; |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Initializes a new grid configuration key. |
| | | 42 | | /// </summary> |
| | | 43 | | public GridConfigurationKey( |
| | | 44 | | Vector3d boundsMin, |
| | | 45 | | Vector3d boundsMax, |
| | | 46 | | GridTopologyKind topologyKind, |
| | | 47 | | GridTopologyMetrics topologyMetrics) |
| | | 48 | | { |
| | 438 | 49 | | BoundsMin = boundsMin; |
| | 438 | 50 | | BoundsMax = boundsMax; |
| | 438 | 51 | | TopologyKind = topologyKind; |
| | 438 | 52 | | TopologyMetrics = topologyMetrics; |
| | 438 | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <inheritdoc/> |
| | | 56 | | public override readonly int GetHashCode() |
| | | 57 | | { |
| | 834 | 58 | | int hash = SwiftHashTools.CombineHashCodes(BoundsMin.GetHashCode(), BoundsMax.GetHashCode()); |
| | 834 | 59 | | hash = SwiftHashTools.CombineHashCodes(hash, TopologyKind.GetHashCode()); |
| | 834 | 60 | | return SwiftHashTools.CombineHashCodes(hash, TopologyMetrics.GetHashCode()); |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <inheritdoc/> |
| | | 64 | | public readonly bool Equals(GridConfigurationKey other) |
| | | 65 | | { |
| | 35 | 66 | | return BoundsMin == other.BoundsMin |
| | 35 | 67 | | && BoundsMax == other.BoundsMax |
| | 35 | 68 | | && TopologyKind == other.TopologyKind |
| | 35 | 69 | | && TopologyMetrics == other.TopologyMetrics; |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | /// <inheritdoc/> |
| | 2 | 73 | | public override readonly bool Equals(object? obj) => obj is GridConfigurationKey other && Equals(other); |
| | | 74 | | |
| | | 75 | | /// <inheritdoc/> |
| | 2 | 76 | | public static bool operator ==(GridConfigurationKey left, GridConfigurationKey right) => left.Equals(right); |
| | | 77 | | |
| | | 78 | | /// <inheritdoc/> |
| | 2 | 79 | | public static bool operator !=(GridConfigurationKey left, GridConfigurationKey right) => !left.Equals(right); |
| | | 80 | | } |