23#ifndef LSST_SPHGEOM_BOX3D_H_
24#define LSST_SPHGEOM_BOX3D_H_
45 static Box3d empty() {
50 return Box3d(Interval1d::full(),
88 _intervals[0] =
Interval1d(v.x()).dilatedBy(w);
89 _intervals[1] =
Interval1d(v.y()).dilatedBy(h);
90 _intervals[2] =
Interval1d(v.z()).dilatedBy(d);
103 _enforceInvariants();
108 return _intervals[0] == b._intervals[0] &&
109 _intervals[1] == b._intervals[1] &&
110 _intervals[2] == b._intervals[2];
113 bool operator!=(
Box3d const & b)
const {
return !(*
this == b); }
118 bool operator!=(
Vector3d const & v)
const {
return !(*
this == v); }
123 Interval1d const & x()
const {
return _intervals[0]; }
124 Interval1d
const & y()
const {
return _intervals[1]; }
125 Interval1d
const & z()
const {
return _intervals[2]; }
170 bool contains(
double x_,
double y_,
double z_)
const {
218 _intervals[0].
clipTo(b.x());
219 _intervals[1].
clipTo(b.y());
220 _intervals[2].
clipTo(b.z());
221 _enforceInvariants();
226 _intervals[0].
clipTo(b.x());
227 _intervals[1].
clipTo(b.y());
228 _intervals[2].
clipTo(b.z());
229 _enforceInvariants();
237 return Box3d(*this).clipTo(b);
241 return Box3d(*this).clipTo(b);
266 return Box3d(*this).expandTo(b);
270 return Box3d(*this).expandTo(b);
281 Box3d dilatedBy(
double r)
const {
return Box3d(*this).dilateBy(r); }
294 _enforceInvariants();
297 Box3d dilatedBy(
double w,
double h,
double d)
const {
298 return Box3d(*this).dilateBy(w, h, d);
301 Box3d erodedBy(
double r)
const {
return dilatedBy(-r); }
302 Box3d & erodeBy(
double w,
double h,
double d) {
305 Box3d erodedBy(
double w,
double h,
double d)
const {
306 return dilatedBy(-w, -h, -d);
318 return ((xr & yr & zr) & (CONTAINS | WITHIN)) |
319 ((xr | yr | zr) & DISJOINT);
324 void _enforceInvariants() {
328 _intervals[0] = Interval1d();
329 _intervals[1] = Interval1d();
330 _intervals[2] = Interval1d();
334 Interval1d _intervals[3];
337std::ostream & operator<<(std::ostream &, Box3d
const &);
This file defines a class for representing intervals of ℝ.
This file declares a class for representing vectors in ℝ³.
double getHeight() const
Definition: Box3d.h:149
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Definition: Box3d.h:128
bool isFull() const
isFull returns true if this box contains all points in ℝ³.
Definition: Box3d.h:133
bool intersects(Vector3d const &b) const
Definition: Box3d.h:186
double getDepth() const
Definition: Box3d.h:153
bool operator==(Box3d const &b) const
Two 3D boxes are equal if they contain the same points.
Definition: Box3d.h:107
Box3d(Vector3d const &v1, Vector3d const &v2)
Definition: Box3d.h:76
Box3d & dilateBy(double r)
Definition: Box3d.h:280
Box3d(Vector3d const &v, double w, double h, double d)
Definition: Box3d.h:86
Box3d & dilateBy(double w, double h, double d)
Definition: Box3d.h:290
Box3d & expandTo(Vector3d const &b)
Definition: Box3d.h:247
bool isDisjointFrom(Vector3d const &b) const
Definition: Box3d.h:178
Interval1d operator()(int i) const
The function call operator returns the i-th interval of this box.
Definition: Box3d.h:121
bool isWithin(Vector3d const &b) const
Definition: Box3d.h:202
Box3d & clipTo(Vector3d const &b)
Definition: Box3d.h:217
Box3d()
This constructor creates an empty 3D box.
Definition: Box3d.h:63
bool operator==(Vector3d const &v) const
A box is equal to a point if it contains only that point.
Definition: Box3d.h:116
Box3d expandedTo(Vector3d const &b) const
Definition: Box3d.h:265
Box3d(Vector3d const &v)
This constructor creates a box containing a single point.
Definition: Box3d.h:66
double getWidth() const
Definition: Box3d.h:145
Box3d clippedTo(Vector3d const &b) const
Definition: Box3d.h:236
static Box3d aroundUnitSphere()
aroundUnitSphere returns a minimal Box3d containing the unit sphere.
Definition: Box3d.h:56
Vector3d getCenter() const
Definition: Box3d.h:139
bool contains(Vector3d const &b) const
Definition: Box3d.h:158
Box3d(Interval1d const &x, Interval1d const &y, Interval1d const &z)
Definition: Box3d.h:96
Definition: Interval1d.h:40
bool isFull() const
isFull returns true if this interval = ℝ.
Definition: Interval1d.h:63
bool isWithin(Scalar x) const
Definition: Interval.h:140
Interval & dilateBy(Scalar x)
Definition: Interval.h:230
Scalar getSize() const
Definition: Interval.h:93
Interval & clipTo(Scalar x)
Definition: Interval.h:159
bool isEmpty() const
isEmpty returns true if this interval does not contain any points.
Definition: Interval.h:83
Relationship relate(Scalar x) const
Definition: Interval.h:249
bool intersects(Scalar x) const
Definition: Interval.h:130
Interval & expandTo(Scalar x)
Definition: Interval.h:192
bool contains(Scalar x) const
Definition: Interval.h:98
Vector3d is a vector in ℝ³ with components stored in double precision.
Definition: Vector3d.h:44
This file provides a type alias for describing set relationships.
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35