< Summary

Information
Class: GridForge.Configuration.NormalizedGridConfiguration
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Configuration/NormalizedGridConfiguration.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 120
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_IsValid()100%44100%
.ctor(...)100%11100%
IsValidIndex(...)100%44100%
TryGetCellPrism(...)100%44100%

File(s)

/home/runner/work/GridForge/GridForge/src/GridForge/Configuration/NormalizedGridConfiguration.cs

#LineLine coverage
 1//=======================================================================
 2// NormalizedGridConfiguration.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 System.Runtime.CompilerServices;
 9using FixedMathSharp;
 10using GridForge.Grids.Topology;
 11using GridForge.Spatial;
 12
 13namespace GridForge.Configuration;
 14
 15/// <summary>
 16/// Describes a validated grid configuration after topology-specific bounds
 17/// normalization, without registering a live grid.
 18/// </summary>
 19public readonly struct NormalizedGridConfiguration
 20{
 21    internal IGridTopology? Topology { get; }
 22
 23    internal GridDimensions Dimensions { get; }
 24
 25    /// <summary>
 26    /// The normalized configuration. Its bounds are topology-aligned, while
 27    /// scan-cell and storage settings retain the caller's requested values.
 28    /// </summary>
 29    public GridConfiguration Configuration { get; }
 30
 31    /// <summary>
 32    /// The exact normalized bounds-and-topology key used to bind equivalent grids.
 33    /// Storage kind and scan-cell size are deliberately excluded from this identity.
 34    /// </summary>
 35    public GridConfigurationKey Key { get; }
 36
 37    /// <summary>
 38    /// The number of valid topology-local X or axial-Q addresses.
 39    /// </summary>
 40    public int Width { get; }
 41
 42    /// <summary>
 43    /// The number of valid topology-local vertical layers.
 44    /// </summary>
 45    public int Height { get; }
 46
 47    /// <summary>
 48    /// The number of valid topology-local Z or axial-R addresses.
 49    /// </summary>
 50    public int Length { get; }
 51
 52    /// <summary>
 53    /// The total number of topology-local addresses in the normalized grid.
 54    /// Sparse storage may materialize only a subset of these addresses.
 55    /// </summary>
 56    public int AddressCount { get; }
 57
 58    /// <summary>
 59    /// Indicates whether this descriptor contains a valid normalized address space.
 60    /// </summary>
 1061    public bool IsValid => Width > 0 && Height > 0 && Length > 0;
 62
 63    internal NormalizedGridConfiguration(
 64        GridConfiguration configuration,
 65        IGridTopology topology,
 66        GridDimensions dimensions)
 67    {
 95568        Topology = topology;
 95569        Dimensions = dimensions;
 95570        Configuration = configuration;
 95571        Key = configuration.ToGridKey();
 95572        Width = dimensions.Width;
 95573        Height = dimensions.Height;
 95574        Length = dimensions.Length;
 95575        AddressCount = checked(dimensions.Width * dimensions.Height * dimensions.Length);
 95576    }
 77
 78    /// <summary>
 79    /// Determines whether an index belongs to this topology-local address space.
 80    /// Validation is independent of sparse physical-voxel presence.
 81    /// </summary>
 82    /// <remarks>
 83    /// Validation uses coordinate values only; <see cref="VoxelIndex.IsAllocated"/>
 84    /// does not change whether the address is in range.
 85    /// </remarks>
 86    /// <param name="index">The topology-local index to validate.</param>
 87    /// <returns>True when each coordinate is inside the normalized dimensions.</returns>
 88    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 89    public bool IsValidIndex(VoxelIndex index) =>
 3390        (uint)index.x < (uint)Width
 3391        && (uint)index.y < (uint)Height
 3392        && (uint)index.z < (uint)Length;
 93
 94    /// <summary>
 95    /// Attempts to derive the exact offline prism for a topology-local address.
 96    /// </summary>
 97    /// <remarks>
 98    /// The returned prism has no runtime world/grid identity. It is suitable for
 99    /// authoring validation before a matching physical grid exists.
 100    /// </remarks>
 101    /// <param name="index">The topology-local address.</param>
 102    /// <param name="prism">The exact cell prism when the address and metrics are representable.</param>
 103    /// <returns>True when the address is valid and its prism is exactly representable.</returns>
 104    public bool TryGetCellPrism(VoxelIndex index, out GridCellPrism prism)
 105    {
 22106        if (!IsValidIndex(index) || Topology == null)
 107        {
 6108            prism = default;
 6109            return false;
 110        }
 111
 16112        Vector3d center = Topology.GetWorldPosition(Configuration.BoundsMin, index);
 16113        return GridCellGeometry.TryCreatePrism(
 16114            Configuration.TopologyKind,
 16115            Configuration.TopologyMetrics,
 16116            center,
 16117            default,
 16118            out prism);
 119    }
 120}