From ef58a8a56ab21a61afacb70e9a4ad005e7e65da9 Mon Sep 17 00:00:00 2001 From: dellaert Date: Sun, 7 Dec 2014 13:24:59 +0100 Subject: [PATCH] Attempt at satisfying Group concept by deriving from base class. Needs to be fixed, also, test does not link :-( --- gtsam/geometry/Cyclic.h | 35 +++++++++++++++++++++-------- gtsam/geometry/tests/testCyclic.cpp | 5 +++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/gtsam/geometry/Cyclic.h b/gtsam/geometry/Cyclic.h index 71c7cbc4a..aded063e7 100644 --- a/gtsam/geometry/Cyclic.h +++ b/gtsam/geometry/Cyclic.h @@ -20,8 +20,15 @@ namespace gtsam { +/// Additive Group +template +class AdditiveGroup { + +}; + +/// Cyclic group of order N template -class Cyclic { +class Cyclic : AdditiveGroup > { size_t i_; ///< we just use an unsigned int public: /// Constructor @@ -44,6 +51,16 @@ public: Cyclic operator-() const { return (N - i_) % N; } + /// print with optional string + void print(const std::string& s = "") const { + std::cout << s << i_ << std::endl; + } + + /// equals with an tolerance, prints out message if unequal + bool equals(const Cyclic& other, double tol = 1e-9) const { + return other.i_ == i_; + } + }; namespace traits { @@ -55,18 +72,18 @@ template struct structure_category > { namespace group { -template -Cyclic compose(const Cyclic&g, const Cyclic& h) { +template +AdditiveGroup compose(const AdditiveGroup&g, const AdditiveGroup& h) { return g + h; } -template -Cyclic between(const Cyclic&g, const Cyclic& h) { +template +AdditiveGroup between(const AdditiveGroup&g, const AdditiveGroup& h) { return h - g; } -template -Cyclic inverse(const Cyclic&g) { +template +AdditiveGroup inverse(const AdditiveGroup&g) { return -g; } @@ -81,8 +98,8 @@ template struct identity > { template const Cyclic identity >::value = Cyclic(0); -/// Define the trait that asserts Cyclic is an additive group -template struct flavor > { +/// Define the trait that asserts AdditiveGroup is an additive group +template struct flavor > { typedef additive_tag type; }; diff --git a/gtsam/geometry/tests/testCyclic.cpp b/gtsam/geometry/tests/testCyclic.cpp index 3cfa6b2c8..1a30beb1c 100644 --- a/gtsam/geometry/tests/testCyclic.cpp +++ b/gtsam/geometry/tests/testCyclic.cpp @@ -26,7 +26,8 @@ typedef Cyclic<6> G; // Let's use the cyclic group of order 6 //****************************************************************************** TEST(Cyclic, Concept) { - BOOST_CONCEPT_ASSERT((IsGroup)); +// BOOST_CONCEPT_ASSERT((IsGroup)); + BOOST_CONCEPT_ASSERT((AdditiveGroup)); EXPECT_LONGS_EQUAL(0, group::traits::identity::value); G g(2), h(3); // EXPECT(Group().check_invariants(g,h)) @@ -40,7 +41,7 @@ TEST(Cyclic, Constructor) { //****************************************************************************** TEST(Cyclic, Compose) { EXPECT_LONGS_EQUAL(0, group::compose(G(0),G(0))); - EXPECT_LONGS_EQUAL(1, group::compose(G(0),G(1))); + EXPECT_LONGS_EQUAL(1, group::compose(G(0),G(0))); EXPECT_LONGS_EQUAL(2, group::compose(G(0),G(2))); EXPECT_LONGS_EQUAL(3, group::compose(G(0),G(3))); EXPECT_LONGS_EQUAL(4, group::compose(G(0),G(4)));