/// <summary> /// Returns the bounding box containing this box and the given box. /// </summary> public void Enlarge(Box2d box) { Min.x = Math.Min(Min.x, box.Min.x); Min.y = Math.Min(Min.y, box.Min.y); Max.x = Math.Max(Max.x, box.Max.x); Max.y = Math.Max(Max.y, box.Max.y); }
/// <summary> /// Returns true if this bounding box contains the given bounding box. /// </summary> public bool Intersects(Box2d a) { if (Max.x < a.Min.x || Min.x > a.Max.x) { return(false); } if (Max.y < a.Min.y || Min.y > a.Max.y) { return(false); } return(true); }
/// <summary> /// Returns the bounding box containing this box and the given box. /// </summary> public Box2d Enlarge(Box2d r) { return(new Box2d(Math.Min(Min.x, r.Min.x), Math.Max(Max.x, r.Max.x), Math.Min(Min.y, r.Min.y), Math.Max(Max.y, r.Max.y))); }
public static Box2d CalculateBoundsXZ(Box2d box, Matrix4x4d localToWorld) { Box2d bounds = new Box2d(float.PositiveInfinity, float.NegativeInfinity); Vector3d corners0 = localToWorld * new Vector3d(box.Min.x, 0, box.Min.y); Vector3d corners1 = localToWorld * new Vector3d(box.Min.x, 0, box.Max.y); Vector3d corners2 = localToWorld * new Vector3d(box.Max.x, 0, box.Max.y); Vector3d corners3 = localToWorld * new Vector3d(box.Max.x, 0, box.Min.y); double x = corners0.x; double y = corners0.z; if (x < bounds.Min.x) { bounds.Min.x = x; } if (y < bounds.Min.y) { bounds.Min.y = y; } if (x > bounds.Max.x) { bounds.Max.x = x; } if (y > bounds.Max.y) { bounds.Max.y = y; } x = corners1.x; y = corners1.z; if (x < bounds.Min.x) { bounds.Min.x = x; } if (y < bounds.Min.y) { bounds.Min.y = y; } if (x > bounds.Max.x) { bounds.Max.x = x; } if (y > bounds.Max.y) { bounds.Max.y = y; } x = corners2.x; y = corners2.z; if (x < bounds.Min.x) { bounds.Min.x = x; } if (y < bounds.Min.y) { bounds.Min.y = y; } if (x > bounds.Max.x) { bounds.Max.x = x; } if (y > bounds.Max.y) { bounds.Max.y = y; } x = corners3.x; y = corners3.z; if (x < bounds.Min.x) { bounds.Min.x = x; } if (y < bounds.Min.y) { bounds.Min.y = y; } if (x > bounds.Max.x) { bounds.Max.x = x; } if (y > bounds.Max.y) { bounds.Max.y = y; } return(bounds); }