< Summary

Information
Class: Trailblazer.Navigation.NavigatorHeightmapGroundingSettings
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Navigator/Heightmaps/NavigatorHeightmapGroundingSettings.cs
Line coverage
92%
Covered lines: 36
Uncovered lines: 3
Coverable lines: 39
Total lines: 106
Line coverage: 92.3%
Branch coverage
88%
Covered branches: 23
Total branches: 26
Branch coverage: 88.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Configure(...)90%101088.88%
Reset()100%11100%
RecordData(...)92.85%141495.45%
ValidateMode(...)50%3250%

File(s)

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

#LineLine coverage
 1using Chronicler;
 2using FixedMathSharp;
 3using System;
 4
 5namespace Trailblazer.Navigation;
 6
 7/// <summary>
 8/// Navigator-owned opt-in settings for consuming context-registered heightmap layers.
 9/// </summary>
 10public sealed class NavigatorHeightmapGroundingSettings : IRecordable
 11{
 12    /// <summary>
 13    /// Gets the configured heightmap grounding mode.
 14    /// </summary>
 15    public HeightmapGroundingMode Mode { get; private set; }
 16
 17    /// <summary>
 18    /// Gets the optional configured layer preference used before an active layer has been established.
 19    /// </summary>
 20    public string? LayerName { get; private set; }
 21
 22    /// <summary>
 23    /// Gets the active layer selected by the most recent successful heightmap grounding sample.
 24    /// </summary>
 25    public string? ActiveLayerName { get; internal set; }
 26
 27    /// <summary>
 28    /// Gets the extra root offset applied above sampled ground Y.
 29    /// </summary>
 30    public Fixed64 GroundOffset { get; private set; }
 31
 32    /// <summary>
 33    /// Gets the maximum allowed root-Y correction for positional projection, or null for no limit.
 34    /// </summary>
 35    public Fixed64? SnapTolerance { get; private set; }
 36
 37    internal void Configure(
 38        HeightmapGroundingMode mode,
 39        string? layerName,
 40        Fixed64? groundOffset,
 41        Fixed64? snapTolerance)
 42    {
 1243        ValidateMode(mode);
 1244        if (snapTolerance.HasValue && snapTolerance.Value < Fixed64.Zero)
 045            throw new ArgumentOutOfRangeException(nameof(snapTolerance), "Heightmap snap tolerance cannot be negative.")
 46
 1247        Mode = mode;
 1248        LayerName = string.IsNullOrWhiteSpace(layerName) ? null : layerName;
 1249        GroundOffset = groundOffset ?? Fixed64.Zero;
 1250        SnapTolerance = snapTolerance;
 1251        ActiveLayerName = mode == HeightmapGroundingMode.Disabled ? null : LayerName;
 1252    }
 53
 54    internal void Reset()
 55    {
 356        Mode = HeightmapGroundingMode.Disabled;
 357        LayerName = null;
 358        ActiveLayerName = null;
 359        GroundOffset = Fixed64.Zero;
 360        SnapTolerance = null;
 361    }
 62
 63    /// <inheritdoc/>
 64    public void RecordData(IChronicler chronicler)
 65    {
 8666        HeightmapGroundingMode mode = Mode;
 8667        string? layerName = LayerName;
 8668        string? activeLayerName = ActiveLayerName;
 8669        Fixed64 groundOffset = GroundOffset;
 8670        bool hasSnapTolerance = SnapTolerance.HasValue;
 8671        Fixed64 snapTolerance = SnapTolerance ?? Fixed64.Zero;
 72
 8673        RecordValues.Look(chronicler, ref mode, "Mode", HeightmapGroundingMode.Disabled);
 8674        RecordValues.Look(chronicler, ref layerName, "LayerName", null);
 8675        RecordValues.Look(chronicler, ref activeLayerName, "ActiveLayerName", null);
 8676        RecordValues.Look(chronicler, ref groundOffset, "GroundOffset", Fixed64.Zero);
 8677        RecordValues.Look(chronicler, ref hasSnapTolerance, "HasSnapTolerance", false);
 8678        RecordValues.Look(chronicler, ref snapTolerance, "SnapTolerance", Fixed64.Zero);
 79
 8680        if (chronicler.Mode == SerializationMode.Loading)
 81        {
 4482            ValidateMode(mode);
 4483            if (hasSnapTolerance && snapTolerance < Fixed64.Zero)
 084                throw new ArgumentOutOfRangeException(nameof(SnapTolerance), "Heightmap snap tolerance cannot be negativ
 85
 4486            Mode = mode;
 4487            LayerName = string.IsNullOrWhiteSpace(layerName) ? null : layerName;
 4488            ActiveLayerName = string.IsNullOrWhiteSpace(activeLayerName) ? null : activeLayerName;
 4489            GroundOffset = groundOffset;
 4490            SnapTolerance = hasSnapTolerance ? snapTolerance : null;
 91        }
 8692    }
 93
 94    private static void ValidateMode(HeightmapGroundingMode mode)
 95    {
 96        switch (mode)
 97        {
 98            case HeightmapGroundingMode.Disabled:
 99            case HeightmapGroundingMode.SurfaceLevelOnly:
 100            case HeightmapGroundingMode.SurfaceLevelAndPosition:
 56101                return;
 102            default:
 0103                throw new ArgumentOutOfRangeException(nameof(mode), "Unknown heightmap grounding mode.");
 104        }
 105    }
 106}