< 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 FixedMathSharp;
 9using GridForge.Spatial;
 10using System.Runtime.CompilerServices;
 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    {
 13322        Min = min;
 13323        Max = max;
 13324    }
 25
 26    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 27    public static TopologyVoxelAabb FromVoxel(VoxelGrid grid, Voxel voxel) =>
 7228        FromIndex(grid, voxel.Index);
 29
 30    public static TopologyVoxelAabb FromIndex(VoxelGrid grid, VoxelIndex index)
 31    {
 9632        Vector3d center = grid.GetWorldPosition(index);
 9633        Vector3d halfExtents = GetHalfExtents(grid.Topology);
 9634        return new TopologyVoxelAabb(center - halfExtents, center + halfExtents);
 35    }
 36
 37    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 38    public TopologyVoxelAabb Expand(Fixed64 tolerance)
 39    {
 5040        if (tolerance <= Fixed64.Zero)
 2441            return this;
 42
 2643        Vector3d expansion = new(tolerance, tolerance, tolerance);
 2644        return new TopologyVoxelAabb(Min - expansion, Max + expansion);
 45    }
 46
 47    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 48    public bool Overlaps(TopologyVoxelAabb other, Fixed64 tolerance) =>
 6749        AxisOverlaps(Min.X, Max.X, other.Min.X, other.Max.X, tolerance)
 6750        && AxisOverlaps(Min.Y, Max.Y, other.Min.Y, other.Max.Y, tolerance)
 6751        && AxisOverlaps(Min.Z, Max.Z, other.Min.Z, other.Max.Z, tolerance);
 52
 53    private static Vector3d GetHalfExtents(IGridTopology topology)
 54    {
 9655        GridTopologyMetrics metrics = topology.Metrics;
 9656        Fixed64 halfY = metrics.LayerHeight * Fixed64.Half;
 57
 9658        if (topology.Kind == GridTopologyKind.HexPrism)
 59        {
 3160            Fixed64 halfHexWidth = HexCoordinateUtility.Sqrt3 * metrics.CellRadius * Fixed64.Half;
 3161            return metrics.HexOrientation == HexOrientation.FlatTop
 3162                ? new Vector3d(metrics.CellRadius, halfY, halfHexWidth)
 3163                : new Vector3d(halfHexWidth, halfY, metrics.CellRadius);
 64        }
 65
 6566        return new Vector3d(
 6567            metrics.CellWidth * Fixed64.Half,
 6568            halfY,
 6569            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    {
 18780        Fixed64 resolvedTolerance = tolerance > Fixed64.Zero ? tolerance : Fixed64.Zero;
 18781        return firstMax >= secondMin - resolvedTolerance
 18782            && firstMin <= secondMax + resolvedTolerance;
 83    }
 84}