[core] Remove ambiguous get{Width,Height} accessors from style::Image
This commit is contained in:
@@ -22,9 +22,6 @@ public:
|
||||
// Whether this image should be interpreted as a signed distance field icon.
|
||||
bool isSdf() const;
|
||||
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
class Impl;
|
||||
Immutable<Impl> impl;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
|
||||
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithCGImage:image];
|
||||
CGImageRelease(image);
|
||||
if (self = [self initWithSize:NSMakeSize(styleImage->getWidth(), styleImage->getHeight())]) {
|
||||
CGFloat w = styleImage->getImage().size.width / styleImage->getPixelRatio();
|
||||
CGFloat h = styleImage->getImage().size.height / styleImage->getPixelRatio();
|
||||
if (self = [self initWithSize:NSMakeSize(w, h)]) {
|
||||
[self addRepresentation:rep];
|
||||
[self setTemplate:styleImage->isSdf()];
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ SpriteAtlasElement::SpriteAtlasElement(Rect<uint16_t> rect_,
|
||||
: pos(std::move(rect_)),
|
||||
sdf(image.sdf),
|
||||
relativePixelRatio(image.pixelRatio / pixelRatio),
|
||||
width(image.getWidth()),
|
||||
height(image.getHeight()) {
|
||||
width(image.image.size.width / image.pixelRatio),
|
||||
height(image.image.size.height / image.pixelRatio) {
|
||||
|
||||
|
||||
const float w = image.getWidth() * relativePixelRatio;
|
||||
const float h = image.getHeight() * relativePixelRatio;
|
||||
const float w = image.image.size.width / pixelRatio;
|
||||
const float h = image.image.size.height / pixelRatio;
|
||||
|
||||
size = {{ float(image.getWidth()), image.getHeight() }};
|
||||
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 }};
|
||||
}
|
||||
|
||||
@@ -28,13 +28,5 @@ float Image::getPixelRatio() const {
|
||||
return impl->pixelRatio;
|
||||
}
|
||||
|
||||
float Image::getWidth() const {
|
||||
return impl->getWidth();
|
||||
}
|
||||
|
||||
float Image::getHeight() const {
|
||||
return impl->getHeight();
|
||||
}
|
||||
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -18,9 +18,6 @@ public:
|
||||
|
||||
// Whether this image should be interpreted as a signed distance field icon.
|
||||
const bool sdf;
|
||||
|
||||
float getWidth() const { return image.size.width / pixelRatio; }
|
||||
float getHeight() const { return image.size.height / pixelRatio; }
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -143,8 +143,6 @@ TEST(Sprite, SpriteImageCreation1x) {
|
||||
{ // "museum_icon":{"x":177,"y":187,"width":18,"height":18,"pixelRatio":1,"sdf":false}
|
||||
const auto sprite = createStyleImage("test", image_1x, 177, 187, 18, 18, 1, false);
|
||||
ASSERT_TRUE(sprite.get());
|
||||
EXPECT_EQ(18, sprite->getWidth());
|
||||
EXPECT_EQ(18, sprite->getHeight());
|
||||
EXPECT_EQ(18u, sprite->getImage().size.width);
|
||||
EXPECT_EQ(18u, sprite->getImage().size.height);
|
||||
EXPECT_EQ(1, sprite->getPixelRatio());
|
||||
@@ -159,8 +157,6 @@ TEST(Sprite, SpriteImageCreation2x) {
|
||||
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
|
||||
const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 2, false);
|
||||
ASSERT_TRUE(sprite.get());
|
||||
EXPECT_EQ(18, sprite->getWidth());
|
||||
EXPECT_EQ(18, sprite->getHeight());
|
||||
EXPECT_EQ(36u, sprite->getImage().size.width);
|
||||
EXPECT_EQ(36u, sprite->getImage().size.height);
|
||||
EXPECT_EQ(2, sprite->getPixelRatio());
|
||||
@@ -174,8 +170,6 @@ TEST(Sprite, SpriteImageCreation1_5x) {
|
||||
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
|
||||
const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 1.5, false);
|
||||
ASSERT_TRUE(sprite.get());
|
||||
EXPECT_EQ(24, sprite->getWidth());
|
||||
EXPECT_EQ(24, sprite->getHeight());
|
||||
EXPECT_EQ(36u, sprite->getImage().size.width);
|
||||
EXPECT_EQ(36u, sprite->getImage().size.height);
|
||||
EXPECT_EQ(1.5, sprite->getPixelRatio());
|
||||
@@ -185,8 +179,6 @@ TEST(Sprite, SpriteImageCreation1_5x) {
|
||||
// "hospital_icon":{"x":314,"y":518,"width":36,"height":36,"pixelRatio":2,"sdf":false}
|
||||
const auto sprite2 = createStyleImage("test", image_2x, 314, 518, 35, 35, 1.5, false);
|
||||
ASSERT_TRUE(sprite2.get());
|
||||
EXPECT_EQ(float(35 / 1.5), sprite2->getWidth());
|
||||
EXPECT_EQ(float(35 / 1.5), sprite2->getHeight());
|
||||
EXPECT_EQ(35u, sprite2->getImage().size.width);
|
||||
EXPECT_EQ(35u, sprite2->getImage().size.height);
|
||||
EXPECT_EQ(1.5, sprite2->getPixelRatio());
|
||||
@@ -281,8 +273,6 @@ TEST(Sprite, SpriteParsing) {
|
||||
|
||||
{
|
||||
auto& sprite = *std::find_if(images.begin(), images.end(), [] (const auto& image) { return image->getID() == "generic-metro"; });
|
||||
EXPECT_EQ(18, sprite->getWidth());
|
||||
EXPECT_EQ(18, sprite->getHeight());
|
||||
EXPECT_EQ(18u, sprite->getImage().size.width);
|
||||
EXPECT_EQ(18u, sprite->getImage().size.height);
|
||||
EXPECT_EQ(1, sprite->getPixelRatio());
|
||||
|
||||
@@ -35,18 +35,14 @@ TEST(StyleImage, ZeroRatio) {
|
||||
|
||||
TEST(StyleImage, Retina) {
|
||||
style::Image image("test", PremultipliedImage({ 32, 24 }), 2.0);
|
||||
EXPECT_EQ(16, image.getWidth());
|
||||
EXPECT_EQ(32u, image.getImage().size.width);
|
||||
EXPECT_EQ(12, image.getHeight());
|
||||
EXPECT_EQ(24u, image.getImage().size.height);
|
||||
EXPECT_EQ(2, image.getPixelRatio());
|
||||
}
|
||||
|
||||
TEST(StyleImage, FractionalRatio) {
|
||||
style::Image image("test", PremultipliedImage({ 20, 12 }), 1.5);
|
||||
EXPECT_EQ(float(20.0 / 1.5), image.getWidth());
|
||||
EXPECT_EQ(20u, image.getImage().size.width);
|
||||
EXPECT_EQ(float(12.0 / 1.5), image.getHeight());
|
||||
EXPECT_EQ(12u, image.getImage().size.height);
|
||||
EXPECT_EQ(1.5, image.getPixelRatio());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user