| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationMediumStateRef.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 | | using SwiftCollections.Utility; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary>Identifies one traversal-medium state over an immutable physical node.</summary> |
| | | 14 | | internal readonly struct NavigationMediumStateRef : |
| | | 15 | | IEquatable<NavigationMediumStateRef>, |
| | | 16 | | IComparable<NavigationMediumStateRef> |
| | | 17 | | { |
| | | 18 | | internal NavigationMediumStateRef(NavigationNodeRef node, TraversalMedium medium) |
| | | 19 | | { |
| | 353133 | 20 | | Node = node; |
| | 353133 | 21 | | Medium = medium; |
| | 353133 | 22 | | } |
| | | 23 | | |
| | | 24 | | internal NavigationNodeRef Node { get; } |
| | | 25 | | |
| | | 26 | | internal TraversalMedium Medium { get; } |
| | | 27 | | |
| | 12 | 28 | | internal bool IsValid => Node.IsValid && NavigationCell.IsKnownMedium(Medium); |
| | | 29 | | |
| | | 30 | | public int CompareTo(NavigationMediumStateRef other) |
| | | 31 | | { |
| | 6 | 32 | | int comparison = Node.MapOrdinal.CompareTo(other.Node.MapOrdinal); |
| | 6 | 33 | | if (comparison != 0) |
| | 1 | 34 | | return comparison; |
| | 5 | 35 | | comparison = Node.CellSlot.CompareTo(other.Node.CellSlot); |
| | 5 | 36 | | if (comparison != 0) |
| | 1 | 37 | | return comparison; |
| | 4 | 38 | | int medium = (int)Medium; |
| | 4 | 39 | | int otherMedium = (int)other.Medium; |
| | 4 | 40 | | return medium < otherMedium ? -1 : medium > otherMedium ? 1 : 0; |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public bool Equals(NavigationMediumStateRef other) => |
| | 87296 | 44 | | Node.Equals(other.Node) && Medium == other.Medium; |
| | | 45 | | |
| | | 46 | | public override int GetHashCode() => |
| | 83170 | 47 | | SwiftHashTools.CombineHashCodes(Node.GetHashCode(), (int)Medium); |
| | | 48 | | |
| | | 49 | | } |