1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

[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>
This commit is contained in:
Biggles Bristol
2023-04-30 15:17:41 +01:00
parent 809a982162
commit c920a4f051
2 changed files with 23 additions and 12 deletions

View File

@@ -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<real_t>(_bake_resolution);
real_t x = i / static_cast<real_t>(_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;