diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2021-01-25 14:46:35 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2021-01-26 13:04:22 -0500 |
commit | 1be0d6b30e673b209fa8b1f2aa77995c9534df5e (patch) | |
tree | a3d63faae7b54415c54dd0010ba0578c51f55872 /core | |
parent | fa498f6105bb18a038210f4c000e1a97b7c86354 (diff) |
Type consistencies in core
Diffstat (limited to 'core')
-rw-r--r-- | core/io/resource_format_binary.cpp | 10 | ||||
-rw-r--r-- | core/math/aabb.h | 8 | ||||
-rw-r--r-- | core/math/color.cpp | 47 | ||||
-rw-r--r-- | core/math/color.h | 12 | ||||
-rw-r--r-- | core/string/ustring.cpp | 7 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 2 |
6 files changed, 40 insertions, 46 deletions
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index ae4643a19f..fad58d65fd 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -261,11 +261,11 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; case VARIANT_COLOR: { - Color v; - v.r = f->get_real(); - v.g = f->get_real(); - v.b = f->get_real(); - v.a = f->get_real(); + Color v; // Colors should always be in single-precision. + v.r = f->get_float(); + v.g = f->get_float(); + v.b = f->get_float(); + v.a = f->get_float(); r_v = v; } break; diff --git a/core/math/aabb.h b/core/math/aabb.h index 2861358e32..e16246902a 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -107,8 +107,8 @@ public: Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const; - _FORCE_INLINE_ void quantize(float p_unit); - _FORCE_INLINE_ AABB quantized(float p_unit) const; + _FORCE_INLINE_ void quantize(real_t p_unit); + _FORCE_INLINE_ AABB quantized(real_t p_unit) const; _FORCE_INLINE_ void set_end(const Vector3 &p_end) { size = p_end - position; @@ -430,7 +430,7 @@ void AABB::grow_by(real_t p_amount) { size.z += 2.0 * p_amount; } -void AABB::quantize(float p_unit) { +void AABB::quantize(real_t p_unit) { size += position; position.x -= Math::fposmodp(position.x, p_unit); @@ -448,7 +448,7 @@ void AABB::quantize(float p_unit) { size -= position; } -AABB AABB::quantized(float p_unit) const { +AABB AABB::quantized(real_t p_unit) const { AABB ret = *this; ret.quantize(p_unit); return ret; diff --git a/core/math/color.cpp b/core/math/color.cpp index 588aedf821..0398d43838 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -544,12 +544,12 @@ Color Color::operator*(const Color &p_color) const { a * p_color.a); } -Color Color::operator*(real_t p_rvalue) const { +Color Color::operator*(float p_scalar) const { return Color( - r * p_rvalue, - g * p_rvalue, - b * p_rvalue, - a * p_rvalue); + r * p_scalar, + g * p_scalar, + b * p_scalar, + a * p_scalar); } void Color::operator*=(const Color &p_color) { @@ -559,11 +559,11 @@ void Color::operator*=(const Color &p_color) { a = a * p_color.a; } -void Color::operator*=(real_t p_rvalue) { - r = r * p_rvalue; - g = g * p_rvalue; - b = b * p_rvalue; - a = a * p_rvalue; +void Color::operator*=(float p_scalar) { + r = r * p_scalar; + g = g * p_scalar; + b = b * p_scalar; + a = a * p_scalar; } Color Color::operator/(const Color &p_color) const { @@ -574,12 +574,12 @@ Color Color::operator/(const Color &p_color) const { a / p_color.a); } -Color Color::operator/(real_t p_rvalue) const { +Color Color::operator/(float p_scalar) const { return Color( - r / p_rvalue, - g / p_rvalue, - b / p_rvalue, - a / p_rvalue); + r / p_scalar, + g / p_scalar, + b / p_scalar, + a / p_scalar); } void Color::operator/=(const Color &p_color) { @@ -589,18 +589,11 @@ void Color::operator/=(const Color &p_color) { a = a / p_color.a; } -void Color::operator/=(real_t p_rvalue) { - if (p_rvalue == 0) { - r = 1.0; - g = 1.0; - b = 1.0; - a = 1.0; - } else { - r = r / p_rvalue; - g = g / p_rvalue; - b = b / p_rvalue; - a = a / p_rvalue; - } +void Color::operator/=(float p_scalar) { + r = r / p_scalar; + g = g / p_scalar; + b = b / p_scalar; + a = a / p_scalar; } Color Color::operator-() const { diff --git a/core/math/color.h b/core/math/color.h index 779f770761..d3b27a9c65 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -78,14 +78,14 @@ struct Color { void operator-=(const Color &p_color); Color operator*(const Color &p_color) const; - Color operator*(real_t p_rvalue) const; + Color operator*(float p_scalar) const; void operator*=(const Color &p_color); - void operator*=(real_t p_rvalue); + void operator*=(float p_scalar); Color operator/(const Color &p_color) const; - Color operator/(real_t p_rvalue) const; + Color operator/(float p_scalar) const; void operator/=(const Color &p_color); - void operator/=(real_t p_rvalue); + void operator/=(float p_scalar); bool is_equal_approx(const Color &p_color) const; @@ -259,8 +259,8 @@ bool Color::operator<(const Color &p_color) const { } } -_FORCE_INLINE_ Color operator*(real_t p_real, const Color &p_color) { - return p_color * p_real; +_FORCE_INLINE_ Color operator*(float p_scalar, const Color &p_color) { + return p_color * p_scalar; } #endif // COLOR_H diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 6b6d0a8ab4..0d4a81b590 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1409,8 +1409,9 @@ String String::num(double p_num, int p_decimals) { if (digit == MAX_DIGITS) //no point in going to infinite break; - if ((dec - (double)((int)dec)) < 1e-6) + if (dec - (double)((int)dec) < 1e-6) { break; + } } if (digit == p_decimals) @@ -3255,8 +3256,8 @@ float String::similarity(const String &p_string) const { int src_size = src_bigrams.size(); int tgt_size = tgt_bigrams.size(); - double sum = src_size + tgt_size; - double inter = 0; + int sum = src_size + tgt_size; + int inter = 0; for (int i = 0; i < src_size; i++) { for (int j = 0; j < tgt_size; j++) { if (src_bigrams[i] == tgt_bigrams[j]) { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 6ff7602b4e..02a5d8a2c8 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1212,7 +1212,7 @@ static void _register_variant_builtin_methods() { bind_method(Basis, transposed, sarray(), varray()); bind_method(Basis, orthonormalized, sarray(), varray()); bind_method(Basis, determinant, sarray(), varray()); - bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, float) const>(&Basis::rotated), sarray("axis", "phi"), varray()); + bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, real_t) const>(&Basis::rotated), sarray("axis", "phi"), varray()); bind_method(Basis, scaled, sarray("scale"), varray()); bind_method(Basis, get_scale, sarray(), varray()); bind_method(Basis, get_euler, sarray(), varray()); |