[all] Rationalize style::Image
A style has a collection of images, just as it has collections of sources and layers. * Name things appropriately * Use std::unique_ptr
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include <mbgl/test/fixture_log_observer.hpp>
|
||||
|
||||
#include <mbgl/sprite/sprite_parser.hpp>
|
||||
#include <mbgl/sprite/sprite_image.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
@@ -27,19 +27,19 @@ TEST(Sprite, SpriteImageCreationInvalid) {
|
||||
ASSERT_EQ(200u, image_1x.size.width);
|
||||
ASSERT_EQ(299u, image_1x.size.height);
|
||||
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 0, 16, 1, false)); // width == 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, 0, 1, false)); // height == 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, -1, 16, 1, false)); // width < 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, -1, 1, false)); // height < 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 1, 1, 0, false)); // ratio == 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 1, 1, -1, false)); // ratio < 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 1, 1, 23, false)); // ratio too large
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 2048, 16, 1, false)); // too wide
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, 1025, 1, false)); // too tall
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, image_1x.size.width + 1, 16, 1, false)); // right edge out of bounds
|
||||
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, image_1x.size.height + 1, 1, false)); // bottom edge out of bounds
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 0, 16, 1, false)); // width == 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, 0, 1, false)); // height == 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, -1, 16, 1, false)); // width < 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, -1, 1, false)); // height < 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, 0, false)); // ratio == 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, -1, false)); // ratio < 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, 23, false)); // ratio too large
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 2048, 16, 1, false)); // too wide
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, 1025, 1, false)); // too tall
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, image_1x.size.width + 1, 16, 1, false)); // right edge out of bounds
|
||||
ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, image_1x.size.height + 1, 1, false)); // bottom edge out of bounds
|
||||
|
||||
EXPECT_EQ(1u, log.count({
|
||||
EventSeverity::Error,
|
||||
@@ -141,7 +141,7 @@ TEST(Sprite, SpriteImageCreation1x) {
|
||||
ASSERT_EQ(299u, image_1x.size.height);
|
||||
|
||||
{ // "museum_icon":{"x":177,"y":187,"width":18,"height":18,"pixelRatio":1,"sdf":false}
|
||||
const auto sprite = createSpriteImage(image_1x, 177, 187, 18, 18, 1, false);
|
||||
const auto sprite = createStyleImage(image_1x, 177, 187, 18, 18, 1, false);
|
||||
ASSERT_TRUE(sprite.get());
|
||||
EXPECT_EQ(18, sprite->getWidth());
|
||||
EXPECT_EQ(18, sprite->getHeight());
|
||||
@@ -157,7 +157,7 @@ TEST(Sprite, SpriteImageCreation2x) {
|
||||
const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
|
||||
|
||||
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
|
||||
const auto sprite = createSpriteImage(image_2x, 354, 374, 36, 36, 2, false);
|
||||
const auto sprite = createStyleImage(image_2x, 354, 374, 36, 36, 2, false);
|
||||
ASSERT_TRUE(sprite.get());
|
||||
EXPECT_EQ(18, sprite->getWidth());
|
||||
EXPECT_EQ(18, sprite->getHeight());
|
||||
@@ -172,7 +172,7 @@ TEST(Sprite, SpriteImageCreation1_5x) {
|
||||
const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
|
||||
|
||||
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
|
||||
const auto sprite = createSpriteImage(image_2x, 354, 374, 36, 36, 1.5, false);
|
||||
const auto sprite = createStyleImage(image_2x, 354, 374, 36, 36, 1.5, false);
|
||||
ASSERT_TRUE(sprite.get());
|
||||
EXPECT_EQ(24, sprite->getWidth());
|
||||
EXPECT_EQ(24, sprite->getHeight());
|
||||
@@ -183,7 +183,7 @@ TEST(Sprite, SpriteImageCreation1_5x) {
|
||||
sprite->image);
|
||||
|
||||
// "hospital_icon":{"x":314,"y":518,"width":36,"height":36,"pixelRatio":2,"sdf":false}
|
||||
const auto sprite2 = createSpriteImage(image_2x, 314, 518, 35, 35, 1.5, false);
|
||||
const auto sprite2 = createStyleImage(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());
|
||||
@@ -280,7 +280,7 @@ TEST(Sprite, SpriteParsing) {
|
||||
names);
|
||||
|
||||
{
|
||||
auto sprite = images.find("generic-metro")->second;
|
||||
auto& sprite = images.find("generic-metro")->second;
|
||||
EXPECT_EQ(18, sprite->getWidth());
|
||||
EXPECT_EQ(18, sprite->getHeight());
|
||||
EXPECT_EQ(18u, sprite->image.size.width);
|
||||
|
||||
Reference in New Issue
Block a user