From c920a4f051aa260c9bfc9aed1839eb1803a9a78f Mon Sep 17 00:00:00 2001 From: Biggles Bristol Date: Sun, 30 Apr 2023 15:17:41 +0100 Subject: [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> --- scene/resources/curve.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scene/resources/curve.cpp') diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index 97ab91e26d..a0bd22c79b 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -452,7 +452,7 @@ void Curve::bake() { _baked_cache.resize(_bake_resolution); for (int i = 1; i < _bake_resolution - 1; ++i) { - real_t x = i / static_cast(_bake_resolution); + real_t x = i / static_cast(_bake_resolution - 1); real_t y = sample(x); _baked_cache.write[i] = y; } @@ -489,7 +489,7 @@ real_t Curve::sample_baked(real_t p_offset) const { } // Get interpolation index - real_t fi = p_offset * _baked_cache.size(); + real_t fi = p_offset * (_baked_cache.size() - 1); int i = Math::floor(fi); if (i < 0) { i = 0; -- cgit v1.2.3