diff options
author | reduz <reduzio@gmail.com> | 2022-02-03 22:16:58 +0100 |
---|---|---|
committer | RĂ©mi Verschelde <rverschelde@gmail.com> | 2022-02-06 13:34:41 +0100 |
commit | 8c7268664da7ef98f802ec90fa2ba17b4d695847 (patch) | |
tree | b8f3bb21e79375402ceb68ed981693eb5189592d /core/math | |
parent | fd0d2dcabf5b7418691b693cd01baecbb69fdeb9 (diff) |
Fix integer vector mul/div operators and bindings.
* Vector2i and Vector3i mul/div by a float results in Vector2 and Vector3 respectively.
* Create specializations to allow proper bindings.
This fixes #44408 and supersedes #44441 and keeps the same rule of int <op> float returnig float, like with scalars.
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/audio_frame.h | 12 | ||||
-rw-r--r-- | core/math/vector2.h | 35 | ||||
-rw-r--r-- | core/math/vector2i.h | 10 | ||||
-rw-r--r-- | core/math/vector3.h | 3 | ||||
-rw-r--r-- | core/math/vector3i.h | 10 |
5 files changed, 46 insertions, 24 deletions
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index 94fc3de2b1..8b244e9fe4 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -140,4 +140,16 @@ struct AudioFrame { _ALWAYS_INLINE_ AudioFrame() {} }; +_ALWAYS_INLINE_ AudioFrame operator*(float p_scalar, const AudioFrame &p_frame) { + return AudioFrame(p_frame.l * p_scalar, p_frame.r * p_scalar); +} + +_ALWAYS_INLINE_ AudioFrame operator*(int32_t p_scalar, const AudioFrame &p_frame) { + return AudioFrame(p_frame.l * p_scalar, p_frame.r * p_scalar); +} + +_ALWAYS_INLINE_ AudioFrame operator*(int64_t p_scalar, const AudioFrame &p_frame) { + return AudioFrame(p_frame.l * p_scalar, p_frame.r * p_scalar); +} + #endif // AUDIO_FRAME_H diff --git a/core/math/vector2.h b/core/math/vector2.h index 9edaaebf89..123e3dc7b6 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -180,22 +180,6 @@ _FORCE_INLINE_ Vector2 Vector2::plane_project(const real_t p_d, const Vector2 &p return p_vec - *this * (dot(p_vec) - p_d); } -_FORCE_INLINE_ Vector2 operator*(const float p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; -} - -_FORCE_INLINE_ Vector2 operator*(const double p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; -} - -_FORCE_INLINE_ Vector2 operator*(const int32_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; -} - -_FORCE_INLINE_ Vector2 operator*(const int64_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; -} - _FORCE_INLINE_ Vector2 Vector2::operator+(const Vector2 &p_v) const { return Vector2(x + p_v.x, y + p_v.y); } @@ -280,6 +264,25 @@ Vector2 Vector2::direction_to(const Vector2 &p_to) const { return ret; } +// Multiplication operators required to workaround issues with LLVM using implicit conversion +// to Vector2i instead for integers where it should not. + +_FORCE_INLINE_ Vector2 operator*(const float p_scalar, const Vector2 &p_vec) { + return p_vec * p_scalar; +} + +_FORCE_INLINE_ Vector2 operator*(const double p_scalar, const Vector2 &p_vec) { + return p_vec * p_scalar; +} + +_FORCE_INLINE_ Vector2 operator*(const int32_t p_scalar, const Vector2 &p_vec) { + return p_vec * p_scalar; +} + +_FORCE_INLINE_ Vector2 operator*(const int64_t p_scalar, const Vector2 &p_vec) { + return p_vec * p_scalar; +} + typedef Vector2 Size2; typedef Vector2 Point2; diff --git a/core/math/vector2i.h b/core/math/vector2i.h index 446e05f5dd..707c8c9490 100644 --- a/core/math/vector2i.h +++ b/core/math/vector2i.h @@ -119,19 +119,21 @@ struct _NO_DISCARD_ Vector2i { } }; -_FORCE_INLINE_ Vector2i operator*(const int32_t &p_scalar, const Vector2i &p_vector) { +// Multiplication operators required to workaround issues with LLVM using implicit conversion. + +_FORCE_INLINE_ Vector2i operator*(const int32_t p_scalar, const Vector2i &p_vector) { return p_vector * p_scalar; } -_FORCE_INLINE_ Vector2i operator*(const int64_t &p_scalar, const Vector2i &p_vector) { +_FORCE_INLINE_ Vector2i operator*(const int64_t p_scalar, const Vector2i &p_vector) { return p_vector * p_scalar; } -_FORCE_INLINE_ Vector2i operator*(const float &p_scalar, const Vector2i &p_vector) { +_FORCE_INLINE_ Vector2i operator*(const float p_scalar, const Vector2i &p_vector) { return p_vector * p_scalar; } -_FORCE_INLINE_ Vector2i operator*(const double &p_scalar, const Vector2i &p_vector) { +_FORCE_INLINE_ Vector2i operator*(const double p_scalar, const Vector2i &p_vector) { return p_vector * p_scalar; } diff --git a/core/math/vector3.h b/core/math/vector3.h index 79ba5c4f15..345329f7f3 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -343,6 +343,9 @@ Vector3 &Vector3::operator*=(const real_t p_scalar) { return *this; } +// Multiplication operators required to workaround issues with LLVM using implicit conversion +// to Vector2i instead for integers where it should not. + _FORCE_INLINE_ Vector3 operator*(const float p_scalar, const Vector3 &p_vec) { return p_vec * p_scalar; } diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 1564ee9173..d166de80aa 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -194,6 +194,12 @@ Vector3i &Vector3i::operator*=(const int32_t p_scalar) { return *this; } +Vector3i Vector3i::operator*(const int32_t p_scalar) const { + return Vector3i(x * p_scalar, y * p_scalar, z * p_scalar); +} + +// Multiplication operators required to workaround issues with LLVM using implicit conversion. + _FORCE_INLINE_ Vector3i operator*(const int32_t p_scalar, const Vector3i &p_vector) { return p_vector * p_scalar; } @@ -210,10 +216,6 @@ _FORCE_INLINE_ Vector3i operator*(const double p_scalar, const Vector3i &p_vecto return p_vector * p_scalar; } -Vector3i Vector3i::operator*(const int32_t p_scalar) const { - return Vector3i(x * p_scalar, y * p_scalar, z * p_scalar); -} - Vector3i &Vector3i::operator/=(const int32_t p_scalar) { x /= p_scalar; y /= p_scalar; |