< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
FromVoxel(...)100%11100%
FromIndex(...)100%11100%
Expand(...)100%22100%
Overlaps(...)100%44100%
GetHalfExtents(...)100%44100%
AxisOverlaps(...)100%44100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// TopologyVoxelAabb.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.Spatial;
 11
 12namespace GridForge.Grids.Topology;
 13
 14internal readonly struct TopologyVoxelAabb
 15{
 16    public readonly Vector3d Min;
 17
 18    public readonly Vector3d Max;
 19
 20    public TopologyVoxelAabb(Vector3d min, Vector3d max)
 21    {
 19822        Min = min;
 19823        Max = max;
 19824    }
 25
 26    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 27    public static TopologyVoxelAabb FromVoxel(VoxelGrid grid, Voxel voxel) =>
 9428        FromIndex(grid, voxel.Index);
 29
 30    public static TopologyVoxelAabb FromIndex(VoxelGrid grid, VoxelIndex index)
 31    {
 14832        Vector3d center = grid.GetWorldPosition(index);
 14833        Vector3d halfExtents = GetHalfExtents(grid.Topology);
 14834        return new TopologyVoxelAabb(center - halfExtents, center + halfExtents);
 35    }
 36
 37    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 38    public TopologyVoxelAabb Expand(Fixed64 tolerance)
 39    {
 6640        if (tolerance <= Fixed64.Zero)
 3241            return this;
 42
 3443        Vector3d expansion = new(tolerance, tolerance, tolerance);
 3444        return new TopologyVoxelAabb(Min - expansion, Max + expansion);
 45    }
 46
 47    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 48    public bool Overlaps(TopologyVoxelAabb other, Fixed64 tolerance) =>
 11149        AxisOverlaps(Min.X, Max.X, other.Min.X, other.Max.X, tolerance)
 11150        && AxisOverlaps(Min.Y, Max.Y, other.Min.Y, other.Max.Y, tolerance)
 11151        && AxisOverlaps(Min.Z, Max.Z, other.Min.Z, other.Max.Z, tolerance);
 52
 53    private static Vector3d GetHalfExtents(IGridTopology topology)
 54    {
 14855        GridTopologyMetrics metrics = topology.Metrics;
 14856        Fixed64 halfY = metrics.LayerHeight * Fixed64.Half;
 57
 14858        if (topology.Kind == GridTopologyKind.HexPrism)
 59        {
 3960            Fixed64 halfHexWidth = HexCoordinateUtility.Sqrt3 * metrics.CellRadius * Fixed64.Half;
 3961            return metrics.HexOrientation == HexOrientation.FlatTop
 3962                ? new Vector3d(metrics.CellRadius, halfY, halfHexWidth)
 3963                : new Vector3d(halfHexWidth, halfY, metrics.CellRadius);
 64        }
 65
 10966        return new Vector3d(
 10967            metrics.CellWidth * Fixed64.Half,
 10968            halfY,
 10969            metrics.CellLength * Fixed64.Half);
 70    }
 71
 72    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 73    private static bool AxisOverlaps(
 74        Fixed64 firstMin,
 75        Fixed64 firstMax,
 76        Fixed64 secondMin,
 77        Fixed64 secondMax,
 78        Fixed64 tolerance)
 79    {
 31980        Fixed64 resolvedTolerance = tolerance > Fixed64.Zero ? tolerance : Fixed64.Zero;
 31981        return firstMax >= secondMin - resolvedTolerance
 31982            && firstMin <= secondMax + resolvedTolerance;
 83    }
 84}