< 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: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 105
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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_IsAllocated()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
ToString()100%11100%
GetHashCode()100%11100%
Equals(...)100%44100%
Equals(...)100%22100%

File(s)

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

#LineLine coverage
 1using SwiftCollections;
 2using System;
 3using System.Runtime.CompilerServices;
 4
 5namespace GridForge.Spatial;
 6
 7/// <summary>
 8/// Represents the local coordinates of a voxel within a single grid.
 9/// Used to index voxels within a grid's spatial structure.
 10/// </summary>
 11public struct VoxelIndex : IEquatable<VoxelIndex>
 12{
 13    #region Properties
 14
 15    /// <summary>
 16    /// The X position of the voxel in the local grid.
 17    /// </summary>
 18    public int x;
 19
 20    /// <summary>
 21    /// The Y position of the voxel in the local grid.
 22    /// </summary>
 23    public int y;
 24
 25    /// <summary>
 26    /// The Z position of the voxel in the local grid.
 27    /// </summary>
 28    public int z;
 29
 30    /// <summary>
 31    /// Flag to determine is the struct instance was constructed or is default
 32    /// </summary>
 7999533    public bool IsAllocated { get; private set; }
 34
 35    #endregion
 36
 37    #region Constructors
 38
 39    /// <summary>
 40    /// Initializes a new instance of <see cref="VoxelIndex"/> with an X and Y coordinate.
 41    /// Defaults Z to zero.
 42    /// </summary>
 243    public VoxelIndex(int xCord, int yCord) : this(xCord, yCord, 0) { }
 44
 45    /// <summary>
 46    /// Initializes a new instance of <see cref="VoxelIndex"/> with X, Y, and Z coordinates.
 47    /// </summary>
 48    public VoxelIndex(int xCord, int yCord, int zCord)
 49    {
 7999450        x = xCord;
 7999451        y = yCord;
 7999452        z = zCord;
 53
 7999454        IsAllocated = true;
 7999455    }
 56
 57    #endregion
 58
 59    #region operators
 60
 61    /// <inheritdoc/>
 62    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 63    public static bool operator ==(VoxelIndex left, VoxelIndex right)
 64    {
 265        return left.Equals(right);
 66    }
 67
 68    /// <inheritdoc/>
 69    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 70    public static bool operator !=(VoxelIndex left, VoxelIndex right)
 71    {
 172        return !(left == right);
 73    }
 74
 75    #endregion
 76
 77    #region Overrides
 78
 79    /// <summary>
 80    /// Returns a string representation of the coordinates.
 81    /// </summary>
 82    public readonly override string ToString()
 83    {
 4284        return string.Format("({0}, {1}, {2})", x, y, z);
 85    }
 86
 87    /// <summary>
 88    /// Computes a hash code for the coordinates, ensuring uniqueness in hashing collections.
 89    /// Uses <see cref="SwiftHashTools"/> to generate a stable and consistent hash.
 90    /// </summary>
 263591    public override readonly int GetHashCode() => SwiftHashTools.CombineHashCodes(x, y, z);
 92
 93    /// <inheritdoc/>
 94    public readonly bool Equals(VoxelIndex other)
 95    {
 134696        return x == other.x
 134697            && y == other.y
 134698            && z == other.z;
 99    }
 100
 101    /// <inheritdoc/>
 2102    public override readonly bool Equals(object? obj) => obj is VoxelIndex other && Equals(other);
 103
 104    #endregion
 105}