< Summary

Information
Class: Trailblazer.Navigation.NavigatorHeightmapGroundingSettings
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Navigator/Heightmaps/NavigatorHeightmapGroundingSettings.cs
Line coverage
100%
Covered lines: 45
Uncovered lines: 0
Coverable lines: 45
Total lines: 119
Line coverage: 100%
Branch coverage
100%
Covered branches: 22
Total branches: 22
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Configure(...)100%88100%
Reset()100%11100%
RecordData(...)100%1212100%
ValidateMode(...)100%22100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Navigator/Heightmaps/NavigatorHeightmapGroundingSettings.cs

#LineLine coverage
 1//=======================================================================
 2// NavigatorHeightmapGroundingSettings.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 Chronicler;
 10using FixedMathSharp;
 11
 12namespace Trailblazer.Navigation;
 13
 14/// <summary>
 15/// Navigator-owned opt-in settings for consuming context-registered heightmap layers.
 16/// </summary>
 17public sealed class NavigatorHeightmapGroundingSettings : IRecordable
 18{
 19    /// <summary>
 20    /// Gets the configured heightmap grounding mode.
 21    /// </summary>
 22    public HeightmapGroundingMode Mode { get; private set; }
 23
 24    /// <summary>
 25    /// Gets the optional configured layer preference used before an active layer has been established.
 26    /// </summary>
 27    public string? LayerName { get; private set; }
 28
 29    /// <summary>
 30    /// Gets the active layer selected by the most recent successful heightmap grounding sample.
 31    /// </summary>
 32    public string? ActiveLayerName { get; internal set; }
 33
 34    /// <summary>
 35    /// Gets the extra root offset applied above sampled ground Y.
 36    /// </summary>
 37    public Fixed64 GroundOffset { get; private set; }
 38
 39    /// <summary>
 40    /// Gets the maximum allowed root-Y correction for positional projection, or null for no limit.
 41    /// </summary>
 42    public Fixed64? SnapTolerance { get; private set; }
 43
 44    internal void Configure(
 45        HeightmapGroundingMode mode,
 46        string? layerName,
 47        Fixed64? groundOffset,
 48        Fixed64? snapTolerance)
 49    {
 2750        ValidateMode(mode);
 2651        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 2652            snapTolerance.HasValue && snapTolerance.Value < Fixed64.Zero,
 2653            actualValue: null,
 2654            paramName: nameof(snapTolerance),
 2655            message: "Heightmap snap tolerance cannot be negative.");
 56
 2557        Mode = mode;
 2558        LayerName = string.IsNullOrWhiteSpace(layerName) ? null : layerName;
 2559        GroundOffset = groundOffset ?? Fixed64.Zero;
 2560        SnapTolerance = snapTolerance;
 2561        ActiveLayerName = mode == HeightmapGroundingMode.Disabled ? null : LayerName;
 2562    }
 63
 64    internal void Reset()
 65    {
 2966        Mode = HeightmapGroundingMode.Disabled;
 2967        LayerName = null;
 2968        ActiveLayerName = null;
 2969        GroundOffset = Fixed64.Zero;
 2970        SnapTolerance = null;
 2971    }
 72
 73    /// <inheritdoc/>
 74    public void RecordData(IChronicler chronicler)
 75    {
 10976        HeightmapGroundingMode mode = Mode;
 10977        string? layerName = LayerName;
 10978        string? activeLayerName = ActiveLayerName;
 10979        Fixed64 groundOffset = GroundOffset;
 10980        bool hasSnapTolerance = SnapTolerance.HasValue;
 10981        Fixed64 snapTolerance = SnapTolerance ?? Fixed64.Zero;
 82
 10983        RecordValues.Look(chronicler, ref mode, "Mode", HeightmapGroundingMode.Disabled);
 10984        RecordValues.Look(chronicler, ref layerName, "LayerName", null);
 10985        RecordValues.Look(chronicler, ref activeLayerName, "ActiveLayerName", null);
 10986        RecordValues.Look(chronicler, ref groundOffset, "GroundOffset", Fixed64.Zero);
 10987        RecordValues.Look(chronicler, ref hasSnapTolerance, "HasSnapTolerance", false);
 10988        RecordValues.Look(chronicler, ref snapTolerance, "SnapTolerance", Fixed64.Zero);
 89
 10990        if (chronicler.Mode == SerializationMode.Loading)
 91        {
 3292            ValidateMode(mode);
 3293            SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 3294                hasSnapTolerance && snapTolerance < Fixed64.Zero,
 3295                actualValue: null,
 3296                paramName: nameof(SnapTolerance),
 3297                message: "Heightmap snap tolerance cannot be negative.");
 98
 3099            Mode = mode;
 30100            LayerName = string.IsNullOrWhiteSpace(layerName) ? null : layerName;
 30101            ActiveLayerName = string.IsNullOrWhiteSpace(activeLayerName) ? null : activeLayerName;
 30102            GroundOffset = groundOffset;
 30103            SnapTolerance = hasSnapTolerance ? snapTolerance : null;
 104        }
 107105    }
 106
 107    private static void ValidateMode(HeightmapGroundingMode mode)
 108    {
 109        switch (mode)
 110        {
 111            case HeightmapGroundingMode.Disabled:
 112            case HeightmapGroundingMode.SurfaceLevelOnly:
 113            case HeightmapGroundingMode.SurfaceLevelAndPosition:
 58114                return;
 115            default:
 1116                throw new ArgumentOutOfRangeException(nameof(mode), "Unknown heightmap grounding mode.");
 117        }
 118    }
 119}