diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 924eea0be..e744a3569 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -172,6 +172,10 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const { return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y); } +bool Vector2::is_zero_approx() const { + return Math::is_zero_approx(x) && Math::is_zero_approx(y); +} + Vector2::operator String() const { return "(" + String::num_real(x) + ", " + String::num_real(y) + ")"; } diff --git a/core/math/vector2.h b/core/math/vector2.h index cffa971fe..666801dd6 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -126,6 +126,7 @@ struct _NO_DISCARD_CLASS_ Vector2 { Vector2 reflect(const Vector2 &p_normal) const; bool is_equal_approx(const Vector2 &p_v) const; + bool is_zero_approx() const; Vector2 operator+(const Vector2 &p_v) const; void operator+=(const Vector2 &p_v); diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index b7d639684..3010e52d2 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -106,6 +106,10 @@ bool Vector3::is_equal_approx(const Vector3 &p_v) const { return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y) && Math::is_equal_approx(z, p_v.z); } +bool Vector3::is_zero_approx() const { + return Math::is_zero_approx(x) && Math::is_zero_approx(y) && Math::is_zero_approx(z); +} + Vector3::operator String() const { return "(" + String::num_real(x) + ", " + String::num_real(y) + ", " + String::num_real(z) + ")"; } diff --git a/core/math/vector3.h b/core/math/vector3.h index e7f64da9b..bc40f23be 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -137,6 +137,7 @@ struct _NO_DISCARD_CLASS_ Vector3 { bool is_equal_approx(const Vector3 &p_v) const; inline bool is_equal_approx(const Vector3 &p_v, real_t p_tolerance) const; inline bool is_equal_approxt(const Vector3 &p_v, real_t p_tolerance) const; + bool is_zero_approx() const; /* Operators */ diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index e3eab6f3e..ba6a9f04e 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -547,6 +547,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(Vector2, bounce); VCALL_LOCALMEM1R(Vector2, reflect); VCALL_LOCALMEM1R(Vector2, is_equal_approx); + VCALL_LOCALMEM0R(Vector2, is_zero_approx); VCALL_LOCALMEM0R(Vector2, angle); VCALL_LOCALMEM1(Vector2, set_rotation); VCALL_LOCALMEM0R(Vector2, abs); @@ -682,6 +683,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(Vector3, reflect); VCALL_LOCALMEM1R(Vector3, is_equal_approx); VCALL_LOCALMEM2R(Vector3, is_equal_approxt); + VCALL_LOCALMEM0R(Vector3, is_zero_approx); VCALL_LOCALMEM2(Vector3i, set_axis); VCALL_LOCALMEM1R(Vector3i, get_axis); @@ -2657,6 +2659,7 @@ void register_variant_methods() { ADDFUNC1R(VECTOR2, VECTOR2, Vector2, bounce, VECTOR2, "n", varray()); ADDFUNC1R(VECTOR2, VECTOR2, Vector2, reflect, VECTOR2, "n", varray()); ADDFUNC1R(VECTOR2, BOOL, Vector2, is_equal_approx, VECTOR2, "v", varray()); + ADDFUNC0R(VECTOR2, BOOL, Vector2, is_zero_approx, varray()); ADDFUNC0R(VECTOR2, REAL, Vector2, angle, varray()); ADDFUNC1(VECTOR2, NIL, Vector2, set_rotation, REAL, "radians", varray()); ADDFUNC0R(VECTOR2, VECTOR2, Vector2, abs, varray()); @@ -2781,6 +2784,7 @@ void register_variant_methods() { ADDFUNC1R(VECTOR3, VECTOR3, Vector3, reflect, VECTOR3, "n", varray()); ADDFUNC1R(VECTOR3, BOOL, Vector3, is_equal_approx, VECTOR3, "v", varray()); ADDFUNC2R(VECTOR3, BOOL, Vector3, is_equal_approxt, VECTOR3, "v", REAL, "tolerance", varray()); + ADDFUNC0R(VECTOR3, BOOL, Vector3, is_zero_approx, varray()); ADDFUNC2(VECTOR3I, NIL, Vector3i, set_axis, INT, "axis", INT, "value", varray()); ADDFUNC1R(VECTOR3I, INT, Vector3i, get_axis, INT, "axis", varray()); diff --git a/doc/classes/Vector2.xml b/doc/classes/Vector2.xml index f9c44807c..b24f551ce 100644 --- a/doc/classes/Vector2.xml +++ b/doc/classes/Vector2.xml @@ -159,6 +159,13 @@ Returns [code]true[/code] if the vector is normalized, [code]false[/code] otherwise. + + + + Returns [code]true[/code] if this vector's values are approximately zero, by running [method @GDScript.is_zero_approx] on each component. + This method is faster than using [method is_equal_approx] with one value as a zero vector. + + diff --git a/doc/classes/Vector3.xml b/doc/classes/Vector3.xml index c6b7e6f7b..10b92a6e8 100644 --- a/doc/classes/Vector3.xml +++ b/doc/classes/Vector3.xml @@ -160,6 +160,13 @@ Returns [code]true[/code] if the vector is normalized, [code]false[/code] otherwise. + + + + Returns [code]true[/code] if this vector's values are approximately zero, by running [method @GDScript.is_zero_approx] on each component. + This method is faster than using [method is_equal_approx] with one value as a zero vector. + + diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 05c5b1465..4d5b333d4 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -685,7 +685,7 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { const bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0); // Only enable antialiasing if it is actually needed. This improve performances // and maximizes sharpness for non-skewed StyleBoxes with sharp corners. - const bool aa_on = (rounded_corners || !skew.is_equal_approx(Vector2())) && anti_aliased; + const bool aa_on = (rounded_corners || !skew.is_zero_approx()) && anti_aliased; const bool blend_on = blend_border && draw_border;