| | | 1 | | //======================================================================= |
| | | 2 | | // WorldVoxelIndexOrdering.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using GridForge.Spatial; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | |
| | | 11 | | namespace Gravitas; |
| | | 12 | | |
| | | 13 | | internal static class WorldVoxelIndexOrdering |
| | | 14 | | { |
| | | 15 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 16 | | public static int Compare3D(WorldVoxelIndex left, WorldVoxelIndex right) |
| | | 17 | | { |
| | 863357 | 18 | | int compare = CompareGrid(left, right); |
| | 863357 | 19 | | if (compare != 0) |
| | 2 | 20 | | return compare; |
| | | 21 | | |
| | 863355 | 22 | | compare = left.VoxelIndex.x.CompareTo(right.VoxelIndex.x); |
| | 863355 | 23 | | if (compare != 0) |
| | 482884 | 24 | | return compare; |
| | | 25 | | |
| | 380471 | 26 | | compare = left.VoxelIndex.y.CompareTo(right.VoxelIndex.y); |
| | 380471 | 27 | | if (compare != 0) |
| | 219223 | 28 | | return compare; |
| | | 29 | | |
| | 161248 | 30 | | return left.VoxelIndex.z.CompareTo(right.VoxelIndex.z); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 34 | | public static int ComparePlanar(WorldVoxelIndex left, WorldVoxelIndex right) |
| | | 35 | | { |
| | 468728 | 36 | | int compare = CompareGrid(left, right); |
| | 468728 | 37 | | if (compare != 0) |
| | 2 | 38 | | return compare; |
| | | 39 | | |
| | 468726 | 40 | | compare = left.VoxelIndex.x.CompareTo(right.VoxelIndex.x); |
| | 468726 | 41 | | if (compare != 0) |
| | 352339 | 42 | | return compare; |
| | | 43 | | |
| | 116387 | 44 | | compare = left.VoxelIndex.z.CompareTo(right.VoxelIndex.z); |
| | 116387 | 45 | | if (compare != 0) |
| | 116385 | 46 | | return compare; |
| | | 47 | | |
| | 2 | 48 | | return left.VoxelIndex.y.CompareTo(right.VoxelIndex.y); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 52 | | private static int CompareGrid(WorldVoxelIndex left, WorldVoxelIndex right) |
| | | 53 | | { |
| | 1332085 | 54 | | int compare = left.GridIndex.CompareTo(right.GridIndex); |
| | 1332085 | 55 | | if (compare != 0) |
| | 2 | 56 | | return compare; |
| | | 57 | | |
| | 1332083 | 58 | | return left.GridSpawnToken.CompareTo(right.GridSpawnToken); |
| | | 59 | | } |
| | | 60 | | } |