From 1bb81488bbb04f024731a2b9a03abdac29cc8501 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 10 Nov 2020 14:30:02 -0500 Subject: [PATCH] Minor clamp and float fixes (cherry picked from commit ee79fc627c18d26221adeae2b641ba81ba662184) --- core/math/transform_2d.cpp | 2 +- modules/gdscript/gdscript_functions.cpp | 16 ++++++++-------- .../GodotSharp/GodotSharp/Core/Transform2D.cs | 3 +-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 953e5559e0f..679c3a1ca00 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -257,7 +257,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t real_t dot = v1.dot(v2); - dot = (dot < -1.0) ? -1.0 : ((dot > 1.0) ? 1.0 : dot); //clamp dot to [-1,1] + dot = CLAMP(dot, -1.0, 1.0); Vector2 v; diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 2d3812fc8c1..228b065c819 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -293,7 +293,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_ret = i < 0 ? -1 : (i > 0 ? +1 : 0); } else if (p_args[0]->get_type() == Variant::REAL) { - real_t r = *p_args[0]; + double r = *p_args[0]; r_ret = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); } else { @@ -520,8 +520,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - real_t a = *p_args[0]; - real_t b = *p_args[1]; + double a = *p_args[0]; + double b = *p_args[1]; r_ret = MAX(a, b); } @@ -538,8 +538,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - real_t a = *p_args[0]; - real_t b = *p_args[1]; + double a = *p_args[0]; + double b = *p_args[1]; r_ret = MIN(a, b); } @@ -557,9 +557,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - real_t a = *p_args[0]; - real_t b = *p_args[1]; - real_t c = *p_args[2]; + double a = *p_args[0]; + double b = *p_args[1]; + double c = *p_args[2]; r_ret = CLAMP(a, b, c); } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index 6adf1836631..4704c1c6042 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -221,8 +221,7 @@ namespace Godot real_t dot = v1.Dot(v2); - // Clamp dot to [-1, 1] - dot = dot < -1.0f ? -1.0f : (dot > 1.0f ? 1.0f : dot); + dot = Mathf.Clamp(dot, -1.0f, 1.0f); Vector2 v;