* [core] Bump gl-js version * [core] Implement image expression * [core] Use new image expression * [core] Coerce image expression to / from string * [core] Serialize evaluated image * [core] Pass available images to layout * [core] Pass images to evaluation context * [core] Set available flag value based on image availability * [core] Allow image coercion to boolean to indicate image availability * [core] Coalesce image expression * [core] Add image expression to next build system * [core] Align serialization format and evaluated type with gl-js * [core] Add images to expression evaluation method * [core] Add support for Image expression to expression test runner * [core] Unskip image expression tests * [core] Update unit tests * [core] Use image expression in annotation manager * [core] Add string to ImageExpression conversion * [core] Add image expression to expression dsl * [core] Convert tokens for implicitly created Image literal * [core] Fix clang format * [core] Split generated style code lines that are over 120 characters * [core] Add unit test for image expression equality * [core] Add image property expression evaluation unit test * [core] Unskip image expression render test * [core] Skip 'in' expression tests * [core] Ignore fill-pattern/update-feature-state render test * [core] Rename Image::serialize to Image::toValue
103 lines
3.8 KiB
C++
103 lines
3.8 KiB
C++
#pragma once
|
|
|
|
#include <mbgl/style/expression/expression.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/util/range.hpp>
|
|
|
|
namespace mbgl {
|
|
namespace style {
|
|
|
|
class PropertyExpressionBase {
|
|
public:
|
|
explicit PropertyExpressionBase(std::unique_ptr<expression::Expression>);
|
|
|
|
bool isZoomConstant() const noexcept;
|
|
bool isFeatureConstant() const noexcept;
|
|
bool isRuntimeConstant() const noexcept;
|
|
float interpolationFactor(const Range<float>&, const float) const noexcept;
|
|
Range<float> getCoveringStops(const float, const float) const noexcept;
|
|
const expression::Expression& getExpression() const noexcept;
|
|
|
|
bool useIntegerZoom = false;
|
|
|
|
protected:
|
|
std::shared_ptr<const expression::Expression> expression;
|
|
variant<std::nullptr_t, const expression::Interpolate*, const expression::Step*> zoomCurve;
|
|
bool isZoomConstant_;
|
|
bool isFeatureConstant_;
|
|
bool isRuntimeConstant_;
|
|
};
|
|
|
|
template <class T>
|
|
class PropertyExpression final : public PropertyExpressionBase {
|
|
public:
|
|
// Second parameter to be used only for conversions from legacy functions.
|
|
PropertyExpression(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = nullopt)
|
|
: PropertyExpressionBase(std::move(expression_)),
|
|
defaultValue(std::move(defaultValue_)) {
|
|
}
|
|
|
|
T evaluate(const expression::EvaluationContext& context, T finalDefaultValue = T()) const {
|
|
const expression::EvaluationResult result = expression->evaluate(context);
|
|
if (result) {
|
|
const optional<T> typed = expression::fromExpressionValue<T>(*result);
|
|
return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue;
|
|
}
|
|
return defaultValue ? *defaultValue : finalDefaultValue;
|
|
}
|
|
|
|
T evaluate(float zoom) const {
|
|
assert(!isZoomConstant());
|
|
assert(isFeatureConstant());
|
|
return evaluate(expression::EvaluationContext(zoom));
|
|
}
|
|
|
|
T evaluate(const GeometryTileFeature& feature, T finalDefaultValue) const {
|
|
assert(isZoomConstant());
|
|
assert(!isFeatureConstant());
|
|
return evaluate(expression::EvaluationContext(&feature), finalDefaultValue);
|
|
}
|
|
|
|
T evaluate(const GeometryTileFeature& feature,
|
|
const std::set<std::string>& availableImages,
|
|
T finalDefaultValue) const {
|
|
return evaluate(expression::EvaluationContext(&feature).withAvailableImages(&availableImages),
|
|
finalDefaultValue);
|
|
}
|
|
|
|
T evaluate(float zoom, const GeometryTileFeature& feature, T finalDefaultValue) const {
|
|
return evaluate(expression::EvaluationContext(zoom, &feature), finalDefaultValue);
|
|
}
|
|
|
|
T evaluate(float zoom,
|
|
const GeometryTileFeature& feature,
|
|
const std::set<std::string>& availableImages,
|
|
T finalDefaultValue) const {
|
|
return evaluate(expression::EvaluationContext(zoom, &feature).withAvailableImages(&availableImages),
|
|
finalDefaultValue);
|
|
}
|
|
|
|
T evaluate(float zoom, const GeometryTileFeature& feature, const FeatureState& state, T finalDefaultValue) const {
|
|
assert(!isFeatureConstant());
|
|
return evaluate(expression::EvaluationContext(zoom, &feature, &state), finalDefaultValue);
|
|
}
|
|
|
|
std::vector<optional<T>> possibleOutputs() const {
|
|
return expression::fromExpressionValues<T>(expression->possibleOutputs());
|
|
}
|
|
|
|
friend bool operator==(const PropertyExpression& lhs,
|
|
const PropertyExpression& rhs) {
|
|
return *lhs.expression == *rhs.expression;
|
|
}
|
|
|
|
private:
|
|
optional<T> defaultValue;
|
|
};
|
|
|
|
} // namespace style
|
|
} // namespace mbgl
|