Created
February 14, 2017 08:08
-
-
Save thewickedaxe/8a75dd8168342313148c6692d9799893 to your computer and use it in GitHub Desktop.
Correct Comparator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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