Fixing Curve2D/3D baked interpolated values

If bake interval is a multiple of the curve length, the curve would return NaN for some offset values (when `frac == 0.0`, it matches the start and end of the curve segment so `fmod == 0.0`, `frac` becomes NaN)

```
# Godot 3.1.1
var c = Curve3D.new()
c.add_point(Vector3())
c.add_point(Vector3(0.5,0,0))
c.add_point(Vector3(1,0,0))
c.bake_interval = 0.5
c.interpolate_baked(0.5) == Vector3(NAN, NAN, NAN)

```
This commit is contained in:
Maxime Leroy 2019-05-01 20:47:38 +02:00 committed by GitHub
parent 9f49e50d6d
commit 6bd271139d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -782,6 +782,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const {
if (idx >= bpc - 1) { if (idx >= bpc - 1) {
return r[bpc - 1]; return r[bpc - 1];
} else if (idx == bpc - 2) { } else if (idx == bpc - 2) {
if (frac > 0)
frac /= Math::fmod(baked_max_ofs, bake_interval); frac /= Math::fmod(baked_max_ofs, bake_interval);
} else { } else {
frac /= bake_interval; frac /= bake_interval;
@ -1352,6 +1353,7 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const {
if (idx >= bpc - 1) { if (idx >= bpc - 1) {
return r[bpc - 1]; return r[bpc - 1];
} else if (idx == bpc - 2) { } else if (idx == bpc - 2) {
if (frac > 0)
frac /= Math::fmod(baked_max_ofs, bake_interval); frac /= Math::fmod(baked_max_ofs, bake_interval);
} else { } else {
frac /= bake_interval; frac /= bake_interval;
@ -1396,6 +1398,7 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const {
if (idx >= bpc - 1) { if (idx >= bpc - 1) {
return r[bpc - 1]; return r[bpc - 1];
} else if (idx == bpc - 2) { } else if (idx == bpc - 2) {
if (frac > 0)
frac /= Math::fmod(baked_max_ofs, bake_interval); frac /= Math::fmod(baked_max_ofs, bake_interval);
} else { } else {
frac /= bake_interval; frac /= bake_interval;