| | | 1 | | using GridForge.Spatial; |
| | | 2 | | using System.Diagnostics; |
| | | 3 | | |
| | | 4 | | namespace GridForge.Grids; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Provides stateless helpers for translating relative grid offsets into directions. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class GridDirectionUtility |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Converts a 3D offset into a corresponding <see cref="SpatialDirection"/> in a 3x3x3 grid. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="gridOffset">The (x, y, z) offset from the center voxel.</param> |
| | | 15 | | /// <returns>The corresponding <see cref="SpatialDirection"/>, or <see cref="SpatialDirection.None"/> if invalid.</r |
| | | 16 | | public static SpatialDirection GetNeighborDirectionFromOffset((int x, int y, int z) gridOffset) |
| | | 17 | | { |
| | | 18 | | Debug.Assert(gridOffset.x >= -1 && gridOffset.x <= 1, "Invalid x offset."); |
| | | 19 | | Debug.Assert(gridOffset.y >= -1 && gridOffset.y <= 1, "Invalid y offset."); |
| | | 20 | | Debug.Assert(gridOffset.z >= -1 && gridOffset.z <= 1, "Invalid z offset."); |
| | | 21 | | |
| | 43 | 22 | | if (gridOffset == (0, 0, 0)) |
| | 2 | 23 | | return SpatialDirection.None; |
| | | 24 | | |
| | 418 | 25 | | for (int i = 0; i < SpatialAwareness.DirectionOffsets.Length; i++) |
| | | 26 | | { |
| | 209 | 27 | | if (SpatialAwareness.DirectionOffsets[i] == gridOffset) |
| | 41 | 28 | | return (SpatialDirection)i; |
| | | 29 | | } |
| | | 30 | | |
| | 0 | 31 | | return SpatialDirection.None; |
| | | 32 | | } |
| | | 33 | | } |