You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Merge pull request #42133 from vnen/variant-op-consistency
Allow commutative multiplication in Variant
This commit is contained in:
@@ -234,4 +234,8 @@ bool Color::operator<(const Color &p_color) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ Color operator*(const real_t &p_real, const Color &p_color) {
|
||||||
|
return p_color * p_real;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // COLOR_H
|
#endif // COLOR_H
|
||||||
|
|||||||
@@ -224,4 +224,8 @@ bool Quat::operator!=(const Quat &p_quat) const {
|
|||||||
return x != p_quat.x || y != p_quat.y || z != p_quat.z || w != p_quat.w;
|
return x != p_quat.x || y != p_quat.y || z != p_quat.z || w != p_quat.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ Quat operator*(const real_t &p_real, const Quat &p_quat) {
|
||||||
|
return p_quat * p_real;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QUAT_H
|
#endif // QUAT_H
|
||||||
|
|||||||
@@ -150,7 +150,19 @@ _FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec)
|
|||||||
return p_vec - *this * (dot(p_vec) - p_d);
|
return p_vec - *this * (dot(p_vec) - p_d);
|
||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) {
|
_FORCE_INLINE_ Vector2 operator*(float p_scalar, const Vector2 &p_vec) {
|
||||||
|
return p_vec * p_scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ Vector2 operator*(double p_scalar, const Vector2 &p_vec) {
|
||||||
|
return p_vec * p_scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ Vector2 operator*(int32_t p_scalar, const Vector2 &p_vec) {
|
||||||
|
return p_vec * p_scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ Vector2 operator*(int64_t p_scalar, const Vector2 &p_vec) {
|
||||||
return p_vec * p_scalar;
|
return p_vec * p_scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,6 +316,22 @@ struct Vector2i {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_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) {
|
||||||
|
return p_vector * p_scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
_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) {
|
||||||
|
return p_vector * p_scalar;
|
||||||
|
}
|
||||||
|
|
||||||
typedef Vector2i Size2i;
|
typedef Vector2i Size2i;
|
||||||
typedef Vector2i Point2i;
|
typedef Vector2i Point2i;
|
||||||
|
|
||||||
|
|||||||
@@ -1031,6 +1031,9 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
|
|||||||
case FLOAT: {
|
case FLOAT: {
|
||||||
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._float);
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._float);
|
||||||
}
|
}
|
||||||
|
case INT: {
|
||||||
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._int);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
_RETURN_FAIL;
|
_RETURN_FAIL;
|
||||||
}
|
}
|
||||||
@@ -1062,8 +1065,64 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, INT, *, _int);
|
CASE_TYPE(math, OP_MULTIPLY, INT) {
|
||||||
DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, FLOAT, *, _float);
|
if (p_b.type == INT) {
|
||||||
|
_RETURN(p_a._data._int * p_b._data._int);
|
||||||
|
}
|
||||||
|
if (p_b.type == FLOAT) {
|
||||||
|
_RETURN(p_a._data._int * p_b._data._float);
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR2) {
|
||||||
|
_RETURN(p_a._data._int * *reinterpret_cast<const Vector2 *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR3) {
|
||||||
|
_RETURN(p_a._data._int * *reinterpret_cast<const Vector3 *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR2I) {
|
||||||
|
_RETURN(p_a._data._int * *reinterpret_cast<const Vector2i *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR3I) {
|
||||||
|
_RETURN(p_a._data._int * *reinterpret_cast<const Vector3i *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == QUAT) {
|
||||||
|
_RETURN(p_a._data._int * *reinterpret_cast<const Quat *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == COLOR) {
|
||||||
|
_RETURN(p_a._data._int * *reinterpret_cast<const Color *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
|
||||||
|
_RETURN_FAIL
|
||||||
|
}
|
||||||
|
|
||||||
|
CASE_TYPE(math, OP_MULTIPLY, FLOAT) {
|
||||||
|
if (p_b.type == INT) {
|
||||||
|
_RETURN(p_a._data._float * p_b._data._int);
|
||||||
|
}
|
||||||
|
if (p_b.type == FLOAT) {
|
||||||
|
_RETURN(p_a._data._float * p_b._data._float);
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR2) {
|
||||||
|
_RETURN(p_a._data._float * *reinterpret_cast<const Vector2 *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR3) {
|
||||||
|
_RETURN(p_a._data._float * *reinterpret_cast<const Vector3 *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR2I) {
|
||||||
|
_RETURN(p_a._data._float * *reinterpret_cast<const Vector2i *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == VECTOR3I) {
|
||||||
|
_RETURN(p_a._data._float * *reinterpret_cast<const Vector3i *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == QUAT) {
|
||||||
|
_RETURN(p_a._data._float * *reinterpret_cast<const Quat *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
if (p_b.type == COLOR) {
|
||||||
|
_RETURN(p_a._data._float * *reinterpret_cast<const Color *>(p_b._data._mem));
|
||||||
|
}
|
||||||
|
|
||||||
|
_RETURN_FAIL
|
||||||
|
}
|
||||||
|
|
||||||
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2, *, Vector2);
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2, *, Vector2);
|
||||||
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2I, *, Vector2i);
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2I, *, Vector2i);
|
||||||
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3, *, Vector3);
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3, *, Vector3);
|
||||||
|
|||||||
Reference in New Issue
Block a user