[core] Merge PiecewiseConstantFunction into Function
This commit is contained in:
@@ -7,7 +7,7 @@ void BackgroundLayer::parsePaints(const JSVal& layer) {
|
||||
paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
|
||||
parseProperty<Function<float>>("background-opacity", PropertyKey::BackgroundOpacity, paint, value);
|
||||
parseProperty<Function<Color>>("background-color", PropertyKey::BackgroundColor, paint, value);
|
||||
parseProperty<PiecewiseConstantFunction<Faded<std::string>>>("background-pattern", PropertyKey::BackgroundImage, paint, value, "background-pattern-transition");
|
||||
parseProperty<Function<Faded<std::string>>>("background-pattern", PropertyKey::BackgroundImage, paint, value, "background-pattern-transition");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ void FillLayer::parsePaints(const JSVal& layer) {
|
||||
parseProperty<Function<std::array<float, 2>>>("fill-translate", PropertyKey::FillTranslate, paint, value);
|
||||
parseProperty<PropertyTransition>("fill-translate-transition", PropertyKey::FillTranslate, paint, value);
|
||||
parseProperty<Function<TranslateAnchorType>>("fill-translate-anchor", PropertyKey::FillTranslateAnchor, paint, value);
|
||||
parseProperty<PiecewiseConstantFunction<Faded<std::string>>>("fill-pattern", PropertyKey::FillImage, paint, value, "fill-pattern-transition");
|
||||
parseProperty<Function<Faded<std::string>>>("fill-pattern", PropertyKey::FillImage, paint, value, "fill-pattern-transition");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ void LineLayer::parsePaints(const JSVal& layer) {
|
||||
parseProperty<PropertyTransition>("line-gap-width-transition", PropertyKey::LineGapWidth, paint, value);
|
||||
parseProperty<Function<float>>("line-blur", PropertyKey::LineBlur, paint, value);
|
||||
parseProperty<PropertyTransition>("line-blur-transition", PropertyKey::LineBlur, paint, value);
|
||||
parseProperty<PiecewiseConstantFunction<Faded<std::vector<float>>>>("line-dasharray", PropertyKey::LineDashArray, paint, value, "line-dasharray-transition");
|
||||
parseProperty<PiecewiseConstantFunction<Faded<std::string>>>("line-pattern", PropertyKey::LineImage, paint, value, "line-pattern-transition");
|
||||
parseProperty<Function<Faded<std::vector<float>>>>("line-dasharray", PropertyKey::LineDashArray, paint, value, "line-dasharray-transition");
|
||||
parseProperty<Function<Faded<std::string>>>("line-pattern", PropertyKey::LineImage, paint, value, "line-pattern-transition");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ public:
|
||||
void calculate(PropertyKey key, T& target, const float z) const {
|
||||
auto it = properties.find(key);
|
||||
if (it != properties.end()) {
|
||||
const PropertyEvaluator<T> evaluator(z);
|
||||
target = mapbox::util::apply_visitor(evaluator, it->second);
|
||||
target = mapbox::util::apply_visitor(PropertyEvaluator<T>(StyleCalculationParameters(z)), it->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/style/function.hpp>
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/style/style_calculation_parameters.hpp>
|
||||
#include <mbgl/util/interpolate.hpp>
|
||||
|
||||
#include <cmath>
|
||||
@@ -27,7 +27,8 @@ template <> inline TextTransformType defaultStopsValue() { return {}; };
|
||||
template <> inline RotationAlignmentType defaultStopsValue() { return {}; };
|
||||
|
||||
template <typename T>
|
||||
T Function<T>::evaluate(float z) const {
|
||||
T Function<T>::evaluate(const StyleCalculationParameters& parameters) const {
|
||||
float z = parameters.z;
|
||||
bool smaller = false;
|
||||
float smaller_z = 0.0f;
|
||||
T smaller_val = T();
|
||||
@@ -73,21 +74,66 @@ T Function<T>::evaluate(float z) const {
|
||||
}
|
||||
}
|
||||
|
||||
template bool Function<bool>::evaluate(float z) const;
|
||||
template float Function<float>::evaluate(float z) const;
|
||||
template Color Function<Color>::evaluate(float z) const;
|
||||
template std::vector<float> Function<std::vector<float>>::evaluate(float z) const;
|
||||
template std::array<float, 2> Function<std::array<float, 2>>::evaluate(float z) const;
|
||||
template class Function<bool>;
|
||||
template class Function<float>;
|
||||
template class Function<Color>;
|
||||
template class Function<std::vector<float>>;
|
||||
template class Function<std::array<float, 2>>;
|
||||
|
||||
template std::string Function<std::string>::evaluate(float z) const;
|
||||
template TranslateAnchorType Function<TranslateAnchorType>::evaluate(float z) const;
|
||||
template RotateAnchorType Function<RotateAnchorType>::evaluate(float z) const;
|
||||
template CapType Function<CapType>::evaluate(float z) const;
|
||||
template JoinType Function<JoinType>::evaluate(float z) const;
|
||||
template PlacementType Function<PlacementType>::evaluate(float z) const;
|
||||
template TextAnchorType Function<TextAnchorType>::evaluate(float z) const;
|
||||
template TextJustifyType Function<TextJustifyType>::evaluate(float z) const;
|
||||
template TextTransformType Function<TextTransformType>::evaluate(float z) const;
|
||||
template RotationAlignmentType Function<RotationAlignmentType>::evaluate(float z) const;
|
||||
template class Function<std::string>;
|
||||
template class Function<TranslateAnchorType>;
|
||||
template class Function<RotateAnchorType>;
|
||||
template class Function<CapType>;
|
||||
template class Function<JoinType>;
|
||||
template class Function<PlacementType>;
|
||||
template class Function<TextAnchorType>;
|
||||
template class Function<TextJustifyType>;
|
||||
template class Function<TextTransformType>;
|
||||
template class Function<RotationAlignmentType>;
|
||||
|
||||
template <typename T>
|
||||
size_t getBiggestStopLessThan(std::vector<std::pair<float, T>> stops, float z) {
|
||||
for (uint32_t i = 0; i < stops.size(); i++) {
|
||||
if (stops[i].first > z) {
|
||||
return i == 0 ? i : i - 1;
|
||||
}
|
||||
}
|
||||
return stops.size() - 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Faded<T> Function<Faded<T>>::evaluate(const StyleCalculationParameters& parameters) const {
|
||||
Faded<T> result;
|
||||
|
||||
float z = parameters.z;
|
||||
float fraction = std::fmod(z, 1.0f);
|
||||
std::chrono::duration<float> d = duration ? *duration : parameters.defaultFadeDuration;
|
||||
float t = std::min((Clock::now() - parameters.zoomHistory.lastIntegerZoomTime) / d, 1.0f);
|
||||
float fromScale = 1.0f;
|
||||
float toScale = 1.0f;
|
||||
size_t from, to;
|
||||
|
||||
if (z > parameters.zoomHistory.lastIntegerZoom) {
|
||||
result.t = fraction + (1.0f - fraction) * t;
|
||||
from = getBiggestStopLessThan(stops, z - 1.0f);
|
||||
to = getBiggestStopLessThan(stops, z);
|
||||
fromScale *= 2.0f;
|
||||
|
||||
} else {
|
||||
result.t = 1 - (1 - t) * fraction;
|
||||
to = getBiggestStopLessThan(stops, z);
|
||||
from = getBiggestStopLessThan(stops, z + 1.0f);
|
||||
fromScale /= 2.0f;
|
||||
}
|
||||
|
||||
result.from = stops[from].second;
|
||||
result.to = stops[to].second;
|
||||
result.fromScale = fromScale;
|
||||
result.toScale = toScale;
|
||||
return result;
|
||||
}
|
||||
|
||||
template class Function<Faded<std::string>>;
|
||||
template class Function<Faded<std::vector<float>>>;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
#ifndef MBGL_STYLE_FUNCTION
|
||||
#define MBGL_STYLE_FUNCTION
|
||||
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <mapbox/optional.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class StyleCalculationParameters;
|
||||
|
||||
template <typename T>
|
||||
class Function {
|
||||
public:
|
||||
@@ -19,13 +26,35 @@ public:
|
||||
explicit Function(const Stops& stops_, float base_)
|
||||
: base(base_), stops(stops_) {}
|
||||
|
||||
T evaluate(float z) const;
|
||||
T evaluate(const StyleCalculationParameters&) const;
|
||||
|
||||
private:
|
||||
const float base = 1;
|
||||
const std::vector<std::pair<float, T>> stops;
|
||||
};
|
||||
|
||||
// Partial specialization for cross-faded properties (*-pattern, line-dasharray).
|
||||
template <typename T>
|
||||
class Function<Faded<T>> {
|
||||
public:
|
||||
using Stop = std::pair<float, T>;
|
||||
using Stops = std::vector<Stop>;
|
||||
|
||||
// TODO: make explicit
|
||||
/* explicit */ Function(const T& constant)
|
||||
: stops({{ 0, constant }}) {}
|
||||
|
||||
explicit Function(const Stops& stops_,
|
||||
mapbox::util::optional<Duration> duration_)
|
||||
: stops(stops_), duration(duration_) {}
|
||||
|
||||
Faded<T> evaluate(const StyleCalculationParameters&) const;
|
||||
|
||||
private:
|
||||
const std::vector<std::pair<float, T>> stops;
|
||||
const mapbox::util::optional<Duration> duration = {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#include <mbgl/style/piecewisefunction_properties.hpp>
|
||||
#include <mbgl/style/types.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
template <typename T>
|
||||
size_t getBiggestStopLessThan(std::vector<std::pair<float, T>> stops, float z) {
|
||||
for (uint32_t i = 0; i < stops.size(); i++) {
|
||||
if (stops[i].first > z) {
|
||||
return i == 0 ? i : i - 1;
|
||||
}
|
||||
}
|
||||
return stops.size() - 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T PiecewiseConstantFunction<T>::evaluate(const StyleCalculationParameters& parameters) const {
|
||||
T result;
|
||||
|
||||
float z = parameters.z;
|
||||
float fraction = std::fmod(z, 1.0f);
|
||||
std::chrono::duration<float> d = duration ? *duration : parameters.defaultFadeDuration;
|
||||
float t = std::min((Clock::now() - parameters.zoomHistory.lastIntegerZoomTime) / d, 1.0f);
|
||||
float fromScale = 1.0f;
|
||||
float toScale = 1.0f;
|
||||
size_t from, to;
|
||||
|
||||
if (z > parameters.zoomHistory.lastIntegerZoom) {
|
||||
result.t = fraction + (1.0f - fraction) * t;
|
||||
from = getBiggestStopLessThan(values, z - 1.0f);
|
||||
to = getBiggestStopLessThan(values, z);
|
||||
fromScale *= 2.0f;
|
||||
|
||||
} else {
|
||||
result.t = 1 - (1 - t) * fraction;
|
||||
to = getBiggestStopLessThan(values, z);
|
||||
from = getBiggestStopLessThan(values, z + 1.0f);
|
||||
fromScale /= 2.0f;
|
||||
}
|
||||
|
||||
|
||||
result.from = values[from].second.to;
|
||||
result.to = values[to].second.to;
|
||||
result.fromScale = fromScale;
|
||||
result.toScale = toScale;
|
||||
return result;
|
||||
}
|
||||
|
||||
template Faded<std::string> PiecewiseConstantFunction<Faded<std::string>>::evaluate(const StyleCalculationParameters&) const;
|
||||
template Faded<std::vector<float>> PiecewiseConstantFunction<Faded<std::vector<float>>>::evaluate(const StyleCalculationParameters&) const;
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef MBGL_STYLE_FADEDFUNCTION_PROPERTIES
|
||||
#define MBGL_STYLE_FADEDFUNCTION_PROPERTIES
|
||||
|
||||
#include <mbgl/style/style_calculation_parameters.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <mapbox/optional.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
template <typename T>
|
||||
struct PiecewiseConstantFunction {
|
||||
PiecewiseConstantFunction(const std::vector<std::pair<float, T>>& values_,
|
||||
mapbox::util::optional<Duration> duration_)
|
||||
: values(values_),
|
||||
duration(duration_) {
|
||||
}
|
||||
|
||||
PiecewiseConstantFunction(const T& value)
|
||||
: values({{ 0, value }}),
|
||||
duration() {
|
||||
}
|
||||
|
||||
T evaluate(const StyleCalculationParameters&) const;
|
||||
|
||||
private:
|
||||
const std::vector<std::pair<float, T>> values;
|
||||
const mapbox::util::optional<Duration> duration;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <mbgl/style/zoom_history.hpp>
|
||||
#include <mbgl/style/function.hpp>
|
||||
#include <mbgl/style/piecewisefunction_properties.hpp>
|
||||
#include <mbgl/style/style_calculation_parameters.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -24,10 +23,6 @@ public:
|
||||
}
|
||||
|
||||
T operator()(const Function<T>& value) const {
|
||||
return value.evaluate(parameters.z);
|
||||
}
|
||||
|
||||
T operator()(const PiecewiseConstantFunction<T>& value) const {
|
||||
return value.evaluate(parameters);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,29 +7,6 @@
|
||||
namespace mbgl {
|
||||
namespace detail {
|
||||
|
||||
optional<std::vector<float>> parseFloatArray(const JSVal& value) {
|
||||
if (!value.IsArray()) {
|
||||
Log::Warning(Event::ParseStyle, "dasharray value must be an array of numbers");
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<float> result;
|
||||
|
||||
for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
|
||||
const JSVal& part = value[i];
|
||||
|
||||
if (!part.IsNumber()) {
|
||||
Log::Warning(Event::ParseStyle, "dasharray value must be an array of numbers");
|
||||
return {};
|
||||
}
|
||||
|
||||
result.push_back(part.GetDouble());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
optional<bool> parseProperty(const char* name, const JSVal& value) {
|
||||
if (!value.IsBool()) {
|
||||
@@ -205,6 +182,29 @@ optional<std::array<float, 2>> parseProperty(const char* name, const JSVal& valu
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
optional<std::vector<float>> parseProperty(const char* name, const JSVal& value) {
|
||||
if (!value.IsArray()) {
|
||||
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", name);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<float> result;
|
||||
|
||||
for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
|
||||
const JSVal& part = value[i];
|
||||
|
||||
if (!part.IsNumber()) {
|
||||
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", name);
|
||||
return {};
|
||||
}
|
||||
|
||||
result.push_back(part.GetDouble());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
optional<PropertyTransition> parseProperty(const char *, const JSVal& value) {
|
||||
PropertyTransition transition;
|
||||
@@ -360,7 +360,7 @@ template<> optional<Function<Color>> parseProperty(const char* name, const JSVal
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
optional<PiecewiseConstantFunction<T>> parsePiecewiseConstantFunction(const JSVal& value, const JSVal& transition) {
|
||||
optional<Function<Faded<T>>> parseFadedFunction(const JSVal& value, const JSVal& transition) {
|
||||
mapbox::util::optional<Duration> duration;
|
||||
if (transition.HasMember("duration")) {
|
||||
duration = std::chrono::milliseconds(transition["duration"].GetUint());
|
||||
@@ -377,57 +377,33 @@ optional<PiecewiseConstantFunction<T>> parsePiecewiseConstantFunction(const JSVa
|
||||
return {};
|
||||
}
|
||||
|
||||
return PiecewiseConstantFunction<T>(*stops, duration);
|
||||
return Function<Faded<T>>(*stops, duration);
|
||||
}
|
||||
|
||||
template <>
|
||||
optional<Faded<std::vector<float>>> parseProperty(const char*, const JSVal& value) {
|
||||
auto floatarray = parseFloatArray(value);
|
||||
if (!floatarray) {
|
||||
return {};
|
||||
}
|
||||
|
||||
Faded<std::vector<float>> parsed;
|
||||
parsed.to = *floatarray;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
template <>
|
||||
optional<Faded<std::string>> parseProperty(const char* name, const JSVal& value) {
|
||||
if (!value.IsString()) {
|
||||
Log::Warning(Event::ParseStyle, "value of '%s' must be a string, or a string function", name);
|
||||
return {};
|
||||
}
|
||||
|
||||
Faded<std::string> parsed;
|
||||
parsed.to = { value.GetString(), value.GetStringLength() };
|
||||
return parsed;
|
||||
}
|
||||
|
||||
template <>
|
||||
optional<PiecewiseConstantFunction<Faded<std::vector<float>>>> parseProperty(const char* name, const JSVal& value, const JSVal& transition) {
|
||||
optional<Function<Faded<std::vector<float>>>> parseProperty(const char* name, const JSVal& value, const JSVal& transition) {
|
||||
if (value.IsObject()) {
|
||||
return parsePiecewiseConstantFunction<Faded<std::vector<float>>>(value, transition);
|
||||
return parseFadedFunction<std::vector<float>>(value, transition);
|
||||
}
|
||||
|
||||
auto constant = parseProperty<Faded<std::vector<float>>>(name, value);
|
||||
auto constant = parseProperty<std::vector<float>>(name, value);
|
||||
if (!constant) {
|
||||
return {};
|
||||
}
|
||||
return PiecewiseConstantFunction<Faded<std::vector<float>>>(*constant);
|
||||
return Function<Faded<std::vector<float>>>(*constant);
|
||||
}
|
||||
|
||||
template <>
|
||||
optional<PiecewiseConstantFunction<Faded<std::string>>> parseProperty(const char* name, const JSVal& value, const JSVal& transition) {
|
||||
optional<Function<Faded<std::string>>> parseProperty(const char* name, const JSVal& value, const JSVal& transition) {
|
||||
if (value.IsObject()) {
|
||||
return parsePiecewiseConstantFunction<Faded<std::string>>(value, transition);
|
||||
return parseFadedFunction<std::string>(value, transition);
|
||||
}
|
||||
|
||||
auto constant = parseProperty<Faded<std::string>>(name, value);
|
||||
auto constant = parseProperty<std::string>(name, value);
|
||||
if (!constant) {
|
||||
return {};
|
||||
}
|
||||
return PiecewiseConstantFunction<Faded<std::string>>(*constant);
|
||||
return Function<Faded<std::string>>(*constant);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
#include <mbgl/style/function.hpp>
|
||||
#include <mbgl/style/piecewisefunction_properties.hpp>
|
||||
#include <mbgl/style/types.hpp>
|
||||
|
||||
#include <vector>
|
||||
@@ -28,8 +27,8 @@ typedef mapbox::util::variant<
|
||||
Function<bool>,
|
||||
Function<float>,
|
||||
Function<Color>,
|
||||
PiecewiseConstantFunction<Faded<std::vector<float>>>,
|
||||
PiecewiseConstantFunction<Faded<std::string>>
|
||||
Function<Faded<std::vector<float>>>,
|
||||
Function<Faded<std::string>>
|
||||
> PropertyValue;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace mbgl {
|
||||
|
||||
class StyleCalculationParameters {
|
||||
public:
|
||||
StyleCalculationParameters(float z_)
|
||||
explicit StyleCalculationParameters(float z_)
|
||||
: z(z_) {}
|
||||
|
||||
StyleCalculationParameters(float z_,
|
||||
|
||||
@@ -7,53 +7,53 @@
|
||||
using namespace mbgl;
|
||||
|
||||
TEST(Function, Constant) {
|
||||
EXPECT_EQ(2.0f, mbgl::Function<float>(2).evaluate(0));
|
||||
EXPECT_EQ(3.8f, mbgl::Function<float>(3.8).evaluate(0));
|
||||
EXPECT_EQ(22.0f, mbgl::Function<float>(22).evaluate(0));
|
||||
EXPECT_EQ(2.0f, mbgl::Function<float>(2).evaluate(4));
|
||||
EXPECT_EQ(3.8f, mbgl::Function<float>(3.8).evaluate(4));
|
||||
EXPECT_EQ(22.0f, mbgl::Function<float>(22).evaluate(4));
|
||||
EXPECT_EQ(2.0f, mbgl::Function<float>(2).evaluate(22));
|
||||
EXPECT_EQ(3.8f, mbgl::Function<float>(3.8).evaluate(22));
|
||||
EXPECT_EQ(22.0f, mbgl::Function<float>(22).evaluate(22));
|
||||
EXPECT_EQ(2.0f, mbgl::Function<float>(2).evaluate(StyleCalculationParameters(0)));
|
||||
EXPECT_EQ(3.8f, mbgl::Function<float>(3.8).evaluate(StyleCalculationParameters(0)));
|
||||
EXPECT_EQ(22.0f, mbgl::Function<float>(22).evaluate(StyleCalculationParameters(0)));
|
||||
EXPECT_EQ(2.0f, mbgl::Function<float>(2).evaluate(StyleCalculationParameters(4)));
|
||||
EXPECT_EQ(3.8f, mbgl::Function<float>(3.8).evaluate(StyleCalculationParameters(4)));
|
||||
EXPECT_EQ(22.0f, mbgl::Function<float>(22).evaluate(StyleCalculationParameters(4)));
|
||||
EXPECT_EQ(2.0f, mbgl::Function<float>(2).evaluate(StyleCalculationParameters(22)));
|
||||
EXPECT_EQ(3.8f, mbgl::Function<float>(3.8).evaluate(StyleCalculationParameters(22)));
|
||||
EXPECT_EQ(22.0f, mbgl::Function<float>(22).evaluate(StyleCalculationParameters(22)));
|
||||
}
|
||||
|
||||
TEST(Function, Stops) {
|
||||
// Explicit constant slope in fringe regions.
|
||||
mbgl::Function<float> slope_1({ { 0, 1.5 }, { 6, 1.5 }, { 8, 3 }, { 22, 3 } }, 1.75);
|
||||
EXPECT_EQ(1.5, slope_1.evaluate(0));
|
||||
EXPECT_EQ(1.5, slope_1.evaluate(4));
|
||||
EXPECT_EQ(1.5, slope_1.evaluate(6));
|
||||
ASSERT_FLOAT_EQ(2.0454545454545454, slope_1.evaluate(7));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(8));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(9));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(15));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(22));
|
||||
EXPECT_EQ(1.5, slope_1.evaluate(StyleCalculationParameters(0)));
|
||||
EXPECT_EQ(1.5, slope_1.evaluate(StyleCalculationParameters(4)));
|
||||
EXPECT_EQ(1.5, slope_1.evaluate(StyleCalculationParameters(6)));
|
||||
ASSERT_FLOAT_EQ(2.0454545454545454, slope_1.evaluate(StyleCalculationParameters(7)));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(StyleCalculationParameters(8)));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(StyleCalculationParameters(9)));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(StyleCalculationParameters(15)));
|
||||
EXPECT_EQ(3.0, slope_1.evaluate(StyleCalculationParameters(22)));
|
||||
|
||||
|
||||
// Test constant values in fringe regions.
|
||||
mbgl::Function<float> slope_2({ { 6, 1.5 }, { 8, 3 } }, 1.75);
|
||||
EXPECT_EQ(1.5, slope_2.evaluate(0));
|
||||
EXPECT_EQ(1.5, slope_2.evaluate(4));
|
||||
EXPECT_EQ(1.5, slope_2.evaluate(6));
|
||||
ASSERT_FLOAT_EQ(2.0454545454545454, slope_2.evaluate(7));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(8));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(9));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(15));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(22));
|
||||
EXPECT_EQ(1.5, slope_2.evaluate(StyleCalculationParameters(0)));
|
||||
EXPECT_EQ(1.5, slope_2.evaluate(StyleCalculationParameters(4)));
|
||||
EXPECT_EQ(1.5, slope_2.evaluate(StyleCalculationParameters(6)));
|
||||
ASSERT_FLOAT_EQ(2.0454545454545454, slope_2.evaluate(StyleCalculationParameters(7)));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(StyleCalculationParameters(8)));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(StyleCalculationParameters(9)));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(StyleCalculationParameters(15)));
|
||||
EXPECT_EQ(3.0, slope_2.evaluate(StyleCalculationParameters(22)));
|
||||
|
||||
// Test no values.
|
||||
mbgl::Function<float> slope_3({}, 1.75);
|
||||
EXPECT_EQ(1, slope_3.evaluate(2));
|
||||
EXPECT_EQ(1, slope_3.evaluate(6));
|
||||
EXPECT_EQ(1, slope_3.evaluate(12));
|
||||
EXPECT_EQ(1, slope_3.evaluate(StyleCalculationParameters(2)));
|
||||
EXPECT_EQ(1, slope_3.evaluate(StyleCalculationParameters(6)));
|
||||
EXPECT_EQ(1, slope_3.evaluate(StyleCalculationParameters(12)));
|
||||
|
||||
|
||||
// Explicit constant slope in fringe regions.
|
||||
mbgl::Function<float> slope_4({ { 0, 2 }, { 8, 10 } }, 1);
|
||||
EXPECT_EQ(2, slope_4.evaluate(0));
|
||||
EXPECT_EQ(3, slope_4.evaluate(1));
|
||||
EXPECT_EQ(4, slope_4.evaluate(2));
|
||||
EXPECT_EQ(4.75, slope_4.evaluate(2.75));
|
||||
EXPECT_EQ(10, slope_4.evaluate(8));
|
||||
EXPECT_EQ(2, slope_4.evaluate(StyleCalculationParameters(0)));
|
||||
EXPECT_EQ(3, slope_4.evaluate(StyleCalculationParameters(1)));
|
||||
EXPECT_EQ(4, slope_4.evaluate(StyleCalculationParameters(2)));
|
||||
EXPECT_EQ(4.75, slope_4.evaluate(StyleCalculationParameters(2.75)));
|
||||
EXPECT_EQ(10, slope_4.evaluate(StyleCalculationParameters(8)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user