< Summary

Information
Class: Trailblazer.Pathing.NavigationMediumSlots<T>
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/NavigationMediumSlots.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 57
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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%11100%
TryGet(...)100%66100%
Set(...)100%44100%
GetBit(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// NavigationMediumSlots.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
 8namespace Trailblazer.Pathing;
 9
 10/// <summary>Stores at most one value for each exact known traversal medium.</summary>
 11internal readonly struct NavigationMediumSlots<T>
 12{
 13    private readonly T _solid;
 14    private readonly T _gas;
 15    private readonly T _liquid;
 16    private readonly byte _mask;
 17
 18    private NavigationMediumSlots(T solid, T gas, T liquid, byte mask)
 19    {
 7216020        _solid = solid;
 7216021        _gas = gas;
 7216022        _liquid = liquid;
 7216023        _mask = mask;
 7216024    }
 25
 26    internal bool TryGet(TraversalMedium medium, out T value)
 27    {
 687123428        byte bit = GetBit(medium);
 687123429        if ((_mask & bit) == 0)
 30        {
 231            value = default!;
 232            return false;
 33        }
 687123234        value = medium == TraversalMedium.Solid
 687123235            ? _solid
 687123236            : medium == TraversalMedium.Gas
 687123237                ? _gas
 687123238                : _liquid;
 687123239        return true;
 40    }
 41
 42    internal NavigationMediumSlots<T> Set(TraversalMedium medium, T value)
 43    {
 7216044        byte bit = GetBit(medium);
 7216045        return medium == TraversalMedium.Solid
 7216046            ? new NavigationMediumSlots<T>(value, _gas, _liquid, (byte)(_mask | bit))
 7216047            : medium == TraversalMedium.Gas
 7216048                ? new NavigationMediumSlots<T>(_solid, value, _liquid, (byte)(_mask | bit))
 7216049                : new NavigationMediumSlots<T>(_solid, _gas, value, (byte)(_mask | bit));
 50    }
 51
 52    internal static byte GetBit(TraversalMedium medium)
 53    {
 54        System.Diagnostics.Debug.Assert(NavigationCell.IsKnownMedium(medium));
 700063255        return (byte)(1 << ((int)medium - (int)TraversalMedium.Solid));
 56    }
 57}