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

Commit

Permalink
[core] Round-trip linear interpolators
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Mar 29, 2018
1 parent 6a3fd64 commit 02de0ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/mbgl/style/expression/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ mbgl::Value Interpolate<T>::serialize() const {

interpolator.match(
[&](const ExponentialInterpolator& exponential) {
serialized.emplace_back(std::vector<mbgl::Value>{{ std::string("exponential"), exponential.base }});
if (exponential.base == 1) {
serialized.emplace_back(std::vector<mbgl::Value>{{ std::string("linear") }});
} else {
serialized.emplace_back(std::vector<mbgl::Value>{{ std::string("exponential"), exponential.base }});
}
},
[&](const CubicBezierInterpolator& cubicBezier) {
static const std::string cubicBezierTag("cubic-bezier");
Expand Down
4 changes: 3 additions & 1 deletion test/style/conversion/stringify.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ TEST(Stringify, Filter) {
}

TEST(Stringify, CameraFunction) {
ASSERT_EQ(stringify(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 1 })),
"[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0]");
ASSERT_EQ(stringify(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 2 })),
"[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]");
ASSERT_EQ(stringify(CameraFunction<float>(IntervalStops<float> { {{0, 1}} })),
Expand Down Expand Up @@ -109,7 +111,7 @@ TEST(Stringify, CompositeFunction) {
2
}, 0.0f)),
"[\"interpolate\","
"[\"exponential\",1.0],"
"[\"linear\"],"
"[\"zoom\"],"
"0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0],"
"1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]]");
Expand Down

0 comments on commit 02de0ce

Please sign in to comment.