From fcc8518bce17a72041de43efdeb64c9064bd0256 Mon Sep 17 00:00:00 2001 From: Hristo Iliev Date: Fri, 30 Aug 2024 16:11:18 +0300 Subject: [PATCH] Add modf function and fix snap behavior Fixes #96159 --- core/math/math_funcs.h | 3 +++ editor/animation_track_editor.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index fd53ed28fd3..1afc5f4bbbd 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -105,6 +105,9 @@ public: static _ALWAYS_INLINE_ double fmod(double p_x, double p_y) { return ::fmod(p_x, p_y); } static _ALWAYS_INLINE_ float fmod(float p_x, float p_y) { return ::fmodf(p_x, p_y); } + static _ALWAYS_INLINE_ double modf(double p_x, double *r_y) { return ::modf(p_x, r_y); } + static _ALWAYS_INLINE_ float modf(float p_x, float *r_y) { return ::modff(p_x, r_y); } + static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); } static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index f4403780c2b..0a55ae5ad99 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -7079,7 +7079,10 @@ void AnimationTrackEditor::_update_snap_unit() { if (timeline->is_using_fps()) { snap_unit = 1.0 / step->get_value(); } else { - snap_unit = 1.0 / Math::round(1.0 / step->get_value()); // Follow the snap behavior of the timeline editor. + double integer; + double fraction = Math::modf(step->get_value(), &integer); + fraction = 1.0 / Math::round(1.0 / fraction); + snap_unit = integer + fraction; } }