| | | 1 | | //======================================================================= |
| | | 2 | | // SwiftSpatialHashCellIndex.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 | | |
| | | 8 | | using System; |
| | | 9 | | |
| | | 10 | | namespace SwiftCollections.Query; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Represents an integer cell coordinate in a spatial hash grid. |
| | | 14 | | /// </summary> |
| | | 15 | | public readonly struct SwiftSpatialHashCellIndex : IEquatable<SwiftSpatialHashCellIndex> |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Initializes a new instance of the <see cref="SwiftSpatialHashCellIndex"/> struct. |
| | | 19 | | /// </summary> |
| | | 20 | | public SwiftSpatialHashCellIndex(int x, int y, int z) |
| | | 21 | | { |
| | 1057 | 22 | | X = x; |
| | 1057 | 23 | | Y = y; |
| | 1057 | 24 | | Z = z; |
| | 1057 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets the X-axis cell coordinate. |
| | | 29 | | /// </summary> |
| | | 30 | | public int X { get; } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets the Y-axis cell coordinate. |
| | | 34 | | /// </summary> |
| | | 35 | | public int Y { get; } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets the Z-axis cell coordinate. |
| | | 39 | | /// </summary> |
| | | 40 | | public int Z { get; } |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | public bool Equals(SwiftSpatialHashCellIndex other) |
| | | 44 | | { |
| | 240 | 45 | | return X == other.X && Y == other.Y && Z == other.Z; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <inheritdoc /> |
| | 2 | 49 | | public override bool Equals(object? obj) => obj is SwiftSpatialHashCellIndex other && Equals(other); |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Determines whether two SwiftSpatialHashCellIndex instances are equal. |
| | | 53 | | /// </summary> |
| | 2 | 54 | | public static bool operator ==(SwiftSpatialHashCellIndex left, SwiftSpatialHashCellIndex right) => left.Equals(right |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Determines whether two SwiftSpatialHashCellIndex instances are not equal. |
| | | 58 | | /// </summary> |
| | 1 | 59 | | public static bool operator !=(SwiftSpatialHashCellIndex left, SwiftSpatialHashCellIndex right) => !left.Equals(righ |
| | | 60 | | |
| | | 61 | | /// <inheritdoc /> |
| | 1523 | 62 | | public override int GetHashCode() => HashCode.Combine(X, Y, Z); |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Returns a string that represents the current object in the format "(X, Y, Z)". |
| | | 66 | | /// </summary> |
| | | 67 | | /// <remarks> |
| | | 68 | | /// This method is useful for debugging or logging purposes to quickly view the values of the |
| | | 69 | | /// object's coordinates. |
| | | 70 | | /// </remarks> |
| | | 71 | | /// <returns>A string representation of the object, showing the values of X, Y, and Z in parentheses and separated b |
| | 1 | 72 | | public override string ToString() => $"({X}, {Y}, {Z})"; |
| | | 73 | | } |