Class DirectionComparer
An IEqualityComparer<T> for Direction2 that delegates to the built-in value equality of the Direction2 record struct.
Use this when you need to store Direction2 values in a collection that requires an explicit equality comparer — for example, a HashSet<T> or as the key in a Dictionary<TKey, TValue>.
For approximate equality (where floating-point drift is a concern) use ApproximatelyEquals(Direction2, Direction2, Angle) instead.
public sealed class DirectionComparer : IEqualityComparer<Direction2>
- Inheritance
-
DirectionComparer
- Implements
- Inherited Members
Examples
var comparer = new DirectionComparer();
var set = new HashSet<Direction2>(comparer);
set.Add(Direction2.FromDegrees(45));
bool found = set.Contains(Direction2.FromDegrees(45)); // true
Methods
Equals(Direction2, Direction2)
Determines whether two Direction2 values are equal using the record struct's built-in value equality.
public bool Equals(Direction2 x, Direction2 y)
Parameters
xDirection2The first Direction2 to compare.
yDirection2The second Direction2 to compare.
Returns
Examples
var comparer = new DirectionComparer();
bool equal = comparer.Equals(Direction2.FromDegrees(45), Direction2.FromDegrees(45)); // true
GetHashCode(Direction2)
Returns a hash code for the specified Direction2 value, consistent with the equality defined by Equals(Direction2, Direction2).
public int GetHashCode(Direction2 obj)
Parameters
objDirection2The Direction2 for which to get a hash code.
Returns
- int
A hash code for
obj.
Examples
var comparer = new DirectionComparer();
int hash = comparer.GetHashCode(Direction2.FromDegrees(45));