From 123dc78f2b36af563e92df1d108855d96d39f877 Mon Sep 17 00:00:00 2001 From: Maxime Leroy Date: Wed, 1 May 2019 20:47:38 +0200 Subject: [PATCH] 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) ``` (cherry picked from commit 6bd271139d8192bdac9c9cf0e5fd2d007b967598) --- scene/resources/curve.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index ece8ad4bb06..950518aa6e0 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -782,7 +782,8 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { if (idx >= bpc - 1) { return r[bpc - 1]; } else if (idx == bpc - 2) { - frac /= Math::fmod(baked_max_ofs, bake_interval); + if (frac > 0) + frac /= Math::fmod(baked_max_ofs, bake_interval); } else { frac /= bake_interval; } @@ -1352,7 +1353,8 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { if (idx >= bpc - 1) { return r[bpc - 1]; } else if (idx == bpc - 2) { - frac /= Math::fmod(baked_max_ofs, bake_interval); + if (frac > 0) + frac /= Math::fmod(baked_max_ofs, bake_interval); } else { frac /= bake_interval; } @@ -1396,7 +1398,8 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { if (idx >= bpc - 1) { return r[bpc - 1]; } else if (idx == bpc - 2) { - frac /= Math::fmod(baked_max_ofs, bake_interval); + if (frac > 0) + frac /= Math::fmod(baked_max_ofs, bake_interval); } else { frac /= bake_interval; }