[core] Remove stops-based *Function constructors
This commit is contained in:
@@ -504,6 +504,7 @@ set(MBGL_CORE_FILES
|
||||
include/mbgl/style/function/interval_stops.hpp
|
||||
include/mbgl/style/function/source_function.hpp
|
||||
src/mbgl/style/function/categorical_stops.cpp
|
||||
src/mbgl/style/function/convert.cpp
|
||||
src/mbgl/style/function/expression.cpp
|
||||
src/mbgl/style/function/identity_stops.cpp
|
||||
|
||||
|
||||
@@ -3,9 +3,18 @@
|
||||
#include <mbgl/style/function/camera_function.hpp>
|
||||
#include <mbgl/style/function/source_function.hpp>
|
||||
#include <mbgl/style/function/composite_function.hpp>
|
||||
#include <mbgl/style/function/convert.hpp>
|
||||
#include <mbgl/style/function/categorical_stops.hpp>
|
||||
#include <mbgl/style/function/exponential_stops.hpp>
|
||||
#include <mbgl/style/function/interval_stops.hpp>
|
||||
#include <mbgl/style/function/identity_stops.hpp>
|
||||
#include <mbgl/style/function/composite_exponential_stops.hpp>
|
||||
#include <mbgl/style/function/composite_interval_stops.hpp>
|
||||
#include <mbgl/style/function/composite_categorical_stops.hpp>
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/style/conversion/constant.hpp>
|
||||
#include <mbgl/util/ignore.hpp>
|
||||
#include <mbgl/util/variant.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -193,12 +202,22 @@ struct Converter<CameraFunction<T>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto stops = StopsConverter<T, typename CameraFunction<T>::Stops>()(value, error);
|
||||
using Stops = std::conditional_t<
|
||||
util::Interpolatable<T>::value,
|
||||
variant<
|
||||
ExponentialStops<T>,
|
||||
IntervalStops<T>>,
|
||||
variant<
|
||||
IntervalStops<T>>>;
|
||||
|
||||
auto stops = StopsConverter<T, Stops>()(value, error);
|
||||
if (!stops) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return CameraFunction<T>(*stops);
|
||||
return CameraFunction<T>((*stops).match([&] (const auto& s) {
|
||||
return expression::Convert::toExpression(s);
|
||||
}), false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -238,7 +257,19 @@ struct Converter<SourceFunction<T>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto stops = StopsConverter<T, typename SourceFunction<T>::Stops>()(value, error);
|
||||
using Stops = std::conditional_t<
|
||||
util::Interpolatable<T>::value,
|
||||
variant<
|
||||
ExponentialStops<T>,
|
||||
IntervalStops<T>,
|
||||
CategoricalStops<T>,
|
||||
IdentityStops<T>>,
|
||||
variant<
|
||||
IntervalStops<T>,
|
||||
CategoricalStops<T>,
|
||||
IdentityStops<T>>>;
|
||||
|
||||
auto stops = StopsConverter<T, Stops>()(value, error);
|
||||
if (!stops) {
|
||||
return {};
|
||||
}
|
||||
@@ -248,7 +279,9 @@ struct Converter<SourceFunction<T>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
return SourceFunction<T>(*propertyString, *stops, *defaultValue);
|
||||
return SourceFunction<T>((*stops).match([&] (const auto& s) {
|
||||
return expression::Convert::toExpression(*propertyString, s);
|
||||
}), *defaultValue);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -374,7 +407,17 @@ struct Converter<CompositeFunction<T>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto stops = StopsConverter<T, typename CompositeFunction<T>::Stops>()(value, error);
|
||||
using Stops = std::conditional_t<
|
||||
util::Interpolatable<T>::value,
|
||||
variant<
|
||||
CompositeExponentialStops<T>,
|
||||
CompositeIntervalStops<T>,
|
||||
CompositeCategoricalStops<T>>,
|
||||
variant<
|
||||
CompositeIntervalStops<T>,
|
||||
CompositeCategoricalStops<T>>>;
|
||||
|
||||
auto stops = StopsConverter<T, Stops>()(value, error);
|
||||
if (!stops) {
|
||||
return {};
|
||||
}
|
||||
@@ -384,7 +427,9 @@ struct Converter<CompositeFunction<T>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
return CompositeFunction<T>(*propertyString, *stops, *defaultValue);
|
||||
return CompositeFunction<T>((*stops).match([&] (const auto& s) {
|
||||
return expression::Convert::toExpression(*propertyString, s);
|
||||
}), *defaultValue);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/style/expression/value.hpp>
|
||||
#include <mbgl/style/expression/is_constant.hpp>
|
||||
#include <mbgl/style/expression/interpolate.hpp>
|
||||
#include <mbgl/style/expression/step.hpp>
|
||||
#include <mbgl/style/expression/find_zoom_curve.hpp>
|
||||
#include <mbgl/style/expression/value.hpp>
|
||||
#include <mbgl/style/expression/is_constant.hpp>
|
||||
#include <mbgl/style/function/convert.hpp>
|
||||
#include <mbgl/style/function/exponential_stops.hpp>
|
||||
#include <mbgl/style/function/interval_stops.hpp>
|
||||
#include <mbgl/util/interpolate.hpp>
|
||||
#include <mbgl/util/variant.hpp>
|
||||
#include <mbgl/util/range.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -18,31 +14,15 @@ namespace style {
|
||||
template <class T>
|
||||
class CameraFunction {
|
||||
public:
|
||||
using Stops = std::conditional_t<
|
||||
util::Interpolatable<T>::value,
|
||||
variant<
|
||||
ExponentialStops<T>,
|
||||
IntervalStops<T>>,
|
||||
variant<
|
||||
IntervalStops<T>>>;
|
||||
|
||||
CameraFunction(std::unique_ptr<expression::Expression> expression_)
|
||||
: isExpression(true),
|
||||
// The second parameter should be used only for conversions from legacy functions.
|
||||
CameraFunction(std::unique_ptr<expression::Expression> expression_, bool isExpression_ = true)
|
||||
: isExpression(isExpression_),
|
||||
expression(std::move(expression_)),
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get()))
|
||||
{
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get())) {
|
||||
assert(!expression::isZoomConstant(*expression));
|
||||
assert(expression::isFeatureConstant(*expression));
|
||||
}
|
||||
|
||||
CameraFunction(const Stops& stops)
|
||||
: isExpression(false),
|
||||
expression(stops.match([&] (const auto& s) {
|
||||
return expression::Convert::toExpression(s);
|
||||
})),
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get()))
|
||||
{}
|
||||
|
||||
T evaluate(float zoom) const {
|
||||
const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(zoom, nullptr));
|
||||
if (result) {
|
||||
@@ -82,7 +62,7 @@ public:
|
||||
const expression::Expression& getExpression() const { return *expression; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<expression::Expression> expression;
|
||||
std::shared_ptr<const expression::Expression> expression;
|
||||
const variant<const expression::Interpolate*, const expression::Step*> zoomCurve;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,74 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/style/expression/value.hpp>
|
||||
#include <mbgl/style/expression/is_constant.hpp>
|
||||
#include <mbgl/style/expression/interpolate.hpp>
|
||||
#include <mbgl/style/expression/step.hpp>
|
||||
#include <mbgl/style/expression/find_zoom_curve.hpp>
|
||||
#include <mbgl/style/expression/value.hpp>
|
||||
#include <mbgl/style/expression/is_constant.hpp>
|
||||
#include <mbgl/style/function/convert.hpp>
|
||||
#include <mbgl/style/function/composite_exponential_stops.hpp>
|
||||
#include <mbgl/style/function/composite_interval_stops.hpp>
|
||||
#include <mbgl/style/function/composite_categorical_stops.hpp>
|
||||
#include <mbgl/util/interpolate.hpp>
|
||||
#include <mbgl/util/range.hpp>
|
||||
#include <mbgl/util/variant.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class GeometryTileFeature;
|
||||
|
||||
namespace style {
|
||||
|
||||
// A CompositeFunction consists of an outer zoom function whose stop range values are
|
||||
// "inner" source functions. It provides the GL Native implementation of
|
||||
// "zoom-and-property" functions from the style spec.
|
||||
|
||||
template <class T>
|
||||
class CompositeFunction {
|
||||
public:
|
||||
using InnerStops = std::conditional_t<
|
||||
util::Interpolatable<T>::value,
|
||||
variant<
|
||||
ExponentialStops<T>,
|
||||
IntervalStops<T>,
|
||||
CategoricalStops<T>>,
|
||||
variant<
|
||||
IntervalStops<T>,
|
||||
CategoricalStops<T>>>;
|
||||
|
||||
using Stops = std::conditional_t<
|
||||
util::Interpolatable<T>::value,
|
||||
variant<
|
||||
CompositeExponentialStops<T>,
|
||||
CompositeIntervalStops<T>,
|
||||
CompositeCategoricalStops<T>>,
|
||||
variant<
|
||||
CompositeIntervalStops<T>,
|
||||
CompositeCategoricalStops<T>>>;
|
||||
|
||||
// The second parameter should be used only for conversions from legacy functions.
|
||||
CompositeFunction(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {})
|
||||
: isExpression(true),
|
||||
defaultValue(std::move(defaultValue_)),
|
||||
expression(std::move(expression_)),
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get()))
|
||||
{
|
||||
: isExpression(defaultValue_),
|
||||
expression(std::move(expression_)),
|
||||
defaultValue(std::move(defaultValue_)),
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get())) {
|
||||
assert(!expression::isZoomConstant(*expression));
|
||||
assert(!expression::isFeatureConstant(*expression));
|
||||
}
|
||||
|
||||
CompositeFunction(const std::string& property, const Stops& stops, optional<T> defaultValue_ = {})
|
||||
: isExpression(false),
|
||||
defaultValue(std::move(defaultValue_)),
|
||||
expression(stops.match([&] (const auto& s) {
|
||||
return expression::Convert::toExpression(property, s);
|
||||
})),
|
||||
zoomCurve(expression::findZoomCurveChecked(expression.get()))
|
||||
{}
|
||||
|
||||
// Return the range obtained by evaluating the function at each of the zoom levels in zoomRange
|
||||
template <class Feature>
|
||||
Range<T> evaluate(const Range<float>& zoomRange, const Feature& feature, T finalDefaultValue) {
|
||||
@@ -118,8 +73,8 @@ public:
|
||||
bool isExpression;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const expression::Expression> expression;
|
||||
optional<T> defaultValue;
|
||||
std::shared_ptr<expression::Expression> expression;
|
||||
const variant<const expression::Interpolate*, const expression::Step*> zoomCurve;
|
||||
};
|
||||
|
||||
|
||||
@@ -306,40 +306,15 @@ struct Convert {
|
||||
return std::move(*zoomCurve);
|
||||
}
|
||||
|
||||
|
||||
static std::unique_ptr<Expression> fromIdentityFunction(type::Type type, const std::string& property)
|
||||
template <typename T>
|
||||
static std::unique_ptr<Expression> toExpression(const std::string& property,
|
||||
const IdentityStops<T>&)
|
||||
{
|
||||
std::unique_ptr<Expression> input = type.match(
|
||||
[&] (const type::StringType&) {
|
||||
return makeGet(type::String, property);
|
||||
},
|
||||
[&] (const type::NumberType&) {
|
||||
return makeGet(type::Number, property);
|
||||
},
|
||||
[&] (const type::BooleanType&) {
|
||||
return makeGet(type::Boolean, property);
|
||||
},
|
||||
[&] (const type::ColorType&) {
|
||||
std::vector<std::unique_ptr<Expression>> args;
|
||||
args.push_back(makeGet(type::String, property));
|
||||
return std::make_unique<Coercion>(type::Color, std::move(args));
|
||||
},
|
||||
[&] (const type::Array& arr) {
|
||||
std::vector<std::unique_ptr<Expression>> getArgs;
|
||||
getArgs.push_back(makeLiteral(property));
|
||||
ParsingContext ctx;
|
||||
ParseResult get = createCompoundExpression("get", std::move(getArgs), ctx);
|
||||
assert(get);
|
||||
assert(ctx.getErrors().size() == 0);
|
||||
return std::make_unique<ArrayAssertion>(arr, std::move(*get));
|
||||
},
|
||||
[&] (const auto&) -> std::unique_ptr<Expression> {
|
||||
return makeLiteral(Null);
|
||||
}
|
||||
);
|
||||
|
||||
return input;
|
||||
return fromIdentityFunction(property, expression::valueTypeToExpressionType<T>());
|
||||
}
|
||||
|
||||
private:
|
||||
static std::unique_ptr<Expression> fromIdentityFunction(const std::string& property, type::Type type);
|
||||
};
|
||||
|
||||
} // namespace expression
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/style/expression/value.hpp>
|
||||
#include <mbgl/style/expression/is_constant.hpp>
|
||||
#include <mbgl/style/function/convert.hpp>
|
||||
#include <mbgl/style/function/exponential_stops.hpp>
|
||||
#include <mbgl/style/function/interval_stops.hpp>
|
||||
#include <mbgl/style/function/categorical_stops.hpp>
|
||||
#include <mbgl/style/function/identity_stops.hpp>
|
||||
#include <mbgl/util/interpolate.hpp>
|
||||
#include <mbgl/util/variant.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -17,37 +10,15 @@ namespace style {
|
||||
template <class T>
|
||||
class SourceFunction {
|
||||
public:
|
||||
using Stops = std::conditional_t<
|
||||
util::Interpolatable<T>::value,
|
||||
variant<
|
||||
ExponentialStops<T>,
|
||||
IntervalStops<T>,
|
||||
CategoricalStops<T>,
|
||||
IdentityStops<T>>,
|
||||
variant<
|
||||
IntervalStops<T>,
|
||||
CategoricalStops<T>,
|
||||
IdentityStops<T>>>;
|
||||
|
||||
// The second parameter should be used only for conversions from legacy functions.
|
||||
SourceFunction(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = {})
|
||||
: isExpression(true),
|
||||
defaultValue(std::move(defaultValue_)),
|
||||
expression(std::move(expression_))
|
||||
{
|
||||
: isExpression(defaultValue_),
|
||||
expression(std::move(expression_)),
|
||||
defaultValue(std::move(defaultValue_)) {
|
||||
assert(expression::isZoomConstant(*expression));
|
||||
assert(!expression::isFeatureConstant(*expression));
|
||||
}
|
||||
|
||||
SourceFunction(const std::string& property, const Stops& stops, optional<T> defaultValue_ = {})
|
||||
: isExpression(false),
|
||||
defaultValue(std::move(defaultValue_)),
|
||||
expression(stops.match([&] (const IdentityStops<T>&) {
|
||||
return expression::Convert::fromIdentityFunction(expression::valueTypeToExpressionType<T>(), property);
|
||||
}, [&] (const auto& s) {
|
||||
return expression::Convert::toExpression(property, s);
|
||||
}))
|
||||
{}
|
||||
|
||||
template <class Feature>
|
||||
T evaluate(const Feature& feature, T finalDefaultValue) const {
|
||||
const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(&feature));
|
||||
@@ -73,8 +44,8 @@ public:
|
||||
const expression::Expression& getExpression() const { return *expression; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<const expression::Expression> expression;
|
||||
optional<T> defaultValue;
|
||||
std::shared_ptr<expression::Expression> expression;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
40
src/mbgl/style/function/convert.cpp
Normal file
40
src/mbgl/style/function/convert.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <mbgl/style/function/convert.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
namespace expression {
|
||||
|
||||
std::unique_ptr<Expression> Convert::fromIdentityFunction(const std::string& property, type::Type type) {
|
||||
return type.match(
|
||||
[&] (const type::StringType&) {
|
||||
return makeGet(type::String, property);
|
||||
},
|
||||
[&] (const type::NumberType&) {
|
||||
return makeGet(type::Number, property);
|
||||
},
|
||||
[&] (const type::BooleanType&) {
|
||||
return makeGet(type::Boolean, property);
|
||||
},
|
||||
[&] (const type::ColorType&) {
|
||||
std::vector<std::unique_ptr<Expression>> args;
|
||||
args.push_back(makeGet(type::String, property));
|
||||
return std::make_unique<Coercion>(type::Color, std::move(args));
|
||||
},
|
||||
[&] (const type::Array& arr) {
|
||||
std::vector<std::unique_ptr<Expression>> getArgs;
|
||||
getArgs.push_back(makeLiteral(property));
|
||||
ParsingContext ctx;
|
||||
ParseResult get = createCompoundExpression("get", std::move(getArgs), ctx);
|
||||
assert(get);
|
||||
assert(ctx.getErrors().size() == 0);
|
||||
return std::make_unique<ArrayAssertion>(arr, std::move(*get));
|
||||
},
|
||||
[&] (const auto&) -> std::unique_ptr<Expression> {
|
||||
return makeLiteral(Null);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace expression
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user