26 #ifndef WFMATH_BALL_FUNCS_H
27 #define WFMATH_BALL_FUNCS_H
29 #include <wfmath/ball.h>
31 #include <wfmath/axisbox.h>
32 #include <wfmath/miniball.h>
39 AxisBox<dim> Ball<dim>::boundingBox()
const
41 Point<dim> p_low, p_high;
43 for(
int i = 0; i < dim; ++i) {
44 p_low[i] = m_center[i] - m_radius;
45 p_high[i] = m_center[i] + m_radius;
48 bool valid = m_center.isValid();
50 p_low.setValid(valid);
51 p_high.setValid(valid);
53 return AxisBox<dim>(p_low, p_high,
true);
56 template<
int dim,
template<
class,
class>
class container>
59 _miniball::Miniball<dim> m;
60 _miniball::Wrapped_array<dim> w;
62 typename container<Point<dim>, std::allocator<Point<dim> > >::const_iterator i, end = c.end();
65 for(i = c.begin(); i != end; ++i) {
66 valid = valid && i->isValid();
67 for(
int j = 0; j < dim; ++j)
77 assert(
"Check that bounding sphere is good to library accuracy" &&
78 m.accuracy(dummy) < numeric_constants<CoordType>::epsilon());
83 for(
int j = 0; j < dim; ++j)
88 return Ball<dim>(center, std::sqrt(m.squared_radius()));
91 template<
int dim,
template<
class,
class>
class container>
98 typename container<Point<dim>, std::allocator<Point<dim> > >::const_iterator i = c.begin(),
105 typename container<Point<dim>, std::allocator<Point<dim> > >::const_iterator min_p[dim], max_p[dim];
106 bool valid = i->isValid();
108 for(
int j = 0; j < dim; ++j) {
109 min[j] = max[j] = (*i)[j];
110 min_p[j] = max_p[j] = i;
114 valid = valid && i->isValid();
115 for(
int j = 0; j < dim; ++j) {
116 if(min[j] > (*i)[j]) {
120 if(max[j] < (*i)[j]) {
130 for(
int j = 0; j < dim; ++j) {
132 if(new_span > span) {
138 assert(
"Have a direction of maximum size" && direction != -1);
141 CoordType dist = SloppyDistance(*(min_p[direction]), center);
143 for(i = c.begin(); i != end; ++i) {
144 if(i == min_p[direction] || i == max_p[direction])
147 CoordType new_dist = SloppyDistance(*i, center);
149 if(new_dist > dist) {
150 CoordType delta_dist = (new_dist - dist) / 2;
153 center += (*i - center) * delta_dist / new_dist;
155 assert(
"Shifted ball contains new point" &&
156 SquaredDistance(*i, center) <= dist * dist);
169 inline Ball<dim> Point<dim>::boundingSphere()
const
171 return Ball<dim>(*
this, 0);
175 inline Ball<dim> Point<dim>::boundingSphereSloppy()
const
177 return Ball<dim>(*
this, 0);
182 #endif // WFMATH_BALL_FUNCS_H