| | | 1 | | //======================================================================= |
| | | 2 | | // GridTraceInterval.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 FixedMathSharp; |
| | | 9 | | using GridForge.Configuration; |
| | | 10 | | using GridForge.Spatial; |
| | | 11 | | |
| | | 12 | | namespace GridForge.Grids; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Reports completion or a deterministic caller-supplied trace ceiling. |
| | | 16 | | /// </summary> |
| | | 17 | | public enum GridTraceIntervalStatus : byte |
| | | 18 | | { |
| | | 19 | | /// <summary>The complete trace was written.</summary> |
| | | 20 | | Complete, |
| | | 21 | | /// <summary>The candidate-address ceiling was exhausted.</summary> |
| | | 22 | | AddressCandidateLimitExceeded, |
| | | 23 | | /// <summary>The output interval ceiling was exceeded.</summary> |
| | | 24 | | OutputLimitExceeded, |
| | | 25 | | /// <summary>A candidate grid cell could not be represented exactly.</summary> |
| | | 26 | | UnrepresentableGeometry, |
| | | 27 | | /// <summary>The candidate-grid ceiling was exhausted.</summary> |
| | | 28 | | GridCandidateLimitExceeded, |
| | | 29 | | /// <summary>The combined candidate-grid and candidate-address work ceiling was exhausted.</summary> |
| | | 30 | | CandidateWorkLimitExceeded |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Describes the exact closed parameter interval where a segment intersects one grid address. |
| | | 35 | | /// </summary> |
| | | 36 | | public readonly struct GridTraceInterval |
| | | 37 | | { |
| | | 38 | | /// <summary>The exact world, grid-generation, and topology-local address.</summary> |
| | | 39 | | public WorldVoxelIndex Cell { get; } |
| | | 40 | | |
| | | 41 | | /// <summary>The normalized grid binding key, independent of the recyclable runtime slot.</summary> |
| | | 42 | | public GridConfigurationKey ConfigurationKey { get; } |
| | | 43 | | |
| | | 44 | | /// <summary>Whether physical storage currently contains the addressed voxel.</summary> |
| | | 45 | | public bool IsPhysicallyPresent { get; } |
| | | 46 | | |
| | | 47 | | /// <summary>The last committed sequence applied to the traced grid generation.</summary> |
| | | 48 | | public ulong GridLastChangeSequence { get; } |
| | | 49 | | |
| | | 50 | | /// <summary>The first inclusive segment parameter in the cell prism.</summary> |
| | | 51 | | public Fixed64 TEnter { get; } |
| | | 52 | | |
| | | 53 | | /// <summary>The last inclusive segment parameter in the cell prism.</summary> |
| | | 54 | | public Fixed64 TExit { get; } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Stable group for peers whose interval interiors overlap, or point peers at one exact parameter. |
| | | 58 | | /// </summary> |
| | | 59 | | /// <remarks> |
| | | 60 | | /// Closed intervals that merely hand off at one endpoint remain successive groups. Group membership |
| | | 61 | | /// expresses simultaneous geometric coverage only; it does not imply voxel adjacency. |
| | | 62 | | /// </remarks> |
| | | 63 | | public int TieGroupId { get; } |
| | | 64 | | |
| | | 65 | | /// <summary>The canonical identity order within <see cref="TieGroupId"/>.</summary> |
| | | 66 | | public int TieOrder { get; } |
| | | 67 | | |
| | | 68 | | internal GridTraceInterval( |
| | | 69 | | WorldVoxelIndex cell, |
| | | 70 | | GridConfigurationKey configurationKey, |
| | | 71 | | bool isPhysicallyPresent, |
| | | 72 | | ulong gridLastChangeSequence, |
| | | 73 | | Fixed64 tEnter, |
| | | 74 | | Fixed64 tExit, |
| | | 75 | | int tieGroupId = -1, |
| | | 76 | | int tieOrder = -1) |
| | | 77 | | { |
| | 409 | 78 | | Cell = cell; |
| | 409 | 79 | | ConfigurationKey = configurationKey; |
| | 409 | 80 | | IsPhysicallyPresent = isPhysicallyPresent; |
| | 409 | 81 | | GridLastChangeSequence = gridLastChangeSequence; |
| | 409 | 82 | | TEnter = tEnter; |
| | 409 | 83 | | TExit = tExit; |
| | 409 | 84 | | TieGroupId = tieGroupId; |
| | 409 | 85 | | TieOrder = tieOrder; |
| | 409 | 86 | | } |
| | | 87 | | |
| | | 88 | | internal GridTraceInterval WithTie(int tieGroupId, int tieOrder) => |
| | 204 | 89 | | new( |
| | 204 | 90 | | Cell, |
| | 204 | 91 | | ConfigurationKey, |
| | 204 | 92 | | IsPhysicallyPresent, |
| | 204 | 93 | | GridLastChangeSequence, |
| | 204 | 94 | | TEnter, |
| | 204 | 95 | | TExit, |
| | 204 | 96 | | tieGroupId, |
| | 204 | 97 | | tieOrder); |
| | | 98 | | } |
| | | 99 | | |
| | | 100 | | /// <summary> |
| | | 101 | | /// Summarizes one bounded ordered trace. |
| | | 102 | | /// </summary> |
| | | 103 | | public readonly struct GridTraceIntervalReport |
| | | 104 | | { |
| | | 105 | | /// <summary>The completion status.</summary> |
| | | 106 | | public GridTraceIntervalStatus Status { get; } |
| | | 107 | | |
| | | 108 | | /// <summary>The number of candidate grids discovered.</summary> |
| | | 109 | | public int GridCandidateCount { get; } |
| | | 110 | | |
| | | 111 | | /// <summary>The number of unique candidate addresses enumerated.</summary> |
| | | 112 | | public int AddressCandidateCount { get; } |
| | | 113 | | |
| | | 114 | | /// <summary>The number of intervals written.</summary> |
| | | 115 | | public int IntervalCount { get; } |
| | | 116 | | |
| | | 117 | | /// <summary>The number of simultaneous-coverage groups.</summary> |
| | | 118 | | public int TieGroupCount { get; } |
| | | 119 | | |
| | | 120 | | /// <summary>Whether all parameters from zero through one are covered by grid addresses.</summary> |
| | | 121 | | public bool HasContinuousAddressCoverage { get; } |
| | | 122 | | |
| | | 123 | | /// <summary>Whether all parameters from zero through one are covered by physically present voxels.</summary> |
| | | 124 | | public bool HasContinuousPhysicalCoverage { get; } |
| | | 125 | | |
| | | 126 | | /// <summary>Whether the complete trace was written.</summary> |
| | | 127 | | public bool IsComplete => Status == GridTraceIntervalStatus.Complete; |
| | | 128 | | |
| | | 129 | | internal GridTraceIntervalReport( |
| | | 130 | | GridTraceIntervalStatus status, |
| | | 131 | | int gridCandidateCount, |
| | | 132 | | int candidateCount, |
| | | 133 | | int intervalCount, |
| | | 134 | | int tieGroupCount, |
| | | 135 | | bool hasContinuousAddressCoverage, |
| | | 136 | | bool hasContinuousPhysicalCoverage) |
| | | 137 | | { |
| | | 138 | | Status = status; |
| | | 139 | | GridCandidateCount = gridCandidateCount; |
| | | 140 | | AddressCandidateCount = candidateCount; |
| | | 141 | | IntervalCount = intervalCount; |
| | | 142 | | TieGroupCount = tieGroupCount; |
| | | 143 | | HasContinuousAddressCoverage = hasContinuousAddressCoverage; |
| | | 144 | | HasContinuousPhysicalCoverage = hasContinuousPhysicalCoverage; |
| | | 145 | | } |
| | | 146 | | } |