From 72b13cef6a83594b15f47bfeaee782504def619e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 17 May 2017 17:00:56 -0700 Subject: [core] Remove unnecessary optionals in PositionedIcon Lack of icon is already checked at the call site of shapeIcon; no need to check hasArea() here. --- src/mbgl/text/quads.cpp | 2 +- src/mbgl/text/shaping.cpp | 8 ++------ src/mbgl/text/shaping.hpp | 7 +++---- test/text/quads.test.cpp | 26 ++++++++++++-------------- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 6f13331d4c..dc48634fb0 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -22,7 +22,7 @@ SymbolQuad getIconQuad(const Anchor& anchor, const float layoutTextSize, const style::SymbolPlacementType placement, const Shaping& shapedText) { - auto image = *shapedIcon.image(); + const SpriteAtlasElement& image = shapedIcon.image(); const float border = 1.0; auto left = shapedIcon.left() - border; diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 5c99a49133..6ee646be96 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -10,11 +10,7 @@ namespace mbgl { -optional PositionedIcon::shapeIcon(const SpriteAtlasElement& image, const std::array& iconOffset, const float iconRotation) { - if (!image.pos.hasArea()) { - return {}; - } - +PositionedIcon PositionedIcon::shapeIcon(const SpriteAtlasElement& image, const std::array& iconOffset, const float iconRotation) { float dx = iconOffset[0]; float dy = iconOffset[1]; float x1 = dx - image.size[0] / 2.0f; @@ -22,7 +18,7 @@ optional PositionedIcon::shapeIcon(const SpriteAtlasElement& ima float y1 = dy - image.size[1] / 2.0f; float y2 = y1 + image.size[1]; - return { PositionedIcon { image, y1, y2, x1, x2, iconRotation } }; + return PositionedIcon { image, y1, y2, x1, x2, iconRotation }; } void align(Shaping& shaping, diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp index b7eee5a5db..bf81b9213c 100644 --- a/src/mbgl/text/shaping.hpp +++ b/src/mbgl/text/shaping.hpp @@ -3,7 +3,6 @@ #include #include #include -#include namespace mbgl { @@ -26,7 +25,7 @@ private: _right(right_), _angle(angle_) {} - optional _image; + SpriteAtlasElement _image; float _top; float _bottom; float _left; @@ -34,9 +33,9 @@ private: float _angle; public: - static optional shapeIcon(const class SpriteAtlasElement&, const std::array& iconOffset, const float iconRotation); + static PositionedIcon shapeIcon(const SpriteAtlasElement&, const std::array& iconOffset, const float iconRotation); - optional image() const { return _image; } + const SpriteAtlasElement& image() const { return _image; } float top() const { return _top; } float bottom() const { return _bottom; } float left() const { return _left; } diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp index dcc51bf6a3..1f2e24ca5e 100644 --- a/test/text/quads.test.cpp +++ b/test/text/quads.test.cpp @@ -20,13 +20,12 @@ TEST(getIconQuads, normal) { }; auto shapedIcon = PositionedIcon::shapeIcon(image, {{ -6.5f, -4.5f }}, 0); - ASSERT_TRUE(shapedIcon); GeometryCoordinates line; Shaping shapedText; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 16.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 16.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.anchorPoint.x, 2); ASSERT_EQ(quad.anchorPoint.y, 3); @@ -53,7 +52,6 @@ TEST(getIconQuads, style) { }; auto shapedIcon = PositionedIcon::shapeIcon(image, {{ -9.5f, -9.5f }}, 0); - ASSERT_TRUE(shapedIcon); GeometryCoordinates line; Shaping shapedText; @@ -67,7 +65,7 @@ TEST(getIconQuads, style) { { SymbolLayoutProperties::Evaluated layout; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.anchorPoint.x, 0); ASSERT_EQ(quad.anchorPoint.y, 0); @@ -90,7 +88,7 @@ TEST(getIconQuads, style) { layout.get() = 24.0f; layout.get() = IconTextFitType::Width; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -60); ASSERT_EQ(quad.tl.y, 0); @@ -108,7 +106,7 @@ TEST(getIconQuads, style) { layout.get() = 12.0f; layout.get() = IconTextFitType::Width; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -30); ASSERT_EQ(quad.tl.y, -5); @@ -130,7 +128,7 @@ TEST(getIconQuads, style) { layout.get()[2] = 5.0f; layout.get()[3] = 10.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -40); ASSERT_EQ(quad.tl.y, -10); @@ -148,7 +146,7 @@ TEST(getIconQuads, style) { layout.get() = 24.0f; layout.get() = IconTextFitType::Height; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -30); ASSERT_EQ(quad.tl.y, -10); @@ -166,7 +164,7 @@ TEST(getIconQuads, style) { layout.get() = 12.0f; layout.get() = IconTextFitType::Height; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -20); ASSERT_EQ(quad.tl.y, -5); @@ -188,7 +186,7 @@ TEST(getIconQuads, style) { layout.get()[2] = 5.0f; layout.get()[3] = 10.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -30); ASSERT_EQ(quad.tl.y, -10); @@ -206,7 +204,7 @@ TEST(getIconQuads, style) { layout.get() = 24.0f; layout.get() = IconTextFitType::Both; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -60); ASSERT_EQ(quad.tl.y, -10); @@ -224,7 +222,7 @@ TEST(getIconQuads, style) { layout.get() = 12.0f; layout.get() = IconTextFitType::Both; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -30); ASSERT_EQ(quad.tl.y, -5); @@ -246,7 +244,7 @@ TEST(getIconQuads, style) { layout.get()[2] = 5.0f; layout.get()[3] = 10.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -40); ASSERT_EQ(quad.tl.y, -10); @@ -268,7 +266,7 @@ TEST(getIconQuads, style) { layout.get()[2] = 10.0f; layout.get()[3] = 15.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); + getIconQuad(anchor, shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); ASSERT_EQ(quad.tl.x, -45); ASSERT_EQ(quad.tl.y, -5); -- cgit v1.2.1