BoundingBox == and !=

Jan 22, 2011 at 10:15 PM
Edited Jan 22, 2011 at 10:16 PM

There is a bug in at least one of the operator overloads in Balder, specificly Bounding box.  Please see the URL below for info on overloading == and !=

I'm getting an error if I try to see if a bounding box is null

BoundingBox bb = null;
if(bb==null)
  messagebox.show("IsNULL");

The code above will fail on the if line, because I can't check a bounding box with null.  The URL below outlines how to address this.
Notice how there is logic to deal with same instance, and null objects.

// Example
public static bool operator ==(ThreeDPoint a, ThreeDPoint b)
{
    // If both are null, or both are same instance, return true.
    if (System.Object.ReferenceEquals(a, b))
    {
        return true;
    }

    // If one is null, but not both, return false.
    if (((object)a == null) || ((object)b == null))
    {
        return false;
    }

    // Return true if the fields match:
    return a.x == b.x && a.y == b.y && a.z == b.z;
}

public static bool operator !=(ThreeDPoint a, ThreeDPoint b)
{
    return !(a == b);
}


http://msdn.microsoft.com/en-us/library/ms173147(v=vs.80).aspx

Coordinator
Jan 23, 2011 at 9:53 AM

Hi,

thanks for the input on this one. BoundingBox used to be a struct and was not a reference type, so a bit to be desired in that implementation. Your implementation is more correct. 

 

Coordinator
Jan 23, 2011 at 9:53 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.