diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-01-17 11:48:37 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-01-17 15:18:14 -0600 |
commit | 531a1c3070a098b5b31082c0500f0a3ce6a500bb (patch) | |
tree | dc01f3f1b164fc564624d498aea02b6c42576cd8 | |
parent | b04e11b5ca377e288b9ad27406603e4e1076a375 (diff) | |
download | qtlocation-mapboxgl-531a1c3070a098b5b31082c0500f0a3ce6a500bb.tar.gz |
[core] Fix calculation of delayed transitions
-rw-r--r-- | cmake/test-files.cmake | 2 | ||||
-rw-r--r-- | src/mbgl/style/paint_property.hpp | 3 | ||||
-rw-r--r-- | test/style/paint_property.test.cpp | 94 |
3 files changed, 99 insertions, 0 deletions
diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 7eca71299f..bf908e758c 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -55,6 +55,7 @@ set(MBGL_TEST_FILES test/src/mbgl/test/stub_file_source.hpp test/src/mbgl/test/stub_layer_observer.hpp test/src/mbgl/test/stub_style_observer.hpp + test/src/mbgl/test/stub_tile_observer.hpp test/src/mbgl/test/test.cpp test/src/mbgl/test/util.cpp test/src/mbgl/test/util.hpp @@ -80,6 +81,7 @@ set(MBGL_TEST_FILES test/style/filter.test.cpp test/style/functions.test.cpp test/style/group_by_layout.test.cpp + test/style/paint_property.test.cpp test/style/source.test.cpp test/style/style.test.cpp test/style/style_layer.test.cpp diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 15df2a77c7..7b56f6415d 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -45,6 +45,9 @@ public: // Transition from prior value is now complete. prior = {}; return finalValue; + } else if (parameters.now < begin) { + // Transition hasn't started yet. + return prior->get().evaluate(parameters, defaultValue); } else { // Interpolate between recursively-calculated prior value and final. float t = std::chrono::duration<float>(parameters.now - begin) / (end - begin); diff --git a/test/style/paint_property.test.cpp b/test/style/paint_property.test.cpp new file mode 100644 index 0000000000..487dbe9652 --- /dev/null +++ b/test/style/paint_property.test.cpp @@ -0,0 +1,94 @@ +#include <mbgl/test/util.hpp> + +#include <mbgl/style/paint_property.hpp> + +using namespace mbgl; +using namespace mbgl::style; +using namespace std::literals::chrono_literals; + +TEST(UnevaluatedPaintProperty, EvaluateDefaultValue) { + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> property; + ASSERT_EQ(0.0f, property.evaluate(PropertyEvaluationParameters(0), 0.0f)); +} + +TEST(UnevaluatedPaintProperty, EvaluateUntransitionedConstant) { + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> property { + PropertyValue<float>(1.0f), + UnevaluatedPaintProperty<float, PropertyEvaluator<float>>(), + TransitionOptions(), + TimePoint::min() + }; + + ASSERT_EQ(1.0f, property.evaluate(PropertyEvaluationParameters(0), 0.0f)); +} + +TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithoutDelay) { + TransitionOptions transition; + transition.duration = { 1000ms }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t0 { + PropertyValue<float>(0.0f), + UnevaluatedPaintProperty<float, PropertyEvaluator<float>>(), + TransitionOptions(), + TimePoint::min() + }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t1 { + PropertyValue<float>(1.0f), + t0, + transition, + TimePoint::min() + }; + + auto evaluate = [&] (Duration delta) { + PropertyEvaluationParameters parameters { + 0, + TimePoint::min() + delta, + ZoomHistory(), + Duration::zero() + }; + + return t1.evaluate(parameters, 0.0f); + }; + + ASSERT_FLOAT_EQ(0.0f, evaluate(0ms)); + ASSERT_FLOAT_EQ(0.823099f, evaluate(500ms)); + ASSERT_FLOAT_EQ(1.0f, evaluate(1500ms)); +} + +TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithDelay) { + TransitionOptions transition; + transition.delay = { 1000ms }; + transition.duration = { 1000ms }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t0 { + PropertyValue<float>(0.0f), + UnevaluatedPaintProperty<float, PropertyEvaluator<float>>(), + TransitionOptions(), + TimePoint::min() + }; + + UnevaluatedPaintProperty<float, PropertyEvaluator<float>> t1 { + PropertyValue<float>(1.0f), + t0, + transition, + TimePoint::min() + }; + + auto evaluate = [&] (Duration delta) { + PropertyEvaluationParameters parameters { + 0, + TimePoint::min() + delta, + ZoomHistory(), + Duration::zero() + }; + + return t1.evaluate(parameters, 0.0f); + }; + + ASSERT_FLOAT_EQ(0.0f, evaluate(0ms)); + ASSERT_FLOAT_EQ(0.0f, evaluate(500ms)); + ASSERT_FLOAT_EQ(0.0f, evaluate(612ms)); + ASSERT_FLOAT_EQ(0.823099f, evaluate(1500ms)); + ASSERT_FLOAT_EQ(1.0f, evaluate(2500ms)); +} |