diff options
| author | Rémi Verschelde | 2017-03-19 00:36:26 +0100 |
|---|---|---|
| committer | Rémi Verschelde | 2017-03-19 00:36:26 +0100 |
| commit | f8db8a3faa30b71dca33ced38be16d3f93f43e8a (patch) | |
| tree | 3b798318132cca7eccfbca5818ab55656a2896d7 /core/math/math_funcs.cpp | |
| parent | 1d418afe863c9e553b69174ce63aef203c46d2f0 (diff) | |
| download | godot-f8db8a3faa30b71dca33ced38be16d3f93f43e8a.tar.gz godot-f8db8a3faa30b71dca33ced38be16d3f93f43e8a.tar.zst godot-f8db8a3faa30b71dca33ced38be16d3f93f43e8a.zip | |
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6e3e905b94b8764e99491e608122261.
Diffstat (limited to 'core/math/math_funcs.cpp')
| -rw-r--r-- | core/math/math_funcs.cpp | 114 |
1 files changed, 52 insertions, 62 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 38f45e331..a8a063384 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -29,10 +29,9 @@ #include "math_funcs.h" #include "core/os/os.h" -#include <math.h> #include "float.h" -uint32_t Math::default_seed=1; - +#include <math.h> +uint32_t Math::default_seed = 1; #define PHI 0x9e3779b9 @@ -49,8 +48,8 @@ uint32_t Math::rand_from_seed(uint32_t *seed) { s = 0x12345987; k = s / 127773; s = 16807 * (s - k * 127773) - 2836 * k; -// if (s < 0) -// s += 2147483647; + // if (s < 0) + // s += 2147483647; (*seed) = s; return (s & Math::RANDOM_MAX); #else @@ -70,19 +69,19 @@ void Math::seed(uint32_t x) { for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; #else - default_seed=x; + default_seed = x; #endif } void Math::randomize() { OS::Time time = OS::get_singleton()->get_time(); - seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); /* *OS::get_singleton()->get_time().sec); // windows doesn't have get_time(), returns always 0 */ + seed(OS::get_singleton()->get_ticks_usec() * (time.hour + 1) * (time.min + 1) * (time.sec + 1) * rand()); /* *OS::get_singleton()->get_time().sec); // windows doesn't have get_time(), returns always 0 */ } uint32_t Math::rand() { - return rand_from_seed(&default_seed)&0x7FFFFFFF; + return rand_from_seed(&default_seed) & 0x7FFFFFFF; } double Math::randf() { @@ -93,19 +92,16 @@ double Math::randf() { double Math::sin(double p_x) { return ::sin(p_x); - } double Math::cos(double p_x) { return ::cos(p_x); - } double Math::tan(double p_x) { return ::tan(p_x); - } double Math::sinh(double p_x) { @@ -122,31 +118,29 @@ double Math::tanh(double p_x) { return ::tanh(p_x); } - double Math::deg2rad(double p_y) { - return p_y*Math_PI/180.0; + return p_y * Math_PI / 180.0; } double Math::rad2deg(double p_y) { - return p_y*180.0/Math_PI; + return p_y * 180.0 / Math_PI; } double Math::round(double p_val) { - if (p_val>=0) { - return ::floor(p_val+0.5); + if (p_val >= 0) { + return ::floor(p_val + 0.5); } else { - p_val=-p_val; - return -::floor(p_val+0.5); + p_val = -p_val; + return -::floor(p_val + 0.5); } } double Math::asin(double p_x) { return ::asin(p_x); - } double Math::acos(double p_x) { @@ -159,42 +153,40 @@ double Math::atan(double p_x) { return ::atan(p_x); } -double Math::dectime(double p_value,double p_amount, double p_step) { +double Math::dectime(double p_value, double p_amount, double p_step) { float sgn = p_value < 0 ? -1.0 : 1.0; float val = absf(p_value); - val-=p_amount*p_step; - if (val<0.0) - val=0.0; - return val*sgn; + val -= p_amount * p_step; + if (val < 0.0) + val = 0.0; + return val * sgn; } double Math::atan2(double p_y, double p_x) { - return ::atan2(p_y,p_x); - + return ::atan2(p_y, p_x); } double Math::sqrt(double p_x) { return ::sqrt(p_x); } -double Math::fmod(double p_x,double p_y) { +double Math::fmod(double p_x, double p_y) { - return ::fmod(p_x,p_y); + return ::fmod(p_x, p_y); } -double Math::fposmod(double p_x,double p_y) { +double Math::fposmod(double p_x, double p_y) { - if (p_x>=0) { + if (p_x >= 0) { - return Math::fmod(p_x,p_y); + return Math::fmod(p_x, p_y); } else { - return p_y-Math::fmod(-p_x,p_y); + return p_y - Math::fmod(-p_x, p_y); } - } double Math::floor(double p_x) { @@ -208,8 +200,8 @@ double Math::ceil(double p_x) { int Math::step_decimals(double p_step) { - static const int maxn=9; - static const double sd[maxn]={ + static const int maxn = 9; + static const double sd[maxn] = { 0.9999, // somehow compensate for floating point error 0.09999, 0.009999, @@ -221,9 +213,9 @@ int Math::step_decimals(double p_step) { 0.000000009999 }; - double as=absf(p_step); - for(int i=0;i<maxn;i++) { - if (as>=sd[i]) { + double as = absf(p_step); + for (int i = 0; i < maxn; i++) { + if (as >= sd[i]) { return i; } } @@ -233,41 +225,40 @@ int Math::step_decimals(double p_step) { double Math::ease(double p_x, double p_c) { - if (p_x<0) - p_x=0; - else if (p_x>1.0) - p_x=1.0; - if (p_c>0) { - if (p_c<1.0) { - return 1.0-Math::pow(1.0-p_x,1.0/p_c); + if (p_x < 0) + p_x = 0; + else if (p_x > 1.0) + p_x = 1.0; + if (p_c > 0) { + if (p_c < 1.0) { + return 1.0 - Math::pow(1.0 - p_x, 1.0 / p_c); } else { - return Math::pow(p_x,p_c); + return Math::pow(p_x, p_c); } - } else if (p_c<0) { + } else if (p_c < 0) { //inout ease - if (p_x<0.5) { - return Math::pow(p_x*2.0,-p_c)*0.5; + if (p_x < 0.5) { + return Math::pow(p_x * 2.0, -p_c) * 0.5; } else { - return (1.0-Math::pow(1.0-(p_x-0.5)*2.0,-p_c))*0.5+0.5; + return (1.0 - Math::pow(1.0 - (p_x - 0.5) * 2.0, -p_c)) * 0.5 + 0.5; } } else return 0; // no ease (raw) - } -double Math::stepify(double p_value,double p_step) { +double Math::stepify(double p_value, double p_step) { - if (p_step!=0) { + if (p_step != 0) { - p_value=floor( p_value / p_step + 0.5 ) * p_step; + p_value = floor(p_value / p_step + 0.5) * p_step; } return p_value; } bool Math::is_nan(double p_val) { - return (p_val!=p_val); + return (p_val != p_val); } bool Math::is_inf(double p_val) { @@ -277,7 +268,6 @@ bool Math::is_inf(double p_val) { #else return isinf(p_val); #endif - } uint32_t Math::larger_prime(uint32_t p_val) { @@ -315,11 +305,11 @@ uint32_t Math::larger_prime(uint32_t p_val) { 0, }; - int idx=0; + int idx = 0; while (true) { - ERR_FAIL_COND_V(primes[idx]==0,0); - if (primes[idx]>p_val) + ERR_FAIL_COND_V(primes[idx] == 0, 0); + if (primes[idx] > p_val) return primes[idx]; idx++; } @@ -330,13 +320,13 @@ uint32_t Math::larger_prime(uint32_t p_val) { double Math::random(double from, double to) { unsigned int r = Math::rand(); - double ret = (double)r/(double)RANDOM_MAX; - return (ret)*(to-from) + from; + double ret = (double)r / (double)RANDOM_MAX; + return (ret) * (to - from) + from; } double Math::pow(double x, double y) { - return ::pow(x,y); + return ::pow(x, y); } double Math::log(double x) { |
