< Summary

Information
Class: GridForge.Spatial.VoxelIndex
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Spatial/VoxelIndex.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 124
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
ToString()100%11100%
GetHashCode()100%11100%
Equals(...)100%44100%
CompareTo(...)100%44100%
Equals(...)100%22100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// VoxelIndex.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 SwiftCollections.Utility;
 9using System;
 10using System.Runtime.CompilerServices;
 11
 12namespace GridForge.Spatial;
 13
 14/// <summary>
 15/// Represents the topology-local coordinates of a voxel within a single grid.
 16/// Rectangular-prism grids interpret the fields as X, Y, and Z. Hex-prism
 17/// grids interpret them as axial Q, vertical layer, and axial R.
 18/// </summary>
 19public struct VoxelIndex : IEquatable<VoxelIndex>, IComparable<VoxelIndex>
 20{
 21    #region Properties
 22
 23    /// <summary>
 24    /// The local X coordinate for rectangular-prism grids, or axial Q coordinate for hex-prism grids.
 25    /// </summary>
 26    public int x;
 27
 28    /// <summary>
 29    /// The local Y coordinate for rectangular-prism grids, or vertical layer for hex-prism grids.
 30    /// </summary>
 31    public int y;
 32
 33    /// <summary>
 34    /// The local Z coordinate for rectangular-prism grids, or axial R coordinate for hex-prism grids.
 35    /// </summary>
 36    public int z;
 37
 38    /// <summary>
 39    /// Flag to determine is the struct instance was constructed or is default
 40    /// </summary>
 41    public bool IsAllocated { get; private set; }
 42
 43    #endregion
 44
 45    #region Constructors
 46
 47    /// <summary>
 48    /// Initializes a new instance of <see cref="VoxelIndex"/> with an X and Y coordinate.
 49    /// Defaults Z to zero.
 50    /// </summary>
 251    public VoxelIndex(int xCord, int yCord) : this(xCord, yCord, 0) { }
 52
 53    /// <summary>
 54    /// Initializes a new instance of <see cref="VoxelIndex"/> with X, Y, and Z coordinates.
 55    /// </summary>
 56    public VoxelIndex(int xCord, int yCord, int zCord)
 57    {
 9938258        x = xCord;
 9938259        y = yCord;
 9938260        z = zCord;
 61
 9938262        IsAllocated = true;
 9938263    }
 64
 65    #endregion
 66
 67    #region operators
 68
 69    /// <inheritdoc/>
 70    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 71    public static bool operator ==(VoxelIndex left, VoxelIndex right)
 72    {
 27473        return left.Equals(right);
 74    }
 75
 76    /// <inheritdoc/>
 77    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 78    public static bool operator !=(VoxelIndex left, VoxelIndex right)
 79    {
 380        return !(left == right);
 81    }
 82
 83    #endregion
 84
 85    #region Overrides
 86
 87    /// <summary>
 88    /// Returns a string representation of the coordinates.
 89    /// </summary>
 90    public readonly override string ToString()
 91    {
 4792        return string.Format("({0}, {1}, {2})", x, y, z);
 93    }
 94
 95    /// <summary>
 96    /// Computes a hash code for the coordinates, ensuring uniqueness in hashing collections.
 97    /// Uses <see cref="SwiftHashTools"/> to generate a stable and consistent hash.
 98    /// </summary>
 370399    public override readonly int GetHashCode() => SwiftHashTools.CombineHashCodes(x, y, z);
 100
 101    /// <inheritdoc/>
 102    public readonly bool Equals(VoxelIndex other)
 103    {
 2242104        return x == other.x
 2242105            && y == other.y
 2242106            && z == other.z;
 107    }
 108
 109    /// <inheritdoc/>
 110    public readonly int CompareTo(VoxelIndex other)
 111    {
 452112        int result = x.CompareTo(other.x);
 452113        if (result != 0)
 324114            return result;
 115
 128116        result = y.CompareTo(other.y);
 128117        return result != 0 ? result : z.CompareTo(other.z);
 118    }
 119
 120    /// <inheritdoc/>
 2121    public override readonly bool Equals(object? obj) => obj is VoxelIndex other && Equals(other);
 122
 123    #endregion
 124}