ratio => pixelRatio

This commit is contained in:
Konstantin Käfer
2015-06-24 17:39:36 +02:00
parent 55ef14f3a8
commit a68b47b969
5 changed files with 13 additions and 12 deletions

View File

@@ -8,13 +8,13 @@ namespace mbgl {
SpriteImage::SpriteImage(const uint16_t width_,
const uint16_t height_,
const float ratio_,
const float pixelRatio_,
std::string&& data_)
: width(width_),
height(height_),
ratio(ratio_),
pixelWidth(std::ceil(width * ratio)),
pixelHeight(std::ceil(height * ratio)),
pixelRatio(pixelRatio_),
pixelWidth(std::ceil(width * pixelRatio)),
pixelHeight(std::ceil(height * pixelRatio)),
data(std::move(data_)) {
const size_t size = pixelWidth * pixelHeight * 4;
if (size == 0) {

View File

@@ -12,14 +12,14 @@ namespace mbgl {
class SpriteImage : private util::noncopyable {
public:
SpriteImage(uint16_t width, uint16_t height, float ratio, std::string&& data);
SpriteImage(uint16_t width, uint16_t height, float pixelRatio, std::string&& data);
// Logical dimensions of the sprite image.
const uint16_t width;
const uint16_t height;
// Pixel ratio of the sprite image.
const float ratio;
const float pixelRatio;
// Physical dimensions of the sprite image.
const uint16_t pixelWidth;

View File

@@ -4,11 +4,11 @@
namespace mbgl {
SpriteStore::SpriteStore(const float ratio_) : ratio(ratio_) {
SpriteStore::SpriteStore(const float pixelRatio_) : pixelRatio(pixelRatio_) {
}
void SpriteStore::setSprite(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
if (sprite && sprite->ratio != ratio) {
if (sprite && sprite->pixelRatio != pixelRatio) {
throw util::SpriteImageException("Sprite image has wrong pixel ratio");
}
std::lock_guard<std::mutex> lock(mutex);

View File

@@ -34,9 +34,10 @@ public:
// Returns Sprite images that changed since the last invocation of this function.
Sprites getDirty();
private:
const float ratio;
// Pixel ratio of all sprite images in this storage object.
const float pixelRatio;
private:
// Lock for sprites and dirty maps.
std::mutex mutex;

View File

@@ -48,7 +48,7 @@ TEST(Annotations, SpriteImage) {
EXPECT_EQ(32, sprite.pixelWidth);
EXPECT_EQ(12, sprite.height);
EXPECT_EQ(24, sprite.pixelHeight);
EXPECT_EQ(2, sprite.ratio);
EXPECT_EQ(2, sprite.pixelRatio);
EXPECT_EQ(32u * 24 * 4, sprite.data.size());
}
@@ -59,6 +59,6 @@ TEST(Annotations, SpriteImageFractionalRatio) {
EXPECT_EQ(20, sprite.pixelWidth);
EXPECT_EQ(8, sprite.height);
EXPECT_EQ(12, sprite.pixelHeight);
EXPECT_EQ(1.5, sprite.ratio);
EXPECT_EQ(1.5, sprite.pixelRatio);
EXPECT_EQ(20u * 12 * 4, sprite.data.size());
}