< Summary

Information
Class: Trailblazer.Pathing.NavigationCell
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Map/NavigationCell.cs
Line coverage
100%
Covered lines: 59
Uncovered lines: 0
Coverable lines: 59
Total lines: 164
Line coverage: 100%
Branch coverage
100%
Covered branches: 24
Total branches: 24
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsKnownMedium(...)100%44100%
ToMedia(...)100%44100%
SupportsMedium(...)100%11100%
.ctor(...)100%22100%
Equals(...)100%1212100%
Equals(...)100%22100%
GetHashCode()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Map/NavigationCell.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationCell.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 System;
 9using FixedMathSharp;
 10using SwiftCollections.Utility;
 11
 12namespace Trailblazer.Pathing;
 13
 14/// <summary>
 15/// Stores the complete immutable semantic payload for one authored navigation cell.
 16/// </summary>
 17public readonly struct NavigationCell : IEquatable<NavigationCell>
 18{
 19    internal const TraversalMedia KnownMedia =
 20        TraversalMedia.Solid | TraversalMedia.Gas | TraversalMedia.Liquid;
 21
 22    internal const TraversalCapability KnownCapabilities =
 23        TraversalCapability.Jump
 24        | TraversalCapability.Climb
 25        | TraversalCapability.Swim
 26        | TraversalCapability.Fly
 27        | TraversalCapability.Teleport;
 28
 29    internal const NavigationCellFlags KnownFlags =
 30        NavigationCellFlags.TransitionSourceHint
 31        | NavigationCellFlags.TransitionDestinationHint
 32        | NavigationCellFlags.ClimbSurfaceHint;
 33
 34    internal static bool IsKnownMedium(TraversalMedium medium) =>
 379983735        medium == TraversalMedium.Solid
 379983736        || medium == TraversalMedium.Gas
 379983737        || medium == TraversalMedium.Liquid;
 38
 59803939    internal static TraversalMedia ToMedia(TraversalMedium medium) => medium switch
 59803940    {
 34179541        TraversalMedium.Solid => TraversalMedia.Solid,
 13418342        TraversalMedium.Gas => TraversalMedia.Gas,
 12206043        TraversalMedium.Liquid => TraversalMedia.Liquid,
 144        _ => TraversalMedia.None
 59803945    };
 46
 47    internal bool SupportsMedium(TraversalMedium medium) =>
 56060948        (Media & ToMedia(medium)) != 0;
 49
 50    /// <summary>
 51    /// The traversal media supported by this cell.
 52    /// </summary>
 53    public TraversalMedia Media { get; }
 54
 55    /// <summary>
 56    /// The complete set of capabilities an agent must possess to enter this cell.
 57    /// </summary>
 58    public TraversalCapability RequiredCapabilities { get; }
 59
 60    /// <summary>
 61    /// The stable host-defined navigation area used by query-specific policies.
 62    /// </summary>
 63    public NavigationAreaId Area { get; }
 64
 65    /// <summary>
 66    /// The non-negative cost charged when an edge enters this cell.
 67    /// </summary>
 68    public Fixed64 EnterCost { get; }
 69
 70    /// <summary>
 71    /// The inclusive horizontal radius clearance at the cell anchor.
 72    /// </summary>
 73    public Fixed64 RadiusClearance { get; }
 74
 75    /// <summary>
 76    /// The inclusive vertical clearance above the cell anchor.
 77    /// </summary>
 78    public Fixed64 HeightClearance { get; }
 79
 80    /// <summary>
 81    /// Optional transition-generation hints.
 82    /// </summary>
 83    public NavigationCellFlags Flags { get; }
 84
 85    /// <summary>
 86    /// Creates a complete authored navigation-cell payload.
 87    /// </summary>
 88    public NavigationCell(
 89        TraversalMedia media,
 90        TraversalCapability requiredCapabilities,
 91        NavigationAreaId area,
 92        Fixed64 enterCost,
 93        Fixed64 radiusClearance,
 94        Fixed64 heightClearance,
 95        NavigationCellFlags flags = NavigationCellFlags.None)
 96    {
 174597        SwiftThrowHelper.ThrowIfArgument(
 174598            media == TraversalMedia.None || (media & ~KnownMedia) != 0,
 174599            nameof(media),
 1745100            "Media must contain at least one known traversal-medium bit.");
 1743101        SwiftThrowHelper.ThrowIfArgument(
 1743102            (requiredCapabilities & ~KnownCapabilities) != 0,
 1743103            nameof(requiredCapabilities),
 1743104            "Required capabilities contain an unknown bit.");
 1742105        SwiftThrowHelper.ThrowIfArgument(
 1742106            enterCost < Fixed64.Zero,
 1742107            nameof(enterCost),
 1742108            "Enter cost must be non-negative.");
 1741109        SwiftThrowHelper.ThrowIfArgument(
 1741110            radiusClearance < Fixed64.Zero,
 1741111            nameof(radiusClearance),
 1741112            "Radius clearance must be non-negative.");
 1741113        SwiftThrowHelper.ThrowIfArgument(
 1741114            heightClearance < Fixed64.Zero,
 1741115            nameof(heightClearance),
 1741116            "Height clearance must be non-negative.");
 1741117        SwiftThrowHelper.ThrowIfArgument(
 1741118            (flags & ~KnownFlags) != 0,
 1741119            nameof(flags),
 1741120            "Cell flags contain an unknown bit.");
 121
 1741122        Media = media;
 1741123        RequiredCapabilities = requiredCapabilities;
 1741124        Area = area;
 1741125        EnterCost = enterCost;
 1741126        RadiusClearance = radiusClearance;
 1741127        HeightClearance = heightClearance;
 1741128        Flags = flags;
 1741129    }
 130
 131    /// <inheritdoc/>
 132    public bool Equals(NavigationCell other) =>
 47133        Media == other.Media
 47134        && RequiredCapabilities == other.RequiredCapabilities
 47135        && Area == other.Area
 47136        && EnterCost == other.EnterCost
 47137        && RadiusClearance == other.RadiusClearance
 47138        && HeightClearance == other.HeightClearance
 47139        && Flags == other.Flags;
 140
 141    /// <inheritdoc/>
 23142    public override bool Equals(object? obj) => obj is NavigationCell other && Equals(other);
 143
 144    /// <inheritdoc/>
 145    public override int GetHashCode()
 146    {
 16147        int hash = SwiftHashTools.CombineHashCodes((int)Media, (int)RequiredCapabilities);
 16148        hash = SwiftHashTools.CombineHashCodes(hash, Area.GetHashCode());
 16149        hash = SwiftHashTools.CombineHashCodes(hash, EnterCost.GetHashCode());
 16150        hash = SwiftHashTools.CombineHashCodes(hash, RadiusClearance.GetHashCode());
 16151        hash = SwiftHashTools.CombineHashCodes(hash, HeightClearance.GetHashCode());
 16152        return SwiftHashTools.CombineHashCodes(hash, (int)Flags);
 153    }
 154
 155    /// <summary>
 156    /// Tests two cell payloads for value equality.
 157    /// </summary>
 1158    public static bool operator ==(NavigationCell left, NavigationCell right) => left.Equals(right);
 159
 160    /// <summary>
 161    /// Tests two cell payloads for value inequality.
 162    /// </summary>
 1163    public static bool operator !=(NavigationCell left, NavigationCell right) => !left.Equals(right);
 164}