| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationSurfaceComponentKey.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 Trailblazer.Pathing; |
| | | 11 | | |
| | | 12 | | /// <summary>Identifies one exact weak surface component by its minimum member address.</summary> |
| | | 13 | | internal readonly struct NavigationSurfaceComponentKey : |
| | | 14 | | IEquatable<NavigationSurfaceComponentKey>, |
| | | 15 | | IComparable<NavigationSurfaceComponentKey> |
| | | 16 | | { |
| | | 17 | | internal NavigationSurfaceComponentKey( |
| | | 18 | | NavigationCellAddress representative, |
| | | 19 | | TraversalMedium medium) |
| | | 20 | | { |
| | 6600 | 21 | | Representative = representative; |
| | 6600 | 22 | | Medium = medium; |
| | 6600 | 23 | | } |
| | | 24 | | |
| | | 25 | | internal NavigationCellAddress Representative { get; } |
| | | 26 | | |
| | | 27 | | internal TraversalMedium Medium { get; } |
| | | 28 | | |
| | | 29 | | public int CompareTo(NavigationSurfaceComponentKey other) |
| | | 30 | | { |
| | 169 | 31 | | int value = Representative.CompareTo(other.Representative); |
| | 169 | 32 | | if (value != 0) |
| | 149 | 33 | | return value; |
| | 20 | 34 | | int medium = (int)Medium; |
| | 20 | 35 | | int otherMedium = (int)other.Medium; |
| | 20 | 36 | | return medium < otherMedium ? -1 : medium > otherMedium ? 1 : 0; |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public bool Equals(NavigationSurfaceComponentKey other) => |
| | 2152167 | 40 | | Representative.Equals(other.Representative) && Medium == other.Medium; |
| | | 41 | | |
| | 14642 | 42 | | public override int GetHashCode() => SwiftCollections.Utility.SwiftHashTools.CombineHashCodes( |
| | 14642 | 43 | | Representative.GetHashCode(), |
| | 14642 | 44 | | (int)Medium); |
| | | 45 | | |
| | | 46 | | } |