Thank you for the valid question, and thanks to Maxim for his very helpful answer.
Afaik, the correct best practice in .NET is to implement a comparison operator named Compare or a Comparer class:
https://duckduckgo.com/?q=.net+comparer
Also, since the X, Y and Z coordinates are real values, you need to define a tolerance and add some fuzz to be able to determine equality.
Here is The Building Coder comparer method for XYZ objects:
https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/U...
/// <summary>
/// Default tolerance used to add fuzz
/// for real number equality detection
/// </summary>
public const double _eps = 1.0e-9;
/// <summary>
/// Predicate to determine whether the given
/// real number should be considered equal to
/// zero, adding fuzz according to the specified
/// tolerance
/// </summary>
public static bool IsZero(
double a,
double tolerance = _eps )
{
return tolerance > Math.Abs( a );
}
/// <summary>
/// Predicate to determine whether the two given
/// real numbers should be considered equal, adding
/// fuzz according to the specified tolerance
/// </summary>
public static bool IsEqual(
double a,
double b,
double tolerance = _eps )
{
return IsZero( b - a, tolerance );
}
/// <summary>
/// Comparison method for two real numbers
/// returning 0 if they are to be considered equal,
/// -1 if the first is smaller and +1 otherwise
/// </summary>
public static int Compare(
double a,
double b,
double tolerance = _eps )
{
return IsEqual( a, b, tolerance )
? 0
: (a < b ? -1 : 1);
}
/// <summary>
/// Comparison method for two XYZ objects
/// returning 0 if they are to be considered equal,
/// -1 if the first is smaller and +1 otherwise
/// </summary>
public static int Compare(
XYZ p,
XYZ q,
double tolerance = _eps )
{
int d = Compare( p.X, q.X, tolerance );
if( 0 == d )
{
d = Compare( p.Y, q.Y, tolerance );
if( 0 == d )
{
d = Compare( p.Z, q.Z, tolerance );
}
}
return d;
}