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/circle_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/circle_layer_impl.cpp')
-rw-r--r-- | src/mbgl/style/layers/circle_layer_impl.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index 33699b6665..6599126702 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -12,13 +12,13 @@ void CircleLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool CircleLayer::Impl::recalculate(const CalculationParameters& parameters) { - bool hasTransitions = paint.recalculate(parameters); +bool CircleLayer::Impl::evaluate(const PropertyEvaluationParameters& parameters) { + paint.evaluate(parameters); - passes = (paint.circleRadius > 0 && paint.circleColor.value.a > 0 && paint.circleOpacity > 0) + passes = (paint.evaluated.get<CircleRadius>() > 0 && paint.evaluated.get<CircleColor>().a > 0 && paint.evaluated.get<CircleOpacity>() > 0) ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; + return paint.hasTransition(); } std::unique_ptr<Bucket> CircleLayer::Impl::createBucket(BucketParameters& parameters) const { @@ -35,8 +35,8 @@ std::unique_ptr<Bucket> CircleLayer::Impl::createBucket(BucketParameters& parame } float CircleLayer::Impl::getQueryRadius() const { - const std::array<float, 2>& translate = paint.circleTranslate; - return paint.circleRadius + util::length(translate[0], translate[1]); + const std::array<float, 2>& translate = paint.evaluated.get<CircleTranslate>(); + return paint.evaluated.get<CircleRadius>() + util::length(translate[0], translate[1]); } bool CircleLayer::Impl::queryIntersectsGeometry( @@ -46,9 +46,9 @@ bool CircleLayer::Impl::queryIntersectsGeometry( const float pixelsToTileUnits) const { auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.circleTranslate, paint.circleTranslateAnchor, bearing, pixelsToTileUnits); + queryGeometry, paint.evaluated.get<CircleTranslate>(), paint.evaluated.get<CircleTranslateAnchor>(), bearing, pixelsToTileUnits); - auto circleRadius = paint.circleRadius * pixelsToTileUnits; + auto circleRadius = paint.evaluated.get<CircleRadius>() * pixelsToTileUnits; return util::polygonIntersectsBufferedMultiPoint( translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius); |