/usr/include/wfmath-0.3/wfmath/ball_funcs.h is in libwfmath-0.3-dev 0.3.12-3ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | // ball_funcs.h (n-dimensional ball implementation)
//
// The WorldForge Project
// Copyright (C) 2000, 2001 The WorldForge Project
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// For information about WorldForge and its authors, please contact
// the Worldforge Web Site at http://www.worldforge.org.
//
// Author: Ron Steinke
#ifndef WFMATH_BALL_FUNCS_H
#define WFMATH_BALL_FUNCS_H
#include <wfmath/ball.h>
#include <wfmath/axisbox.h>
#include <wfmath/miniball.h>
#include <cassert>
namespace WFMath {
template<int dim>
inline bool Ball<dim>::isEqualTo(const Ball<dim>& b, double epsilon) const
{
return Equal(m_center, b.m_center, epsilon)
&& Equal(m_radius, b.m_radius, epsilon);
}
template<int dim>
AxisBox<dim> Ball<dim>::boundingBox() const
{
Point<dim> p_low, p_high;
for(int i = 0; i < dim; ++i) {
p_low[i] = m_center[i] - m_radius;
p_high[i] = m_center[i] + m_radius;
}
bool valid = m_center.isValid();
p_low.setValid(valid);
p_high.setValid(valid);
return AxisBox<dim>(p_low, p_high, true);
}
template<int dim, template<class, class> class container>
Ball<dim> BoundingSphere(const container<Point<dim>, std::allocator<Point<dim> > >& c)
{
_miniball::Miniball<dim> m;
_miniball::Wrapped_array<dim> w;
typename container<Point<dim>, std::allocator<Point<dim> > >::const_iterator i, end = c.end();
bool valid = true;
for(i = c.begin(); i != end; ++i) {
valid = valid && i->isValid();
for(int j = 0; j < dim; ++j)
w[j] = (*i)[j];
m.check_in(w);
}
m.build();
#ifndef NDEBUG
double dummy;
#endif
assert("Check that bounding sphere is good to library accuracy" &&
m.accuracy(dummy) < WFMATH_EPSILON);
w = m.center();
Point<dim> center;
for(int j = 0; j < dim; ++j)
center[j] = w[j];
center.setValid(valid);
return Ball<dim>(center, std::sqrt(m.squared_radius()));
}
template<int dim, template<class, class> class container>
Ball<dim> BoundingSphereSloppy(const container<Point<dim>, std::allocator<Point<dim> > >& c)
{
// This is based on the algorithm given by Jack Ritter
// in Volume 2, Number 4 of Ray Tracing News
// <http://www.acm.org/tog/resources/RTNews/html/rtnews7b.html>
typename container<Point<dim>, std::allocator<Point<dim> > >::const_iterator i = c.begin(),
end = c.end();
if (i == end) {
return Ball<dim>();
}
CoordType min[dim], max[dim];
typename container<Point<dim>, std::allocator<Point<dim> > >::const_iterator min_p[dim], max_p[dim];
bool valid = i->isValid();
for(int j = 0; j < dim; ++j) {
min[j] = max[j] = (*i)[j];
min_p[j] = max_p[j] = i;
}
while(++i != end) {
valid = valid && i->isValid();
for(int j = 0; j < dim; ++j) {
if(min[j] > (*i)[j]) {
min[j] = (*i)[j];
min_p[j] = i;
}
if(max[j] < (*i)[j]) {
max[j] = (*i)[j];
max_p[j] = i;
}
}
}
CoordType span = -1;
int direction = -1;
for(int j = 0; j < dim; ++j) {
CoordType new_span = max[j] - min[j];
if(new_span > span) {
span = new_span;
direction = j;
}
}
assert("Have a direction of maximum size" && direction != -1);
Point<dim> center = Midpoint(*(min_p[direction]), *(max_p[direction]));
CoordType dist = SloppyDistance(*(min_p[direction]), center);
for(i = c.begin(); i != end; ++i) {
if(i == min_p[direction] || i == max_p[direction])
continue; // We already have these
CoordType new_dist = SloppyDistance(*i, center);
if(new_dist > dist) {
CoordType delta_dist = (new_dist - dist) / 2;
// Even though new_dist may be too large, delta_dist / new_dist
// always gives enough of a shift to include the new point.
center += (*i - center) * delta_dist / new_dist;
dist += delta_dist;
assert("Shifted ball contains new point" &&
SquaredDistance(*i, center) <= dist * dist);
}
}
center.setValid(valid);
return Ball<2>(center, dist);
}
// These two are here, instead of defined in the class, to
// avoid include order problems
template<int dim>
inline Ball<dim> Point<dim>::boundingSphere() const
{
return Ball<dim>(*this, 0);
}
template<int dim>
inline Ball<dim> Point<dim>::boundingSphereSloppy() const
{
return Ball<dim>(*this, 0);
}
} // namespace WFMath
#endif // WFMATH_BALL_FUNCS_H
|