[core] Remove unnecessary optionals in PositionedIcon
Lack of icon is already checked at the call site of shapeIcon; no need to check hasArea() here.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
optional<PositionedIcon> PositionedIcon::shapeIcon(const SpriteAtlasElement& image, const std::array<float, 2>& iconOffset, const float iconRotation) {
|
||||
if (!image.pos.hasArea()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
PositionedIcon PositionedIcon::shapeIcon(const SpriteAtlasElement& image, const std::array<float, 2>& 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> 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,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/sprite/sprite_atlas.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -26,7 +25,7 @@ private:
|
||||
_right(right_),
|
||||
_angle(angle_) {}
|
||||
|
||||
optional<SpriteAtlasElement> _image;
|
||||
SpriteAtlasElement _image;
|
||||
float _top;
|
||||
float _bottom;
|
||||
float _left;
|
||||
@@ -34,9 +33,9 @@ private:
|
||||
float _angle;
|
||||
|
||||
public:
|
||||
static optional<PositionedIcon> shapeIcon(const class SpriteAtlasElement&, const std::array<float, 2>& iconOffset, const float iconRotation);
|
||||
static PositionedIcon shapeIcon(const SpriteAtlasElement&, const std::array<float, 2>& iconOffset, const float iconRotation);
|
||||
|
||||
optional<class SpriteAtlasElement> 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; }
|
||||
|
||||
@@ -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<TextSize>() = 24.0f;
|
||||
layout.get<IconTextFit>() = 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<TextSize>() = 12.0f;
|
||||
layout.get<IconTextFit>() = 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<IconTextFitPadding>()[2] = 5.0f;
|
||||
layout.get<IconTextFitPadding>()[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<TextSize>() = 24.0f;
|
||||
layout.get<IconTextFit>() = 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<TextSize>() = 12.0f;
|
||||
layout.get<IconTextFit>() = 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<IconTextFitPadding>()[2] = 5.0f;
|
||||
layout.get<IconTextFitPadding>()[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<TextSize>() = 24.0f;
|
||||
layout.get<IconTextFit>() = 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<TextSize>() = 12.0f;
|
||||
layout.get<IconTextFit>() = 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<IconTextFitPadding>()[2] = 5.0f;
|
||||
layout.get<IconTextFitPadding>()[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<IconTextFitPadding>()[2] = 10.0f;
|
||||
layout.get<IconTextFitPadding>()[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);
|
||||
|
||||
Reference in New Issue
Block a user