summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-10-26 15:45:32 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-10-26 16:44:55 +0100
commit75dec6ffac6f3e79e5a173cd8a3f98d374ed1c09 (patch)
treedd3e2752cfe2c1ea741ac1b97d38e5e4bc4aa008 /src/mbgl/text
parentc0c554e36fd43bfe57ef13fe60f9cd50b5c018fd (diff)
downloadqtlocation-mapboxgl-75dec6ffac6f3e79e5a173cd8a3f98d374ed1c09.tar.gz
[core] always reparse with the freshest possible placement config
Fixes an issue where updates to stale tiles would remove labels altogether until the map was rotated.
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/collision_tile.cpp13
-rw-r--r--src/mbgl/text/collision_tile.hpp38
-rw-r--r--src/mbgl/text/placement_config.hpp28
3 files changed, 51 insertions, 28 deletions
diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp
index d18860ccf5..ecd615a520 100644
--- a/src/mbgl/text/collision_tile.cpp
+++ b/src/mbgl/text/collision_tile.cpp
@@ -3,17 +3,16 @@
namespace mbgl {
-CollisionTile::CollisionTile(const float angle_, const float pitch, bool debug_) :
- angle(angle_), debug(debug_) {
+CollisionTile::CollisionTile(PlacementConfig config_) : config(config_) {
tree.clear();
- // Compute the transformation matrix.
- float angle_sin = std::sin(angle);
- float angle_cos = std::cos(angle);
- rotationMatrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}};
+ // Compute the transformation matrix.
+ const float angle_sin = std::sin(config.angle);
+ const float angle_cos = std::cos(config.angle);
+ rotationMatrix = { { angle_cos, -angle_sin, angle_sin, angle_cos } };
// Stretch boxes in y direction to account for the map tilt.
- const float _yStretch = 1.0f / std::cos(pitch);
+ const float _yStretch = 1.0f / std::cos(config.pitch);
// The amount the map is squished depends on the y position.
// Sort of account for this by making all boxes a bit bigger.
diff --git a/src/mbgl/text/collision_tile.hpp b/src/mbgl/text/collision_tile.hpp
index 3fd1b0a4c8..edd5eb61a0 100644
--- a/src/mbgl/text/collision_tile.hpp
+++ b/src/mbgl/text/collision_tile.hpp
@@ -2,6 +2,7 @@
#define MBGL_TEXT_COLLISION_TILE
#include <mbgl/text/collision_feature.hpp>
+#include <mbgl/text/placement_config.hpp>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
@@ -24,39 +25,34 @@
namespace mbgl {
- namespace bg = boost::geometry;
- namespace bgm = bg::model;
- namespace bgi = bg::index;
- typedef bgm::point<float, 2, bg::cs::cartesian> CollisionPoint;
- typedef bgm::box<CollisionPoint> Box;
- typedef std::pair<Box, CollisionBox> CollisionTreeBox;
- typedef bgi::rtree<CollisionTreeBox, bgi::linear<16,4>> Tree;
+namespace bg = boost::geometry;
+namespace bgm = bg::model;
+namespace bgi = bg::index;
+typedef bgm::point<float, 2, bg::cs::cartesian> CollisionPoint;
+typedef bgm::box<CollisionPoint> Box;
+typedef std::pair<Box, CollisionBox> CollisionTreeBox;
+typedef bgi::rtree<CollisionTreeBox, bgi::linear<16, 4>> Tree;
class CollisionTile {
+public:
+ explicit CollisionTile(PlacementConfig);
- public:
- explicit CollisionTile(float angle_, float pitch_, bool debug_);
+ float placeFeature(const CollisionFeature& feature);
+ void insertFeature(CollisionFeature& feature, const float minPlacementScale);
- float placeFeature(const CollisionFeature &feature);
- void insertFeature(CollisionFeature &feature, const float minPlacementScale);
-
- bool getDebug() { return debug; }
-
- const float angle = 0;
+ const PlacementConfig config;
const float minScale = 0.5f;
const float maxScale = 2.0f;
float yStretch;
- private:
-
- Box getTreeBox(const vec2<float> &anchor, const CollisionBox &box);
+private:
+ Box getTreeBox(const vec2<float>& anchor, const CollisionBox& box);
Tree tree;
std::array<float, 4> rotationMatrix;
- bool debug;
-
};
-}
+
+} // namespace mbgl
#endif
diff --git a/src/mbgl/text/placement_config.hpp b/src/mbgl/text/placement_config.hpp
new file mode 100644
index 0000000000..6680f52449
--- /dev/null
+++ b/src/mbgl/text/placement_config.hpp
@@ -0,0 +1,28 @@
+#ifndef MBGL_TEXT_PLACEMENT_CONFIG
+#define MBGL_TEXT_PLACEMENT_CONFIG
+
+namespace mbgl {
+
+class PlacementConfig {
+public:
+ inline PlacementConfig(float angle_ = 0, float pitch_ = 0, bool debug_ = false)
+ : angle(angle_), pitch(pitch_), debug(debug_) {
+ }
+
+ inline bool operator==(const PlacementConfig& rhs) const {
+ return angle == rhs.angle && pitch == rhs.pitch && debug == rhs.debug;
+ }
+
+ inline bool operator!=(const PlacementConfig& rhs) const {
+ return !operator==(rhs);
+ }
+
+public:
+ float angle;
+ float pitch;
+ bool debug;
+};
+
+} // namespace mbgl
+
+#endif