diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-30 11:06:59 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-11-17 15:13:38 -0800 |
commit | 38fcbe21d48186c4630a3b8a76d1b20e156faadd (patch) | |
tree | 098f73bfea98deb5202fe1c13b1277e43e322755 /src/mbgl/style/layers/line_layer_impl.cpp | |
parent | d4fc66af3924805d40576989c1e139ddafcc4670 (diff) | |
download | qtlocation-mapboxgl-38fcbe21d48186c4630a3b8a76d1b20e156faadd.tar.gz |
[core] Convert style properties to a tuple-based approach
This converts the style property classes (CirclePaintProperties and so on) to the same tuple-based approach as gl::Attribute and gl::Uniform. The approach is outlined in https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md.
The main advantage of this approach is it allows writing algorithms that work on sets of style properties, without resorting to code generation or manually repetitive code. This lets us iterate on approaches to data-driven properties more easily.
Another advantage is that the cascading, unevaluated, and evaluated states of a set of properties exist as independent structures, instead of individual properties holding their own state. This is a more functional approach that makes data flow clearer and reduces state.
Diffstat (limited to 'src/mbgl/style/layers/line_layer_impl.cpp')
-rw-r--r-- | src/mbgl/style/layers/line_layer_impl.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index c116af5fc2..e6ec21a659 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -12,26 +12,24 @@ void LineLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool LineLayer::Impl::recalculate(const CalculationParameters& parameters) { +bool LineLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { // for scaling dasharrays - CalculationParameters dashArrayParams = parameters; + PropertyEvaluationParameters dashArrayParams = parameters; dashArrayParams.z = std::floor(dashArrayParams.z); - paint.lineWidth.calculate(dashArrayParams); - dashLineWidth = paint.lineWidth; + dashLineWidth = paint.evaluate<LineWidth>(dashArrayParams); - bool hasTransitions = paint.recalculate(parameters); + paint.evaluate(parameters); - passes = (paint.lineOpacity > 0 && paint.lineColor.value.a > 0 && paint.lineWidth > 0) + passes = (paint.evaluated.get<LineOpacity>() > 0 && paint.evaluated.get<LineColor>().a > 0 && paint.evaluated.get<LineWidth>() > 0) ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr<Bucket> LineLayer::Impl::createBucket(BucketParameters& parameters) const { auto bucket = std::make_unique<LineBucket>(parameters.tileID.overscaleFactor()); - bucket->layout = layout; - bucket->layout.recalculate(CalculationParameters(parameters.tileID.overscaledZ)); + bucket->layout = layout.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ)); auto& name = bucketName(); parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { @@ -44,10 +42,10 @@ std::unique_ptr<Bucket> LineLayer::Impl::createBucket(BucketParameters& paramete } float LineLayer::Impl::getLineWidth() const { - if (paint.lineGapWidth > 0) { - return paint.lineGapWidth + 2 * paint.lineWidth; + if (paint.evaluated.get<LineGapWidth>() > 0) { + return paint.evaluated.get<LineGapWidth>() + 2 * paint.evaluated.get<LineWidth>(); } else { - return paint.lineWidth; + return paint.evaluated.get<LineWidth>(); } } @@ -82,8 +80,8 @@ optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const d } float LineLayer::Impl::getQueryRadius() const { - const std::array<float, 2>& translate = paint.lineTranslate; - return getLineWidth() / 2.0 + std::abs(paint.lineOffset) + util::length(translate[0], translate[1]); + const std::array<float, 2>& translate = paint.evaluated.get<LineTranslate>(); + return getLineWidth() / 2.0 + std::abs(paint.evaluated.get<LineOffset>()) + util::length(translate[0], translate[1]); } bool LineLayer::Impl::queryIntersectsGeometry( @@ -95,8 +93,8 @@ bool LineLayer::Impl::queryIntersectsGeometry( const float halfWidth = getLineWidth() / 2.0 * pixelsToTileUnits; auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.lineTranslate, paint.lineTranslateAnchor, bearing, pixelsToTileUnits); - auto offsetGeometry = offsetLine(geometry, paint.lineOffset * pixelsToTileUnits); + queryGeometry, paint.evaluated.get<LineTranslate>(), paint.evaluated.get<LineTranslateAnchor>(), bearing, pixelsToTileUnits); + auto offsetGeometry = offsetLine(geometry, paint.evaluated.get<LineOffset>() * pixelsToTileUnits); return util::polygonIntersectsBufferedMultiLine( translatedQueryGeometry.value_or(queryGeometry), |