< Summary

Information
Class: GridForge.Grids.Topology.GridTopologyMetricUtility
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Grids/Topology/GridTopologyMetricUtility.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 55
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetMaxCellEdge(...)100%22100%
GetPlanarMaxCellEdge(...)100%22100%
GetRepresentativeCellEdge(...)100%44100%

File(s)

/home/runner/work/GridForge/GridForge/src/GridForge/Grids/Topology/GridTopologyMetricUtility.cs

#LineLine coverage
 1//=======================================================================
 2// GridTopologyMetricUtility.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;
 10
 11namespace GridForge.Grids.Topology;
 12
 13/// <summary>
 14/// Provides deterministic cell-edge measurements for grid topology-aware traversal and padding.
 15/// </summary>
 16public static class GridTopologyMetricUtility
 17{
 18    /// <summary>
 19    /// Gets the largest 3D cell edge for the supplied grid.
 20    /// </summary>
 21    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 22    public static Fixed64 GetMaxCellEdge(VoxelGrid grid)
 23    {
 104824        GridTopologyMetrics metrics = grid.Configuration.TopologyMetrics;
 104825        if (grid.Configuration.TopologyKind == GridTopologyKind.HexPrism)
 126            return FixedMath.Max(metrics.CellRadius * (Fixed64)2, metrics.LayerHeight);
 27
 104728        Fixed64 max = FixedMath.Max(metrics.CellWidth, metrics.LayerHeight);
 104729        return FixedMath.Max(max, metrics.CellLength);
 30    }
 31
 32    /// <summary>
 33    /// Gets the largest X/Z-plane cell edge for the supplied grid.
 34    /// </summary>
 35    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 36    public static Fixed64 GetPlanarMaxCellEdge(VoxelGrid grid)
 37    {
 338        GridTopologyMetrics metrics = grid.Configuration.TopologyMetrics;
 339        return grid.Configuration.TopologyKind == GridTopologyKind.HexPrism
 340            ? metrics.CellRadius * (Fixed64)2
 341            : FixedMath.Max(metrics.CellWidth, metrics.CellLength);
 42    }
 43
 44    /// <summary>
 45    /// Gets a representative cell edge for a world, or the default rectangular cell size when no grid is active.
 46    /// </summary>
 47    public static Fixed64 GetRepresentativeCellEdge(GridWorld world)
 48    {
 549        foreach (VoxelGrid grid in world.ActiveGrids)
 150            if (grid.IsActive)
 151                return GetMaxCellEdge(grid);
 52
 153        return GridWorld.DefaultRectangularCellSize;
 154    }
 55}