[core] Split Interpolator into a separate file

This commit is contained in:
John Firebaugh
2018-06-27 16:57:23 -07:00
parent eabf209bad
commit bc771ee02e
5 changed files with 53 additions and 46 deletions

View File

@@ -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

View File

@@ -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_,

View File

@@ -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

View File

@@ -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),

View File

@@ -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) {