Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Remove redundant SpriteAtlasElement members
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed May 17, 2017
1 parent 7867076 commit e7154ad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/mbgl/sprite/sprite_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ SpriteAtlasElement::SpriteAtlasElement(Rect<uint16_t> rect_,
: pos(std::move(rect_)),
sdf(image.sdf),
relativePixelRatio(image.pixelRatio / pixelRatio),
width(image.image.size.width / image.pixelRatio),
height(image.image.size.height / image.pixelRatio) {

size{{image.image.size.width / image.pixelRatio,
image.image.size.height / image.pixelRatio}} {

const float w = image.image.size.width / pixelRatio;
const float h = image.image.size.height / pixelRatio;

size = {{ width, height }};
tl = {{ float(pos.x + padding) / size_.width, float(pos.y + padding) / size_.height }};
br = {{ float(pos.x + padding + w) / size_.width, float(pos.y + padding + h) / size_.height }};
}
Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/sprite/sprite_atlas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class SpriteAtlasElement {
std::array<float, 2> size;
std::array<float, 2> tl;
std::array<float, 2> br;
float width;
float height;
};

using IconMap = std::unordered_map<std::string, SpriteAtlasElement>;
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/text/shaping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ optional<PositionedIcon> PositionedIcon::shapeIcon(const SpriteAtlasElement& ima

float dx = iconOffset[0];
float dy = iconOffset[1];
float x1 = dx - image.width/ 2.0f;
float x2 = x1 + image.width;
float y1 = dy - image.height / 2.0f;
float y2 = y1 + image.height;
float x1 = dx - image.size[0] / 2.0f;
float x2 = x1 + image.size[0];
float y1 = dy - image.size[1] / 2.0f;
float y2 = y1 + image.size[1];

return { PositionedIcon { image, y1, y2, x1, x2, iconRotation } };
}
Expand Down
24 changes: 12 additions & 12 deletions test/sprite/sprite_atlas.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ TEST(SpriteAtlas, Basic) {
EXPECT_EQ(0, metro.pos.y);
EXPECT_EQ(20, metro.pos.w);
EXPECT_EQ(20, metro.pos.h);
EXPECT_EQ(18, metro.width);
EXPECT_EQ(18, metro.height);
EXPECT_EQ(18u, metro.width * imagePixelRatio);
EXPECT_EQ(18u, metro.height * imagePixelRatio);
EXPECT_EQ(18, metro.size[0]);
EXPECT_EQ(18, metro.size[1]);
EXPECT_EQ(18u, metro.size[0] * imagePixelRatio);
EXPECT_EQ(18u, metro.size[1] * imagePixelRatio);
EXPECT_EQ(1.0f, imagePixelRatio);


Expand Down Expand Up @@ -93,10 +93,10 @@ TEST(SpriteAtlas, Size) {
EXPECT_EQ(0, metro.pos.y);
EXPECT_EQ(15, metro.pos.w);
EXPECT_EQ(15, metro.pos.h);
EXPECT_EQ(18, metro.width);
EXPECT_EQ(18, metro.height);
EXPECT_EQ(18u, metro.width * imagePixelRatio);
EXPECT_EQ(18u, metro.height * imagePixelRatio);
EXPECT_EQ(18, metro.size[0]);
EXPECT_EQ(18, metro.size[1]);
EXPECT_EQ(18u, metro.size[0] * imagePixelRatio);
EXPECT_EQ(18u, metro.size[1] * imagePixelRatio);
EXPECT_EQ(1.0f, imagePixelRatio);

// Now the image was created lazily.
Expand All @@ -120,10 +120,10 @@ TEST(SpriteAtlas, Updates) {
EXPECT_EQ(0, one.pos.y);
EXPECT_EQ(18, one.pos.w);
EXPECT_EQ(14, one.pos.h);
EXPECT_EQ(16, one.width);
EXPECT_EQ(12, one.height);
EXPECT_EQ(16u, one.width * imagePixelRatio);
EXPECT_EQ(12u, one.height * imagePixelRatio);
EXPECT_EQ(16, one.size[0]);
EXPECT_EQ(12, one.size[1]);
EXPECT_EQ(16u, one.size[0] * imagePixelRatio);
EXPECT_EQ(12u, one.size[1] * imagePixelRatio);
EXPECT_EQ(1.0f, imagePixelRatio);

// Now the image was created lazily.
Expand Down

0 comments on commit e7154ad

Please sign in to comment.