[core] Fixed to-rgba with zero opacity
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -37,6 +38,7 @@ public:
|
||||
|
||||
static optional<Color> parse(const std::string&);
|
||||
std::string stringify() const;
|
||||
std::array<double, 4> toArray() const;
|
||||
};
|
||||
|
||||
inline bool operator==(const Color& colorA, const Color& colorB) {
|
||||
|
||||
Submodule mapbox-gl-js updated: 34902f8db3...bbee7e5169
@@ -209,12 +209,7 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
|
||||
);
|
||||
});
|
||||
define("to-rgba", [](const Color& color) -> Result<std::array<double, 4>> {
|
||||
return std::array<double, 4> {{
|
||||
255 * color.r / color.a,
|
||||
255 * color.g / color.a,
|
||||
255 * color.b / color.a,
|
||||
color.a
|
||||
}};
|
||||
return color.toArray();
|
||||
});
|
||||
|
||||
define("rgba", rgba);
|
||||
|
||||
@@ -106,12 +106,13 @@ Value ValueConverter<mbgl::Value>::toExpressionValue(const mbgl::Value& value) {
|
||||
mbgl::Value ValueConverter<mbgl::Value>::fromExpressionValue(const Value& value) {
|
||||
return value.match(
|
||||
[&](const Color& color)->mbgl::Value {
|
||||
std::array<double, 4> array = color.toArray();
|
||||
return std::vector<mbgl::Value>{
|
||||
std::string("rgba"),
|
||||
double(255 * color.r / color.a),
|
||||
double(255 * color.g / color.a),
|
||||
double(255 * color.b / color.a),
|
||||
double(color.a)
|
||||
array[0],
|
||||
array[1],
|
||||
array[2],
|
||||
array[3],
|
||||
};
|
||||
},
|
||||
[&](const std::vector<Value>& values)->mbgl::Value {
|
||||
|
||||
@@ -23,11 +23,25 @@ optional<Color> Color::parse(const std::string& s) {
|
||||
}
|
||||
|
||||
std::string Color::stringify() const {
|
||||
std::array<double, 4> array = toArray();
|
||||
return "rgba(" +
|
||||
util::toString(r * 255 / a) + "," +
|
||||
util::toString(g * 255 / a) + "," +
|
||||
util::toString(b * 255 / a) + "," +
|
||||
util::toString(a) + ")";
|
||||
util::toString(array[0]) + "," +
|
||||
util::toString(array[1]) + "," +
|
||||
util::toString(array[2]) + "," +
|
||||
util::toString(array[3]) + ")";
|
||||
}
|
||||
|
||||
std::array<double, 4> Color::toArray() const {
|
||||
if (a == 0) {
|
||||
return {{ 0, 0, 0, 0 }};
|
||||
} else {
|
||||
return {{
|
||||
r * 255 / a,
|
||||
g * 255 / a,
|
||||
b * 255 / a,
|
||||
a,
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user