/usr/include/dolfin/geometry/Point.h is in libdolfin-dev 1.4.0+dfsg-4.
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | // Copyright (C) 2006-2014 Anders Logg
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// Modified by Garth N. Wells, 2006.
// Modified by Andre Massing, 2009.
//
// First added: 2006-06-12
// Last changed: 2014-01-06
#ifndef __POINT_H
#define __POINT_H
#include <cmath>
#include <iostream>
#include <dolfin/log/log.h>
namespace dolfin
{
/// A Point represents a point in :math:`\mathbb{R}^3` with
/// coordinates :math:`x, y, z,` or alternatively, a vector in
/// :math:`\mathbb{R}^3`, supporting standard operations like the
/// norm, distances, scalar and vector products etc.
class Point
{
public:
/// Create a point at (x, y, z). Default value (0, 0, 0).
///
/// *Arguments*
/// x (double)
/// The x-coordinate.
/// y (double)
/// The y-coordinate.
/// z (double)
/// The z-coordinate.
Point(const double x=0.0, const double y=0.0, const double z=0.0)
{ _x[0] = x; _x[1] = y; _x[2] = z; }
/// Create point from array
///
/// *Arguments*
/// dim (std::size_t)
/// Dimension of the array.
/// x (double)
/// The array to create a Point from.
Point(std::size_t dim, const double* x)
{ for (std::size_t i = 0; i < 3; i++) _x[i] = (i < dim ? x[i] : 0.0); }
/// Copy constructor
///
/// *Arguments*
/// p (_Point_)
/// The object to be copied.
Point(const Point& p)
{ _x[0] = p._x[0]; _x[1] = p._x[1]; _x[2] = p._x[2]; }
/// Destructor
~Point() {}
/// Return address of coordinate in direction i
///
/// *Arguments*
/// i (std::size_t)
/// Direction.
///
/// *Returns*
/// double
/// Adress of coordinate in the given direction.
double& operator[] (std::size_t i)
{ dolfin_assert(i < 3); return _x[i]; }
/// Return coordinate in direction i
///
/// *Arguments*
/// i (std::size_t)
/// Direction.
///
/// *Returns*
/// double
/// The coordinate in the given direction.
double operator[] (std::size_t i) const
{ dolfin_assert(i < 3); return _x[i]; }
/// Return x-coordinate
///
/// *Returns*
/// double
/// The x-coordinate.
double x() const
{ return _x[0]; }
/// Return y-coordinate
///
/// *Returns*
/// double
/// The y-coordinate.
double y() const
{ return _x[1]; }
/// Return z-coordinate
///
/// *Returns*
/// double
/// The z-coordinate.
double z() const
{ return _x[2]; }
/// Return coordinate array
///
/// *Returns*
/// list of doubles
/// The coordinates.
double* coordinates()
{ return _x; }
/// Return coordinate array (const. version)
///
/// *Returns*
/// list of doubles
/// The coordinates.
const double* coordinates() const
{ return _x; }
/// Compute sum of two points
Point operator+ (const Point& p) const
{ Point q(_x[0] + p._x[0], _x[1] + p._x[1], _x[2] + p._x[2]); return q; }
/// Compute difference of two points
Point operator- (const Point& p) const
{ Point q(_x[0] - p._x[0], _x[1] - p._x[1], _x[2] - p._x[2]); return q; }
/// Add given point
const Point& operator+= (const Point& p)
{ _x[0] += p._x[0]; _x[1] += p._x[1]; _x[2] += p._x[2]; return *this; }
/// Subtract given point
const Point& operator-= (const Point& p)
{ _x[0] -= p._x[0]; _x[1] -= p._x[1]; _x[2] -= p._x[2]; return *this; }
/// Unary minus
Point operator- ()
{ Point p(-_x[0], -_x[1], -_x[2]); return p; }
/// Multiplication with scalar
Point operator* (double a) const
{ Point p(a*_x[0], a*_x[1], a*_x[2]); return p; }
/// Incremental multiplication with scalar
const Point& operator*= (double a)
{ _x[0] *= a; _x[1] *= a; _x[2] *= a; return *this; }
/// Division by scalar
Point operator/ (double a) const
{ Point p(_x[0]/a, _x[1]/a, _x[2]/a); return p; }
/// Incremental division by scalar
const Point& operator/= (double a)
{ _x[0] /= a; _x[1] /= a; _x[2] /= a; return *this; }
/// Assignment operator
const Point& operator= (const Point& p)
{ _x[0] = p._x[0]; _x[1] = p._x[1]; _x[2] = p._x[2]; return *this; }
/// Compute squared distance to given point
///
/// *Arguments*
/// p (_Point_)
/// The point to compute distance to.
///
/// *Returns*
/// double
/// The squared distance.
///
/// *Example*
/// .. code-block:: c++
///
/// Point p1(0, 4, 0);
/// Point p2(2, 0, 4);
/// info("%g", p1.squared_distance(p2));
///
/// output::
///
/// 6
double squared_distance(const Point& p) const;
/// Compute distance to given point
///
/// *Arguments*
/// p (_Point_)
/// The point to compute distance to.
///
/// *Returns*
/// double
/// The distance.
///
/// *Example*
/// .. code-block:: c++
///
/// Point p1(0, 4, 0);
/// Point p2(2, 0, 4);
/// info("%g", p1.distance(p2));
///
/// output::
///
/// 6
inline double distance(const Point& p) const
{ return sqrt(squared_distance(p)); }
/// Compute norm of point representing a vector from the origin
///
/// *Returns*
/// double
/// The (Euclidean) norm of the vector from the origin to
/// the point.
///
/// *Example*
/// .. code-block:: c++
///
/// Point p(1.0, 2.0, 2.0);
/// info("%g", p.norm());
///
/// output::
///
/// 3
double norm() const
{
return std::sqrt(_x[0]*_x[0] + _x[1]*_x[1] + _x[2]*_x[2]);
}
/// Compute norm of point representing a vector from the origin
///
/// *Returns*
/// double
/// The squared (Euclidean) norm of the vector from the
/// origin of the point.
///
/// *Example*
/// .. code-block:: c++
///
/// Point p(1.0, 2.0, 2.0);
/// info("%g", p.squared_norm());
///
/// output::
///
/// 9
double squared_norm() const
{
return _x[0]*_x[0] + _x[1]*_x[1] + _x[2]*_x[2];
}
/// Compute cross product with given vector
///
/// *Arguments*
/// p (_Point_)
/// Another point.
///
/// *Returns*
/// Point
/// The cross product.
const Point cross(const Point& p) const;
/// Compute dot product with given vector
///
/// *Arguments*
/// p (_Point_)
/// Another point.
///
/// *Returns*
/// double
/// The dot product.
///
/// *Example*
/// .. code-block:: c++
///
/// Point p1(1.0, 4.0, 8.0);
/// Point p2(2.0, 0.0, 0.0);
/// info("%g", p1.dot(p2));
///
/// output::
///
/// 2
double dot(const Point& p) const;
/// Rotate around a given axis
///
/// *Arguments*
/// a (_Point_)
/// The axis to rotate around. Must be unit length.
/// theta (_double_)
/// The rotation angle.
///
/// *Returns*
/// Point
/// The rotated point.
Point rotate(const Point& a, double theta) const;
// Note: Not a subclass of Variable for efficiency!
/// Return informal string representation (pretty-print)
///
/// *Arguments*
/// verbose (bool)
/// Flag to turn on additional output.
///
/// *Returns*
/// std::string
/// An informal representation of the function space.
std::string str(bool verbose=false) const;
private:
double _x[3];
};
/// Multiplication with scalar
inline Point operator*(double a, const Point& p)
{ return p*a; }
inline std::ostream& operator<<(std::ostream& stream, const Point& point)
{ stream << point.str(false); return stream; }
}
#endif
|