Skip to content
Snippets Groups Projects
Commit b9a20b91 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[MaL] Move lessEq() for Point3d to TemplatePoint.

Extend the input to arbitrary TemplatePoint,
but it is working only for TemplatePoint<double, 3>
== Point3d for now.
parent 9ef33ea6
No related branches found
No related tags found
No related merge requests found
...@@ -18,33 +18,4 @@ ...@@ -18,33 +18,4 @@
namespace MathLib namespace MathLib
{ {
bool lessEq(const MathLib::Point3d& p0, const MathLib::Point3d& p1, double tol)
{
// test a relative and an absolute criterion
if (fabs(p0[0]-p1[0]) > tol * std::min(fabs(p1[0]), fabs(p0[0])) && fabs(p0[0]-p1[0]) > tol) {
if (p0[0] <= p1[0])
return true;
else
return false;
} else {
// assume p0[0] == p1[0]
if (fabs (p0[1]-p1[1]) > tol * fabs(p0[1]) && fabs(p0[1]-p1[1]) > tol) {
if (p0[1] <= p1[1])
return true;
else
return false;
} else {
// assume p0[1] == p1[1] and p0[0] == p1[0]
if (fabs (p0[2]-p1[2]) > tol * fabs(p0[2]) && fabs(p0[2]-p1[2]) > tol) {
if (p0[2] <= p1[2])
return true;
else
return false;
} else {
return true;
}
}
}
}
} // namespace MathLib } // namespace MathLib
...@@ -23,18 +23,6 @@ namespace MathLib ...@@ -23,18 +23,6 @@ namespace MathLib
{ {
typedef MathLib::TemplatePoint<double,3> Point3d; typedef MathLib::TemplatePoint<double,3> Point3d;
/**
* lexicographical comparison of points taking an epsilon into account
* @param p0 first input Point3d
* @param p1 second input Point3d
* @param tol tolerance (if in the comparison operation the property fabs(p0[k] - p1[k]) < tol
* 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 MathLib::Point3d& p0,
const MathLib::Point3d& p1,
double tol = std::numeric_limits<double>::epsilon());
/** /**
* rotation of points * rotation of points
* @param mat a rotation matrix * @param mat a rotation matrix
......
...@@ -130,6 +130,45 @@ bool operator< (TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b) ...@@ -130,6 +130,45 @@ bool operator< (TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b)
return false; return false;
} }
/**
* lexicographical comparison of points taking an epsilon into account
* @param p0 first input Point3d
* @param p1 second input Point3d
* @param tol tolerance (if in the comparison operation the property fabs(p0[k] - p1[k]) < tol
* 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
*/
template <typename T, std::size_t DIM>
bool lessEq(TemplatePoint<T, DIM> const& a, TemplatePoint<T, DIM> const& b,
double tol = std::numeric_limits<double>::epsilon())
{
// test a relative and an absolute criterion
if (fabs(a[0]-b[0]) > tol * std::min(fabs(b[0]), fabs(a[0])) && fabs(a[0]-b[0]) > tol) {
if (a[0] <= b[0])
return true;
else
return false;
} else {
// assume a[0] == b[0]
if (fabs (a[1]-b[1]) > tol * fabs(a[1]) && fabs(a[1]-b[1]) > tol) {
if (a[1] <= b[1])
return true;
else
return false;
} else {
// assume a[1] == b[1] and a[0] == b[0]
if (fabs (a[2]-b[2]) > tol * fabs(a[2]) && fabs(a[2]-b[2]) > tol) {
if (a[2] <= b[2])
return true;
else
return false;
} else {
return true;
}
}
}
}
/** Distance between points p0 and p1 in the maximum norm. */ /** Distance between points p0 and p1 in the maximum norm. */
template <typename T> template <typename T>
T maxNormDist(const MathLib::TemplatePoint<T>* p0, const MathLib::TemplatePoint<T>* p1) T maxNormDist(const MathLib::TemplatePoint<T>* p0, const MathLib::TemplatePoint<T>* p1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment