| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationNodeRef.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 stable cell slot within one immutable graph root.</summary> |
| | | 14 | | internal readonly struct NavigationNodeRef : IEquatable<NavigationNodeRef> |
| | | 15 | | { |
| | | 16 | | private readonly int _encodedMapOrdinal; |
| | | 17 | | private readonly int _encodedCellSlot; |
| | | 18 | | |
| | | 19 | | internal NavigationNodeRef(int mapOrdinal, int cellSlot) |
| | | 20 | | { |
| | 1679290 | 21 | | if (mapOrdinal < 0 |
| | 1679290 | 22 | | || mapOrdinal == int.MaxValue |
| | 1679290 | 23 | | || cellSlot < 0 |
| | 1679290 | 24 | | || cellSlot == int.MaxValue) |
| | | 25 | | { |
| | 6 | 26 | | _encodedMapOrdinal = 0; |
| | 6 | 27 | | _encodedCellSlot = 0; |
| | 6 | 28 | | return; |
| | | 29 | | } |
| | | 30 | | |
| | 1679284 | 31 | | _encodedMapOrdinal = mapOrdinal + 1; |
| | 1679284 | 32 | | _encodedCellSlot = cellSlot + 1; |
| | 1679284 | 33 | | } |
| | | 34 | | |
| | 8226827 | 35 | | internal int MapOrdinal => _encodedMapOrdinal - 1; |
| | | 36 | | |
| | 7022441 | 37 | | internal int CellSlot => _encodedCellSlot - 1; |
| | | 38 | | |
| | 5312509 | 39 | | internal bool IsValid => _encodedMapOrdinal > 0 && _encodedCellSlot > 0; |
| | | 40 | | |
| | | 41 | | public bool Equals(NavigationNodeRef other) => |
| | 615353 | 42 | | _encodedMapOrdinal == other._encodedMapOrdinal |
| | 615353 | 43 | | && _encodedCellSlot == other._encodedCellSlot; |
| | | 44 | | |
| | | 45 | | public override int GetHashCode() => |
| | 263172 | 46 | | SwiftHashTools.CombineHashCodes(_encodedMapOrdinal, _encodedCellSlot); |
| | | 47 | | |
| | | 48 | | } |