[core] property function statistics collection

This commit is contained in:
Ivo van Dongen
2017-04-06 18:06:27 +03:00
committed by Ivo van Dongen
parent 1ca8f4e2f3
commit 935cf531e4
2 changed files with 44 additions and 1 deletions

View File

@@ -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;
};

View File

@@ -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