Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and expose Basis/Transform2D/3D division by float operator #86364

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/math/basis.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ struct _NO_DISCARD_ Basis {
_FORCE_INLINE_ Basis operator-(const Basis &p_matrix) const;
_FORCE_INLINE_ void operator*=(const real_t p_val);
_FORCE_INLINE_ Basis operator*(const real_t p_val) const;
_FORCE_INLINE_ void operator/=(const real_t p_val);
_FORCE_INLINE_ Basis operator/(const real_t p_val) const;

bool is_orthogonal() const;
bool is_orthonormal() const;
Expand Down Expand Up @@ -289,6 +291,18 @@ _FORCE_INLINE_ Basis Basis::operator*(const real_t p_val) const {
return ret;
}

_FORCE_INLINE_ void Basis::operator/=(const real_t p_val) {
rows[0] /= p_val;
rows[1] /= p_val;
rows[2] /= p_val;
}

_FORCE_INLINE_ Basis Basis::operator/(const real_t p_val) const {
Basis ret(*this);
ret /= p_val;
return ret;
}

Vector3 Basis::xform(const Vector3 &p_vector) const {
return Vector3(
rows[0].dot(p_vector),
Expand Down
12 changes: 12 additions & 0 deletions core/math/transform_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ Transform2D Transform2D::operator*(const real_t p_val) const {
return ret;
}

void Transform2D::operator/=(const real_t p_val) {
columns[0] /= p_val;
columns[1] /= p_val;
columns[2] /= p_val;
}

Transform2D Transform2D::operator/(const real_t p_val) const {
Transform2D ret(*this);
ret /= p_val;
return ret;
}

Transform2D::operator String() const {
return "[X: " + columns[0].operator String() +
", Y: " + columns[1].operator String() +
Expand Down
2 changes: 2 additions & 0 deletions core/math/transform_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ struct _NO_DISCARD_ Transform2D {
Transform2D operator*(const Transform2D &p_transform) const;
void operator*=(const real_t p_val);
Transform2D operator*(const real_t p_val) const;
void operator/=(const real_t p_val);
Transform2D operator/(const real_t p_val) const;

Transform2D interpolate_with(const Transform2D &p_transform, const real_t p_c) const;

Expand Down
11 changes: 11 additions & 0 deletions core/math/transform_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ Transform3D Transform3D::operator*(const real_t p_val) const {
return ret;
}

void Transform3D::operator/=(const real_t p_val) {
basis /= p_val;
origin /= p_val;
}

Transform3D Transform3D::operator/(const real_t p_val) const {
Transform3D ret(*this);
ret /= p_val;
return ret;
}

Transform3D::operator String() const {
return "[X: " + basis.get_column(0).operator String() +
", Y: " + basis.get_column(1).operator String() +
Expand Down
2 changes: 2 additions & 0 deletions core/math/transform_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ struct _NO_DISCARD_ Transform3D {
Transform3D operator*(const Transform3D &p_transform) const;
void operator*=(const real_t p_val);
Transform3D operator*(const real_t p_val) const;
void operator/=(const real_t p_val);
Transform3D operator/(const real_t p_val) const;

Transform3D interpolate_with(const Transform3D &p_transform, real_t p_c) const;

Expand Down
9 changes: 9 additions & 0 deletions core/variant/variant_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,15 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorDivNZ<Vector4, Vector4i, double>>(Variant::OP_DIVIDE, Variant::VECTOR4I, Variant::FLOAT);
register_op<OperatorEvaluatorDivNZ<Vector4i, Vector4i, int64_t>>(Variant::OP_DIVIDE, Variant::VECTOR4I, Variant::INT);

register_op<OperatorEvaluatorDiv<Transform2D, Transform2D, int64_t>>(Variant::OP_DIVIDE, Variant::TRANSFORM2D, Variant::INT);
register_op<OperatorEvaluatorDiv<Transform2D, Transform2D, double>>(Variant::OP_DIVIDE, Variant::TRANSFORM2D, Variant::FLOAT);

register_op<OperatorEvaluatorDiv<Transform3D, Transform3D, int64_t>>(Variant::OP_DIVIDE, Variant::TRANSFORM3D, Variant::INT);
register_op<OperatorEvaluatorDiv<Transform3D, Transform3D, double>>(Variant::OP_DIVIDE, Variant::TRANSFORM3D, Variant::FLOAT);

register_op<OperatorEvaluatorDiv<Basis, Basis, int64_t>>(Variant::OP_DIVIDE, Variant::BASIS, Variant::INT);
register_op<OperatorEvaluatorDiv<Basis, Basis, double>>(Variant::OP_DIVIDE, Variant::BASIS, Variant::FLOAT);

register_op<OperatorEvaluatorDiv<Quaternion, Quaternion, double>>(Variant::OP_DIVIDE, Variant::QUATERNION, Variant::FLOAT);
register_op<OperatorEvaluatorDiv<Quaternion, Quaternion, int64_t>>(Variant::OP_DIVIDE, Variant::QUATERNION, Variant::INT);

Expand Down
14 changes: 14 additions & 0 deletions doc/classes/Basis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@
This operator multiplies all components of the [Basis], which scales it uniformly.
</description>
</operator>
<operator name="operator /">
<return type="Basis" />
<param index="0" name="right" type="float" />
<description>
This operator divides all components of the [Basis], which inversely scales it uniformly.
</description>
</operator>
<operator name="operator /">
<return type="Basis" />
<param index="0" name="right" type="int" />
<description>
This operator divides all components of the [Basis], which inversely scales it uniformly.
</description>
</operator>
<operator name="operator ==">
<return type="bool" />
<param index="0" name="right" type="Basis" />
Expand Down
14 changes: 14 additions & 0 deletions doc/classes/Transform2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@
This operator multiplies all components of the [Transform2D], including the [member origin] vector, which scales it uniformly.
</description>
</operator>
<operator name="operator /">
<return type="Transform2D" />
<param index="0" name="right" type="float" />
<description>
This operator divides all components of the [Transform2D], including the [member origin] vector, which inversely scales it uniformly.
</description>
</operator>
<operator name="operator /">
<return type="Transform2D" />
<param index="0" name="right" type="int" />
<description>
This operator divides all components of the [Transform2D], including the [member origin] vector, which inversely scales it uniformly.
</description>
</operator>
<operator name="operator ==">
<return type="bool" />
<param index="0" name="right" type="Transform2D" />
Expand Down
14 changes: 14 additions & 0 deletions doc/classes/Transform3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@
This operator multiplies all components of the [Transform3D], including the [member origin] vector, which scales it uniformly.
</description>
</operator>
<operator name="operator /">
<return type="Transform3D" />
<param index="0" name="right" type="float" />
<description>
This operator divides all components of the [Transform3D], including the [member origin] vector, which inversely scales it uniformly.
</description>
</operator>
<operator name="operator /">
<return type="Transform3D" />
<param index="0" name="right" type="int" />
<description>
This operator divides all components of the [Transform3D], including the [member origin] vector, which inversely scales it uniformly.
</description>
</operator>
<operator name="operator ==">
<return type="bool" />
<param index="0" name="right" type="Transform3D" />
Expand Down
Loading