diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-06-27 16:57:23 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-06-28 10:00:40 -0700 |
commit | bc771ee02e813e0f05663f108d34d3fd057dbd66 (patch) | |
tree | bdd4bc1bce209ec34419e1aa4a988dc3ecf6a405 /include/mbgl/style | |
parent | eabf209bad80634e1dd4fbe7784408ee7d332c5a (diff) | |
download | qtlocation-mapboxgl-bc771ee02e813e0f05663f108d34d3fd057dbd66.tar.gz |
[core] Split Interpolator into a separate file
Diffstat (limited to 'include/mbgl/style')
-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 |
3 files changed, 52 insertions, 43 deletions
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), |