From da1998ca786f2f03d9de3e1427022dabcc11aab2 Mon Sep 17 00:00:00 2001 From: Konstantin Pastbin Date: Wed, 8 Mar 2023 22:21:32 +0000 Subject: [PATCH] [drape] Increase max dash length limit Signed-off-by: Konstantin Pastbin --- drape/stipple_pen_resource.cpp | 2 -- drape/stipple_pen_resource.hpp | 10 ++++++---- drape_frontend/line_shape.cpp | 2 +- drape_frontend/visual_params.cpp | 3 +++ drape_frontend/visual_params.hpp | 1 + map/style_tests/dashes_test.cpp | 26 +++++++++++++------------- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/drape/stipple_pen_resource.cpp b/drape/stipple_pen_resource.cpp index 59b7ea24b5..934a2f5000 100644 --- a/drape/stipple_pen_resource.cpp +++ b/drape/stipple_pen_resource.cpp @@ -12,8 +12,6 @@ namespace dp { -uint32_t const kMaxStipplePenLength = 512; /// @todo Should be equal with kStippleTextureWidth? - StipplePenPacker::StipplePenPacker(m2::PointU const & canvasSize) : m_canvasSize(canvasSize) , m_currentRow(0) diff --git a/drape/stipple_pen_resource.hpp b/drape/stipple_pen_resource.hpp index f02efa2a0b..73c3624526 100644 --- a/drape/stipple_pen_resource.hpp +++ b/drape/stipple_pen_resource.hpp @@ -17,12 +17,14 @@ namespace dp { -// Based on ./data/patterns.txt, all paterns have 2 entries now. -using PenPatternT = buffer_vector; +uint32_t constexpr kMaxStipplePenLength = 512; /// @todo Should be equal with kStippleTextureWidth? -inline uint8_t PatternFloat2Pixel(double d) +// Based on ./data/patterns.txt, the most of patterns have 2 entries (4 entries for triangles pattern). +using PenPatternT = buffer_vector; + +inline constexpr uint16_t PatternFloat2Pixel(double d) { - return static_cast(std::round(d)); + return static_cast(std::round(d)); } inline bool IsTrianglePattern(PenPatternT const & p) diff --git a/drape_frontend/line_shape.cpp b/drape_frontend/line_shape.cpp index 7b59744e43..5b7bfd7203 100644 --- a/drape_frontend/line_shape.cpp +++ b/drape_frontend/line_shape.cpp @@ -364,7 +364,7 @@ void LineShape::Construct(DashedLineBuilder & builder) const // Each segment should lie in pattern mask according to the "longest" possible pixel length in current tile. // Since, we calculate vertices once, usually for the "smallest" tile scale, need to apply divide factor here. // In other words, if m_baseGtoPScale = Scale(tileLevel), we should use Scale(tileLevel + 1) to calculate 'maskLengthG'. - /// @todo Logically, the factor should be 2, but drawing artifacts still present. + /// @todo Logically, the factor should be 2, but drawing artifacts are still present at higher visual scales. /// Use 3 for the best quality, but need to review here, probably I missed something. float const maskLengthG = builder.GetMaskLengthG() / 3; diff --git a/drape_frontend/visual_params.cpp b/drape_frontend/visual_params.cpp index 84c3ed1b74..6fb6419a60 100644 --- a/drape_frontend/visual_params.cpp +++ b/drape_frontend/visual_params.cpp @@ -49,6 +49,8 @@ VisualParams & VisualParams::Instance() void VisualParams::Init(double vs, uint32_t tileSize) { + ASSERT_LESS_OR_EQUAL(vs, kMaxVisualScale, ()); + VisualParams & vizParams = Instance(); vizParams.m_tileSize = tileSize; vizParams.m_visualScale = vs; @@ -97,6 +99,7 @@ void VisualParams::SetFontScale(double fontScale) void VisualParams::SetVisualScale(double visualScale) { ASSERT_INITED; + ASSERT_LESS_OR_EQUAL(visualScale, kMaxVisualScale, ()); m_visualScale = visualScale; LOG(LINFO, ("Visual scale =", visualScale)); diff --git a/drape_frontend/visual_params.hpp b/drape_frontend/visual_params.hpp index ccfd3e8272..5a4260c7f6 100644 --- a/drape_frontend/visual_params.hpp +++ b/drape_frontend/visual_params.hpp @@ -14,6 +14,7 @@ namespace df { double constexpr kBoundingBoxScale = 1.2; +double constexpr kMaxVisualScale = 4.0; class VisualParams { diff --git a/map/style_tests/dashes_test.cpp b/map/style_tests/dashes_test.cpp index 7510226a8f..dcdee0506a 100644 --- a/map/style_tests/dashes_test.cpp +++ b/map/style_tests/dashes_test.cpp @@ -1,19 +1,12 @@ #include "testing/testing.hpp" #include "helpers.hpp" +#include "drape/stipple_pen_resource.hpp" +#include "drape_frontend/visual_params.hpp" #include "indexer/classificator_loader.hpp" #include "indexer/drawing_rules.hpp" #include "indexer/drules_include.hpp" -namespace -{ -double constexpr kMaxVisualScale = 4.; - -double constexpr kMaxDashLength = 128 / kMaxVisualScale; -// Why 128? 7 bits are used to pack dash value (see stipple_pen_resource.cpp, StipplePenHandle::Init) -// Max value, which can be packed in 7 bits, is 128. -} // namespace - UNIT_TEST(Test_Dashes) { styles::RunForEveryMapStyle([](MapStyle) @@ -27,11 +20,18 @@ UNIT_TEST(Test_Dashes) DashDotProto const & dd = line->dashdot(); int const n = dd.dd_size(); - for (int i = 0; i < n; ++i) + if (n > 0) { - double const value = dd.dd(i); - TEST_GREATER_OR_EQUAL(value, 0.0, ()); - TEST_LESS_OR_EQUAL(value, kMaxDashLength, ()); + TEST_GREATER_OR_EQUAL(n, 2, ()); + TEST_LESS_OR_EQUAL(n, 4, ()); + for (int i = 0; i < n; ++i) + { + double const value = dd.dd(i); + TEST_GREATER_OR_EQUAL(value, 0.0, ()); + } + + double const patternLength = (dd.dd(0) + dd.dd(1)) * df::kMaxVisualScale; + TEST_LESS_OR_EQUAL(patternLength, dp::kMaxStipplePenLength, (dd.dd(0), dd.dd(1))); } }); });