diff --git a/MathLib/MathTools.h b/MathLib/MathTools.h index 16f0a637a1692adc0e85a17a44af20ad1b86304a..9ca7b1f888c9c5708cef9a4c1a6c2b727cd90b7e 100644 --- a/MathLib/MathTools.h +++ b/MathLib/MathTools.h @@ -107,14 +107,6 @@ void crossProd (const double u[3], const double v[3], double r[3]); double calcProjPntToLineAndDists(const double p[3], const double a[3], const double b[3], double &lambda, double &d0); -template <typename T, std::size_t DIM> -bool operator==(TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b) -{ - T const sqr_dist(sqrDist(a,b)); - auto const eps = std::numeric_limits<T>::epsilon(); - return (sqr_dist < eps*eps); -} - /// Computes the squared dist between the two points p0 and p1. inline double sqrDist(MathLib::Point3d const& p0, MathLib::Point3d const& p1) @@ -131,17 +123,6 @@ double sqrDist(const double* p0, const double* p1) return scalarProduct<double,3>(v,v); } -/** Distance between points p0 and p1 in the maximum norm. */ -template <typename T> -T maxNormDist(const MathLib::TemplatePoint<T>* p0, const MathLib::TemplatePoint<T>* p1) -{ - const T x = fabs((*p1)[0] - (*p0)[0]); - const T y = fabs((*p1)[1] - (*p0)[1]); - const T z = fabs((*p1)[2] - (*p0)[2]); - - return std::max(x, std::max(y, z)); -} - /** * Let \f$p_0, p_1, p_2 \in R^3\f$. The function getAngle * computes the angle between the edges \f$(p_0,p_1)\f$ and \f$(p_1,p_2)\f$ diff --git a/MathLib/TemplatePoint.h b/MathLib/TemplatePoint.h index 9ba8953e6382a9d43eeed385010c6e7ab5b2f667..b8be4e918afb2b39c97970f995843a7f1271fbb3 100644 --- a/MathLib/TemplatePoint.h +++ b/MathLib/TemplatePoint.h @@ -101,6 +101,27 @@ TemplatePoint<T,DIM>::TemplatePoint(std::array<T,DIM> const& x) : _x(x) {} +/** Equality of TemplatePoint's up to an epsilon. + */ +template <typename T, std::size_t DIM> +bool operator==(TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b) +{ + T const sqr_dist(sqrDist(a,b)); + auto const eps = std::numeric_limits<T>::epsilon(); + return (sqr_dist < eps*eps); +} + +/** Distance between points p0 and p1 in the maximum norm. */ +template <typename T> +T maxNormDist(const MathLib::TemplatePoint<T>* p0, const MathLib::TemplatePoint<T>* p1) +{ + const T x = fabs((*p1)[0] - (*p0)[0]); + const T y = fabs((*p1)[1] - (*p0)[1]); + const T z = fabs((*p1)[2] - (*p0)[2]); + + return std::max(x, std::max(y, z)); +} + /** overload the output operator for class Point */ template <typename T, std::size_t DIM> std::ostream& operator<< (std::ostream &os, const TemplatePoint<T,DIM> &p)