BoundingBox == and !=

Jan 22, 2011 at 11:15 PM
Edited Jan 22, 2011 at 11: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;

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);

Jan 23, 2011 at 10:53 AM


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. 


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