I have an immutable Vector3 structure, and I'm wondering how to best implement the .Equals() method so that it's useful and still satisfies the Guidelines for Overloading Equals().
Here's a partial implementation of my structure:
public struct Vector3
{
private float _x;
private float _y;
private float _z;
public float X { get { return _x; }}
public float Y { get { return _y; }}
public float Z { get { return _z; } }
public Vector3(float x, float y, float z)
{
_x = x;
_y = y;
_z = z;
}
public override bool Equals(object obj)
{
//What should go here?
}
}
Edit: I don't want to directly compare each X, Y, Z due to the nature of floating point operations. For example, I can tell if two vector3s are parallel by checking to see if u x v == <0, 0, 0>; however with floating point operations this will often fail because one of the zeros is actually <8.205348E-09>.
I'm looking for an Equals() method that is a bit smarter. I want it to work whether the numbers are very large or very small. I