< Summary

Information
Class: GridForge.Utility.GridTraversal
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Utility/GridTraversal.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 75
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryGetUniquePartition(...)100%22100%
IsWorldPositionInPaddedBounds(...)100%1010100%
IsPlanarPositionInPaddedBounds(...)100%66100%

File(s)

/home/runner/work/GridForge/GridForge/src/GridForge/Utility/GridTraversal.cs

#LineLine coverage
 1//=======================================================================
 2// GridTraversal.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.Grids;
 11using GridForge.Spatial;
 12using SwiftCollections;
 13
 14namespace GridForge.Utility;
 15
 16
 17
 18
 19
 20/// <summary>
 21/// Provides deterministic helpers for duplicate-safe voxel traversal.
 22/// </summary>
 23public static class GridTraversal
 24{
 25    /// <summary>
 26    /// Gets a voxel partition once per exact world-scoped voxel identity.
 27    /// </summary>
 28    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 29    public static bool TryGetUniquePartition<TPartition>(
 30        Voxel voxel,
 31        SwiftHashSet<WorldVoxelIndex> visited,
 32        out TPartition? partition)
 33        where TPartition : class, IVoxelPartition
 34    {
 208235        partition = null;
 208236        return visited.Add(voxel.WorldIndex)
 208237            && voxel.TryGetPartition(out partition);
 38    }
 39
 40    /// <summary>
 41    /// Tests whether a 3D world position lies inside bounds expanded by half of a cell edge.
 42    /// </summary>
 43    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 44    public static bool IsWorldPositionInPaddedBounds(
 45        Vector3d min,
 46        Vector3d max,
 47        Fixed64 cellEdge,
 48        Vector3d worldPosition)
 49    {
 250        Fixed64 padding = cellEdge * Fixed64.Half;
 251        return worldPosition.X >= min.X - padding
 252            && worldPosition.X <= max.X + padding
 253            && worldPosition.Y >= min.Y - padding
 254            && worldPosition.Y <= max.Y + padding
 255            && worldPosition.Z >= min.Z - padding
 256            && worldPosition.Z <= max.Z + padding;
 57    }
 58
 59    /// <summary>
 60    /// Tests whether a world position's X/Z projection lies inside bounds expanded by half of a cell edge.
 61    /// </summary>
 62    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 63    public static bool IsPlanarPositionInPaddedBounds(
 64        Vector2d min,
 65        Vector2d max,
 66        Fixed64 cellEdge,
 67        Vector3d worldPosition)
 68    {
 269        Fixed64 padding = cellEdge * Fixed64.Half;
 270        return worldPosition.X >= min.X - padding
 271            && worldPosition.X <= max.X + padding
 272            && worldPosition.Z >= min.Y - padding
 273            && worldPosition.Z <= max.Y + padding;
 74    }
 75}