29 #ifndef WFMATH_AXIS_BOX_H 30 #define WFMATH_AXIS_BOX_H 32 #include <wfmath/intersect_decls.h> 39 bool Intersection(
const AxisBox<dim>& a1,
const AxisBox<dim>& a2, AxisBox<dim>& out);
41 AxisBox<dim> Union(
const AxisBox<dim>& a1,
const AxisBox<dim>& a2);
44 std::ostream& operator<<(std::ostream& os, const AxisBox<dim>& m);
46 std::istream& operator>>(std::istream& is, AxisBox<dim>& m);
49 template<
int dim,
template<
class,
class>
class container>
50 AxisBox<dim>
BoundingBox(
const container<AxisBox<dim>, std::allocator<AxisBox<dim> > >& c);
53 template<
int dim,
template<
class,
class>
class container>
54 AxisBox<dim>
BoundingBox(
const container<Point<dim>, std::allocator<Point<dim> > >& c);
74 explicit AxisBox(
const AtlasInType& a);
76 friend std::ostream& operator<< <dim>(std::ostream& os,
const AxisBox& a);
77 friend std::istream&
operator>> <dim>(std::istream& is,
AxisBox& a);
85 {m_low = a.m_low; m_high = a.m_high;
return *
this;}
87 bool isEqualTo(
const AxisBox& b,
CoordType epsilon = numeric_constants<CoordType>::epsilon())
const;
88 bool operator==(
const AxisBox& a)
const {
return isEqualTo(a);}
89 bool operator!=(
const AxisBox& a)
const {
return !isEqualTo(a);}
91 bool isValid()
const {
return m_low.isValid() && m_high.isValid();}
95 size_t numCorners()
const {
return 1 << dim;}
96 Point<dim> getCorner(
size_t i)
const;
97 Point<dim> getCenter()
const {
return Midpoint(m_low, m_high);}
118 bool ordered =
false);
123 {m_low += v; m_high += v;
return *
this;}
124 AxisBox& moveCornerTo(
const Point<dim>& p,
size_t corner)
125 {
return shift(p - getCorner(corner));}
126 AxisBox& moveCenterTo(
const Point<dim>& p)
127 {
return shift(p - getCenter());}
133 AxisBox boundingBox()
const {
return *
this;}
134 Ball<dim> boundingSphere()
const;
135 Ball<dim> boundingSphereSloppy()
const;
137 AxisBox toParentCoords(
const Point<dim>& origin)
const 138 {
return AxisBox(m_low.toParentCoords(origin), m_high.toParentCoords(origin),
true);}
139 AxisBox toParentCoords(
const AxisBox<dim>& coords)
const 140 {
return AxisBox(m_low.toParentCoords(coords), m_high.toParentCoords(coords),
true);}
146 AxisBox toLocalCoords(
const Point<dim>& origin)
const 147 {
return AxisBox(m_low.toLocalCoords(origin), m_high.toLocalCoords(origin),
true);}
148 AxisBox toLocalCoords(
const AxisBox<dim>& coords)
const 149 {
return AxisBox(m_low.toLocalCoords(coords), m_high.toLocalCoords(coords),
true);}
156 friend bool Intersect<dim>(
const AxisBox& b,
const Point<dim>& p,
bool proper);
157 friend bool Contains<dim>(
const Point<dim>& p,
const AxisBox& b,
bool proper);
159 friend bool Intersect<dim>(
const AxisBox& b1,
const AxisBox& b2,
bool proper);
160 friend bool Contains<dim>(
const AxisBox& outer,
const AxisBox& inner,
bool proper);
162 friend bool Intersect<dim>(
const Ball<dim>& b,
const AxisBox& a,
bool proper);
163 friend bool Contains<dim>(
const Ball<dim>& b,
const AxisBox& a,
bool proper);
164 friend bool Contains<dim>(
const AxisBox& a,
const Ball<dim>& b,
bool proper);
166 friend bool Intersect<dim>(
const Segment<dim>& s,
const AxisBox& b,
bool proper);
167 friend bool Contains<dim>(
const Segment<dim>& s,
const AxisBox& b,
bool proper);
169 friend bool Intersect<dim>(
const RotBox<dim>& r,
const AxisBox& b,
bool proper);
170 friend bool Contains<dim>(
const RotBox<dim>& r,
const AxisBox& b,
bool proper);
171 friend bool Contains<dim>(
const AxisBox& b,
const RotBox<dim>& r,
bool proper);
173 friend bool Intersect<dim>(
const Polygon<dim>& p,
const AxisBox& b,
bool proper);
174 friend bool Contains<dim>(
const Polygon<dim>& p,
const AxisBox& b,
bool proper);
175 friend bool Contains<dim>(
const AxisBox& b,
const Polygon<dim>& p,
bool proper);
179 Point<dim> m_low, m_high;
183 inline bool AxisBox<dim>::isEqualTo(
const AxisBox<dim>& b,
CoordType epsilon)
const 185 return Equal(m_low, b.m_low, epsilon)
186 &&
Equal(m_high, b.m_high, epsilon);
191 #endif // WFMATH_AXIS_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
AxisBox(const Point< dim > &p1, const Point< dim > &p2, bool ordered=false)
Construct a box with opposite corners p1 and p2.
Definition: axisbox.h:68
Generic library namespace.
Definition: atlasconv.h:45
const Point< dim > & lowCorner() const
Get a reference to corner 0.
Definition: axisbox.h:100
A dim dimensional axis-aligned box.
Definition: axisbox.h:62
CoordType upperBound(const int axis) const
Get the upper bound of the box on the i'th axis.
Definition: axisbox.h:109
AtlasOutType toAtlas() const
Create an Atlas object from the box.
Definition: atlasconv.h:225
AxisBox & setCorners(const Point< dim > &p1, const Point< dim > &p2, bool ordered=false)
Set the box to have opposite corners p1 and p2.
Definition: axisbox_funcs.h:72
AxisBox(const AxisBox &a)
Construct a copy of a box.
Definition: axisbox.h:72
Point< dim > Midpoint(const Point< dim > &p1, const Point< dim > &p2, CoordType dist=0.5)
Definition: point_funcs.h:240
A dim dimensional vector.
Definition: const.h:55
const Point< dim > & highCorner() const
Get a reference to corner (2^dim)-1.
Definition: axisbox.h:103
float CoordType
Basic floating point type.
Definition: const.h:140
CoordType lowerBound(const int axis) const
Get the lower bound of the box on the i'th axis.
Definition: axisbox.h:107
AxisBox()
Construct an uninitialized box.
Definition: axisbox.h:66
void fromAtlas(const AtlasInType &a)
Set the box's value to that given by an Atlas object.
Definition: atlasconv.h:191
A dim dimensional point.
Definition: const.h:50
AxisBox< dim > BoundingBox(const container< AxisBox< dim >, std::allocator< AxisBox< dim > > > &c)
Get the axis-aligned bounding box for a set of boxes.
Definition: axisbox_funcs.h:130