-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCellWithDistance.cs
More file actions
45 lines (38 loc) · 1.96 KB
/
CellWithDistance.cs
File metadata and controls
45 lines (38 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Collections.Generic;
namespace RT.Coordinates;
/// <summary>
/// Encapsulates a cell and its distance from an origin cell within a structure.</summary>
/// <typeparam name="TCell">
/// Type of cell (e.g., <see cref="Square"/>, <see cref="Hex"/> or <see cref="Tri"/>).</typeparam>
/// <remarks>
/// Used in the return value of <see cref="Structure{TCell}.FindPaths(TCell)"/>.</remarks>
/// <remarks>
/// Constructor.</remarks>
public struct CellWithDistance<TCell>(TCell cell, TCell parent, int distance)
{
/// <summary>The relevant cell.</summary>
public TCell Cell { get; private set; } = cell;
/// <summary>
/// The previous cell in the path from the origin cell to this cell.</summary>
/// <remarks>
/// If <see cref="Distance"/> is <c>0</c>, this value is meaningless and must be ignored.</remarks>
public TCell Parent { get; private set; } = parent;
/// <summary>
/// The amount of steps required to reach this cell from the origin cell. If this is <c>0</c>, this cell is the origin
/// cell.</summary>
public int Distance { get; private set; } = distance;
/// <inheritdoc/>
public override readonly bool Equals(object obj) => obj is CellWithDistance<TCell> other && EqualityComparer<TCell>.Default.Equals(Parent, other.Parent) && Distance == other.Distance;
/// <inheritdoc/>
public override readonly int GetHashCode() => Parent.GetHashCode() * 1068603923 + Distance;
/// <summary>Deconstructor.</summary>
public readonly void Deconstruct(out TCell parent, out int distance)
{
parent = Parent;
distance = Distance;
}
/// <summary>Equality operator.</summary>
public static bool operator ==(CellWithDistance<TCell> left, CellWithDistance<TCell> right) => left.Equals(right);
/// <summary>Inequality operator.</summary>
public static bool operator !=(CellWithDistance<TCell> left, CellWithDistance<TCell> right) => !left.Equals(right);
}