| | | 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 | | |
| | | 8 | | using GridForge.Spatial; |
| | | 9 | | using SwiftCollections; |
| | | 10 | | |
| | | 11 | | namespace 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> |
| | | 17 | | public 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 | | |
| | | 41 | | internal 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 | | { |
| | 342 | 52 | | Grid = grid; |
| | 342 | 53 | | Index = index; |
| | 342 | 54 | | IsPhysicallyPresent = isPhysicallyPresent; |
| | 342 | 55 | | } |
| | | 56 | | |
| | | 57 | | public GridTraceAddressCandidate WithPhysicalPresence(bool isPhysicallyPresent) => |
| | 3 | 58 | | new(Grid, Index, isPhysicallyPresent); |
| | | 59 | | } |