mirror of
https://github.com/godotengine/godot.git
synced 2024-11-12 23:24:26 +00:00
Use the standard C INFINITY
and NAN
constants directly
The `Math_INF` and `Math_NAN` defines were just aliases for those constants, so we might as well use them directly. Some portions of the code were already using `INFINITY` directly.
This commit is contained in:
parent
8cc599db64
commit
4bd5e4fd9b
@ -181,7 +181,7 @@ DynamicBVH::Volume DynamicBVH::_bounds(Node **leaves, int p_count) {
|
||||
|
||||
void DynamicBVH::_bottom_up(Node **leaves, int p_count) {
|
||||
while (p_count > 1) {
|
||||
real_t minsize = Math_INF;
|
||||
real_t minsize = INFINITY;
|
||||
int minidx[2] = { -1, -1 };
|
||||
for (int i = 0; i < p_count; ++i) {
|
||||
for (int j = i + 1; j < p_count; ++j) {
|
||||
|
@ -397,10 +397,10 @@ Error Expression::_get_token(Token &r_token) {
|
||||
r_token.value = Math_TAU;
|
||||
} else if (id == "INF") {
|
||||
r_token.type = TK_CONSTANT;
|
||||
r_token.value = Math_INF;
|
||||
r_token.value = INFINITY;
|
||||
} else if (id == "NAN") {
|
||||
r_token.type = TK_CONSTANT;
|
||||
r_token.value = Math_NAN;
|
||||
r_token.value = NAN;
|
||||
} else if (id == "not") {
|
||||
r_token.type = TK_OP_NOT;
|
||||
} else if (id == "or") {
|
||||
|
@ -43,8 +43,6 @@
|
||||
#define Math_TAU 6.2831853071795864769252867666
|
||||
#define Math_PI 3.1415926535897932384626433833
|
||||
#define Math_E 2.7182818284590452353602874714
|
||||
#define Math_INF INFINITY
|
||||
#define Math_NAN NAN
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#define MATH_CHECKS
|
||||
|
@ -95,7 +95,7 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381)
|
||||
if (p_in == 0.0f) {
|
||||
u.d = 0.0;
|
||||
} else if (Math::is_nan(p_in)) {
|
||||
u.d = Math_NAN;
|
||||
u.d = NAN;
|
||||
} else {
|
||||
u.d = p_in;
|
||||
}
|
||||
@ -124,7 +124,7 @@ static inline uint64_t hash_djb2_one_float_64(double p_in, uint64_t p_prev = 538
|
||||
if (p_in == 0.0f) {
|
||||
u.d = 0.0;
|
||||
} else if (Math::is_nan(p_in)) {
|
||||
u.d = Math_NAN;
|
||||
u.d = NAN;
|
||||
} else {
|
||||
u.d = p_in;
|
||||
}
|
||||
|
@ -2002,7 +2002,7 @@ static void _register_variant_builtin_methods() {
|
||||
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "ZERO", Vector3(0, 0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "ONE", Vector3(1, 1, 1));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(Math_INF, Math_INF, Math_INF));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(INFINITY, INFINITY, INFINITY));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "LEFT", Vector3(-1, 0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "RIGHT", Vector3(1, 0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "UP", Vector3(0, 1, 0));
|
||||
@ -2031,7 +2031,7 @@ static void _register_variant_builtin_methods() {
|
||||
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "ZERO", Vector2(0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "ONE", Vector2(1, 1));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(Math_INF, Math_INF));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(INFINITY, INFINITY));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "LEFT", Vector2(-1, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "RIGHT", Vector2(1, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1));
|
||||
|
@ -506,9 +506,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
|
||||
} else if (id == "null" || id == "nil") {
|
||||
value = Variant();
|
||||
} else if (id == "inf") {
|
||||
value = Math_INF;
|
||||
value = INFINITY;
|
||||
} else if (id == "nan") {
|
||||
value = Math_NAN;
|
||||
value = NAN;
|
||||
} else if (id == "Vector2") {
|
||||
Vector<real_t> args;
|
||||
Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str);
|
||||
|
@ -1637,8 +1637,8 @@ void GDScriptLanguage::init() {
|
||||
|
||||
_add_global(StaticCString::create("PI"), Math_PI);
|
||||
_add_global(StaticCString::create("TAU"), Math_TAU);
|
||||
_add_global(StaticCString::create("INF"), Math_INF);
|
||||
_add_global(StaticCString::create("NAN"), Math_NAN);
|
||||
_add_global(StaticCString::create("INF"), INFINITY);
|
||||
_add_global(StaticCString::create("NAN"), NAN);
|
||||
|
||||
//populate native classes
|
||||
|
||||
|
@ -457,12 +457,12 @@ void GDScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_const
|
||||
|
||||
Pair<String, Variant> infinity;
|
||||
infinity.first = "INF";
|
||||
infinity.second = Math_INF;
|
||||
infinity.second = INFINITY;
|
||||
p_constants->push_back(infinity);
|
||||
|
||||
Pair<String, Variant> nan;
|
||||
nan.first = "NAN";
|
||||
nan.second = Math_NAN;
|
||||
nan.second = NAN;
|
||||
p_constants->push_back(nan);
|
||||
}
|
||||
|
||||
|
@ -2123,10 +2123,10 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_builtin_constant(Expressio
|
||||
constant->value = Math_TAU;
|
||||
break;
|
||||
case GDScriptTokenizer::Token::CONST_INF:
|
||||
constant->value = Math_INF;
|
||||
constant->value = INFINITY;
|
||||
break;
|
||||
case GDScriptTokenizer::Token::CONST_NAN:
|
||||
constant->value = Math_NAN;
|
||||
constant->value = NAN;
|
||||
break;
|
||||
default:
|
||||
return nullptr; // Unreachable.
|
||||
|
@ -526,10 +526,10 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
|
||||
r_token.value = Math_TAU;
|
||||
} else if (id == "INF") {
|
||||
r_token.type = TK_CONSTANT;
|
||||
r_token.value = Math_INF;
|
||||
r_token.value = INFINITY;
|
||||
} else if (id == "NAN") {
|
||||
r_token.type = TK_CONSTANT;
|
||||
r_token.value = Math_NAN;
|
||||
r_token.value = NAN;
|
||||
} else if (id == "not") {
|
||||
r_token.type = TK_OP_NOT;
|
||||
} else if (id == "or") {
|
||||
|
@ -2182,8 +2182,8 @@ double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX] = {
|
||||
Math_TAU,
|
||||
2.71828182845904523536,
|
||||
Math::sqrt(2.0),
|
||||
Math_INF,
|
||||
Math_NAN
|
||||
INFINITY,
|
||||
NAN
|
||||
};
|
||||
|
||||
int VisualScriptMathConstant::get_output_sequence_port_count() const {
|
||||
|
@ -263,7 +263,7 @@ private:
|
||||
Transform3D physics_last_camera_transform;
|
||||
ObjectID physics_last_id;
|
||||
bool physics_has_last_mousepos = false;
|
||||
Vector2 physics_last_mousepos = Vector2(Math_INF, Math_INF);
|
||||
Vector2 physics_last_mousepos = Vector2(INFINITY, INFINITY);
|
||||
struct {
|
||||
bool alt = false;
|
||||
bool control = false;
|
||||
|
@ -128,7 +128,7 @@ class PlaneShape3DSW : public Shape3DSW {
|
||||
public:
|
||||
Plane get_plane() const;
|
||||
|
||||
virtual real_t get_area() const { return Math_INF; }
|
||||
virtual real_t get_area() const { return INFINITY; }
|
||||
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_PLANE; }
|
||||
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const;
|
||||
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
||||
|
@ -1172,7 +1172,7 @@ struct _SoftBodyIntersectSegmentInfo {
|
||||
Vector3 dir;
|
||||
Vector3 hit_position;
|
||||
uint32_t hit_face_index = -1;
|
||||
real_t hit_dist_sq = Math_INF;
|
||||
real_t hit_dist_sq = INFINITY;
|
||||
|
||||
static bool process_hit(uint32_t p_face_index, void *p_userdata) {
|
||||
_SoftBodyIntersectSegmentInfo &query_info = *(_SoftBodyIntersectSegmentInfo *)(p_userdata);
|
||||
@ -1203,7 +1203,7 @@ bool SoftBodyShape3DSW::intersect_segment(const Vector3 &p_begin, const Vector3
|
||||
|
||||
soft_body->query_ray(p_begin, p_end, _SoftBodyIntersectSegmentInfo::process_hit, &query_info);
|
||||
|
||||
if (query_info.hit_dist_sq != Math_INF) {
|
||||
if (query_info.hit_dist_sq != INFINITY) {
|
||||
r_result = query_info.hit_position;
|
||||
r_normal = soft_body->get_face_normal(query_info.hit_face_index);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user