< 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: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 117
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 System;
 9using System.Runtime.CompilerServices;
 10using GridForge.Grids;
 11using SwiftCollections.Utility;
 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 process-unique 64-bit runtime allocation token of the owning <see cref="GridWorld"/> instance.
 25    /// Used to reject stale or cross-world identities safely.
 26    /// </summary>
 27    public long 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 64-bit world-local allocation generation assigned to the grid during initialization.
 36    /// Used to ensure the correct instance is at the assigned <see cref="GridIndex"/>.
 37    /// </summary>
 38    public long 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        long worldSpawnToken,
 54        ushort gridIndex,
 55        long gridSpawnToken,
 56        VoxelIndex coord)
 57    {
 12233958        WorldSpawnToken = worldSpawnToken;
 12233959        GridIndex = gridIndex;
 12233960        GridSpawnToken = gridSpawnToken;
 12233961        VoxelIndex = coord;
 12233962    }
 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 hash-based lookup. Exact equality remains authoritative.
 96    /// </summary>
 97    public override readonly int GetHashCode() =>
 5866898        SwiftHashTools.CombineHashCodes(
 5866899            WorldSpawnToken.GetHashCode(),
 58668100            GridSpawnToken.GetHashCode(),
 58668101            GridIndex,
 58668102            VoxelIndex.GetHashCode());
 103
 104    /// <inheritdoc/>
 105    public readonly bool Equals(WorldVoxelIndex other)
 106    {
 33470107        return WorldSpawnToken == other.WorldSpawnToken
 33470108            && GridIndex == other.GridIndex
 33470109            && GridSpawnToken == other.GridSpawnToken
 33470110            && VoxelIndex.Equals(other.VoxelIndex);
 111    }
 112
 113    /// <inheritdoc/>
 2114    public override readonly bool Equals(object? obj) => obj is WorldVoxelIndex other && Equals(other);
 115
 116    #endregion
 117}