16template <
class T>
class Cube
24 :tx1_(
x1), tx2_(
x2), ty1_(
y1), ty2_(
y2), tz1_(
z1), tz2_(
z2) { }
27 :tx1_(v111.x()), tx2_(v222.x()), ty1_(v111.y()), ty2_(v222.y()), tz1_(v111.z()), tz2_(v222.z()) { }
30#pragma clang diagnostic ignored "-Wdeprecated-copy"
31 Cube(
const Cube<T> &r) : tx1_(r.tx1_), tx2_(r.tx2_), ty1_(r.ty1_), ty2_(r.ty2_), tz1_(r.tz1_), tz2_(r.tz2_) { }
41 const T &
x1()
const {
return tx1_; }
43 const T &
x2()
const {
return tx2_; }
45 const T &
y1()
const {
return ty1_; }
47 const T &
y2()
const {
return ty2_; }
49 const T &
z1()
const {
return tz1_; }
51 const T &
z2()
const {
return tz2_; }
53 const T &
dof1(uint32 dof)
const { assert(dof<3);
return *(&tx1_+(2*dof)); }
55 const T &
dof2(uint32 dof)
const { assert(dof<3);
return *(&tx2_+(2*dof)); }
57 T
width()
const {
return (tx2_-tx1_); }
59 T
height()
const {
return (ty2_-ty1_); }
61 T
depth()
const {
return (tz2_-tz1_); }
72 if (y) {
if (z)
return c222();
else return c221(); }
73 else {
if (z)
return c212();
else return c211(); }
75 if (y) {
if (z)
return c122();
else return c121(); }
76 else {
if (z)
return c112();
else return c111(); }
106 bool isEmpty()
const {
return ( (tx1_>=tx2_) || (ty1_>=ty2_) || (tz1_>=tz2_) ); }
112 return( (tx1_==c.tx1_)&&(tx2_==c.tx2_)&&(ty1_==c.ty1_)&&(ty2_==c.ty2_)&&(tz1_==c.tz1_)&&(tz2_==c.tz2_) );
123 if ( (v.
x()>=tx1_) && (v.
x()<=tx2_) && (v.
y()>=ty1_) && (v.
y()<=ty2_) && (v.
z()>=tz1_) && (v.
z()<=tz2_) )
return true;
129 if ( (c.
x1()>=tx1_) && (c.
x2()<=tx2_) && (c.
y1()>=ty1_) && (c.
y2()<=ty2_) && (c.
z1()>=tz1_) && (c.
z2()<=tz2_) )
return true;
135 if ( (v.
x()>=tx1_-tol) && (v.
x()<=tx2_+tol) && (v.
y()>=ty1_-tol) && (v.
y()<=ty2_+tol) && (v.
z()>=tz1_-tol) && (v.
z()<=tz2_+tol) )
return true;
141 if ( (c.
x1()>=tx1_-tol) && (c.
x2()<=tx2_+tol) && (c.
y1()>=ty1_-tol) && (c.
y2()<=ty2_+tol) && (c.
z1()>=tz1_-tol) && (c.
z2()<=tz2_+tol) )
return true;
147 if ((c.tx2_<tx1_) || (c.tx1_>tx2_) ||
148 (c.ty2_<ty1_) || (c.ty1_>ty2_) ||
149 (c.tz2_<tz1_) || (c.tz1_>tz2_))
return false;
155 if ((c.tx2_<tx1_-tol) || (c.tx1_>tx2_+tol) ||
156 (c.ty2_<ty1_-tol) || (c.ty1_>ty2_+tol) ||
157 (c.tz2_<tz1_-tol) || (c.tz1_>tz2_+tol))
return false;
169 T &
rdof1(uint32 dof) { assert(dof<3);
return *(&tx1_+(2*dof)); }
171 T &
rdof2(uint32 dof) { assert(dof<3);
return *(&tx2_+(2*dof)); }
174 void width(
const T &t) { tx2_ = tx1_ + t; }
176 void height(
const T &t) { ty2_ = ty1_ + t; }
178 void depth(
const T &t) { tz2_ = tz1_ + t; }
219 Cube<T> out(std::max<T>(tx1_,r.tx1_),std::min<T>(tx2_,r.tx2_),
220 std::max<T>(ty1_,r.ty1_),std::min<T>(ty2_,r.ty2_),
221 std::max<T>(tz1_,r.tz1_),std::min<T>(tz2_,r.tz2_));
227 tx1_ = std::min<T>(tx1_,r.tx1_);
228 ty1_ = std::min<T>(ty1_,r.ty1_);
229 tz1_ = std::min<T>(tz1_,r.tz1_);
230 tx2_ = std::max<T>(tx2_,r.tx2_);
231 ty2_ = std::max<T>(ty2_,r.ty2_);
232 tz2_ = std::max<T>(tz2_,r.tz2_);
238 tx1_ = std::min<T>(tx1_,v.
x());
239 ty1_ = std::min<T>(ty1_,v.
y());
240 tz1_ = std::min<T>(tz1_,v.
z());
241 tx2_ = std::max<T>(tx2_,v.
x());
242 ty2_ = std::max<T>(ty2_,v.
y());
243 tz2_ = std::max<T>(tz2_,v.
z());
273 const Cube<T> &
expand(
const T &tol) { tx1_ -= tol; tx2_ += tol; ty1_ -= tol; ty2_ += tol; tz1_ -= tol; tz2_ += tol;
return *
this; }
283 Cube<T> out(tx1_-s.
x(),tx2_+s.
x(),ty1_-s.
y(),ty2_+s.
y(),tz1_-s.
z(),tz2_+s.
z());
307 T pBound(
const T &min,
const T &v,
const T &max)
const {
return std::min(std::max(v,min),max); }
A Class representing a cartesian extent in 3D.
Definition cube.h:17
void upperBound(const Vector3< T > &v)
Sets the upper bound of the exetnt, keeping the lower bound constant. Synonym to c222().
Definition cube.h:198
Vector3< T > c211() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:86
T & ry1()
Reference access to the minimum y extent.
Definition cube.h:164
bool isEmpty() const
Returns true if the region is "inside out" in any of its three coordinates.
Definition cube.h:106
static Cube< T > nothing()
Returns an Cube with maximum negative size. Useful for calculating bounds.
Definition cube.h:35
Cube< T > expandedToInclude(const Cube< T > &r) const
Returns an extent large enough to contain this one and r.
Definition cube.h:252
Cube(const Extent2< T > &r)
Explicit contructor, from a Rectangle. The z extent is set to (0,1).
Definition cube.h:33
const Cube< T > & operator+=(const Vector3< T > &v)
Adds v to all extent boundaries, effectively translating it.
Definition cube.h:207
const Cube< T > & expand(const T &tol)
Definition cube.h:273
T width() const
Returns the size of the extent in the x-direction.
Definition cube.h:57
Cube< T > expanded(const T &tol) const
Definition cube.h:277
bool tolIsIn(const Vector3< T > &v, const T &tol) const
Returns true if Vector3 v is "inside" the extent, inclusive with an added tolerance factor.
Definition cube.h:133
const T & x2() const
Returns the upper bound of the extent in the x-direction.
Definition cube.h:43
Vector3< T > upperBound() const
Returns the upper bounding corner of the extent, maximum value of x,y, and z.
Definition cube.h:100
const T & dof1(uint32 dof) const
Returns the lower bound of degree-of-freedom dof.
Definition cube.h:53
POPWARNING const T & x1() const
Returns the lower bound of the extent in the x-direction.
Definition cube.h:41
Vector3< T > c112() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:90
bool isIn(const Cube< T > &c) const
Returns true if the Cube c falls completely inside (inclusive) the extent.
Definition cube.h:127
void c222(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:194
Cube< T > center(const Vector3< T > &v) const
Returns a rectangle centered about point v.
Definition cube.h:299
Vector3< T > c222() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:96
Cube(const T &x1, const T &x2, const T &y1, const T &y2, const T &z1, const T &z2)
Explicit constructor, by providing all six cartesian extents.
Definition cube.h:23
Vector3< T > centroid() const
Returns the geometric center of the extent as a Vector3.
Definition cube.h:63
void c112(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:188
const T & z1() const
Returns the lower bound of the extent in the y-direction.
Definition cube.h:49
Vector3< T > c121() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:84
T & rx1()
Reference access to the minimum x extent.
Definition cube.h:162
Cube< T > expandedToInclude(const T &x, const T &y, const T &z) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition cube.h:266
bool operator==(const Cube< T > &c) const
Comparison operator.
Definition cube.h:110
bool operator!=(const Cube< T > &r) const
Comparison operator.
Definition cube.h:115
const Cube< T > & operator-=(const Vector3< T > &v)
Subtracts v from all extent boundaries, effectively translating it.
Definition cube.h:209
Vector3< T > size() const
Returns the size of the extent as a Vector3(width(),height(),depth()).
Definition cube.h:102
const T & y1() const
Returns the lower bound of the extent in the y-direction.
Definition cube.h:45
const T & z2() const
Returns the upper bound of the extent in the y-direction.
Definition cube.h:51
T & rz1()
Reference access to the minimum z extent.
Definition cube.h:166
T & rz2()
Definition cube.h:167
Cube< T > biggerBy(const T &fact) const
Definition cube.h:280
T & ry2()
Reference access to the maximum y extent.
Definition cube.h:165
Cube< T > operator+(const Vector3< T > &v) const
Returns the extent created ty translating this one v units.
Definition cube.h:213
Cube< T > intersectedWith(const Cube< T > &r) const
Returns the extemt formed by the intersections of the two extents. May end up empty.
Definition cube.h:217
T & rx2()
Reference access to the maximum x extent.
Definition cube.h:163
Vector3< T > corner(uint32 x, uint32 y, uint32 z) const
Definition cube.h:70
void c211(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:184
Vector3< T > c111() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:82
void width(const T &t)
Sets the width of the extent by moving the maximum x extent, keeping the minimum constant.
Definition cube.h:174
void c111(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:180
Cube< T > expandedToInclude(const Vector3< T > &v) const
Returns an extent large enough to contain this one and the point v.
Definition cube.h:259
Cube< T > operator-(const Vector3< T > &v) const
Returns the extent created ty translating this one -v units.
Definition cube.h:215
bool tolIsEmpty(const double &tol=limits< double >::epsilon() *100) const
Returns true if the region is "inside out" with a tolerance in any of its three coordinates.
Definition cube.h:108
T depth() const
Returns the size of the extent in the z-direction.
Definition cube.h:61
Vector3< T > lowerBound() const
Returns the lower bounding corner of the extent, minimum value of x,y, and z.
Definition cube.h:98
bool operator>(const Cube< T > &c) const
Comparison operator, based on volume.
Definition cube.h:119
bool intersects(const Cube< T > &c) const
Returns true if the cube C intersects (inclusive) this extent in any way.
Definition cube.h:145
Cube()
Default constructor, no data initialization.
Definition cube.h:21
Vector3< T > c212() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:94
const Cube< T > & center(const Vector3< T > &v)
Centers this rectangle about point v.
Definition cube.h:287
void c221(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:186
void depth(const T &t)
Sets the depth of the extent by moving the maximum z extent, keeping the minimum constant.
Definition cube.h:178
const Cube< T > & expandToInclude(const T &x, const T &y, const T &z)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition cube.h:247
Vector3< T > bound(const Vector3< T > &v) const
Definition cube.h:203
void c212(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:192
bool operator<(const Cube< T > &c) const
Comparison operator, based on volume.
Definition cube.h:117
T diagonal() const
Returns the diagonal length of the extent, or the distance from the lower bound corner to the upper b...
Definition cube.h:67
Vector3< T > c221() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:88
void size(const Vector3< T > &v)
Specifies the size of the extent by moving the upper bound, keeping the lower bound constnat.
Definition cube.h:200
Cube(const Vector3< T > &v111, const Vector3< T > &v222)
Explicit constructor, by providing the lower-bound and upper-bound as two Vector3.
Definition cube.h:26
Vector3< T > c122() const
Returns one of the eith corners that characterize the extent.
Definition cube.h:92
const Cube< T > & expandToInclude(const Cube< T > &r)
Enlarges the extent to include both its original extent and r.
Definition cube.h:225
void lowerBound(const Vector3< T > &v)
Sets the lower bound of the exetnt, keeping the upper bound constant. Synonym to c111().
Definition cube.h:196
bool isIn(const Vector3< T > &v) const
Returns true if Vector3 v is "inside" the extent, inclusive.
Definition cube.h:121
const T & dof2(uint32 dof) const
Returns the upper bound of degree-of-freedom dof.
Definition cube.h:55
bool tolIntersects(const Cube< T > &c, const T &tol) const
Returns true if the cube C intersects (inclusive) this extent in any way with an added tolerance fact...
Definition cube.h:153
bool tolIsIn(const Cube< T > &c, const T &tol) const
Returns true if the Cube c falls completely inside (inclusive) the extent with an added tolerance fac...
Definition cube.h:139
T height() const
Returns the size of the extent in the y-direction.
Definition cube.h:59
void c122(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:190
T & rdof1(uint32 dof)
Reference access to lower bound of degree-of-freedom dof.
Definition cube.h:169
T volume() const
Returns the volume of the extent ( width() * height() * depth() ).
Definition cube.h:65
T & rdof2(uint32 dof)
Reference access to lower bound of degree-of-freedom dof.
Definition cube.h:171
const Cube< T > & expandToInclude(const Vector3< T > &v)
Enlarges the extent to contain v.
Definition cube.h:236
void height(const T &t)
Sets the height of the extent by moving the maximum y extent, keeping the minimum constant.
Definition cube.h:176
void c121(const Vector3< T > &v)
Sets one of the eight characteristic corners of the extent, keeping the other three extents constant.
Definition cube.h:182
const T & y2() const
Returns the upper bound of the extent in the y-direction.
Definition cube.h:47
PUSHWARNING Cube(const Cube< T > &r)
Copy constructor.
Definition cube.h:31
2D cartesian region in space.
Definition extent2.h:12
const T & y1() const
Returns the lower y-bound.
Definition extent2.h:37
const T & y2() const
Returns the upper y-bound.
Definition extent2.h:39
const T & x2() const
Returns the upper x-bound.
Definition extent2.h:35
const T & x1() const
Returns the lower x-bound.
Definition extent2.h:33
3D vector utility class.
Definition vect.h:163
constexpr const T & y() const
The y-component of the vector.
Definition vect.h:186
constexpr const T & x() const
The x-component of the vector.
Definition vect.h:184
constexpr const T & z() const
The z-component of the vector.
Definition vect.h:188
debug checked shorthand for std::numeric_limits<T>::
Definition limit.h:25
const Cube< T > & toCube(const Cube< T > &t)
Returns a cube.
Definition cube.h:324