diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-04-06 18:06:27 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-04-19 17:21:28 -0700 |
commit | 935cf531e43649b6374f7bd59976cf78ab69c522 (patch) | |
tree | 9e8df36920f1e6ef5023b4d4e2c3bce4a4f8d2da | |
parent | 1ca8f4e2f324b34df229e4b47dd96db0018ea451 (diff) | |
download | qtlocation-mapboxgl-935cf531e43649b6374f7bd59976cf78ab69c522.tar.gz |
[core] property function statistics collection
-rw-r--r-- | src/mbgl/style/paint_property_binder.hpp | 14 | ||||
-rw-r--r-- | src/mbgl/style/paint_property_statistics.hpp | 31 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/mbgl/style/paint_property_binder.hpp b/src/mbgl/style/paint_property_binder.hpp index bf98e6ef9a..3915ee588b 100644 --- a/src/mbgl/style/paint_property_binder.hpp +++ b/src/mbgl/style/paint_property_binder.hpp @@ -4,6 +4,7 @@ #include <mbgl/gl/attribute.hpp> #include <mbgl/gl/uniform.hpp> #include <mbgl/util/type_list.hpp> +#include <mbgl/style/paint_property_statistics.hpp> namespace mbgl { namespace style { @@ -90,6 +91,8 @@ public: virtual float interpolationFactor(float currentZoom) const = 0; static std::unique_ptr<PaintPropertyBinder> create(const PossiblyEvaluatedPropertyValue<T>& value, float zoom, T defaultValue); + + PaintPropertyStatistics<T> statistics; }; template <class T, class A> @@ -136,7 +139,9 @@ public: } void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) override { - auto value = attributeValue(function.evaluate(feature, defaultValue)); + auto evaluated = function.evaluate(feature, defaultValue); + this->statistics.add(evaluated); + auto value = attributeValue(evaluated); for (std::size_t i = vertexVector.vertexSize(); i < length; ++i) { vertexVector.emplace_back(BaseVertex { value }); } @@ -187,6 +192,8 @@ public: void populateVertexVector(const GeometryTileFeature& feature, std::size_t length) override { Range<T> range = function.evaluate(std::get<1>(coveringRanges), feature, defaultValue); + this->statistics.add(range.min); + this->statistics.add(range.max); AttributeValue value = zoomInterpolatedAttributeValue( attributeValue(range.min), attributeValue(range.max)); @@ -312,6 +319,11 @@ public: }; } + template <class P> + const auto& statistics() const { + return binders.template get<P>()->statistics; + } + private: Binders binders; }; diff --git a/src/mbgl/style/paint_property_statistics.hpp b/src/mbgl/style/paint_property_statistics.hpp new file mode 100644 index 0000000000..01d634dd6f --- /dev/null +++ b/src/mbgl/style/paint_property_statistics.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <mbgl/util/optional.hpp> + +namespace mbgl { +namespace style { + +template <class T> +class PaintPropertyStatistics { +public: + optional<T> max() const { return {}; } + void add(const T&) {} +}; + +template <> +class PaintPropertyStatistics<float> { +public: + optional<float> max() const { + return _max; + } + + void add(float value) { + _max = _max ? std::max(*_max, value) : value; + } + +private: + optional<float> _max; +}; + +} // namespace style +} // namespace mbgl |