< Summary

Information
Class: GridForge.Grids.GridNavigationBodyTraceScratch
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Grids/Support/GridNavigationBodyTraceScratch.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 105
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Clear()100%11100%

File(s)

/home/runner/work/GridForge/GridForge/src/GridForge/Grids/Support/GridNavigationBodyTraceScratch.cs

#LineLine coverage
 1//=======================================================================
 2// GridNavigationBodyTraceScratch.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.Spatial;
 9using GridForge.Grids.Topology;
 10using SwiftCollections;
 11
 12namespace GridForge.Grids;
 13
 14/// <summary>Owns reusable caller-side storage for allocation-free warmed navigation-body traces.</summary>
 15/// <remarks>Instances retain capacity and are not thread-safe.</remarks>
 16public sealed class GridNavigationBodyTraceScratch
 17{
 18    internal SwiftList<ushort> CandidateGrids { get; }
 19
 20    internal SwiftList<GridNavigationBodyTraceCandidate> AddressCandidates { get; }
 21
 22    internal SwiftList<int> UnionMembers { get; }
 23
 24    /// <summary>Creates scratch with expected grid and address counts.</summary>
 3825    public GridNavigationBodyTraceScratch(int gridCapacity = 0, int addressCapacity = 0)
 26    {
 3827        SwiftThrowHelper.ThrowIfNegative(gridCapacity, nameof(gridCapacity));
 3828        SwiftThrowHelper.ThrowIfNegative(addressCapacity, nameof(addressCapacity));
 29
 3830        CandidateGrids = new SwiftList<ushort>(gridCapacity);
 3831        AddressCandidates = new SwiftList<GridNavigationBodyTraceCandidate>(addressCapacity);
 3832        UnionMembers = new SwiftList<int>(addressCapacity);
 3833    }
 34
 35    /// <summary>Clears temporary values while retaining capacity.</summary>
 36    public void Clear()
 37    {
 13638        CandidateGrids.Clear();
 13639        AddressCandidates.Clear();
 13640        UnionMembers.Clear();
 13641    }
 42}
 43
 44internal readonly struct GridNavigationBodyTraceCandidate
 45{
 46    internal GridNavigationBodyTraceCandidate(
 47        VoxelGrid grid,
 48        VoxelIndex index,
 49        GridCellPrism prism,
 50        bool hasPositiveOverlap,
 51        bool isClosure,
 52        bool isPhysicallyPresent = false,
 53        ulong gridLastChangeSequence = 0UL,
 54        bool isVisited = false)
 55    {
 56        Grid = grid;
 57        Index = index;
 58        Prism = prism;
 59        HasPositiveOverlap = hasPositiveOverlap;
 60        IsClosure = isClosure;
 61        IsPhysicallyPresent = isPhysicallyPresent;
 62        GridLastChangeSequence = gridLastChangeSequence;
 63        IsVisited = isVisited;
 64    }
 65
 66    internal VoxelGrid Grid { get; }
 67
 68    internal VoxelIndex Index { get; }
 69
 70    internal GridCellPrism Prism { get; }
 71
 72    internal bool HasPositiveOverlap { get; }
 73
 74    internal bool IsClosure { get; }
 75
 76    internal bool IsPhysicallyPresent { get; }
 77
 78    internal ulong GridLastChangeSequence { get; }
 79
 80    internal bool IsVisited { get; }
 81
 82    internal GridNavigationBodyTraceCandidate WithPhysicalEvidence(
 83        bool isPhysicallyPresent,
 84        ulong gridLastChangeSequence) =>
 85        new(
 86            Grid,
 87            Index,
 88            Prism,
 89            HasPositiveOverlap,
 90            IsClosure,
 91            isPhysicallyPresent,
 92            gridLastChangeSequence,
 93            IsVisited);
 94
 95    internal GridNavigationBodyTraceCandidate WithVisited() =>
 96        new(
 97            Grid,
 98            Index,
 99            Prism,
 100            HasPositiveOverlap,
 101            IsClosure,
 102            IsPhysicallyPresent,
 103            GridLastChangeSequence,
 104            isVisited: true);
 105}