< Summary

Information
Class: GridForge.Grids.GridTraceIntervalScratch
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Grids/Support/GridTraceIntervalScratch.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 59
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/GridTraceIntervalScratch.cs

#LineLine coverage
 1//=======================================================================
 2// GridTraceIntervalScratch.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 SwiftCollections;
 10
 11namespace GridForge.Grids;
 12
 13/// <summary>
 14/// Owns reusable caller-side storage for allocation-free warmed interval traces.
 15/// </summary>
 16/// <remarks>Instances retain capacity and are not thread-safe.</remarks>
 17public sealed class GridTraceIntervalScratch
 18{
 19    internal SwiftList<ushort> CandidateGrids { get; }
 20
 21    internal SwiftList<GridTraceAddressCandidate> AddressCandidates { get; }
 22
 23    /// <summary>Creates trace scratch with optional expected grid and address counts.</summary>
 4824    public GridTraceIntervalScratch(int gridCapacity = 0, int addressCapacity = 0)
 25    {
 4826        SwiftThrowHelper.ThrowIfNegative(gridCapacity, nameof(gridCapacity));
 4827        SwiftThrowHelper.ThrowIfNegative(addressCapacity, nameof(addressCapacity));
 28
 4829        CandidateGrids = new SwiftList<ushort>(gridCapacity);
 4830        AddressCandidates = new SwiftList<GridTraceAddressCandidate>(addressCapacity);
 4831    }
 32
 33    /// <summary>Clears temporary values while retaining capacity.</summary>
 34    public void Clear()
 35    {
 15436        CandidateGrids.Clear();
 15437        AddressCandidates.Clear();
 15438    }
 39}
 40
 41internal readonly struct GridTraceAddressCandidate
 42{
 43    public readonly VoxelGrid Grid;
 44    public readonly VoxelIndex Index;
 45    public readonly bool IsPhysicallyPresent;
 46
 47    public GridTraceAddressCandidate(
 48        VoxelGrid grid,
 49        VoxelIndex index,
 50        bool isPhysicallyPresent)
 51    {
 52        Grid = grid;
 53        Index = index;
 54        IsPhysicallyPresent = isPhysicallyPresent;
 55    }
 56
 57    public GridTraceAddressCandidate WithPhysicalPresence(bool isPhysicallyPresent) =>
 58        new(Grid, Index, isPhysicallyPresent);
 59}