mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 06:11:29 +03:00
Added various functions basic math classes. Also enabled math checks only for debug builds.
Added set_scale, set_rotation_euler, set_rotation_axis_angle. Addresses #2565 directly. Added an euler angle constructor for Basis in GDScript and also exposed is_normalized for vectors and quaternions. Various other changes mostly cosmetic in nature.
This commit is contained in:
@@ -62,7 +62,8 @@ Vector2 Vector2::normalized() const {
|
||||
}
|
||||
|
||||
bool Vector2::is_normalized() const {
|
||||
return Math::isequal_approx(length(), (real_t)1.0);
|
||||
// use length_squared() instead of length() to avoid sqrt(), makes it more stringent.
|
||||
return Math::is_equal_approx(length_squared(), 1.0);
|
||||
}
|
||||
|
||||
real_t Vector2::distance_to(const Vector2 &p_vector2) const {
|
||||
@@ -280,7 +281,7 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
|
||||
|
||||
// slide returns the component of the vector along the given plane, specified by its normal vector.
|
||||
Vector2 Vector2::slide(const Vector2 &p_n) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2());
|
||||
#endif
|
||||
return *this - p_n * this->dot(p_n);
|
||||
@@ -291,7 +292,7 @@ Vector2 Vector2::bounce(const Vector2 &p_n) const {
|
||||
}
|
||||
|
||||
Vector2 Vector2::reflect(const Vector2 &p_n) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2());
|
||||
#endif
|
||||
return 2.0 * p_n * this->dot(p_n) - *this;
|
||||
@@ -438,7 +439,9 @@ Transform2D Transform2D::inverse() const {
|
||||
void Transform2D::affine_invert() {
|
||||
|
||||
real_t det = basis_determinant();
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND(det == 0);
|
||||
#endif
|
||||
real_t idet = 1.0 / det;
|
||||
|
||||
SWAP(elements[0][0], elements[1][1]);
|
||||
|
||||
Reference in New Issue
Block a user