26 #ifndef WFMATH_ROT_BOX_H 27 #define WFMATH_ROT_BOX_H 29 #include <wfmath/point.h> 30 #include <wfmath/rotmatrix.h> 31 #include <wfmath/intersect_decls.h> 36 std::ostream& operator<<(std::ostream& os, const RotBox<dim>& r);
38 std::istream& operator>>(std::istream& is, RotBox<dim>& r);
50 RotBox() : m_corner0(), m_size(), m_orient() {}
59 m_orient(orientation) {}
61 RotBox(
const RotBox& b) : m_corner0(b.m_corner0), m_size(b.m_size),
62 m_orient(b.m_orient) {}
64 explicit RotBox(
const AtlasInType& a);
73 friend std::ostream& operator<< <dim>(std::ostream& os,
const RotBox& r);
74 friend std::istream&
operator>> <dim>(std::istream& is,
RotBox& r);
78 bool isEqualTo(
const RotBox& b,
CoordType epsilon = numeric_constants<CoordType>::epsilon())
const;
80 bool operator==(
const RotBox& b)
const {
return isEqualTo(b);}
81 bool operator!=(
const RotBox& b)
const {
return !isEqualTo(b);}
83 bool isValid()
const {
return m_corner0.isValid() && m_size.isValid()
84 && m_orient.isValid();}
88 size_t numCorners()
const {
return 1 << dim;}
90 Point<dim> getCenter()
const {
return m_corner0 +
Prod(m_size / 2, m_orient);}
108 {m_corner0 += v;
return *
this;}
110 {
return shift(p - getCorner(corner));}
112 {
return shift(p - getCenter());}
115 {rotatePoint(m, getCorner(corner));
return *
this;}
117 {rotatePoint(m, getCenter());
return *
this;}
119 {m_orient =
Prod(m_orient, m); m_corner0.rotate(m, p);
return *
this;}
130 {
return Ball<dim>(getCenter(), m_size.mag() / 2);}
132 {
return Ball<dim>(getCenter(), m_size.sqrMag() / 2);}
136 {
return RotBox(m_corner0.toParentCoords(origin, rotation), m_size,
137 m_orient * rotation);}
139 {
return RotBox(m_corner0.toParentCoords(coords), m_size, m_orient);}
141 {
return RotBox(m_corner0.toParentCoords(coords), m_size,
142 m_orient * coords.m_orient);}
150 {
return RotBox(m_corner0.toLocalCoords(origin, rotation), m_size,
151 rotation * m_orient);}
153 {
return RotBox(m_corner0.toLocalCoords(coords), m_size, m_orient);}
155 {
return RotBox(m_corner0.toLocalCoords(coords), m_size,
156 coords.m_orient * m_orient);}
162 friend bool Intersect<dim>(
const RotBox& r,
const Point<dim>& p,
bool proper);
163 friend bool Contains<dim>(
const Point<dim>& p,
const RotBox& r,
bool proper);
169 friend bool Intersect<dim>(
const RotBox& r,
const Ball<dim>& b,
bool proper);
170 friend bool Contains<dim>(
const RotBox& r,
const Ball<dim>& b,
bool proper);
171 friend bool Contains<dim>(
const Ball<dim>& b,
const RotBox& r,
bool proper);
177 friend bool Intersect<dim>(
const RotBox& r1,
const RotBox& r2,
bool proper);
178 friend bool Contains<dim>(
const RotBox& outer,
const RotBox& inner,
bool proper);
194 m_corner0 = a.m_corner0;
196 m_orient = a.m_orient;
204 return Equal(m_corner0, b.m_corner0, epsilon)
205 &&
Equal(m_size, b.m_size, epsilon)
206 &&
Equal(m_orient, b.m_orient, epsilon);
211 #endif // WFMATH_ROT_BOX_H bool Equal(const C &c1, const C &c2, CoordType epsilon=numeric_constants< CoordType >::epsilon())
Test for equality up to precision epsilon.
Definition: const.h:158
Generic library namespace.
Definition: atlasconv.h:45
const Vector< dim > & size() const
returns the size of the box
Definition: rotbox.h:97
A dim dimensional axis-aligned box.
Definition: axisbox.h:62
const Point< dim > & corner0() const
returns the base corner of the box
Definition: rotbox.h:93
RotBox()
construct an uninitialized box
Definition: rotbox.h:50
void fromAtlas(const AtlasInType &a)
Set the box's value to that given by an Atlas object.
Definition: atlasconv.h:409
RotMatrix< dim > & orientation()
returns the orientation of the box
Definition: rotbox.h:103
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
Definition: const.h:53
A dim dimensional box, lying at an arbitrary angle.
Definition: const.h:52
Vector< dim > & size()
returns the size of the box
Definition: rotbox.h:99
A polygon, all of whose points lie in a plane, embedded in dim dimensions.
Definition: const.h:51
RotBox(const Point< dim > &p, const Vector< dim > &size, const RotMatrix< dim > &orientation)
construct a box from the given parameters
Definition: rotbox.h:57
RotBox(const RotBox &b)
construct a copy of the box
Definition: rotbox.h:61
A dim dimensional vector.
Definition: const.h:55
const RotMatrix< dim > & orientation() const
returns the orientation of the box
Definition: rotbox.h:101
float CoordType
Basic floating point type.
Definition: const.h:140
A line segment embedded in dim dimensions.
Definition: const.h:54
AtlasOutType toAtlas() const
Create an Atlas object from the box.
Definition: atlasconv.h:437
Point< dim > & corner0()
returns the base corner of the box
Definition: rotbox.h:95
A normalized quaterion.
Definition: quaternion.h:35
RotMatrix< dim > Prod(const RotMatrix< dim > &m1, const RotMatrix< dim > &m2)
returns m1 * m2
Definition: rotmatrix_funcs.h:89
A dim dimensional point.
Definition: const.h:50
A dim dimensional ball.
Definition: ball.h:34