| | | 1 | | //======================================================================= |
| | | 2 | | // GridContactQueryScratch.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 SwiftCollections; |
| | | 9 | | |
| | | 10 | | namespace GridForge.Grids.Topology; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Owns reusable temporary storage for allocation-free warmed exact-contact queries. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <remarks> |
| | | 16 | | /// Instances are caller-owned, retain capacity between calls, and are not thread-safe. |
| | | 17 | | /// </remarks> |
| | | 18 | | public sealed class GridContactQueryScratch |
| | | 19 | | { |
| | | 20 | | internal SwiftList<Voxel> SourceVoxels { get; } |
| | | 21 | | |
| | | 22 | | internal SwiftList<Voxel> CandidateVoxels { get; } |
| | | 23 | | |
| | | 24 | | internal SwiftHashSet<Voxel> ProcessedVoxels { get; } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Initializes scratch storage with optional expected source and per-source candidate counts. |
| | | 28 | | /// </summary> |
| | 7 | 29 | | public GridContactQueryScratch(int sourceCapacity = 0, int candidateCapacity = 0) |
| | | 30 | | { |
| | 7 | 31 | | SwiftThrowHelper.ThrowIfNegative(sourceCapacity, nameof(sourceCapacity)); |
| | 7 | 32 | | SwiftThrowHelper.ThrowIfNegative(candidateCapacity, nameof(candidateCapacity)); |
| | | 33 | | |
| | 7 | 34 | | SourceVoxels = new SwiftList<Voxel>(sourceCapacity); |
| | 7 | 35 | | CandidateVoxels = new SwiftList<Voxel>(candidateCapacity); |
| | 7 | 36 | | ProcessedVoxels = new SwiftHashSet<Voxel>(candidateCapacity); |
| | 7 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Clears retained references without releasing reusable capacity. |
| | | 41 | | /// </summary> |
| | | 42 | | public void Clear() |
| | | 43 | | { |
| | 24 | 44 | | SourceVoxels.Clear(); |
| | 24 | 45 | | CandidateVoxels.Clear(); |
| | 24 | 46 | | ProcessedVoxels.Clear(); |
| | 24 | 47 | | } |
| | | 48 | | } |