< Summary

Information
Class: Trailblazer.Pathing.NavigationAutomaticSeamPairKey
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/NavigationAutomaticSeamPair.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 150
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
CompareTo(...)100%22100%
CompareAddress(...)100%1212100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/NavigationAutomaticSeamPair.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationAutomaticSeamPair.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
 8using GridForge.Grids.Topology;
 9using System;
 10
 11namespace Trailblazer.Pathing;
 12
 13/// <summary>Owns one canonical absolute portal shared by both seam directions.</summary>
 14internal sealed class NavigationAutomaticSeamPair
 15{
 16    internal const long RetainedSize = 168L;
 17
 18    internal NavigationAutomaticSeamPair(
 19        NavigationCellAddress first,
 20        NavigationCellAddress second,
 21        GridNavigationPortal portal)
 22    {
 23        First = first;
 24        Second = second;
 25        Portal = portal;
 26    }
 27
 28    internal NavigationCellAddress First { get; }
 29
 30    internal NavigationCellAddress Second { get; }
 31
 32    internal GridNavigationPortal Portal { get; }
 33}
 34
 35/// <summary>Stores snapshot-local active state without duplicating canonical portal geometry.</summary>
 36internal sealed class NavigationAutomaticSeamPairRecord
 37{
 38    internal const long RetainedSize = 32L;
 39
 40    internal NavigationAutomaticSeamPairRecord(
 41        NavigationAutomaticSeamPair pair,
 42        bool isActive)
 43    {
 44        Pair = pair;
 45        IsActive = isActive;
 46    }
 47
 48    internal NavigationAutomaticSeamPair Pair { get; }
 49
 50    internal bool IsActive { get; }
 51}
 52
 53/// <summary>Identifies one directed use of a canonical automatic seam.</summary>
 54internal readonly struct NavigationAutomaticSeamRef
 55{
 56    internal NavigationAutomaticSeamRef(NavigationAutomaticSeamPair pair, bool reverse)
 57    {
 58        Pair = pair;
 59        IsReverse = reverse;
 60    }
 61
 62    internal NavigationAutomaticSeamPair Pair { get; }
 63
 64    internal bool IsReverse { get; }
 65
 66    internal NavigationCellAddress Source => IsReverse ? Pair.Second : Pair.First;
 67
 68    internal NavigationCellAddress Destination => IsReverse ? Pair.First : Pair.Second;
 69
 70    internal GridNavigationPortal Portal => Pair.Portal;
 71}
 72
 73/// <summary>Orders one canonical unordered durable seam pair.</summary>
 74internal readonly struct NavigationAutomaticSeamPairKey : IComparable<NavigationAutomaticSeamPairKey>
 75{
 76    internal NavigationAutomaticSeamPairKey(
 77        NavigationCellAddress first,
 78        NavigationCellAddress second)
 79    {
 10293980        if (CompareAddress(first, second) > 0)
 179581            (first, second) = (second, first);
 10293982        First = first;
 10293983        Second = second;
 10293984    }
 85
 86    internal NavigationCellAddress First { get; }
 87
 88    internal NavigationCellAddress Second { get; }
 89
 90    public int CompareTo(NavigationAutomaticSeamPairKey other)
 91    {
 90784092        int comparison = CompareAddress(First, other.First);
 90784093        return comparison != 0 ? comparison : CompareAddress(Second, other.Second);
 94    }
 95
 96    private static int CompareAddress(
 97        NavigationCellAddress left,
 98        NavigationCellAddress right)
 99    {
 1289295100        int comparison = string.CompareOrdinal(left.MapId, right.MapId);
 1289295101        if (comparison != 0)
 397034102            return comparison;
 892261103        comparison = left.Index.x < right.Index.x
 892261104            ? -1
 892261105            : left.Index.x > right.Index.x ? 1 : 0;
 892261106        if (comparison != 0)
 294094107            return comparison;
 598167108        comparison = left.Index.y < right.Index.y
 598167109            ? -1
 598167110            : left.Index.y > right.Index.y ? 1 : 0;
 598167111        if (comparison != 0)
 127076112            return comparison;
 471091113        return left.Index.z < right.Index.z
 471091114            ? -1
 471091115            : left.Index.z > right.Index.z ? 1 : 0;
 116    }
 117}
 118
 119/// <summary>Provides an ordinal value key for one structural-link row.</summary>
 120internal readonly struct NavigationAutomaticSeamMapKey : IComparable<NavigationAutomaticSeamMapKey>
 121{
 122    internal NavigationAutomaticSeamMapKey(string mapId) => MapId = mapId;
 123
 124    internal string MapId { get; }
 125
 126    public int CompareTo(NavigationAutomaticSeamMapKey other) =>
 127        string.CompareOrdinal(MapId, other.MapId);
 128}
 129
 130/// <summary>Orders one directed structural seam dependency.</summary>
 131internal readonly struct NavigationAutomaticSeamLinkKey : IComparable<NavigationAutomaticSeamLinkKey>
 132{
 133    internal NavigationAutomaticSeamLinkKey(string sourceMapId, string destinationMapId)
 134    {
 135        SourceMapId = sourceMapId;
 136        DestinationMapId = destinationMapId;
 137    }
 138
 139    internal string SourceMapId { get; }
 140
 141    internal string DestinationMapId { get; }
 142
 143    public int CompareTo(NavigationAutomaticSeamLinkKey other)
 144    {
 145        int comparison = string.CompareOrdinal(SourceMapId, other.SourceMapId);
 146        return comparison != 0
 147            ? comparison
 148            : string.CompareOrdinal(DestinationMapId, other.DestinationMapId);
 149    }
 150}