[core] Split Interpolator into a separate file
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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_,
|
||||
|
||||
50
include/mbgl/style/expression/interpolator.hpp
Normal file
50
include/mbgl/style/expression/interpolator.hpp
Normal 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
|
||||
@@ -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),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user