Merge pull request #45489 from aaronfranke/core

Type consistencies in core
This commit is contained in:
Rémi Verschelde 2021-01-27 21:16:20 +01:00 committed by GitHub
commit 976e768e71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 46 deletions

View file

@ -261,11 +261,11 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = v; r_v = v;
} break; } break;
case VARIANT_COLOR: { case VARIANT_COLOR: {
Color v; Color v; // Colors should always be in single-precision.
v.r = f->get_real(); v.r = f->get_float();
v.g = f->get_real(); v.g = f->get_float();
v.b = f->get_real(); v.b = f->get_float();
v.a = f->get_real(); v.a = f->get_float();
r_v = v; r_v = v;
} break; } break;

View file

@ -107,8 +107,8 @@ public:
Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; 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; Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;
_FORCE_INLINE_ void quantize(float p_unit); _FORCE_INLINE_ void quantize(real_t p_unit);
_FORCE_INLINE_ AABB quantized(float p_unit) const; _FORCE_INLINE_ AABB quantized(real_t p_unit) const;
_FORCE_INLINE_ void set_end(const Vector3 &p_end) { _FORCE_INLINE_ void set_end(const Vector3 &p_end) {
size = p_end - position; size = p_end - position;
@ -430,7 +430,7 @@ void AABB::grow_by(real_t p_amount) {
size.z += 2.0 * p_amount; size.z += 2.0 * p_amount;
} }
void AABB::quantize(float p_unit) { void AABB::quantize(real_t p_unit) {
size += position; size += position;
position.x -= Math::fposmodp(position.x, p_unit); position.x -= Math::fposmodp(position.x, p_unit);
@ -448,7 +448,7 @@ void AABB::quantize(float p_unit) {
size -= position; size -= position;
} }
AABB AABB::quantized(float p_unit) const { AABB AABB::quantized(real_t p_unit) const {
AABB ret = *this; AABB ret = *this;
ret.quantize(p_unit); ret.quantize(p_unit);
return ret; return ret;

View file

@ -544,12 +544,12 @@ Color Color::operator*(const Color &p_color) const {
a * p_color.a); a * p_color.a);
} }
Color Color::operator*(real_t p_rvalue) const { Color Color::operator*(float p_scalar) const {
return Color( return Color(
r * p_rvalue, r * p_scalar,
g * p_rvalue, g * p_scalar,
b * p_rvalue, b * p_scalar,
a * p_rvalue); a * p_scalar);
} }
void Color::operator*=(const Color &p_color) { void Color::operator*=(const Color &p_color) {
@ -559,11 +559,11 @@ void Color::operator*=(const Color &p_color) {
a = a * p_color.a; a = a * p_color.a;
} }
void Color::operator*=(real_t p_rvalue) { void Color::operator*=(float p_scalar) {
r = r * p_rvalue; r = r * p_scalar;
g = g * p_rvalue; g = g * p_scalar;
b = b * p_rvalue; b = b * p_scalar;
a = a * p_rvalue; a = a * p_scalar;
} }
Color Color::operator/(const Color &p_color) const { Color Color::operator/(const Color &p_color) const {
@ -574,12 +574,12 @@ Color Color::operator/(const Color &p_color) const {
a / p_color.a); a / p_color.a);
} }
Color Color::operator/(real_t p_rvalue) const { Color Color::operator/(float p_scalar) const {
return Color( return Color(
r / p_rvalue, r / p_scalar,
g / p_rvalue, g / p_scalar,
b / p_rvalue, b / p_scalar,
a / p_rvalue); a / p_scalar);
} }
void Color::operator/=(const Color &p_color) { void Color::operator/=(const Color &p_color) {
@ -589,18 +589,11 @@ void Color::operator/=(const Color &p_color) {
a = a / p_color.a; a = a / p_color.a;
} }
void Color::operator/=(real_t p_rvalue) { void Color::operator/=(float p_scalar) {
if (p_rvalue == 0) { r = r / p_scalar;
r = 1.0; g = g / p_scalar;
g = 1.0; b = b / p_scalar;
b = 1.0; a = a / p_scalar;
a = 1.0;
} else {
r = r / p_rvalue;
g = g / p_rvalue;
b = b / p_rvalue;
a = a / p_rvalue;
}
} }
Color Color::operator-() const { Color Color::operator-() const {

View file

@ -78,14 +78,14 @@ struct Color {
void operator-=(const Color &p_color); void operator-=(const Color &p_color);
Color operator*(const Color &p_color) const; 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*=(const Color &p_color);
void operator*=(real_t p_rvalue); void operator*=(float p_scalar);
Color operator/(const Color &p_color) const; 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/=(const Color &p_color);
void operator/=(real_t p_rvalue); void operator/=(float p_scalar);
bool is_equal_approx(const Color &p_color) const; 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) { _FORCE_INLINE_ Color operator*(float p_scalar, const Color &p_color) {
return p_color * p_real; return p_color * p_scalar;
} }
#endif // COLOR_H #endif // COLOR_H

View file

@ -1409,8 +1409,9 @@ String String::num(double p_num, int p_decimals) {
if (digit == MAX_DIGITS) //no point in going to infinite if (digit == MAX_DIGITS) //no point in going to infinite
break; break;
if ((dec - (double)((int)dec)) < 1e-6) if (dec - (double)((int)dec) < 1e-6) {
break; break;
}
} }
if (digit == p_decimals) if (digit == p_decimals)
@ -3255,8 +3256,8 @@ float String::similarity(const String &p_string) const {
int src_size = src_bigrams.size(); int src_size = src_bigrams.size();
int tgt_size = tgt_bigrams.size(); int tgt_size = tgt_bigrams.size();
double sum = src_size + tgt_size; int sum = src_size + tgt_size;
double inter = 0; int inter = 0;
for (int i = 0; i < src_size; i++) { for (int i = 0; i < src_size; i++) {
for (int j = 0; j < tgt_size; j++) { for (int j = 0; j < tgt_size; j++) {
if (src_bigrams[i] == tgt_bigrams[j]) { if (src_bigrams[i] == tgt_bigrams[j]) {

View file

@ -1212,7 +1212,7 @@ static void _register_variant_builtin_methods() {
bind_method(Basis, transposed, sarray(), varray()); bind_method(Basis, transposed, sarray(), varray());
bind_method(Basis, orthonormalized, sarray(), varray()); bind_method(Basis, orthonormalized, sarray(), varray());
bind_method(Basis, determinant, 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, scaled, sarray("scale"), varray());
bind_method(Basis, get_scale, sarray(), varray()); bind_method(Basis, get_scale, sarray(), varray());
bind_method(Basis, get_euler, sarray(), varray()); bind_method(Basis, get_euler, sarray(), varray());