summaryrefslogtreecommitdiff
path: root/src/mbgl/programs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/programs')
-rw-r--r--src/mbgl/programs/symbol_program.cpp18
-rw-r--r--src/mbgl/programs/symbol_program.hpp42
2 files changed, 33 insertions, 27 deletions
diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp
index 84a7a53f1d..8df3b4ae3c 100644
--- a/src/mbgl/programs/symbol_program.cpp
+++ b/src/mbgl/programs/symbol_program.cpp
@@ -17,14 +17,20 @@ std::unique_ptr<SymbolSizeBinder> SymbolSizeBinder::create(const float tileZoom,
const style::DataDrivenPropertyValue<float>& sizeProperty,
const float defaultValue) {
return sizeProperty.match(
- [&] (const style::CompositeFunction<float>& function) -> std::unique_ptr<SymbolSizeBinder> {
- return std::make_unique<CompositeFunctionSymbolSizeBinder>(tileZoom, function, defaultValue);
- },
- [&] (const style::SourceFunction<float>& function) {
- return std::make_unique<SourceFunctionSymbolSizeBinder>(tileZoom, function, defaultValue);
+ [&] (const Undefined& value) -> std::unique_ptr<SymbolSizeBinder> {
+ return std::make_unique<ConstantSymbolSizeBinder>(tileZoom, value, defaultValue);
},
- [&] (const auto& value) -> std::unique_ptr<SymbolSizeBinder> {
+ [&] (float value) -> std::unique_ptr<SymbolSizeBinder> {
return std::make_unique<ConstantSymbolSizeBinder>(tileZoom, value, defaultValue);
+ },
+ [&] (const style::PropertyExpression<float>& expression) -> std::unique_ptr<SymbolSizeBinder> {
+ if (expression.isFeatureConstant()) {
+ return std::make_unique<ConstantSymbolSizeBinder>(tileZoom, expression, defaultValue);
+ } else if (expression.isZoomConstant()) {
+ return std::make_unique<SourceFunctionSymbolSizeBinder>(tileZoom, expression, defaultValue);
+ } else {
+ return std::make_unique<CompositeFunctionSymbolSizeBinder>(tileZoom, expression, defaultValue);
+ }
}
);
}
diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp
index 51f9a48f7f..35b5821918 100644
--- a/src/mbgl/programs/symbol_program.hpp
+++ b/src/mbgl/programs/symbol_program.hpp
@@ -143,13 +143,13 @@ public:
ConstantSymbolSizeBinder(const float /*tileZoom*/, const style::Undefined&, const float defaultValue)
: layoutSize(defaultValue) {}
- ConstantSymbolSizeBinder(const float tileZoom, const style::CameraFunction<float>& function_, const float /*defaultValue*/)
- : layoutSize(function_.evaluate(tileZoom + 1)),
- function(function_) {
- const Range<float> zoomLevels = function_.getCoveringStops(tileZoom, tileZoom + 1);
+ ConstantSymbolSizeBinder(const float tileZoom, const style::PropertyExpression<float>& expression_, const float /*defaultValue*/)
+ : layoutSize(expression_.evaluate(tileZoom + 1)),
+ expression(expression_) {
+ const Range<float> zoomLevels = expression_.getCoveringStops(tileZoom, tileZoom + 1);
coveringRanges = std::make_tuple(
zoomLevels,
- Range<float> { function_.evaluate(zoomLevels.min), function_.evaluate(zoomLevels.max) }
+ Range<float> { expression_.evaluate(zoomLevels.min), expression_.evaluate(zoomLevels.max) }
);
}
@@ -157,7 +157,7 @@ public:
ZoomEvaluatedSize evaluateForZoom(float currentZoom) const override {
float size = layoutSize;
- bool isZoomConstant = !(coveringRanges || function);
+ bool isZoomConstant = !(coveringRanges || expression);
if (coveringRanges) {
// Even though we could get the exact value of the camera function
// at z = currentZoom, we intentionally do not: instead, we interpolate
@@ -167,12 +167,12 @@ public:
const Range<float>& zoomLevels = std::get<0>(*coveringRanges);
const Range<float>& sizeLevels = std::get<1>(*coveringRanges);
float t = util::clamp(
- function->interpolationFactor(zoomLevels, currentZoom),
+ expression->interpolationFactor(zoomLevels, currentZoom),
0.0f, 1.0f
);
size = sizeLevels.min + t * (sizeLevels.max - sizeLevels.min);
- } else if (function) {
- size = function->evaluate(currentZoom);
+ } else if (expression) {
+ size = expression->evaluate(currentZoom);
}
const float unused = 0.0f;
@@ -181,7 +181,7 @@ public:
float layoutSize;
optional<std::tuple<Range<float>, Range<float>>> coveringRanges;
- optional<style::CameraFunction<float>> function;
+ optional<style::PropertyExpression<float>> expression;
};
class SourceFunctionSymbolSizeBinder final : public SymbolSizeBinder {
@@ -190,13 +190,13 @@ public:
using VertexVector = gl::VertexVector<Vertex>;
using VertexBuffer = gl::VertexBuffer<Vertex>;
- SourceFunctionSymbolSizeBinder(const float /*tileZoom*/, const style::SourceFunction<float>& function_, const float defaultValue_)
- : function(function_),
+ SourceFunctionSymbolSizeBinder(const float /*tileZoom*/, style::PropertyExpression<float> expression_, const float defaultValue_)
+ : expression(std::move(expression_)),
defaultValue(defaultValue_) {
}
Range<float> getVertexSizeData(const GeometryTileFeature& feature) override {
- const float size = function.evaluate(feature, defaultValue);
+ const float size = expression.evaluate(feature, defaultValue);
return { size, size };
};
@@ -205,30 +205,30 @@ public:
return { true, false, unused, unused, unused };
}
- style::SourceFunction<float> function;
+ style::PropertyExpression<float> expression;
const float defaultValue;
};
class CompositeFunctionSymbolSizeBinder final : public SymbolSizeBinder {
public:
- CompositeFunctionSymbolSizeBinder(const float tileZoom, const style::CompositeFunction<float>& function_, const float defaultValue_)
- : function(function_),
+ CompositeFunctionSymbolSizeBinder(const float tileZoom, style::PropertyExpression<float> expression_, const float defaultValue_)
+ : expression(std::move(expression_)),
defaultValue(defaultValue_),
layoutZoom(tileZoom + 1),
- coveringZoomStops(function.getCoveringStops(tileZoom, tileZoom + 1))
+ coveringZoomStops(expression.getCoveringStops(tileZoom, tileZoom + 1))
{}
Range<float> getVertexSizeData(const GeometryTileFeature& feature) override {
return {
- function.evaluate(coveringZoomStops.min, feature, defaultValue),
- function.evaluate(coveringZoomStops.max, feature, defaultValue)
+ expression.evaluate(coveringZoomStops.min, feature, defaultValue),
+ expression.evaluate(coveringZoomStops.max, feature, defaultValue)
};
};
ZoomEvaluatedSize evaluateForZoom(float currentZoom) const override {
float sizeInterpolationT = util::clamp(
- function.interpolationFactor(coveringZoomStops, currentZoom),
+ expression.interpolationFactor(coveringZoomStops, currentZoom),
0.0f, 1.0f
);
@@ -236,7 +236,7 @@ public:
return { false, false, sizeInterpolationT, unused, unused };
}
- style::CompositeFunction<float> function;
+ style::PropertyExpression<float> expression;
const float defaultValue;
float layoutZoom;
Range<float> coveringZoomStops;