From: Wolfgang Bangerth Date: Fri, 6 Mar 1998 10:52:18 +0000 (+0000) Subject: More operators. X-Git-Tag: v8.0.0~23223 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38cda89da210d30283772c09c8d37b263f533ee5;p=dealii.git More operators. git-svn-id: https://svn.dealii.org/trunk@28 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/point.h b/deal.II/deal.II/include/grid/point.h index 856877fcbc..50dd45013a 100644 --- a/deal.II/deal.II/include/grid/point.h +++ b/deal.II/deal.II/include/grid/point.h @@ -31,7 +31,8 @@ template class Point { public: /** - * Constructor. + * Constructor. Initialize all entries + * to zero. */ Point (); /** @@ -67,17 +68,17 @@ class Point { * Return the dimension of the space this * point is living in. */ - int dimension() const { return dim; }; + unsigned int dimension() const { return dim; }; /** * Read access to the #index#th coordinate. */ - double operator () (const int index) const; + double operator () (const unsigned int index) const; /** * Read and write access to the #index#th * coordinate. */ - double & operator () (const int index); + double & operator () (const unsigned int index); /** * Assignment operator. @@ -99,6 +100,7 @@ class Point { * 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 @@ -106,6 +108,23 @@ class Point { */ 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. @@ -121,6 +140,7 @@ class Point { * all coordinates by #factor#. */ Point & operator *= (const double &factor); + /** * Scale the vector by #1/factor#. */ @@ -138,11 +158,6 @@ class Point { */ double square () const; - /** - * Prints the coordinates of this point in the - * form #(x1,x2,x3,etc)#. - */ -// friend ostream & operator << (ostream &, const Point &p); /** * Exception @@ -184,7 +199,7 @@ inline Point::Point () { Assert (dim>0, ExcDimTooSmall(dim)); - for (int i=0; i::Point (const double x, const double y, const double z) { template inline Point::Point (const Point &p) { - for (int i=0; i::Point (const Point &p) { template inline -double Point::operator () (const int index) const { - Assert ((index>=0) && (index::operator () (const unsigned int index) const { + Assert (index inline -double & Point::operator () (const int index) { - Assert ((index>=0) && (index::operator () (const unsigned int index) { + Assert (index inline Point & Point::operator = (const Point &p) { - for (int i=0; i inline bool Point::operator == (const Point &p) const { - for (int i=0; i inline bool Point::operator != (const Point &p) const { @@ -264,6 +283,7 @@ bool Point::operator != (const Point &p) const { }; + template inline Point Point::operator + (const Point &p) const { @@ -271,64 +291,95 @@ Point Point::operator + (const Point &p) const { }; + 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 (int i=0; i inline Point & Point::operator -= (const Point &p) { - for (int i=0; i inline Point & Point::operator *= (const double &s) { - for (int i=0; i inline Point & Point::operator /= (const double &s) { - for (int i=0; i inline double Point::operator * (const Point &p) const { double q=0; - for (int i=0; i inline double Point::square () const { double q=0; - for (int i=0; i &p) { inline ostream & operator << (ostream &out, const Point<2> &p) { // out << "("; -// for (int i=0; i<1; i++) +// for (unsigned int i=0; i<1; i++) // out << p(i) << ","; // out << p(1) << ")"; out << p(0) << " " << p(1);