From: wolf Date: Fri, 6 Nov 1998 12:09:10 +0000 (+0000) Subject: Move the point class from deal.II/include/grid to here. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30c4008a5e4fcc03fa3104820e2a83cdf5591e56;p=dealii-svn.git Move the point class from deal.II/include/grid to here. git-svn-id: https://svn.dealii.org/trunk@640 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/function.h b/deal.II/base/include/base/function.h index 934d016c33..c7a5687917 100644 --- a/deal.II/base/include/base/function.h +++ b/deal.II/base/include/base/function.h @@ -8,7 +8,7 @@ #include #include -#include +#include diff --git a/deal.II/base/include/base/point.h b/deal.II/base/include/base/point.h new file mode 100644 index 0000000000..a546fe6ca0 --- /dev/null +++ b/deal.II/base/include/base/point.h @@ -0,0 +1,330 @@ +/*---------------------------- point.h ---------------------------*/ +/* $Id$ */ +/* Copyright W. Bangerth, University of Heidelberg, 1998 */ +#ifndef __point_H +#define __point_H +/*---------------------------- point.h ---------------------------*/ + + +#include +#include + + +/** + * The #Point# class provides for a point or vector in a space with arbitrary + * dimension #dim#. + * + * It is the preferred object to be passed to functions which + * operate on points in spaces of a priori unknown dimension: rather than + * using functions like #double f(double x)# and #double f(double x, double y)#, + * you use double #f(Point &p)#. + * + * #Point# also serves as a starting point for the implementation of the + * geometrical primitives like #Polyhedron#, #Triangle#, etc. + * + * #Point#s can also be thought of as vectors, i.e. points in a vector space + * without an obvious meaning. For instance, it may be suitable to let the + * gradient of a function be a #point# vector: + * #Point gradient_of_f (const Point &x)#. #Point#s have all + * functionality for this, e.g. scalar products, addition etc. However, you + * should also consider using the simpler #Tensor<1,dim># class, which seems + * more suited to gradients. + * + * @author Wolfgang Bangerth, 1997 + */ +template +class Point : public Tensor<1,dim> { + public: + /** + * Default constructor. + */ + /** + * Constructor. Initialize all entries + * to zero. + */ + explicit Point (); + + /** + * Constructor for one dimensional points. This + * function is only implemented for #dim==1# + * since the usage is considered unsafe + * for points with #dim!=1#. + */ + explicit Point (const double x); + + /** + * Constructor for two dimensional points. This + * function is only implemented for #dim==2# + * since the usage is considered unsafe + * for points with #dim!=2#. + */ + Point (const double x, const double y); + + /** + * Constructor for three dimensional points. This + * function is only implemented for #dim==3# + * since the usage is considered unsafe + * for points with #dim!=3#. + */ + Point (const double x, const double y, const double z); + + /** + * Read access to the #index#th coordinate. + */ + double operator () (const unsigned int index) const; + + /** + * Read and write access to the #index#th + * coordinate. + */ + double & operator () (const unsigned int index); + + /** + * Add two point vectors. If possible, use + * #operator +=# instead since this does not + * need to copy a point at least once. + */ + Point operator + (const Point &) const; + + /** + * Subtract two point vectors. If possible, use + * #operator +=# instead since this does not + * need to copy a point at least once. + */ + Point operator - (const Point &) const; + + /** + * Multiply by a factor. If possible, use + * #operator *=# instead since this does not + * need to copy a point at least once. + * + * There is a commutative complement to this + * function also + */ + Point operator * (const double) const; + + /** + * Divide by a factor. If possible, use + * #operator /=# instead since this does not + * need to copy a point at least once. + */ + Point operator / (const double) const; + + /** + * Add another vector, i.e. move this point by + * the given offset. + */ + Point & operator += (const Point &); + /** + * Subtract another vector. + */ + Point & operator -= (const Point &); + + /** + * Scale the vector by #factor#, i.e. multiply + * all coordinates by #factor#. + */ + Point & operator *= (const double &factor); + + /** + * Scale the vector by #1/factor#. + */ + Point & operator /= (const double &factor); + + /** + * Returns the scalar product of two vectors. + */ + double operator * (const Point &) const; + + /** + * Returns the scalar product of this point + * vector with itself, i.e. the square, or + * the square of the norm. + */ + double square () const; + + + /** + * Exception + */ + DeclException1 (ExcDimTooSmall, + int, + << "Given dimensions must be >= 1, but was " << arg1); + /** + * Exception + */ + DeclException1 (ExcInvalidIndex, + int, + << "Invalid index " << arg1); +}; + + + + + + + +/*------------------------------- Inline functions: Point ---------------------------*/ + + + +template +inline +Point::Point () : + Tensor<1,dim>() {}; + + + +template <> +inline +Point<1>::Point (const double x) { + values[0] = x; +}; + + + +template <> +inline +Point<2>::Point (const double x, const double y) { + values[0] = x; + values[1] = y; +}; + + + +template <> +inline +Point<3>::Point (const double x, const double y, const double z) { + values[0] = x; + values[1] = y; + values[2] = z; +}; + + + +template +inline +double Point::operator () (const unsigned int index) const { + Assert (index +inline +double & Point::operator () (const unsigned int index) { + Assert (index +inline +Point Point::operator + (const Point &p) const { + return (Point(*this) += p); +}; + + + +template +inline +Point Point::operator - (const Point &p) const { + return (Point(*this) -= p); +}; + + + +template +inline +Point Point::operator * (const double factor) const { + return (Point(*this) *= factor); +}; + + + +template +inline +Point operator * (const double factor, const Point &p) { + return p*factor; +}; + + + +template +inline +Point Point::operator / (const double factor) const { + return (Point(*this) /= factor); +}; + + + +template +inline +Point & Point::operator += (const Point &p) { + for (unsigned int i=0; i +inline +Point & Point::operator -= (const Point &p) { + for (unsigned int i=0; i +inline +Point & Point::operator *= (const double &s) { + for (unsigned int i=0; i +inline +Point & Point::operator /= (const double &s) { + for (unsigned int i=0; i +inline +double Point::operator * (const Point &p) const { + double q=0; + for (unsigned int i=0; i +inline +double Point::square () const { + double q=0; + for (unsigned int i=0; i +#include #include diff --git a/deal.II/deal.II/include/fe/fe.h b/deal.II/deal.II/include/fe/fe.h index 492b427b81..525275ad1d 100644 --- a/deal.II/deal.II/include/fe/fe.h +++ b/deal.II/deal.II/include/fe/fe.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/deal.II/deal.II/include/fe/fe_values.h b/deal.II/deal.II/include/fe/fe_values.h index 35ce803a3a..bf0768e08e 100644 --- a/deal.II/deal.II/include/fe/fe_values.h +++ b/deal.II/deal.II/include/fe/fe_values.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index b17b6020bf..f670670333 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -6,7 +6,7 @@ /*---------------------------- tria.h ---------------------------*/ #include -#include +#include #include diff --git a/deal.II/deal.II/include/grid/tria_boundary.h b/deal.II/deal.II/include/grid/tria_boundary.h index 0dd06b3172..f67f7b4515 100644 --- a/deal.II/deal.II/include/grid/tria_boundary.h +++ b/deal.II/deal.II/include/grid/tria_boundary.h @@ -5,7 +5,7 @@ #define __tria_boundary_H /*---------------------------- boundary-function.h ---------------------------*/ -#include +#include #include diff --git a/deal.II/deal.II/include/grid/tria_iterator.h b/deal.II/deal.II/include/grid/tria_iterator.h index ef6cc9c87b..65dea7aae8 100644 --- a/deal.II/deal.II/include/grid/tria_iterator.h +++ b/deal.II/deal.II/include/grid/tria_iterator.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include diff --git a/deal.II/deal.II/include/grid/tria_levels.h b/deal.II/deal.II/include/grid/tria_levels.h index 397ba597cb..4a212e07ba 100644 --- a/deal.II/deal.II/include/grid/tria_levels.h +++ b/deal.II/deal.II/include/grid/tria_levels.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include /**