From e29f8c15e8f34c8663311c3a5684f1698c8df4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 29 Mar 2018 12:55:29 -0700 Subject: [core] Round-trip linear interpolators Cherry-picked from c231191dbc6f055341fd25ce97309614dc52802f. --- mapbox-gl-js | 2 +- src/mbgl/style/expression/interpolate.cpp | 6 +++++- test/style/conversion/stringify.test.cpp | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mapbox-gl-js b/mapbox-gl-js index 3c07b72a59..34902f8db3 160000 --- a/mapbox-gl-js +++ b/mapbox-gl-js @@ -1 +1 @@ -Subproject commit 3c07b72a59d78bc6240a8e3d77a54bec7619af5d +Subproject commit 34902f8db3f8a3757a465d62a96b8fa731ee1461 diff --git a/src/mbgl/style/expression/interpolate.cpp b/src/mbgl/style/expression/interpolate.cpp index 30b2cba81b..daad8523f2 100644 --- a/src/mbgl/style/expression/interpolate.cpp +++ b/src/mbgl/style/expression/interpolate.cpp @@ -223,7 +223,11 @@ mbgl::Value Interpolate::serialize() const { interpolator.match( [&](const ExponentialInterpolator& exponential) { - serialized.emplace_back(std::vector{{ std::string("exponential"), exponential.base }}); + if (exponential.base == 1) { + serialized.emplace_back(std::vector{{ std::string("linear") }}); + } else { + serialized.emplace_back(std::vector{{ std::string("exponential"), exponential.base }}); + } }, [&](const CubicBezierInterpolator& cubicBezier) { static const std::string cubicBezierTag("cubic-bezier"); diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index cb3b62dc62..136f276aaf 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -80,6 +80,8 @@ TEST(Stringify, Filter) { } TEST(Stringify, CameraFunction) { + ASSERT_EQ(stringify(CameraFunction(ExponentialStops { {{0, 1}}, 1 })), + "[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0]"); ASSERT_EQ(stringify(CameraFunction(ExponentialStops { {{0, 1}}, 2 })), "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]"); ASSERT_EQ(stringify(CameraFunction(IntervalStops { {{0, 1}} })), @@ -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]]"); -- cgit v1.2.1