From c231191dbc6f055341fd25ce97309614dc52802f 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 --- src/mbgl/style/conversion/stringify.hpp | 20 ++++++++++++++------ src/mbgl/style/expression/interpolate.cpp | 6 +++++- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp index 7924a442c4..9e16d8b2c6 100644 --- a/src/mbgl/style/conversion/stringify.hpp +++ b/src/mbgl/style/conversion/stringify.hpp @@ -303,9 +303,13 @@ public: template void operator()(const ExponentialStops& f) { writer.Key("type"); - writer.String("exponential"); - writer.Key("base"); - writer.Double(f.base); + if (f.base == 1) { + writer.String("linear"); + } else { + writer.String("exponential"); + writer.Key("base"); + writer.Double(f.base); + } writer.Key("stops"); stringifyStops(f.stops); } @@ -335,9 +339,13 @@ public: template void operator()(const CompositeExponentialStops& f) { writer.Key("type"); - writer.String("exponential"); - writer.Key("base"); - writer.Double(f.base); + if (f.base == 1) { + writer.String("linear"); + } else { + writer.String("exponential"); + writer.Key("base"); + writer.Double(f.base); + } writer.Key("stops"); stringifyCompositeStops(f.stops); } 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"); -- cgit v1.2.1