RNBoolean R3Contains(const R3Box& box, const R3Point& point) { // Return whether box contains point if (box.IsEmpty()) return FALSE; if (RNIsLess(point.X(), box.XMin())) return FALSE; if (RNIsLess(point.Y(), box.YMin())) return FALSE; if (RNIsLess(point.Z(), box.ZMin())) return FALSE; if (RNIsGreater(point.X(), box.XMax())) return FALSE; if (RNIsGreater(point.Y(), box.YMax())) return FALSE; if (RNIsGreater(point.Z(), box.ZMax())) return FALSE; return TRUE; }
RNBoolean R3Contains(const R3Box& box, const R3Sphere& sphere) { // Return whether box contains sphere if (box.IsEmpty()) return FALSE; if (sphere.IsEmpty()) return TRUE; if (RNIsLess(sphere.Center().X() - sphere.Radius(), box.XMin())) return FALSE; if (RNIsLess(sphere.Center().Y() - sphere.Radius(), box.YMin())) return FALSE; if (RNIsLess(sphere.Center().Z() - sphere.Radius(), box.ZMin())) return FALSE; if (RNIsGreater(sphere.Center().X() + sphere.Radius(), box.XMax())) return FALSE; if (RNIsGreater(sphere.Center().Y() + sphere.Radius(), box.YMax())) return FALSE; if (RNIsGreater(sphere.Center().Z() + sphere.Radius(), box.ZMax())) return FALSE; return TRUE; }
RNBoolean R3Contains(const R3Box& box1, const R3Box& box2) { // Return whether box1 contains box2 if (box1.IsEmpty()) return FALSE; if (box2.IsEmpty()) return TRUE; if (RNIsLess(box2.XMin(), box1.XMin())) return FALSE; if (RNIsLess(box2.YMin(), box1.YMin())) return FALSE; if (RNIsLess(box2.ZMin(), box1.ZMin())) return FALSE; if (RNIsGreater(box2.XMax(), box1.XMax())) return FALSE; if (RNIsGreater(box2.YMax(), box1.YMax())) return FALSE; if (RNIsGreater(box2.ZMax(), box1.ZMax())) return FALSE; return TRUE; }
RNLength R2Distance(const R2Point& point, const R2Box& box) { // Find axial distances from point to box RNLength dx, dy; if (RNIsGreater(point.X(), box.XMax())) dx = point.X() - box.XMax(); else if (RNIsLess(point.X(), box.XMin())) dx = box.XMin()- point.X(); else dx = 0.0; if (RNIsGreater(point.Y(), box.YMax())) dy = point.Y() - box.YMax(); else if (RNIsLess(point.Y(), box.YMin())) dy = box.YMin()- point.Y(); else dy = 0.0; // Return distance between point and closest point in box if (dy == 0.0) return dx; else if (dx == 0.0) return dy; else return sqrt(dx*dx + dy*dy); }
RNBoolean R3Contains(const R3Sphere& sphere1, const R3Sphere& sphere2) { // Return whether sphere1 contains sphere2 RNLength d = R3Distance(sphere1.Center(), sphere2.Center()); return RNIsLess(d + sphere2.Radius(), sphere1.Radius()); }