diff options
author | Biggles Bristol <biggles@tektrip.com> | 2023-04-30 15:17:41 +0100 |
---|---|---|
committer | Biggles Bristol <biggles@tektrip.com> | 2023-05-20 11:28:09 +0100 |
commit | c920a4f051aa260c9bfc9aed1839eb1803a9a78f (patch) | |
tree | 4897c17d83c1965d2329538cae4c61145547e0b9 /tests | |
parent | 809a98216267f3066b9fec2f02b2042bdc9d3e0d (diff) | |
download | redot-engine-c920a4f051aa260c9bfc9aed1839eb1803a9a78f.tar.gz |
[Fixed] for "off-by-1" bug when sampling "baked" curve data towards the end of the curve.
[Fixed] Failing test "[Curve] Custom curve with free tangents" by setting the curve's `bake_resolution` to 11.
[Fixed] test messages in "[Curve] Custom curve with free tangents" to match sample offset used in each test
[Added] New test "[Curve] Straight line offset test" in response to pull request feedback.
Update tests/scene/test_curve.h
Co-authored-by: kleonc <9283098+kleonc@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scene/test_curve.h | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/scene/test_curve.h b/tests/scene/test_curve.h index bfa37e8f69..d67550f9f7 100644 --- a/tests/scene/test_curve.h +++ b/tests/scene/test_curve.h @@ -62,6 +62,7 @@ TEST_CASE("[Curve] Custom curve with free tangents") { curve->add_point(Vector2(0.25, 1)); curve->add_point(Vector2(0.5, 0)); curve->add_point(Vector2(0.75, 1)); + curve->set_bake_resolution(11); CHECK_MESSAGE( Math::is_zero_approx(curve->get_point_left_tangent(0)), @@ -82,41 +83,41 @@ TEST_CASE("[Curve] Custom curve with free tangents") { CHECK_MESSAGE( Math::is_zero_approx(curve->sample(-0.1)), - "Custom free curve should return the expected value at offset 0.1."); + "Custom free curve should return the expected value at offset -0.1."); CHECK_MESSAGE( curve->sample(0.1) == doctest::Approx((real_t)0.352), "Custom free curve should return the expected value at offset 0.1."); CHECK_MESSAGE( curve->sample(0.4) == doctest::Approx((real_t)0.352), - "Custom free curve should return the expected value at offset 0.1."); + "Custom free curve should return the expected value at offset 0.4."); CHECK_MESSAGE( curve->sample(0.7) == doctest::Approx((real_t)0.896), - "Custom free curve should return the expected value at offset 0.1."); + "Custom free curve should return the expected value at offset 0.7."); CHECK_MESSAGE( curve->sample(1) == doctest::Approx(1), - "Custom free curve should return the expected value at offset 0.1."); + "Custom free curve should return the expected value at offset 1."); CHECK_MESSAGE( curve->sample(2) == doctest::Approx(1), - "Custom free curve should return the expected value at offset 0.1."); + "Custom free curve should return the expected value at offset 2."); CHECK_MESSAGE( Math::is_zero_approx(curve->sample_baked(-0.1)), - "Custom free curve should return the expected baked value at offset 0.1."); + "Custom free curve should return the expected baked value at offset -0.1."); CHECK_MESSAGE( curve->sample_baked(0.1) == doctest::Approx((real_t)0.352), "Custom free curve should return the expected baked value at offset 0.1."); CHECK_MESSAGE( curve->sample_baked(0.4) == doctest::Approx((real_t)0.352), - "Custom free curve should return the expected baked value at offset 0.1."); + "Custom free curve should return the expected baked value at offset 0.4."); CHECK_MESSAGE( curve->sample_baked(0.7) == doctest::Approx((real_t)0.896), - "Custom free curve should return the expected baked value at offset 0.1."); + "Custom free curve should return the expected baked value at offset 0.7."); CHECK_MESSAGE( curve->sample_baked(1) == doctest::Approx(1), - "Custom free curve should return the expected baked value at offset 0.1."); + "Custom free curve should return the expected baked value at offset 1."); CHECK_MESSAGE( curve->sample_baked(2) == doctest::Approx(1), - "Custom free curve should return the expected baked value at offset 0.1."); + "Custom free curve should return the expected baked value at offset 2."); curve->remove_point(1); CHECK_MESSAGE( @@ -218,6 +219,16 @@ TEST_CASE("[Curve] Custom curve with linear tangents") { "Custom free curve should return the expected baked value at offset 0.7 after removing point at invalid index 10."); } +TEST_CASE("[Curve] Straight line offset test") { + Ref<Curve> curve = memnew(Curve); + curve->add_point(Vector2(0, 0)); + curve->add_point(Vector2(1, 1)); + + CHECK_MESSAGE( + curve->sample_baked(1.0 - (0.5 / curve->get_bake_resolution())) != curve->sample_baked(1), + "Straight line curve should return different baked values at offset 1 vs offset (1 - 0.5 / bake resolution) ."); +} + TEST_CASE("[Curve2D] Linear sampling should return exact value") { Ref<Curve2D> curve = memnew(Curve2D); real_t len = 2048.0; |