diff options
-rw-r--r-- | cmake/core-files.cmake | 1 | ||||
-rw-r--r-- | include/mbgl/style/expression/interpolate.hpp | 43 | ||||
-rw-r--r-- | include/mbgl/style/expression/interpolator.hpp | 50 | ||||
-rw-r--r-- | include/mbgl/style/function/convert.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/expression/interpolate.cpp | 3 |
5 files changed, 53 insertions, 46 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 7e48b336b4..714d6d5c8f 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -453,6 +453,7 @@ set(MBGL_CORE_FILES include/mbgl/style/expression/find_zoom_curve.hpp include/mbgl/style/expression/get_covering_stops.hpp include/mbgl/style/expression/interpolate.hpp + include/mbgl/style/expression/interpolator.hpp include/mbgl/style/expression/is_constant.hpp include/mbgl/style/expression/is_expression.hpp include/mbgl/style/expression/length.hpp diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp index cc744ac7b7..1f73fc14b4 100644 --- a/include/mbgl/style/expression/interpolate.hpp +++ b/include/mbgl/style/expression/interpolate.hpp @@ -3,12 +3,9 @@ #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/get_covering_stops.hpp> +#include <mbgl/style/expression/interpolator.hpp> #include <mbgl/style/conversion.hpp> -#include <mbgl/util/interpolate.hpp> -#include <mbgl/util/range.hpp> -#include <mbgl/util/unitbezier.hpp> - #include <memory> #include <map> #include <cmath> @@ -17,48 +14,10 @@ namespace mbgl { namespace style { namespace expression { -class ExponentialInterpolator { -public: - ExponentialInterpolator(double base_) : base(base_) {} - - double base; - - double interpolationFactor(const Range<double>& inputLevels, const double input) const { - return util::interpolationFactor(base, - Range<float> { - static_cast<float>(inputLevels.min), - static_cast<float>(inputLevels.max) - }, - input); - } - - bool operator==(const ExponentialInterpolator& rhs) const { - return base == rhs.base; - } -}; - -class CubicBezierInterpolator { -public: - CubicBezierInterpolator(double x1_, double y1_, double x2_, double y2_) : ub(x1_, y1_, x2_, y2_) {} - - double interpolationFactor(const Range<double>& inputLevels, const double input) const { - return ub.solve(input / (inputLevels.max - inputLevels.min), 1e-6); - } - - bool operator==(const CubicBezierInterpolator& rhs) const { - return ub == rhs.ub; - } - - util::UnitBezier ub; -}; - - ParseResult parseInterpolate(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); class InterpolateBase : public Expression { public: - using Interpolator = variant<ExponentialInterpolator, CubicBezierInterpolator>; - InterpolateBase(const type::Type& type_, Interpolator interpolator_, std::unique_ptr<Expression> input_, diff --git a/include/mbgl/style/expression/interpolator.hpp b/include/mbgl/style/expression/interpolator.hpp new file mode 100644 index 0000000000..f37fb2c9cd --- /dev/null +++ b/include/mbgl/style/expression/interpolator.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include <mbgl/util/interpolate.hpp> +#include <mbgl/util/range.hpp> +#include <mbgl/util/unitbezier.hpp> + +namespace mbgl { +namespace style { +namespace expression { + +class ExponentialInterpolator { +public: + ExponentialInterpolator(double base_) : base(base_) {} + + double base; + + double interpolationFactor(const Range<double>& inputLevels, const double input) const { + return util::interpolationFactor(base, + Range<float> { + static_cast<float>(inputLevels.min), + static_cast<float>(inputLevels.max) + }, + input); + } + + bool operator==(const ExponentialInterpolator& rhs) const { + return base == rhs.base; + } +}; + +class CubicBezierInterpolator { +public: + CubicBezierInterpolator(double x1_, double y1_, double x2_, double y2_) : ub(x1_, y1_, x2_, y2_) {} + + double interpolationFactor(const Range<double>& inputLevels, const double input) const { + return ub.solve(input / (inputLevels.max - inputLevels.min), 1e-6); + } + + bool operator==(const CubicBezierInterpolator& rhs) const { + return ub == rhs.ub; + } + + util::UnitBezier ub; +}; + +using Interpolator = variant<ExponentialInterpolator, CubicBezierInterpolator>; + +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/function/convert.hpp b/include/mbgl/style/function/convert.hpp index 401a81d52e..b34071d219 100644 --- a/include/mbgl/style/function/convert.hpp +++ b/include/mbgl/style/function/convert.hpp @@ -95,7 +95,7 @@ struct Convert { static ParseResult makeInterpolate(type::Type type, std::unique_ptr<Expression> input, std::map<double, std::unique_ptr<Expression>> convertedStops, - typename Interpolate<OutputType>::Interpolator interpolator) + Interpolator interpolator) { ParseResult curve = ParseResult(std::make_unique<Interpolate<OutputType>>( std::move(type), diff --git a/src/mbgl/style/expression/interpolate.cpp b/src/mbgl/style/expression/interpolate.cpp index 75f4ce828e..051f2cf9f5 100644 --- a/src/mbgl/style/expression/interpolate.cpp +++ b/src/mbgl/style/expression/interpolate.cpp @@ -5,9 +5,6 @@ namespace mbgl { namespace style { namespace expression { -using Interpolator = variant<ExponentialInterpolator, - CubicBezierInterpolator>; - using namespace mbgl::style::conversion; ParseResult parseInterpolate(const Convertible& value, ParsingContext& ctx) { |