aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-09-11 22:47:32 +0200
committerEven Rouault <even.rouault@spatialys.com>2019-09-12 15:59:23 +0200
commit890c94a730474f057f5237ca07699d6af600ed3f (patch)
treea37ee0956e5bfb86adaf7df275f4a8a23a3c0c02 /src
parentad0c57436c00fdc0af0bb5e7e2c6ff163e0addfc (diff)
downloadPROJ-890c94a730474f057f5237ca07699d6af600ed3f.tar.gz
PROJ-890c94a730474f057f5237ca07699d6af600ed3f.zip
createOperations(): make sure sorting function is transitive (a < b and b < c --> a < c), to get consistent results
Diffstat (limited to 'src')
-rw-r--r--src/iso19111/coordinateoperation.cpp50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/iso19111/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp
index 768ef76f..a1612339 100644
--- a/src/iso19111/coordinateoperation.cpp
+++ b/src/iso19111/coordinateoperation.cpp
@@ -56,7 +56,9 @@
#include <string>
#include <vector>
-#ifdef DEBUG
+// #define DEBUG
+// #define DEBUG_SORT
+#if defined(DEBUG) || defined(DEBUG_SORT)
#include <iostream>
#endif
@@ -10309,16 +10311,12 @@ struct SortFunction {
return false;
}
- if (iterA->second.hasGrids_ && iterB->second.hasGrids_) {
- // Operations where grids are all available go before other
- if (iterA->second.gridsAvailable_ &&
- !iterB->second.gridsAvailable_) {
- return true;
- }
- if (iterB->second.gridsAvailable_ &&
- !iterA->second.gridsAvailable_) {
- return false;
- }
+ // Operations where grids are all available go before other
+ if (iterA->second.gridsAvailable_ && !iterB->second.gridsAvailable_) {
+ return true;
+ }
+ if (iterB->second.gridsAvailable_ && !iterA->second.gridsAvailable_) {
+ return false;
}
// Operations where grids are all known in our DB go before other
@@ -10680,7 +10678,35 @@ struct FilterResults {
}
// Sort !
- std::sort(res.begin(), res.end(), SortFunction(map));
+ SortFunction sortFunc(map);
+ std::sort(res.begin(), res.end(), sortFunc);
+
+// Debug code to check consistency of the sort function
+#ifdef DEBUG_SORT
+ constexpr bool debugSort = true;
+#elif !defined(NDEBUG)
+ const bool debugSort = getenv("PROJ_DEBUG_SORT_FUNCT") != nullptr;
+#endif
+#if defined(DEBUG_SORT) || !defined(NDEBUG)
+ if (debugSort) {
+ const bool assertIfIssue =
+ !(getenv("PROJ_DEBUG_SORT_FUNCT_ASSERT") != nullptr);
+ for (size_t i = 0; i < res.size(); ++i) {
+ for (size_t j = i + 1; j < res.size(); ++j) {
+ if (sortFunc(res[j], res[i])) {
+#ifdef DEBUG_SORT
+ std::cerr << "Sorting issue with entry " << i << "("
+ << res[i]->nameStr() << ") and " << j << "("
+ << res[j]->nameStr() << ")" << std::endl;
+#endif
+ if (assertIfIssue) {
+ assert(false);
+ }
+ }
+ }
+ }
+ }
+#endif
}
// ----------------------------------------------------------------------