Skip to content

Commit

Permalink
Pose3: deprecate - and -= operators (#438)
Browse files Browse the repository at this point in the history
Part of #60.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Jun 8, 2022
1 parent b250500 commit 2bde663
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ release will remove the deprecated code.
+ The addition operators `+` and `+=` are deprecated in favor of multiplication
operators `*` and `*=`, though the order of operands is reversed
(A + B = B * A).
+ The unitary negation operator `-` is deprecated in favor of the
`Inverse()` method.
+ The subtraction operators `-` and `-=` are deprecated in favor of multiplication
by an inverse, though the order of operands is reversed
(A - B = B.Inverse() * A).

1. **Quaternion.hh**
+ ***Deprecation:*** public: void Axis(T, T, T, T)
Expand Down
9 changes: 5 additions & 4 deletions include/gz/math/Pose3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ namespace gz
/// A is the transform from O to P in frame O
/// then -A is transform from P to O specified in frame P
/// \return The resulting pose.
public: inline Pose3<T> operator-() const
public: GZ_DEPRECATED(7) Pose3<T> operator-() const
{
return Pose3<T>() - *this;
return this->Inverse();
}

/// \brief Subtraction operator.
Expand All @@ -221,7 +221,7 @@ namespace gz
/// B - A is the transform from P to Q in frame P
/// \param[in] _pose Pose3<T> to subtract from this one.
/// \return The resulting pose.
public: inline Pose3<T> operator-(const Pose3<T> &_pose) const
public: GZ_DEPRECATED(7) Pose3<T> operator-(const Pose3<T> &_pose) const
{
return Pose3<T>(this->CoordPositionSub(_pose),
this->CoordRotationSub(_pose.q));
Expand All @@ -231,7 +231,8 @@ namespace gz
/// \param[in] _pose Pose3<T> to subtract from this one
/// \sa operator-(const Pose3<T> &_pose) const.
/// \return The resulting pose
public: const Pose3<T> &operator-=(const Pose3<T> &_pose)
public: GZ_DEPRECATED(7) const Pose3<T> &
operator-=(const Pose3<T> &_pose)
{
this->p = this->CoordPositionSub(_pose);
this->q = this->CoordRotationSub(_pose.q);
Expand Down
46 changes: 32 additions & 14 deletions src/Pose_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,29 @@ TEST(PoseTest, Pose)
// then -A is transform from P to O specified in frame P
math::Pose3d A(math::Vector3d(1, 0, 0),
math::Quaterniond(0, 0, IGN_PI/4.0));
EXPECT_TRUE(math::equal((math::Pose3d() - A).Pos().X(), -1.0/sqrt(2)));
EXPECT_TRUE(math::equal((math::Pose3d() - A).Pos().Y(), 1.0/sqrt(2)));
EXPECT_TRUE(math::equal((math::Pose3d() - A).Pos().Z(), 0.0));
EXPECT_TRUE(math::equal((math::Pose3d() - A).Rot().Euler().X(), 0.0));
EXPECT_TRUE(math::equal((math::Pose3d() - A).Rot().Euler().Y(), 0.0));
EXPECT_TRUE(
math::equal((math::Pose3d() - A).Rot().Euler().Z(), -IGN_PI/4));
EXPECT_TRUE(math::equal(
(A.Inverse() * math::Pose3d()).Pos().X(), -1.0/sqrt(2)));
EXPECT_TRUE(math::equal(
(A.Inverse() * math::Pose3d()).Pos().Y(), 1.0/sqrt(2)));
EXPECT_TRUE(math::equal(
(A.Inverse() * math::Pose3d()).Pos().Z(), 0.0));
EXPECT_TRUE(math::equal(
(A.Inverse() * math::Pose3d()).Rot().Euler().X(), 0.0));
EXPECT_TRUE(math::equal(
(A.Inverse() * math::Pose3d()).Rot().Euler().Y(), 0.0));
EXPECT_TRUE(math::equal(
(A.Inverse() * math::Pose3d()).Rot().Euler().Z(), -IGN_PI/4));

IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION
// Coverage for unitary - operator
// test negation operator
EXPECT_TRUE(math::equal((-A).Pos().X(), -1.0/sqrt(2)));
EXPECT_TRUE(math::equal((-A).Pos().Y(), 1.0/sqrt(2)));
EXPECT_TRUE(math::equal((-A).Pos().Z(), 0.0));
EXPECT_TRUE(math::equal((-A).Rot().Euler().X(), 0.0));
EXPECT_TRUE(math::equal((-A).Rot().Euler().Y(), 0.0));
EXPECT_TRUE(math::equal((-A).Rot().Euler().Z(), -IGN_PI/4.0));
IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
}
{
// If:
Expand All @@ -117,12 +125,22 @@ TEST(PoseTest, Pose)
math::Quaterniond(0, 0, IGN_PI/4.0));
math::Pose3d B(math::Vector3d(1, 1, 0),
math::Quaterniond(0, 0, IGN_PI/2.0));
EXPECT_TRUE(math::equal((B - A).Pos().X(), 1.0/sqrt(2)));
EXPECT_TRUE(math::equal((B - A).Pos().Y(), 1.0/sqrt(2)));
EXPECT_TRUE(math::equal((B - A).Pos().Z(), 0.0));
EXPECT_TRUE(math::equal((B - A).Rot().Euler().X(), 0.0));
EXPECT_TRUE(math::equal((B - A).Rot().Euler().Y(), 0.0));
EXPECT_TRUE(math::equal((B - A).Rot().Euler().Z(), IGN_PI/4.0));
EXPECT_TRUE(math::equal((A.Inverse() * B).Pos().X(), 1.0/sqrt(2)));
EXPECT_TRUE(math::equal((A.Inverse() * B).Pos().Y(), 1.0/sqrt(2)));
EXPECT_TRUE(math::equal((A.Inverse() * B).Pos().Z(), 0.0));
EXPECT_TRUE(math::equal((A.Inverse() * B).Rot().Euler().X(), 0.0));
EXPECT_TRUE(math::equal((A.Inverse() * B).Rot().Euler().Y(), 0.0));
EXPECT_TRUE(math::equal((A.Inverse() * B).Rot().Euler().Z(), IGN_PI/4.0));

IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION
// Coverage for - operator
EXPECT_EQ(A.Inverse() * B, B - A);

// Coverage for -= operator
math::Pose3d C(B);
C -= A;
EXPECT_EQ(C, A.Inverse() * B);
IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
}
{
math::Pose3d pose;
Expand Down Expand Up @@ -155,7 +173,7 @@ TEST(PoseTest, Pose)
EXPECT_TRUE(pose ==
math::Pose3d(11.314, 16.0487, 15.2559, 1.49463, 0.184295, 2.13932));

pose -= math::Pose3d(pose);
pose = pose.Inverse() * pose;
EXPECT_TRUE(pose ==
math::Pose3d(0, 0, 0, 0, 0, 0));

Expand Down

0 comments on commit 2bde663

Please sign in to comment.