< 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: 56
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 FixedMathSharp;
 9using GridForge.Grids;
 10using System.Runtime.CompilerServices;
 11
 12namespace GridForge.Grids.Topology;
 13
 14/// <summary>
 15/// Provides deterministic cell-edge measurements for grid topology-aware traversal and padding.
 16/// </summary>
 17public static class GridTopologyMetricUtility
 18{
 19    /// <summary>
 20    /// Gets the largest 3D cell edge for the supplied grid.
 21    /// </summary>
 22    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 23    public static Fixed64 GetMaxCellEdge(VoxelGrid grid)
 24    {
 425        GridTopologyMetrics metrics = grid.Configuration.TopologyMetrics;
 426        if (grid.Configuration.TopologyKind == GridTopologyKind.HexPrism)
 127            return FixedMath.Max(metrics.CellRadius * (Fixed64)2, metrics.LayerHeight);
 28
 329        Fixed64 max = FixedMath.Max(metrics.CellWidth, metrics.LayerHeight);
 330        return FixedMath.Max(max, metrics.CellLength);
 31    }
 32
 33    /// <summary>
 34    /// Gets the largest X/Z-plane cell edge for the supplied grid.
 35    /// </summary>
 36    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 37    public static Fixed64 GetPlanarMaxCellEdge(VoxelGrid grid)
 38    {
 339        GridTopologyMetrics metrics = grid.Configuration.TopologyMetrics;
 340        return grid.Configuration.TopologyKind == GridTopologyKind.HexPrism
 341            ? metrics.CellRadius * (Fixed64)2
 342            : FixedMath.Max(metrics.CellWidth, metrics.CellLength);
 43    }
 44
 45    /// <summary>
 46    /// Gets a representative cell edge for a world, or the default rectangular cell size when no grid is active.
 47    /// </summary>
 48    public static Fixed64 GetRepresentativeCellEdge(GridWorld world)
 49    {
 550        foreach (VoxelGrid grid in world.ActiveGrids)
 151            if (grid.IsActive)
 152                return GetMaxCellEdge(grid);
 53
 154        return GridWorld.DefaultRectangularCellSize;
 155    }
 56}