/usr/include/wfmath-1.0/wfmath/point.h is in libwfmath-1.0-dev 1.0.2+dfsg1-0.3.
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | // point.h (point class copied from libCoal, subsequently modified)
//
// The WorldForge Project
// Copyright (C) 2000, 2001, 2002 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_POINT_H
#define WFMATH_POINT_H
#include <wfmath/const.h>
#include <memory>
#include <iosfwd>
#include <cmath>
namespace WFMath {
template<int dim>
Point<dim>& operator+=(Point<dim>& p, const Vector<dim>& v);
template<int dim>
Point<dim>& operator-=(Point<dim>& p, const Vector<dim>& v);
template<int dim>
Vector<dim> operator-(const Point<dim>& c1, const Point<dim>& c2);
template<int dim>
Point<dim> operator+(const Point<dim>& c, const Vector<dim>& v);
template<int dim>
Point<dim> operator+(const Vector<dim>& v, const Point<dim>& c);
template<int dim>
Point<dim> operator-(const Point<dim>& c, const Vector<dim>& v);
template<int dim>
CoordType SquaredDistance(const Point<dim>& p1, const Point<dim>& p2);
template<int dim>
CoordType Distance(const Point<dim>& p1, const Point<dim>& p2)
{return std::sqrt(SquaredDistance(p1, p2));}
template<int dim>
CoordType SloppyDistance(const Point<dim>& p1, const Point<dim>& p2)
{return (p1 - p2).sloppyMag();}
/// Find the center of a set of points, all weighted equally
template<int dim, template<class, class> class container>
Point<dim> Barycenter(const container<Point<dim>, std::allocator<Point<dim> > >& c);
/// Find the center of a set of points with the given weights
/**
* If the number of points and the number of weights are not equal,
* the excess of either is ignored. The weights (or that subset
* which is used, if there are more weights than points), must not
* sum to zero.
**/
template<int dim, template<class, class> class container,
template<class, class> class container2>
Point<dim> Barycenter(const container<Point<dim>, std::allocator<Point<dim> > >& c,
const container2<CoordType, std::allocator<CoordType> >& weights);
// This is used a couple of places in the library
template<int dim>
Point<dim> Midpoint(const Point<dim>& p1, const Point<dim>& p2,
CoordType dist = 0.5);
template<int dim>
std::ostream& operator<<(std::ostream& os, const Point<dim>& m);
template<int dim>
std::istream& operator>>(std::istream& is, Point<dim>& m);
template<typename Shape>
class ZeroPrimitive;
/// A dim dimensional point
/**
* This class implements the full shape interface, as described in
* the fake class Shape.
**/
template<int dim = 3>
class Point
{
friend class ZeroPrimitive<Point<dim> >;
public:
/// Construct an uninitialized point
Point () : m_valid(false) {}
/// Construct a copy of a point
Point (const Point& p);
/// Construct a point from an object passed by Atlas
explicit Point (const AtlasInType& a);
/// Construct a point from a vector.
explicit Point(const Vector<dim>& vector);
/**
* @brief Provides a global instance preset to zero.
*/
static const Point<dim>& ZERO();
friend std::ostream& operator<< <dim>(std::ostream& os, const Point& p);
friend std::istream& operator>> <dim>(std::istream& is, Point& p);
/// Create an Atlas object from the point
AtlasOutType toAtlas() const;
/// Set the point's value to that given by an Atlas object
void fromAtlas(const AtlasInType& a);
Point& operator= (const Point& rhs);
bool isEqualTo(const Point &p, CoordType epsilon = numeric_constants<CoordType>::epsilon()) const;
bool operator== (const Point& rhs) const {return isEqualTo(rhs);}
bool operator!= (const Point& rhs) const {return !isEqualTo(rhs);}
bool isValid() const {return m_valid;}
/// make isValid() return true if you've initialized the point by hand
void setValid(bool valid = true) {m_valid = valid;}
/// Set point to (0,0,...,0)
Point& setToOrigin();
// Operators
// Documented in vector.h
friend Vector<dim> operator-<dim>(const Point& c1, const Point& c2);
friend Point operator+<dim>(const Point& c, const Vector<dim>& v);
friend Point operator-<dim>(const Point& c, const Vector<dim>& v);
friend Point operator+<dim>(const Vector<dim>& v, const Point& c);
friend Point& operator+=<dim>(Point& p, const Vector<dim>& rhs);
friend Point& operator-=<dim>(Point& p, const Vector<dim>& rhs);
/// Rotate about point p
Point& rotate(const RotMatrix<dim>& m, const Point& p)
{return (*this = p + Prod(*this - p, m));}
// Functions so that Point<> has the generic shape interface
size_t numCorners() const {return 1;}
Point<dim> getCorner(size_t) const { return *this;}
Point<dim> getCenter() const {return *this;}
Point shift(const Vector<dim>& v) {return *this += v;}
Point moveCornerTo(const Point& p, size_t)
{return operator=(p);}
Point moveCenterTo(const Point& p) {return operator=(p);}
Point& rotateCorner(const RotMatrix<dim>&, size_t)
{return *this;}
Point& rotateCenter(const RotMatrix<dim>&) {return *this;}
Point& rotatePoint(const RotMatrix<dim>& m, const Point& p) {return rotate(m, p);}
// 3D rotation functions
Point& rotate(const Quaternion& q, const Point& p);
Point& rotateCorner(const Quaternion&, size_t)
{ return *this;}
Point& rotateCenter(const Quaternion&) {return *this;}
Point& rotatePoint(const Quaternion& q, const Point& p);
// The implementations of these lie in axisbox_funcs.h and
// ball_funcs.h, to reduce include dependencies
AxisBox<dim> boundingBox() const;
Ball<dim> boundingSphere() const;
Ball<dim> boundingSphereSloppy() const;
Point toParentCoords(const Point& origin,
const RotMatrix<dim>& rotation = RotMatrix<dim>().identity()) const
{return origin + (*this - Point().setToOrigin()) * rotation;}
Point toParentCoords(const AxisBox<dim>& coords) const;
Point toParentCoords(const RotBox<dim>& coords) const;
// toLocal is just like toParent, expect we reverse the order of
// translation and rotation and use the opposite sense of the rotation
// matrix
Point toLocalCoords(const Point& origin,
const RotMatrix<dim>& rotation = RotMatrix<dim>().identity()) const
{return Point().setToOrigin() + rotation * (*this - origin);}
Point toLocalCoords(const AxisBox<dim>& coords) const;
Point toLocalCoords(const RotBox<dim>& coords) const;
// 3D only
Point toParentCoords(const Point& origin, const Quaternion& rotation) const;
Point toLocalCoords(const Point& origin, const Quaternion& rotation) const;
// Member access
/// Access the i'th coordinate of the point
CoordType operator[](const int i) const {return m_elem[i];}
/// Access the i'th coordinate of the point
CoordType& operator[](const int i) {return m_elem[i];}
/// Get the square of the distance from p1 to p2
friend CoordType SquaredDistance<dim>(const Point& p1, const Point& p2);
// FIXME instatiation problem when declared as friend
// template<template<class> class container>
// friend Point Barycenter(const container<Point>& c);
/// Find a point on the line containing p1 and p2, by default the midpoint
/**
* The default value of 0.5 for dist gives the midpoint. A value of 0 gives
* p1, and 1 gives p2. Values of dist outside the [0, 1] range are allowed,
* and give points on the line which are not on the segment bounded by
* p1 and p2.
**/
friend Point<dim> Midpoint<dim>(const Point& p1, const Point& p2, CoordType dist);
// 2D/3D stuff
/// 2D only: construct a point from its (x, y) coordinates
Point (CoordType x, CoordType y); // 2D only
/// 3D only: construct a point from its (x, y, z) coordinates
Point (CoordType x, CoordType y, CoordType z); // 3D only
// Label the first three components of the vector as (x,y,z) for
// 2D/3D convienience
/// access the first component of a point
CoordType x() const {return m_elem[0];}
/// access the first component of a point
CoordType& x() {return m_elem[0];}
/// access the second component of a point
CoordType y() const {return m_elem[1];}
/// access the second component of a point
CoordType& y() {return m_elem[1];}
/// access the third component of a point
CoordType z() const;
/// access the third component of a point
CoordType& z();
/// 2D only: construct a vector from polar coordinates
Point& polar(CoordType r, CoordType theta);
/// 2D only: convert a vector to polar coordinates
void asPolar(CoordType& r, CoordType& theta) const;
/// 3D only: construct a vector from polar coordinates
Point& polar(CoordType r, CoordType theta, CoordType z);
/// 3D only: convert a vector to polar coordinates
void asPolar(CoordType& r, CoordType& theta, CoordType& z) const;
/// 3D only: construct a vector from spherical coordinates
Point& spherical(CoordType r, CoordType theta, CoordType phi);
/// 3D only: convert a vector to spherical coordinates
void asSpherical(CoordType& r, CoordType& theta, CoordType& phi) const;
const CoordType* elements() const {return m_elem;}
private:
CoordType m_elem[dim];
bool m_valid;
};
template<>
inline CoordType Point<3>::z() const
{
return m_elem[2];
}
template<>
inline CoordType& Point<3>::z()
{
return m_elem[2];
}
template<int dim>
inline Point<dim> operator+(const Point<dim>& c, const Vector<dim>& v)
{
Point<dim> out(c);
out += v;
return out;
}
template<int dim>
inline Point<dim> operator+(const Vector<dim>& v, const Point<dim>& c)
{
Point<dim> out(c);
out += v;
return out;
}
template<int dim>
inline Point<dim> operator-(const Point<dim>& c, const Vector<dim>& v)
{
Point<dim> out(c);
out -= v;
return out;
}
template<>
inline Point<2>::Point(CoordType x, CoordType y) : m_valid(true)
{
m_elem[0] = x;
m_elem[1] = y;
}
template<>
inline Point<3>::Point(CoordType x, CoordType y, CoordType z) : m_valid(true)
{
m_elem[0] = x;
m_elem[1] = y;
m_elem[2] = z;
}
} // namespace WFMath
#endif // WFMATH_POINT_H
|