< Summary

Information
Class: GridForge.Grids.GridTraceAddressCandidate
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Grids/Support/GridTraceIntervalScratch.cs
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
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%
WithPhysicalPresence(...)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>
 24    public GridTraceIntervalScratch(int gridCapacity = 0, int addressCapacity = 0)
 25    {
 26        SwiftThrowHelper.ThrowIfNegative(gridCapacity, nameof(gridCapacity));
 27        SwiftThrowHelper.ThrowIfNegative(addressCapacity, nameof(addressCapacity));
 28
 29        CandidateGrids = new SwiftList<ushort>(gridCapacity);
 30        AddressCandidates = new SwiftList<GridTraceAddressCandidate>(addressCapacity);
 31    }
 32
 33    /// <summary>Clears temporary values while retaining capacity.</summary>
 34    public void Clear()
 35    {
 36        CandidateGrids.Clear();
 37        AddressCandidates.Clear();
 38    }
 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    {
 34252        Grid = grid;
 34253        Index = index;
 34254        IsPhysicallyPresent = isPhysicallyPresent;
 34255    }
 56
 57    public GridTraceAddressCandidate WithPhysicalPresence(bool isPhysicallyPresent) =>
 358        new(Grid, Index, isPhysicallyPresent);
 59}