Skip to content

Commit

Permalink
Merge pull request #318 from MarshallVielmetti/devel
Browse files Browse the repository at this point in the history
Added NEQ to lie_group_base (Issue #316)
  • Loading branch information
artivis authored Feb 8, 2025
2 parents d745a76 + e5c5d9a commit 9a45168
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/manif/impl/lie_group_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ struct LieGroupBase
template <typename _DerivedOther>
bool operator ==(const LieGroupBase<_DerivedOther>& m) const;


/**
* @brief Inequality operator.
* @param[in] An element of the same Lie group.
* @return false if the Lie group element m is 'close' to this,
* true otherwise.
* @see operator==.
*/
template <typename _DerivedOther>
bool operator!=(
const LieGroupBase<_DerivedOther> &m) const {
return !(*this == m);
}

/**
* @brief Right oplus operator.
* @see rplus.
Expand Down
16 changes: 16 additions & 0 deletions include/manif/impl/tangent_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,22 @@ bool operator ==(
return t.isApprox(v);
}

template <typename _Derived, typename _DerivedOther>
bool operator !=(
const TangentBase<_Derived>& ta,
const TangentBase<_DerivedOther>& tb)
{
return !(ta == tb);
}

template <typename _Derived, typename _EigenDerived>
bool operator !=(
const TangentBase<_Derived>& t,
const Eigen::MatrixBase<_EigenDerived>& v)
{
return !(t == v);
}

// Utils

template <typename _Stream, typename _Derived>
Expand Down
4 changes: 4 additions & 0 deletions test/common_tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,26 +522,30 @@ class CommonTester
EXPECT_TRUE(LieGroup::Identity().isApprox(LieGroup::Identity(), tol_));

EXPECT_TRUE(LieGroup::Identity() == LieGroup::Identity());
EXPECT_FALSE(LieGroup::Identity() != LieGroup::Identity());

EXPECT_TRUE(getState().isApprox(getState(), tol_));
EXPECT_FALSE(getState().isApprox(LieGroup::Random(), tol_));

// cppcheck-suppress duplicateExpression
EXPECT_TRUE(getState() == getState());
EXPECT_FALSE(getState() == LieGroup::Random());
EXPECT_TRUE(getState() != LieGroup::Random());

// Tangent

EXPECT_TRUE(Tangent::Zero().isApprox(Tangent::Zero(), tol_));

EXPECT_TRUE(Tangent::Zero() == Tangent::Zero());
EXPECT_FALSE(Tangent::Zero() != Tangent::Zero());

EXPECT_TRUE(getDelta().isApprox(getDelta(), tol_));
EXPECT_FALSE(getDelta().isApprox(Tangent::Random(), tol_));

// cppcheck-suppress duplicateExpression
EXPECT_TRUE(getDelta() == getDelta());
EXPECT_FALSE(getDelta() == Tangent::Random());
EXPECT_TRUE(getDelta() != Tangent::Random());
}

void evalUnaryMinus()
Expand Down
8 changes: 8 additions & 0 deletions test/se2/gtest_se2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@ TEST(TEST_SE2, TEST_SE2_NORMALIZE)
);
}

TEST(TEST_SE2, TEST_SE2_NEQ)
{
SE2d one(SE2d::DataType(0,0,1,0));
SE2d two(4, 2, 1, 0);

EXPECT_NE(one, two);
}

#endif

MANIF_TEST(SE2d);
Expand Down
11 changes: 11 additions & 0 deletions test/se3/gtest_se3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,17 @@ TEST(TEST_SE3, TEST_SE3_NORMALIZE)
);
}

TEST(TEST_SE3, TEST_SE3_NEQ)
{
SE3d one(SE3d::Translation(1,2,3),
Eigen::Quaterniond::Identity());

SE3d::DataType values; values << 0,0,0, 0,0,0,1;
SE3d two(values);

EXPECT_NE(one, two);
}

#endif

MANIF_TEST(SE3d);
Expand Down
8 changes: 8 additions & 0 deletions test/so2/gtest_so2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ TEST(TEST_SO2, TEST_SO2_NORMALIZE)
);
}

TEST(TEST_SO2, TEST_SO2_NEQ)
{
SO2d one(0, 1);
SO2d two = SO2d::Identity();

EXPECT_NE(one, two);
}

#endif

MANIF_TEST(SO2d);
Expand Down
8 changes: 8 additions & 0 deletions test/so3/gtest_so3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,14 @@ TEST(TEST_SO3, TEST_SO3_NORMALIZE)
);
}

TEST(TEST_SO3, TEST_SO3_NOTEQ)
{
SO3d one(0,0,0,1);
SO3d two(1,0,0,0);

EXPECT_NE(one, two);
}

#endif

MANIF_TEST(SO3d);
Expand Down

0 comments on commit 9a45168

Please sign in to comment.