From 3172dfbcd93b9fdae3cfa14fdd6e4d0096348f5a Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 4 Feb 2022 15:52:48 +0100 Subject: [PATCH] Added 2 helper methods to Math. --- core/math/math.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/math/math.h b/core/math/math.h index 74c9136..ae4ae45 100644 --- a/core/math/math.h +++ b/core/math/math.h @@ -59,6 +59,8 @@ public: inline static float floor(const float x) { return ::floorf(x); } inline static double floor(const double x) { return ::floor(x); } + // x + 0.5 -> so f.e. 0.9999999 will become 1 + inline static int floorf_int(const float x) { return static_cast(x + 0.5); } inline static float ceil(const float x) { return ::ceilf(x); } inline static double ceil(const double x) { return ::ceil(x); } @@ -93,6 +95,9 @@ public: static float is_equal_approx(const float a, const float b); static float is_zero_approx(const float a); + //can save typing static_cast + inline static float divf(const float a, const float b) { return a / b; } + // Taken from the Godot Engine (MIT License) // Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. // Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).