summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2017-01-16 17:43:33 +0200
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-01-16 14:30:36 -0600
commitbd71eb8681529ab70ff892b12128f8b7a5faa4c7 (patch)
treefc407e6936d446597b2da7a9d4dd2a7932be1914
parent76301b252cbc4bc3ae1fc84322bcbcdbd26cae8a (diff)
downloadqtlocation-mapboxgl-bd71eb8681529ab70ff892b12128f8b7a5faa4c7.tar.gz
[core] Fix ambiguous condition on the sort criteria
The previous sorting criteria would sometimes allow C > B, B > A but A > C, making the internal std::sort code sometimes point to an invalid reference. Fixes #7737
-rw-r--r--src/mbgl/style/style.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 2d11d16b1f..0b516f7b9f 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -26,8 +26,10 @@
#include <mbgl/renderer/render_item.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/util/constants.hpp>
+#include <mbgl/util/geometry.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/logging.hpp>
+#include <mbgl/util/math.hpp>
#include <mbgl/math/minmax.hpp>
#include <algorithm>
@@ -409,9 +411,6 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const
}
}
- const bool isLeft = std::abs(angle) > M_PI_2;
- const bool isBottom = angle < 0;
-
for (const auto& layer : layers) {
if (!layer->baseImpl->needsRendering(zoomHistory.lastZoom)) {
continue;
@@ -456,13 +455,14 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const
[](auto& pair) { return std::ref(pair.second); });
if (symbolLayer) {
std::sort(sortedTiles.begin(), sortedTiles.end(),
- [isLeft, isBottom](const RenderTile& a, const RenderTile& b) {
- bool sortX = a.id.canonical.x > b.id.canonical.x;
- bool sortW = a.id.wrap > b.id.wrap;
- bool sortY = a.id.canonical.y > b.id.canonical.y;
- return
- a.id.canonical.y != b.id.canonical.y ? (isLeft ? sortY : !sortY) :
- a.id.wrap != b.id.wrap ? (isBottom ? sortW : !sortW) : (isBottom ? sortX : !sortX);
+ [angle](const RenderTile& a, const RenderTile& b) {
+ Point<float> pa(a.id.canonical.x, a.id.canonical.y);
+ Point<float> pb(b.id.canonical.x, b.id.canonical.y);
+
+ auto par = util::rotate(pa, angle);
+ auto pbr = util::rotate(pb, angle);
+
+ return std::tie(par.y, par.x) < std::tie(pbr.y, pbr.x);
});
}