From 8e459c2a73e7dcdb4cf660cfe61d5c945d7a2513 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 10 Feb 2015 12:52:53 -0800 Subject: [PATCH 1/3] improve line label density Place the first label as close to the beginning of the line as possible. js: 316ed0bd9bff8cd430ad81d0b6397f396fbce124 --- src/mbgl/geometry/resample.cpp | 7 ++++--- src/mbgl/geometry/resample.hpp | 2 +- src/mbgl/renderer/symbol_bucket.cpp | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/mbgl/geometry/resample.cpp b/src/mbgl/geometry/resample.cpp index abb3ef1e3..2fd4a8fd8 100644 --- a/src/mbgl/geometry/resample.cpp +++ b/src/mbgl/geometry/resample.cpp @@ -17,17 +17,18 @@ const std::array, 4> minScaleArrays = {{ Anchors resample(const std::vector &vertices, float spacing, const float /*minScale*/, float maxScale, const float tilePixelRatio, - const int start) { + int offset) { maxScale = std::round(std::fmax(std::fmin(8.0f, maxScale / 2.0f), 1.0f)); spacing *= tilePixelRatio / maxScale; + offset *= tilePixelRatio / maxScale; const size_t index = util::clamp(std::floor(std::log(maxScale) / std::log(2)), 0, minScaleArrays.size() - 1); const std::vector &minScales = minScaleArrays[index]; const size_t len = minScales.size(); - float distance = 0.0f; + float distance = spacing - offset;; float markedDistance = 0.0f; - int added = start; + int added = 0; Anchors points; diff --git a/src/mbgl/geometry/resample.hpp b/src/mbgl/geometry/resample.hpp index bcfe4ca53..febb6360d 100644 --- a/src/mbgl/geometry/resample.hpp +++ b/src/mbgl/geometry/resample.hpp @@ -7,7 +7,7 @@ namespace mbgl { Anchors resample(const std::vector &vertices, float spacing, - float minScale, float maxScale, float tilePixelRatio, int start = 0); + float minScale, float maxScale, float tilePixelRatio, int offset); } #endif diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index f53bbfa95..9d9636b39 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -238,9 +238,26 @@ void SymbolBucket::addFeature(const std::vector &line, const Shaping Anchors anchors; if (properties.placement == PlacementType::Line) { + float textResampleOffset = 0; + float iconResampleOffset = 0; + + if (shaping.size()) { + float minX = std::numeric_limits::infinity(); + float maxX = -std::numeric_limits::infinity(); + for (const auto &glyph : shaping) { + minX = std::min(minX, glyph.x); + maxX = std::max(maxX, glyph.x); + } + const float labelLength = maxX - minX; + textResampleOffset = (labelLength / 2.0 + glyphSize) * fontScale; + } + if (image) { + iconResampleOffset = image.w; + } + // Line labels anchors = resample(line, properties.min_distance, minScale, collision.maxPlacementScale, - collision.tilePixelRatio); + collision.tilePixelRatio, std::max(iconResampleOffset, textResampleOffset)); // Sort anchors by segment so that we can start placement with the // anchors that can be shown at the lowest zoom levels. From c621441def0eb1328f90c31e80f5ff49021e8f44 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 11 Feb 2015 13:21:41 -0800 Subject: [PATCH 2/3] Fix line label interpolation offset. --- src/mbgl/geometry/resample.cpp | 8 ++++---- src/mbgl/geometry/resample.hpp | 2 +- src/mbgl/renderer/symbol_bucket.cpp | 10 +++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mbgl/geometry/resample.cpp b/src/mbgl/geometry/resample.cpp index 2fd4a8fd8..ed086fefd 100644 --- a/src/mbgl/geometry/resample.cpp +++ b/src/mbgl/geometry/resample.cpp @@ -17,17 +17,17 @@ const std::array, 4> minScaleArrays = {{ Anchors resample(const std::vector &vertices, float spacing, const float /*minScale*/, float maxScale, const float tilePixelRatio, - int offset) { + float offset) { maxScale = std::round(std::fmax(std::fmin(8.0f, maxScale / 2.0f), 1.0f)); spacing *= tilePixelRatio / maxScale; - offset *= tilePixelRatio / maxScale; + offset *= tilePixelRatio; const size_t index = util::clamp(std::floor(std::log(maxScale) / std::log(2)), 0, minScaleArrays.size() - 1); const std::vector &minScales = minScaleArrays[index]; const size_t len = minScales.size(); - float distance = spacing - offset;; - float markedDistance = 0.0f; + float distance = 0.0f; + float markedDistance = offset != 0.0f ? offset - spacing : offset; int added = 0; Anchors points; diff --git a/src/mbgl/geometry/resample.hpp b/src/mbgl/geometry/resample.hpp index febb6360d..ce7eba2f1 100644 --- a/src/mbgl/geometry/resample.hpp +++ b/src/mbgl/geometry/resample.hpp @@ -7,7 +7,7 @@ namespace mbgl { Anchors resample(const std::vector &vertices, float spacing, - float minScale, float maxScale, float tilePixelRatio, int offset); + float minScale, float maxScale, float tilePixelRatio, float offset); } #endif diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 9d9636b39..44cc3816a 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -238,8 +238,7 @@ void SymbolBucket::addFeature(const std::vector &line, const Shaping Anchors anchors; if (properties.placement == PlacementType::Line) { - float textResampleOffset = 0; - float iconResampleOffset = 0; + float resampleOffset = 0; if (shaping.size()) { float minX = std::numeric_limits::infinity(); @@ -249,15 +248,12 @@ void SymbolBucket::addFeature(const std::vector &line, const Shaping maxX = std::max(maxX, glyph.x); } const float labelLength = maxX - minX; - textResampleOffset = (labelLength / 2.0 + glyphSize) * fontScale; - } - if (image) { - iconResampleOffset = image.w; + resampleOffset = (labelLength / 2.0 + glyphSize * 2.0) * fontScale; } // Line labels anchors = resample(line, properties.min_distance, minScale, collision.maxPlacementScale, - collision.tilePixelRatio, std::max(iconResampleOffset, textResampleOffset)); + collision.tilePixelRatio, resampleOffset); // Sort anchors by segment so that we can start placement with the // anchors that can be shown at the lowest zoom levels. From 919ac6098303a772c2c9bd6923b3462ca0eeaeee Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 11 Feb 2015 16:27:13 -0800 Subject: [PATCH 3/3] update test suite --- test/suite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suite b/test/suite index d2fff4e20..7423bba25 160000 --- a/test/suite +++ b/test/suite @@ -1 +1 @@ -Subproject commit d2fff4e2048bc4b0b2eb92c779fce01b4a45b063 +Subproject commit 7423bba25d7b62a31475a3ab2e99c68f37374442