Table of Contents

Class DirectionComparer

Namespace
Thunder.UnitsNET.Vectors.Geometry
Assembly
Thunder.UnitsNET.Vectors.Geometry.dll

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

x Direction2

The first Direction2 to compare.

y Direction2

The second Direction2 to compare.

Returns

bool

true if x and y represent the same direction; otherwise false.

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

obj Direction2

The 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));
latest ▼