From f3476b710e22d4bdae11758553588a6c4e69d9be Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 22 Feb 2013 16:18:24 +0100
Subject: [PATCH] Moved TemplatePoint from namespace GeoLib to MathLib.

- Implemented class template GeoPoint (see GeoLib/Point.h) and substituted class templates in the typedef.
- Some changes due to changed namespace in MathLib/Vector3.h and GeoLib/Color.h.
---
 GeoLib/Color.h          | 13 +++----
 GeoLib/Point.h          | 32 ++++++++++++++---
 MathLib/TemplatePoint.h | 24 +++++--------
 MathLib/Vector3.h       | 76 +++++++++++++++++++++--------------------
 4 files changed, 80 insertions(+), 65 deletions(-)

diff --git a/GeoLib/Color.h b/GeoLib/Color.h
index 3f5cf9f46ba..ee9978994cb 100644
--- a/GeoLib/Color.h
+++ b/GeoLib/Color.h
@@ -13,20 +13,19 @@
  *
  */
 
-
 #ifndef COLOR_H_
 #define COLOR_H_
 
 #include "TemplatePoint.h"
 
-#include <fstream>
 #include <cstdlib>
-#include <map>
+#include <fstream>
 #include <list>
+#include <map>
 
-namespace GeoLib {
-
-typedef TemplatePoint<unsigned char> Color;
+namespace GeoLib
+{
+typedef MathLib::TemplatePoint<unsigned char> Color;
 
 /// Returns a random RGB colour.
 Color* getRandomColor();
@@ -40,8 +39,6 @@ const Color* getColor(const std::string &id, std::map<std::string, GeoLib::Color
 
 /// Convenience function to use the getColor method with numbers as identifiers.
 const Color* getColor(double id, std::map<std::string, GeoLib::Color*> &colors);
-
-
 } // namespace
 
 #endif /* COLOR_H_ */
diff --git a/GeoLib/Point.h b/GeoLib/Point.h
index 17a2e8e45c5..47fce4f94a9 100644
--- a/GeoLib/Point.h
+++ b/GeoLib/Point.h
@@ -15,17 +15,38 @@
 #ifndef POINT_H_
 #define POINT_H_
 
+// STL
 #include <limits>
 
-#include "TemplatePoint.h"
+// GeoLib
+#include "GeoObject.h"
 
-namespace GeoLib {
+// MathLib
+#include "TemplatePoint.h"
 
+namespace GeoLib
+{
 /**
  * \ingroup GeoLib
  */
 
-typedef TemplatePoint<double> Point;
+template<typename T> class GeoPoint : public MathLib::TemplatePoint<T>, public GeoLib::GeoObject
+{
+public:
+	GeoPoint(T x1, T x2, T x3) :
+		MathLib::TemplatePoint<T>(x1, x2, x3), GeoLib::GeoObject()
+	{}
+
+	GeoPoint() :
+		MathLib::TemplatePoint<T>(), GeoLib::GeoObject()
+	{}
+
+	GeoPoint (T const* x) :
+		MathLib::TemplatePoint<T>(x), GeoObject()
+	{}
+};
+
+typedef GeoLib::GeoPoint<double> Point;
 
 /**
  * lexicographic comparison of points
@@ -40,8 +61,9 @@ bool operator<= (GeoLib::Point const & p0, GeoLib::Point const & p1);
  * 	holds for the k-th coordinate the points are assumed the be equal in this coordinate)
  * @return true, if p0 is lexicographically smaller than p1
  */
-bool lessEq(const GeoLib::Point& p0, const GeoLib::Point& p1, double tol = std::numeric_limits<double>::epsilon());
+bool lessEq(const GeoLib::Point& p0,
+            const GeoLib::Point& p1,
+            double tol = std::numeric_limits<double>::epsilon());
 }
 
-
 #endif /* POINT_H_ */
diff --git a/MathLib/TemplatePoint.h b/MathLib/TemplatePoint.h
index 2d313ef77bb..d854e739b1b 100644
--- a/MathLib/TemplatePoint.h
+++ b/MathLib/TemplatePoint.h
@@ -15,14 +15,11 @@
 #ifndef TEMPLATEPOINT_H_
 #define TEMPLATEPOINT_H_
 
+// STL
 #include <cassert>
 #include <iostream>
-#include <sstream>
-#include <string>
 
-#include "GeoObject.h"
-
-namespace GeoLib
+namespace MathLib
 {
 /**
  * \ingroup GeoLib
@@ -30,18 +27,18 @@ namespace GeoLib
  * \brief class-template for points can be instantiated by a numeric type.
  * \param T the coordinate type
  */
-template <class T> class TemplatePoint : public GeoObject
+template <class T> class TemplatePoint
 {
 public:
 	/** default constructor */
-	TemplatePoint ();
+	TemplatePoint();
 
 	/** constructor - constructs a TemplatePoint object
 	   \param x1 value for the first coordinate
 	   \param x2 value for the second coordinate
 	   \param x3 value for the third coordinate
 	 */
-	TemplatePoint (T x1, T x2, T x3);
+	TemplatePoint(T x1, T x2, T x3);
 
 	/** constructor - constructs a TemplatePoint object
 	   \param x values for three coordinates
@@ -92,24 +89,21 @@ protected:
 	T _x[3];
 };
 
-template <class T> TemplatePoint<T>::TemplatePoint() :
-	GeoObject()
+template <class T> TemplatePoint<T>::TemplatePoint()
 {
 	_x[0] = static_cast<T>(0);
 	_x[1] = static_cast<T>(0);
 	_x[2] = static_cast<T>(0);
 }
 
-template <class T> TemplatePoint<T>::TemplatePoint(T x1, T x2, T x3) :
-	GeoObject()
+template <class T> TemplatePoint<T>::TemplatePoint(T x1, T x2, T x3)
 {
 	_x[0] = x1;
 	_x[1] = x2;
 	_x[2] = x3;
 }
 
-template <class T> TemplatePoint<T>::TemplatePoint (T const* x) :
-	GeoObject()
+template <class T> TemplatePoint<T>::TemplatePoint (T const* x)
 {
 	for (std::size_t k(0); k < 3; k++)
 		_x[k] = x[k];
@@ -130,6 +124,6 @@ std::istream& operator>> (std::istream &is, TemplatePoint<T> &p)
 	p.read (is);
 	return is;
 }
-} // end namespace GEO
+} // end namespace MathLib
 
 #endif /* TEMPLATEPOINT_H_ */
diff --git a/MathLib/Vector3.h b/MathLib/Vector3.h
index 0d925487dd8..fb9b772f17d 100644
--- a/MathLib/Vector3.h
+++ b/MathLib/Vector3.h
@@ -17,65 +17,67 @@
 #ifndef VECTOR3_H
 #define VECTOR3_H
 
-// GEO
+// MathLib
 #include "TemplatePoint.h"
 
 // MathLib
 #include "MathTools.h"
 
-#include <iostream>
 #include <cmath>
+#include <iostream>
 
-namespace MathLib {
-
+namespace MathLib
+{
 /**
  * The Vector class defines a three-dimensional vector, with appropriate
  *	operators.  (* is cross product.)
  */
 template <class T>
-class TemplateVector : public GeoLib::TemplatePoint<T>
+class TemplateVector : public MathLib::TemplatePoint<T>
 {
 public:
-	TemplateVector() : GeoLib::TemplatePoint<T>() {};
-	TemplateVector(T x1, T x2, T x3) : GeoLib::TemplatePoint<T>(x1, x2, x3) {};
- 	TemplateVector(const GeoLib::TemplatePoint<T> & rhs) :
- 		GeoLib::TemplatePoint<T>(rhs[0], rhs[1], rhs[2])
- 	{}
- 	/** constructs a vector from the gien points */
- 	TemplateVector(const GeoLib::TemplatePoint<T> &a, const GeoLib::TemplatePoint<T> &b) :
- 	 	GeoLib::TemplatePoint<T>(b[0]-a[0], b[1]-a[1], b[2]-a[2])
- 	{}
-	~TemplateVector() {};
+	TemplateVector() : MathLib::TemplatePoint<T>() {}
+	TemplateVector(T x1, T x2, T x3) : MathLib::TemplatePoint<T>(x1, x2, x3) {}
+	TemplateVector(const MathLib::TemplatePoint<T> & rhs) :
+		MathLib::TemplatePoint<T>(rhs[0], rhs[1], rhs[2])
+	{}
+	/** constructs a vector from the gien points */
+	TemplateVector(const MathLib::TemplatePoint<T> &a, const MathLib::TemplatePoint<T> &b) :
+		MathLib::TemplatePoint<T>(b[0] - a[0], b[1] - a[1], b[2] - a[2])
+	{}
+	~TemplateVector() {}
 
 	// vector arithmetic
 
 	TemplateVector operator+(const TemplateVector & pV) const
 	{
-		return TemplateVector(this->x[0]+pV[0], this->x[1]+pV[1], this->x[2]+pV[2] );
+		return TemplateVector(this->x[0] + pV[0], this->x[1] + pV[1], this->x[2] + pV[2] );
 	}
 
-	TemplateVector operator-(const TemplateVector & pV) const {
-		TemplateVector out( this->x[0]-pV[0], this->x[1]-pV[1], this->x[2]-pV[2] );
+	TemplateVector operator-(const TemplateVector & pV) const
+	{
+		TemplateVector out( this->x[0] - pV[0], this->x[1] - pV[1], this->x[2] - pV[2] );
 		return out;
 	}
 
 	TemplateVector operator-() const
 	{ return TemplateVector (-this->x[0], -this->x[1], -this->x[2]); }
 
-	TemplateVector& operator+=(const TemplateVector & pV) {
-		for (std::size_t i(0); i<3; i++) this->x[i]+=pV[i];
+	TemplateVector& operator+=(const TemplateVector & pV)
+	{
+		for (std::size_t i(0); i < 3; i++) this->x[i] += pV[i];
 		return *this;
 	}
 
-	TemplateVector& operator+=(const GeoLib::TemplatePoint<T>& pnt)
+	TemplateVector& operator+=(const MathLib::TemplatePoint<T>& pnt)
 	{
-		for (std::size_t i(0); i<3; i++) this->_x[i] += pnt[i];
+		for (std::size_t i(0); i < 3; i++) this->_x[i] += pnt[i];
 		return *this;
 	}
 
 	TemplateVector& operator-=(const TemplateVector & pV)
 	{
-		for (std::size_t i(0); i<3; i++) this->_x[i] -= pV[i];
+		for (std::size_t i(0); i < 3; i++) this->_x[i] -= pV[i];
 		return *this;
 	}
 
@@ -90,15 +92,16 @@ public:
 	/// Dot product with another vector
 	double Dot(const TemplateVector & pV) const
 	{
-		return this->_x[0]*pV[0] + this->_x[1]*pV[1] + this->_x[2]*pV[2];
+		return this->_x[0] * pV[0] + this->_x[1] * pV[1] + this->_x[2] * pV[2];
 	}
 
 	/// Cross product as the multiplication operator
-	TemplateVector operator*(const TemplateVector & pV) const {
+	TemplateVector operator*(const TemplateVector & pV) const
+	{
 		return TemplateVector (
-				this->_x[1]*pV[2]-this->_x[2]*pV[1],
-				this->_x[2]*pV[0]-this->_x[0]*pV[2],
-				this->_x[0]*pV[1]-this->_x[1]*pV[0] );
+		               this->_x[1] * pV[2] - this->_x[2] * pV[1],
+		               this->_x[2] * pV[0] - this->_x[0] * pV[2],
+		               this->_x[0] * pV[1] - this->_x[1] * pV[0] );
 	}
 
 	/// Cross product with another vector
@@ -111,19 +114,19 @@ public:
 	friend TemplateVector Cross( const TemplateVector & p1, const TemplateVector & p2 )
 	{ return p1 * p2; }
 
-	TemplateVector operator*(double pR) const		// * a scalar
+	TemplateVector operator*(double pR) const   // * a scalar
 	{
-		return TemplateVector(this->x[0]*pR, this->x[1]*pR, this->x[2]*pR);
+		return TemplateVector(this->x[0] * pR, this->x[1] * pR, this->x[2] * pR);
 	}
 
 	friend TemplateVector operator*(double pR, const TemplateVector & pV)
 	{
-		return TemplateVector ( pV[0]*pR, pV[1]*pR, pV[2]*pR );
+		return TemplateVector ( pV[0] * pR, pV[1] * pR, pV[2] * pR );
 	}
 
 	TemplateVector& operator*=(double pR)
 	{
-		for (std::size_t i(0); i<3; i++) this->_x[i]*=pR;
+		for (std::size_t i(0); i < 3; i++) this->_x[i] *= pR;
 		return *this;
 	}
 
@@ -149,21 +152,20 @@ public:
 	/// Comparison if equal
 	bool operator==( const TemplateVector & pV) const
 	{
-		return (std::fabs(this->_x[0] - pV[0]) < sqrt(std::numeric_limits<double>::min()) &&
-				std::fabs(this->_x[1] - pV[1]) < sqrt(std::numeric_limits<double>::min()) &&
-				std::fabs(this->_x[2] - pV[2]) < sqrt(std::numeric_limits<double>::min()));
+		return std::fabs(this->_x[0] - pV[0]) < sqrt(std::numeric_limits<double>::min()) &&
+		       std::fabs(this->_x[1] - pV[1]) < sqrt(std::numeric_limits<double>::min()) &&
+		       std::fabs(this->_x[2] - pV[2]) < sqrt(std::numeric_limits<double>::min());
 	}
 
 	/// Comparison if not equal
 	bool operator!=( const TemplateVector & pV) const
 	{
-		return (! (pV == this));
+		return !(pV == this);
 //		this->_x[0]!=pV[0] || this->_x[1]!=pV[1] || this->_x[2]!=pV[2];
 	}
 };
 
 typedef TemplateVector<double> Vector;
-
 }
 
 #endif // VECTOR3_H
-- 
GitLab