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

Accept constant expressions in non-dds properties #11960

Merged
merged 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ set(MBGL_TEST_FILES
test/style/conversion/geojson_options.test.cpp
test/style/conversion/layer.test.cpp
test/style/conversion/light.test.cpp
test/style/conversion/property_value.test.cpp
test/style/conversion/stringify.test.cpp
test/style/conversion/tileset.test.cpp

Expand Down
14 changes: 11 additions & 3 deletions include/mbgl/style/conversion/property_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ struct Converter<PropertyValue<T>> {
return {};
}

if (isFeatureConstant(**expression)) {
return { CameraFunction<T>(std::move(*expression)) };
} else {
if (!isFeatureConstant(**expression)) {
error = { "property expressions not supported" };
return {};
} else if (!isZoomConstant(**expression)) {
return { CameraFunction<T>(std::move(*expression)) };
} else {
auto literal = dynamic_cast<Literal*>(expression->get());
assert(literal);
optional<T> constant = fromExpressionValue<T>(literal->getValue());
if (!constant) {
return {};
}
return PropertyValue<T>(*constant);
}
} else if (isObject(value)) {
optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error);
Expand Down
21 changes: 21 additions & 0 deletions test/style/conversion/property_value.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <mbgl/test/util.hpp>

#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/util/rapidjson.hpp>

using namespace mbgl;
using namespace mbgl::style;
using namespace mbgl::style::conversion;

TEST(StyleConversion, PropertyValue) {
// PropertyValue<T> accepts a constant expression: https://github.com/mapbox/mapbox-gl-native/issues/11940
Error error;
JSDocument doc;
doc.Parse<0>(R"(["literal", [1, 2]])");
auto expected = std::array<float, 2>{{1, 2}};
auto result = convert<PropertyValue<std::array<float, 2>>>(doc, error);
ASSERT_TRUE(result);
ASSERT_TRUE(result->isConstant());
ASSERT_EQ(result->asConstant(), expected);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chose to go with a unit test rather than a render test here, because the latter would quietly cease to guard against regression if whatever currently-non-DDS property we used became DDS.