From 7f7d97f536ebbf5aa2e9335da728aa2056710297 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 31 Jul 2018 18:34:20 -0500 Subject: [PATCH] [Core] Expose approximate equality methods to GDScript --- doc/classes/@GDScript.xml | 20 ++++++++++++++++++++ modules/gdscript/gdscript_functions.cpp | 23 +++++++++++++++++++++++ modules/gdscript/gdscript_functions.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/doc/classes/@GDScript.xml b/doc/classes/@GDScript.xml index 29bf9b62ce9..22834a4c81e 100644 --- a/doc/classes/@GDScript.xml +++ b/doc/classes/@GDScript.xml @@ -498,6 +498,17 @@ [/codeblock] + + + + + + + + + Returns True/False whether [code]a[/code] and [code]b[/code] are approximately equal to each other. + + @@ -525,6 +536,15 @@ Returns whether [code]s[/code] is a NaN (Not-A-Number) value. + + + + + + + Returns True/False whether [code]s[/code] is zero or almost zero. + + diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 4fd136d5cc1..7552bc6bffb 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -68,6 +68,8 @@ const char *GDScriptFunctions::get_func_name(Function p_func) { "exp", "is_nan", "is_inf", + "is_equal_approx", + "is_zero_approx", "ease", "decimals", "stepify", @@ -316,6 +318,17 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(0); r_ret = Math::is_inf((double)*p_args[0]); } break; + case MATH_ISEQUALAPPROX: { + VALIDATE_ARG_COUNT(2); + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + r_ret = Math::is_equal_approx((real_t)*p_args[0], (real_t)*p_args[1]); + } break; + case MATH_ISZEROAPPROX: { + VALIDATE_ARG_COUNT(1); + VALIDATE_ARG_NUM(0); + r_ret = Math::is_zero_approx((real_t)*p_args[0]); + } break; case MATH_EASE: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); @@ -1596,6 +1609,16 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { mi.return_val.type = Variant::BOOL; return mi; } break; + case MATH_ISEQUALAPPROX: { + MethodInfo mi("is_equal_approx", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b")); + mi.return_val.type = Variant::BOOL; + return mi; + } break; + case MATH_ISZEROAPPROX: { + MethodInfo mi("is_zero_approx", PropertyInfo(Variant::REAL, "s")); + mi.return_val.type = Variant::BOOL; + return mi; + } break; case MATH_EASE: { MethodInfo mi("ease", PropertyInfo(Variant::REAL, "s"), PropertyInfo(Variant::REAL, "curve")); mi.return_val.type = Variant::REAL; diff --git a/modules/gdscript/gdscript_functions.h b/modules/gdscript/gdscript_functions.h index 14bf3d75609..0dbd172acf2 100644 --- a/modules/gdscript/gdscript_functions.h +++ b/modules/gdscript/gdscript_functions.h @@ -59,6 +59,8 @@ public: MATH_EXP, MATH_ISNAN, MATH_ISINF, + MATH_ISEQUALAPPROX, + MATH_ISZEROAPPROX, MATH_EASE, MATH_DECIMALS, MATH_STEPIFY,