< Summary

Information
Class: GridForge.Spatial.WorldVoxelIndex
Assembly: GridForge
File(s): /home/runner/work/GridForge/GridForge/src/GridForge/Spatial/WorldVoxelIndex.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 113
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
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%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
ToString()100%11100%
GetHashCode()100%11100%
Equals(...)100%66100%
Equals(...)100%22100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// WorldVoxelIndex.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 GridForge.Grids;
 9using SwiftCollections.Utility;
 10using System;
 11using System.Runtime.CompilerServices;
 12
 13namespace GridForge.Spatial;
 14
 15/// <summary>
 16/// Represents the world-scoped runtime identity of a voxel.
 17/// Used for uniquely identifying voxels across multiple grids and world instances.
 18/// </summary>
 19public struct WorldVoxelIndex : IEquatable<WorldVoxelIndex>
 20{
 21    #region Properties
 22
 23    /// <summary>
 24    /// The runtime token of the owning <see cref="GridWorld"/> instance.
 25    /// Used to reject stale or cross-world identities safely.
 26    /// </summary>
 27    public int WorldSpawnToken;
 28
 29    /// <summary>
 30    /// The world-local slot index of the grid in <see cref="GridWorld.ActiveGrids"/>.
 31    /// </summary>
 32    public ushort GridIndex;
 33
 34    /// <summary>
 35    /// The unique identifier generated by the grid during initialization.
 36    /// Used to ensure the correct instance is at the assigned <see cref="GridIndex"/>.
 37    /// </summary>
 38    public int GridSpawnToken;
 39
 40    /// <summary>
 41    /// The local coordinate of a voxel within the grid at <see cref="GridIndex"/>.
 42    /// </summary>
 43    public VoxelIndex VoxelIndex;
 44
 45    #endregion
 46
 47    #region Constructors
 48
 49    /// <summary>
 50    /// Initializes a new instance of <see cref="WorldVoxelIndex"/>, linking a voxel to a specific world and grid instan
 51    /// </summary>
 52    public WorldVoxelIndex(
 53        int worldSpawnToken,
 54        ushort gridIndex,
 55        int gridSpawnToken,
 56        VoxelIndex coord)
 57    {
 9598358        WorldSpawnToken = worldSpawnToken;
 9598359        GridIndex = gridIndex;
 9598360        GridSpawnToken = gridSpawnToken;
 9598361        VoxelIndex = coord;
 9598362    }
 63
 64    #endregion
 65
 66    #region operators
 67
 68    /// <inheritdoc/>
 69    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 70    public static bool operator ==(WorldVoxelIndex left, WorldVoxelIndex right)
 71    {
 872        return left.Equals(right);
 73    }
 74
 75    /// <inheritdoc/>
 76    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 77    public static bool operator !=(WorldVoxelIndex left, WorldVoxelIndex right)
 78    {
 179        return !(left == right);
 80    }
 81
 82    #endregion
 83
 84    #region Overrides
 85
 86    /// <summary>
 87    /// Returns a string representation of the world-scoped voxel identity.
 88    /// </summary>
 89    public override readonly string ToString()
 90    {
 1991        return $"World: {WorldSpawnToken}; Grid: {GridIndex}; Coordinate: {VoxelIndex}";
 92    }
 93
 94    /// <summary>
 95    /// Computes a hash code for uniquely identifying this world-scoped voxel identity.
 96    /// </summary>
 97    public override readonly int GetHashCode() =>
 367198        SwiftHashTools.CombineHashCodes(WorldSpawnToken, GridSpawnToken, GridIndex, VoxelIndex.GetHashCode());
 99
 100    /// <inheritdoc/>
 101    public readonly bool Equals(WorldVoxelIndex other)
 102    {
 1734103        return WorldSpawnToken == other.WorldSpawnToken
 1734104            && GridIndex == other.GridIndex
 1734105            && GridSpawnToken == other.GridSpawnToken
 1734106            && VoxelIndex.Equals(other.VoxelIndex);
 107    }
 108
 109    /// <inheritdoc/>
 2110    public override readonly bool Equals(object? obj) => obj is WorldVoxelIndex other && Equals(other);
 111
 112    #endregion
 113}