You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
Several fixes to make GLES2 on HTML5 work much better.
Changed math class error reporting to be a bit less paranoid.
This commit is contained in:
@@ -249,13 +249,25 @@ public:
|
||||
static float random(float from, float to);
|
||||
static real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); }
|
||||
|
||||
static _ALWAYS_INLINE_ bool is_equal_approx(real_t a, real_t b) {
|
||||
static _ALWAYS_INLINE_ bool is_equal_approx_ratio(real_t a, real_t b, real_t epsilon = CMP_EPSILON) {
|
||||
// this is an approximate way to check that numbers are close, as a ratio of their average size
|
||||
// helps compare approximate numbers that may be very big or very small
|
||||
real_t diff = abs(a - b);
|
||||
if (diff == 0.0) {
|
||||
return true;
|
||||
}
|
||||
real_t avg_size = (abs(a) + abs(b)) / 2.0;
|
||||
diff /= avg_size;
|
||||
return diff < epsilon;
|
||||
}
|
||||
|
||||
static _ALWAYS_INLINE_ bool is_equal_approx(real_t a, real_t b, real_t epsilon = CMP_EPSILON) {
|
||||
// TODO: Comparing floats for approximate-equality is non-trivial.
|
||||
// Using epsilon should cover the typical cases in Godot (where a == b is used to compare two reals), such as matrix and vector comparison operators.
|
||||
// A proper implementation in terms of ULPs should eventually replace the contents of this function.
|
||||
// See https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ for details.
|
||||
|
||||
return abs(a - b) < CMP_EPSILON;
|
||||
return abs(a - b) < epsilon;
|
||||
}
|
||||
|
||||
static _ALWAYS_INLINE_ float absf(float g) {
|
||||
|
||||
Reference in New Issue
Block a user