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

[MaL] Replace Point3d op<() with TemplatePoint.op<

The lexicographic comparison is now working for
arbitrary TemplatePoint dimensions and underlying
floating types.
parent a21c5e52
No related branches found
No related tags found
Loading
......@@ -18,36 +18,6 @@
namespace MathLib
{
bool operator< (const MathLib::Point3d& p0, const MathLib::Point3d& p1)
{
if (p0[0] > p1[0]) {
return false;
} else {
if (p0[0] < p1[0]) {
return true;
}
}
// => p0[0] == p1[0]
if (p0[1] > p1[1]) {
return false;
} else {
if (p0[1] < p1[1]) {
return true;
}
}
// => p0[1] == p1[1]
if (p0[2] > p1[2]) {
return false;
} else {
if (p0[2] < p1[2]) {
return true;
}
return false; // p0 == p1
}
}
bool lessEq(const MathLib::Point3d& p0, const MathLib::Point3d& p1, double tol)
{
// test a relative and an absolute criterion
......
......@@ -23,8 +23,6 @@ namespace MathLib
{
typedef MathLib::TemplatePoint<double,3> Point3d;
bool operator< (MathLib::Point3d const & p0, MathLib::Point3d const & p1);
/**
* lexicographical comparison of points taking an epsilon into account
* @param p0 first input Point3d
......
......@@ -111,6 +111,25 @@ bool operator==(TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b)
return (sqr_dist < eps*eps);
}
template <typename T, std::size_t DIM>
bool operator< (TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b)
{
for (std::size_t i = 0; i < DIM; ++i)
{
if (a[i] > b[i]) {
return false;
} else {
if (a[i] < b[i]) {
return true;
}
}
// continue with next dimension, because a[0] == b[0]
}
// The values in all dimenisions are equal.
return false;
}
/** 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)
......
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