< Summary

Information
Class: GridForge.Spatial.HexDirectionUtility
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Spatial/HexDirectionUtility.cs
Line coverage
100%
Covered lines: 117
Uncovered lines: 0
Coverable lines: 117
Total lines: 191
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Offsets()100%11100%
.cctor()100%11100%
get_All()100%11100%
get_Primary()100%11100%
get_Planar()100%11100%
get_Vertical()100%11100%
get_BelowLayer()100%11100%
get_AboveLayer()100%11100%
get_VerticalDiagonal()100%11100%
GetOffset(...)100%11100%
IsPlanar(...)100%11100%
IsVertical(...)100%22100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// HexDirectionUtility.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;
 9using System.Runtime.CompilerServices;
 10
 11namespace GridForge.Spatial;
 12
 13/// <summary>
 14/// Provides hex-prism neighbor direction utilities.
 15/// </summary>
 16public static class HexDirectionUtility
 17{
 18    /// <summary>
 19    /// Hex-prism neighbor offsets in deterministic direction order.
 20    /// </summary>
 37121    public static ReadOnlySpan<VoxelIndex> Offsets => OffsetValues;
 22
 123    private static readonly VoxelIndex[] OffsetValues =
 124    {
 125        new(1, 0, 0),
 126        new(1, 0, -1),
 127        new(0, 0, -1),
 128        new(-1, 0, 0),
 129        new(-1, 0, 1),
 130        new(0, 0, 1),
 131        new(0, -1, 0),
 132        new(1, -1, 0),
 133        new(1, -1, -1),
 134        new(0, -1, -1),
 135        new(-1, -1, 0),
 136        new(-1, -1, 1),
 137        new(0, -1, 1),
 138        new(0, 1, 0),
 139        new(1, 1, 0),
 140        new(1, 1, -1),
 141        new(0, 1, -1),
 142        new(-1, 1, 0),
 143        new(-1, 1, 1),
 144        new(0, 1, 1)
 145    };
 46
 47    /// <summary>
 48    /// All 20 hex-prism neighbor directions excluding None.
 49    /// </summary>
 250    public static ReadOnlySpan<HexDirection> All => AllValues;
 51
 152    private static readonly HexDirection[] AllValues =
 153    {
 154        HexDirection.QPositive,
 155        HexDirection.QPositiveRNegative,
 156        HexDirection.RNegative,
 157        HexDirection.QNegative,
 158        HexDirection.QNegativeRPositive,
 159        HexDirection.RPositive,
 160        HexDirection.Below,
 161        HexDirection.BelowQPositive,
 162        HexDirection.BelowQPositiveRNegative,
 163        HexDirection.BelowRNegative,
 164        HexDirection.BelowQNegative,
 165        HexDirection.BelowQNegativeRPositive,
 166        HexDirection.BelowRPositive,
 167        HexDirection.Above,
 168        HexDirection.AboveQPositive,
 169        HexDirection.AboveQPositiveRNegative,
 170        HexDirection.AboveRNegative,
 171        HexDirection.AboveQNegative,
 172        HexDirection.AboveQNegativeRPositive,
 173        HexDirection.AboveRPositive
 174    };
 75
 76    /// <summary>
 77    /// The 8 face-adjacent hex-prism directions.
 78    /// </summary>
 279    public static ReadOnlySpan<HexDirection> Primary => PrimaryValues;
 80
 181    private static readonly HexDirection[] PrimaryValues =
 182    {
 183        HexDirection.QPositive,
 184        HexDirection.QPositiveRNegative,
 185        HexDirection.RNegative,
 186        HexDirection.QNegative,
 187        HexDirection.QNegativeRPositive,
 188        HexDirection.RPositive,
 189        HexDirection.Below,
 190        HexDirection.Above
 191    };
 92
 93    /// <summary>
 94    /// All 6 planar axial hex directions.
 95    /// </summary>
 296    public static ReadOnlySpan<HexDirection> Planar => PlanarValues;
 97
 198    private static readonly HexDirection[] PlanarValues =
 199    {
 1100        HexDirection.QPositive,
 1101        HexDirection.QPositiveRNegative,
 1102        HexDirection.RNegative,
 1103        HexDirection.QNegative,
 1104        HexDirection.QNegativeRPositive,
 1105        HexDirection.RPositive
 1106    };
 107
 108    /// <summary>
 109    /// All 2 vertical hex-prism directions.
 110    /// </summary>
 2111    public static ReadOnlySpan<HexDirection> Vertical => VerticalValues;
 112
 1113    private static readonly HexDirection[] VerticalValues =
 1114    {
 1115        HexDirection.Below,
 1116        HexDirection.Above
 1117    };
 118
 119    /// <summary>
 120    /// All 7 neighbor directions on the layer below.
 121    /// </summary>
 2122    public static ReadOnlySpan<HexDirection> BelowLayer => BelowLayerValues;
 123
 1124    private static readonly HexDirection[] BelowLayerValues =
 1125    {
 1126        HexDirection.Below,
 1127        HexDirection.BelowQPositive,
 1128        HexDirection.BelowQPositiveRNegative,
 1129        HexDirection.BelowRNegative,
 1130        HexDirection.BelowQNegative,
 1131        HexDirection.BelowQNegativeRPositive,
 1132        HexDirection.BelowRPositive
 1133    };
 134
 135    /// <summary>
 136    /// All 7 neighbor directions on the layer above.
 137    /// </summary>
 2138    public static ReadOnlySpan<HexDirection> AboveLayer => AboveLayerValues;
 139
 1140    private static readonly HexDirection[] AboveLayerValues =
 1141    {
 1142        HexDirection.Above,
 1143        HexDirection.AboveQPositive,
 1144        HexDirection.AboveQPositiveRNegative,
 1145        HexDirection.AboveRNegative,
 1146        HexDirection.AboveQNegative,
 1147        HexDirection.AboveQNegativeRPositive,
 1148        HexDirection.AboveRPositive
 1149    };
 150
 151    /// <summary>
 152    /// All 12 non-vertical directions on the layers above and below.
 153    /// </summary>
 2154    public static ReadOnlySpan<HexDirection> VerticalDiagonal => VerticalDiagonalValues;
 155
 1156    private static readonly HexDirection[] VerticalDiagonalValues =
 1157    {
 1158        HexDirection.BelowQPositive,
 1159        HexDirection.BelowQPositiveRNegative,
 1160        HexDirection.BelowRNegative,
 1161        HexDirection.BelowQNegative,
 1162        HexDirection.BelowQNegativeRPositive,
 1163        HexDirection.BelowRPositive,
 1164        HexDirection.AboveQPositive,
 1165        HexDirection.AboveQPositiveRNegative,
 1166        HexDirection.AboveRNegative,
 1167        HexDirection.AboveQNegative,
 1168        HexDirection.AboveQNegativeRPositive,
 1169        HexDirection.AboveRPositive
 1170    };
 171
 172    /// <summary>
 173    /// Gets the topology-local index offset for a hex direction.
 174    /// </summary>
 175    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 30176    public static VoxelIndex GetOffset(HexDirection direction) => OffsetValues[(int)direction];
 177
 178    /// <summary>
 179    /// True for planar axial directions.
 180    /// </summary>
 181    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 182    public static bool IsPlanar(HexDirection direction) =>
 2183        (uint)direction <= (uint)HexDirection.RPositive;
 184
 185    /// <summary>
 186    /// True for vertical layer directions.
 187    /// </summary>
 188    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 189    public static bool IsVertical(HexDirection direction) =>
 3190        direction == HexDirection.Below || direction == HexDirection.Above;
 191}