Skip to content

Instantly share code, notes, and snippets.

@thewickedaxe
Created February 14, 2017 08:08
Show Gist options
  • Select an option

  • Save thewickedaxe/8a75dd8168342313148c6692d9799893 to your computer and use it in GitHub Desktop.

Select an option

Save thewickedaxe/8a75dd8168342313148c6692d9799893 to your computer and use it in GitHub Desktop.
Correct Comparator
bool areEqualRel(float a, float b, float epsilon) {
return (fabs(a - b) <= epsilon * std::max(fabs(a), fabs(b)));
}
struct PointCompare
{
bool operator() (const Point3D< float >& lhs, const Point3D< float >& rhs) const
{
if (lhs[0] < rhs[0]) {
return true;
} else if (areEqualRel(lhs[0], rhs[0], FLT_EPSILON)) {
if (lhs[1] < rhs[1]) {
return true;
} else if(areEqualRel(lhs[1], rhs[1], FLT_EPSILON)) {
if (lhs[2] < rhs[2]) {
return true;
} else {
return false;
}
}
} else {
return false;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment