< Summary

Information
Class: GridForge.Configuration.GridConfiguration
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Configuration/GridConfiguration.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 95
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_GridCenter()100%11100%
.ctor(...)83.33%66100%
ToBoundsKey()100%11100%
GetHashCode()100%11100%

File(s)

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

#LineLine coverage
 1using FixedMathSharp;
 2using MemoryPack;
 3using SwiftCollections;
 4using System;
 5using System.Text.Json.Serialization;
 6
 7namespace GridForge.Configuration;
 8
 9/// <summary>
 10/// Defines the configuration parameters for a grid, including boundaries and scan cell size.
 11/// Used to describe grid properties before a world normalizes and registers the grid.
 12/// </summary>
 13[Serializable]
 14[MemoryPackable]
 15public readonly partial struct GridConfiguration
 16{
 17    /// <summary>
 18    /// The default size of each scan cell.
 19    /// </summary>
 20    public const int DefaultScanCellSize = 8;
 21
 22    #region Properties
 23
 24    /// <summary>
 25    /// The minimum boundary of the grid in world coordinates.
 26    /// </summary>
 27    [JsonInclude]
 28    [MemoryPackInclude]
 29    public readonly Vector3d BoundsMin;
 30
 31    /// <summary>
 32    /// The maximum boundary of the grid in world coordinates.
 33    /// </summary>
 34    [JsonInclude]
 35    [MemoryPackInclude]
 36    public readonly Vector3d BoundsMax;
 37
 38    /// <summary>
 39    /// The size of each scan cell, determining the granularity of spatial partitioning.
 40    /// Customizable based on grid density and expected entity distribution.
 41    /// </summary>
 42    [JsonInclude]
 43    [MemoryPackInclude]
 44    public readonly int ScanCellSize;
 45
 46    /// <summary>
 47    /// The center point of the grid's bounding volume.
 48    /// </summary>
 49    [JsonIgnore]
 50    [MemoryPackIgnore]
 8751    public readonly Vector3d GridCenter => (BoundsMin + BoundsMax) * Fixed64.Half;
 52
 53    #endregion
 54
 55    #region Constructors
 56
 57    /// <summary>
 58    /// Initializes a new instance of <see cref="GridConfiguration"/> with specified bounds and scan cell size.
 59    /// Ensures that <see cref="BoundsMin"/> is always less than or equal to <see cref="BoundsMax"/>.
 60    /// </summary>
 61    /// <param name="boundsMin">The minimum boundary of the grid.</param>
 62    /// <param name="boundsMax">The maximum boundary of the grid.</param>
 63    /// <param name="scanCellSize">The size of scan cells within the grid. Default is 8.</param>
 64    [JsonConstructor]
 65    public GridConfiguration(
 66        Vector3d boundsMin,
 67        Vector3d boundsMax,
 68        int scanCellSize = DefaultScanCellSize)
 69    {
 36970        if (boundsMin > boundsMax)
 271            GridForgeLogger.Channel.Warn($"GridMin was greater than GridMax, auto-correcting values.");
 72
 36973        BoundsMin = new Vector3d(
 36974            FixedMath.Min(boundsMin.x, boundsMax.x),
 36975            FixedMath.Min(boundsMin.y, boundsMax.y),
 36976            FixedMath.Min(boundsMin.z, boundsMax.z));
 36977        BoundsMax = new Vector3d(
 36978            FixedMath.Max(boundsMin.x, boundsMax.x),
 36979            FixedMath.Max(boundsMin.y, boundsMax.y),
 36980            FixedMath.Max(boundsMin.z, boundsMax.z));
 81
 36982        ScanCellSize = scanCellSize > 0 ? scanCellSize : DefaultScanCellSize;
 36983    }
 84
 85    #endregion
 86
 87    /// <summary>
 88    /// Creates an exact identity key for this configuration's snapped bounds.
 89    /// </summary>
 19990    public readonly BoundsKey ToBoundsKey() => new(BoundsMin, BoundsMax);
 91
 92    /// <inheritdoc/>
 93    public override readonly int GetHashCode() =>
 294        SwiftHashTools.CombineHashCodes(BoundsMin.GetHashCode(), BoundsMax.GetHashCode());
 95}