| | | 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 | | /// Describes the exact closed parameter interval where a segment intersects one grid address. |
| | | 16 | | /// </summary> |
| | | 17 | | public readonly struct GridTraceInterval |
| | | 18 | | { |
| | | 19 | | /// <summary>The exact world, grid-generation, and topology-local address.</summary> |
| | | 20 | | public WorldVoxelIndex Cell { get; } |
| | | 21 | | |
| | | 22 | | /// <summary>The normalized grid binding key, independent of the recyclable runtime slot.</summary> |
| | | 23 | | public GridConfigurationKey ConfigurationKey { get; } |
| | | 24 | | |
| | | 25 | | /// <summary>Whether physical storage currently contains the addressed voxel.</summary> |
| | | 26 | | public bool IsPhysicallyPresent { get; } |
| | | 27 | | |
| | | 28 | | /// <summary>The last committed sequence applied to the traced grid generation.</summary> |
| | | 29 | | public ulong GridLastChangeSequence { get; } |
| | | 30 | | |
| | | 31 | | /// <summary>The first inclusive segment parameter in the cell prism.</summary> |
| | | 32 | | public Fixed64 TEnter { get; } |
| | | 33 | | |
| | | 34 | | /// <summary>The last inclusive segment parameter in the cell prism.</summary> |
| | | 35 | | public Fixed64 TExit { get; } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Stable group for peers whose interval interiors overlap, or point peers at one exact parameter. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <remarks> |
| | | 41 | | /// Closed intervals that merely hand off at one endpoint remain successive groups. Group membership |
| | | 42 | | /// expresses simultaneous geometric coverage only; it does not imply voxel adjacency. |
| | | 43 | | /// </remarks> |
| | | 44 | | public int TieGroupId { get; } |
| | | 45 | | |
| | | 46 | | /// <summary>The canonical identity order within <see cref="TieGroupId"/>.</summary> |
| | | 47 | | public int TieOrder { get; } |
| | | 48 | | |
| | | 49 | | internal GridTraceInterval( |
| | | 50 | | WorldVoxelIndex cell, |
| | | 51 | | GridConfigurationKey configurationKey, |
| | | 52 | | bool isPhysicallyPresent, |
| | | 53 | | ulong gridLastChangeSequence, |
| | | 54 | | Fixed64 tEnter, |
| | | 55 | | Fixed64 tExit, |
| | | 56 | | int tieGroupId = -1, |
| | | 57 | | int tieOrder = -1) |
| | | 58 | | { |
| | 2894 | 59 | | Cell = cell; |
| | 2894 | 60 | | ConfigurationKey = configurationKey; |
| | 2894 | 61 | | IsPhysicallyPresent = isPhysicallyPresent; |
| | 2894 | 62 | | GridLastChangeSequence = gridLastChangeSequence; |
| | 2894 | 63 | | TEnter = tEnter; |
| | 2894 | 64 | | TExit = tExit; |
| | 2894 | 65 | | TieGroupId = tieGroupId; |
| | 2894 | 66 | | TieOrder = tieOrder; |
| | 2894 | 67 | | } |
| | | 68 | | |
| | | 69 | | internal GridTraceInterval WithTie(int tieGroupId, int tieOrder) => |
| | 1330 | 70 | | new( |
| | 1330 | 71 | | Cell, |
| | 1330 | 72 | | ConfigurationKey, |
| | 1330 | 73 | | IsPhysicallyPresent, |
| | 1330 | 74 | | GridLastChangeSequence, |
| | 1330 | 75 | | TEnter, |
| | 1330 | 76 | | TExit, |
| | 1330 | 77 | | tieGroupId, |
| | 1330 | 78 | | tieOrder); |
| | | 79 | | } |