< Summary

Information
Class: GridForge.Spatial.GridPlane2d
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Spatial/GridPlane2d.cs
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 68
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToWorld(...)100%11100%
FromWorld(...)100%11100%
ToWorldBounds(...)100%11100%
DistanceSquaredXZ(...)100%11100%

File(s)

/home/runner/work/GridForge/GridForge/src/GridForge/Spatial/GridPlane2d.cs

#LineLine coverage
 1//=======================================================================
 2// GridPlane2d.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 System.Runtime.CompilerServices;
 10
 11namespace GridForge.Spatial;
 12
 13/// <summary>
 14/// Provides GridForge's 2D XZ-plane projection helpers.
 15/// </summary>
 16/// <remarks>
 17/// In GridForge 2D query APIs, <see cref="Vector2d.X"/> maps to world X,
 18/// <see cref="Vector2d.Y"/> maps to world Z, and the supplied layer maps to world Y.
 19/// </remarks>
 20public static class GridPlane2d
 21{
 22    /// <summary>
 23    /// Converts an XZ-plane 2D position into a world-space 3D position.
 24    /// </summary>
 25    /// <param name="position">The 2D position whose X component maps to world X and Y component maps to world Z.</param
 26    /// <param name="layerY">The world Y layer to apply. Defaults to zero.</param>
 27    /// <returns>The equivalent world-space position.</returns>
 28    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 29    public static Vector3d ToWorld(Vector2d position, Fixed64 layerY = default)
 30    {
 35631        return new Vector3d(position.X, layerY, position.Y);
 32    }
 33
 34    /// <summary>
 35    /// Projects a world-space 3D position into GridForge's 2D XZ plane.
 36    /// </summary>
 37    /// <param name="position">The world-space position to project.</param>
 38    /// <returns>A 2D position containing world X and world Z.</returns>
 39    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 40    public static Vector2d FromWorld(Vector3d position)
 41    {
 142        return new Vector2d(position.X, position.Z);
 43    }
 44
 45    /// <summary>
 46    /// Converts XZ-plane 2D bounds into layer-locked world-space 3D bounds.
 47    /// </summary>
 48    /// <param name="min">The 2D minimum bound whose X component maps to world X and Y component maps to world Z.</param
 49    /// <param name="max">The 2D maximum bound whose X component maps to world X and Y component maps to world Z.</param
 50    /// <param name="layerY">The world Y layer to apply to both bounds. Defaults to zero.</param>
 51    /// <returns>The equivalent layer-locked world-space bounds.</returns>
 52    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 53    public static (Vector3d min, Vector3d max) ToWorldBounds(
 54        Vector2d min,
 55        Vector2d max,
 56        Fixed64 layerY = default)
 57    {
 1458        return (ToWorld(min, layerY), ToWorld(max, layerY));
 59    }
 60
 61    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 62    internal static Fixed64 DistanceSquaredXZ(Vector3d a, Vector3d b)
 63    {
 1645464        Fixed64 deltaX = a.X - b.X;
 1645465        Fixed64 deltaZ = a.Z - b.Z;
 1645466        return (deltaX * deltaX) + (deltaZ * deltaZ);
 67    }
 68}