29 #ifndef WFMATH_AXIS_BOX_FUNCS_H
30 #define WFMATH_AXIS_BOX_FUNCS_H
32 #include <wfmath/axisbox.h>
34 #include <wfmath/point.h>
35 #include <wfmath/ball.h>
40 inline bool AxisBox<dim>::isEqualTo(
const AxisBox<dim>& b,
double epsilon)
const
42 return Equal(m_low, b.m_low, epsilon)
43 &&
Equal(m_high, b.m_high, epsilon);
47 bool Intersection(
const AxisBox<dim>& a1,
const AxisBox<dim>& a2, AxisBox<dim>& out)
49 for(
int i = 0; i < dim; ++i) {
50 out.m_low[i] = FloatMax(a1.m_low[i], a2.m_low[i]);
51 out.m_high[i] = FloatMin(a1.m_high[i], a2.m_high[i]);
52 if(out.m_low[i] > out.m_high[i])
56 out.m_low.setValid(a1.m_low.isValid() && a2.m_low.isValid());
57 out.m_high.setValid(a1.m_high.isValid() && a2.m_high.isValid());
63 AxisBox<dim> Union(
const AxisBox<dim>& a1,
const AxisBox<dim>& a2)
67 for(
int i = 0; i < dim; ++i) {
68 out.m_low[i] = FloatMin(a1.m_low[i], a2.m_low[i]);
69 out.m_high[i] = FloatMax(a1.m_high[i], a2.m_high[i]);
72 out.m_low.setValid(a1.m_low.isValid() && a2.m_low.isValid());
73 out.m_high.setValid(a1.m_high.isValid() && a2.m_high.isValid());
88 for(
int i = 0; i < dim; ++i) {
110 if(i >= (1 << dim) - 1)
115 for(
int j = 0; j < dim; ++j)
116 out[j] = (i & (1 << j)) ? m_high[j] : m_low[j];
118 out.
setValid(m_low.isValid() && m_high.isValid());
124 inline Ball<dim> AxisBox<dim>::boundingSphere()
const
126 return Ball<dim>(getCenter(), Distance(m_low, m_high) / 2);
130 inline Ball<dim> AxisBox<dim>::boundingSphereSloppy()
const
132 return Ball<dim>(getCenter(), SloppyDistance(m_low, m_high) / 2);
136 template<
int dim,
template<
class,
class>
class container>
141 typename container<AxisBox<dim>, std::allocator<AxisBox<dim> > >::const_iterator i = c.begin(), end = c.end();
147 Point<dim> low = i->lowCorner(), high = i->highCorner();
148 bool low_valid = low.isValid(), high_valid = high.isValid();
151 const Point<dim> &new_low = i->lowCorner(), &new_high = i->highCorner();
152 low_valid = low_valid && new_low.isValid();
153 high_valid = high_valid && new_high.isValid();
154 for(
int j = 0; j < dim; ++j) {
155 low[j] = FloatMin(low[j], new_low[j]);
156 high[j] = FloatMax(high[j], new_high[j]);
161 high.setValid(high_valid);
166 template<
int dim,
template<
class,
class>
class container>
169 typename container<Point<dim>, std::allocator<Point<dim> > >::const_iterator i = c.begin(), end = c.end();
176 bool valid = i->isValid();
179 valid = valid && i->isValid();
180 for(
int j = 0; j < dim; ++j) {
181 low[j] = FloatMin(low[j], (*i)[j]);
182 high[j] = FloatMax(high[j], (*i)[j]);
187 high.setValid(valid);
196 inline AxisBox<dim> Point<dim>::boundingBox()
const
198 return AxisBox<dim>(*
this, *
this,
true);
202 Point<dim> Point<dim>::toParentCoords(
const AxisBox<dim>& coords)
const
204 return coords.
lowCorner() + (*
this - Point().setToOrigin());
208 Point<dim> Point<dim>::toLocalCoords(
const AxisBox<dim>& coords)
const
210 return Point().setToOrigin() + (*
this - coords.lowCorner());
215 #endif // WFMATH_AXIS_BOX_FUNCS_H