diff --git a/gtsam/geometry/Cyclic.cpp b/gtsam/geometry/Cyclic.cpp new file mode 100644 index 000000000..2b14ec6ba --- /dev/null +++ b/gtsam/geometry/Cyclic.cpp @@ -0,0 +1,27 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file Cyclic.cpp + * @brief Cyclic group implementation + * @author Frank Dellaert + **/ + +#include + +namespace gtsam { +namespace group { +namespace traits { + +} // \namespace traits +} // \namespace group +} // \namespace gtsam + diff --git a/gtsam/geometry/Cyclic.h b/gtsam/geometry/Cyclic.h new file mode 100644 index 000000000..85602d12d --- /dev/null +++ b/gtsam/geometry/Cyclic.h @@ -0,0 +1,89 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file Cyclic.h + * @brief Cyclic group, i.e., the integers modulo N + * @author Frank Dellaert + **/ + +#include +#include + +namespace gtsam { + +template +class Cyclic { + size_t i_; ///< we just use an unsigned int +public: + /// Constructor + Cyclic(size_t i) : + i_(i) { + } + /// Cast to size_t + operator size_t() const { + return i_; + } + /// Addition modulo N + Cyclic operator+(const Cyclic& h) const { + return (i_ + h.i_) % N; + } + /// Subtraction modulo N + Cyclic operator-(const Cyclic& h) const { + return (N + i_ - h.i_) % N; + } + /// Inverse + Cyclic operator-() const { + return (N - i_) % N; + } +}; + +namespace traits { +/// Define Cyclic to be a model of the Group concept +template struct structure_category > { + typedef group_tag type; +}; +} // \namespace gtsam::traits + +namespace group { + +template +Cyclic compose(const Cyclic&g, const Cyclic& h) { + return g + h; +} + +template +Cyclic between(const Cyclic&g, const Cyclic& h) { + return h - g; +} + +template +Cyclic inverse(const Cyclic&g) { + return -g; +} + +namespace traits { + +/// Define the trait that specifies Cyclic's identity element +template struct identity > { + static const Cyclic value = Cyclic(0); + typedef Cyclic value_type; +}; + +/// Define the trait that asserts Cyclic is an additive group +template struct flavor > { + typedef additive_tag type; +}; + +} // \namespace gtsam::group::traits +} // \namespace gtsam::group +} // \namespace gtsam + diff --git a/gtsam/geometry/tests/testCyclic.cpp b/gtsam/geometry/tests/testCyclic.cpp index 61c700c8a..00ea2c853 100644 --- a/gtsam/geometry/tests/testCyclic.cpp +++ b/gtsam/geometry/tests/testCyclic.cpp @@ -9,106 +9,13 @@ * -------------------------------------------------------------------------- */ -/** - * @file Cyclic.h - * @brief Cyclic group, i.e., the integers modulo N - * @author Frank Dellaert - **/ - -#include -#include - -namespace gtsam { - -template -class Cyclic { - size_t i_; ///< we just use an unsigned int -public: - /// Constructor - Cyclic(size_t i) : - i_(i) { - } - /// Cast to size_t - operator size_t() const { - return i_; - } - /// Addition modulo N - Cyclic operator+(const Cyclic& h) const { - return (i_+h.i_) % N; - } - /// Subtraction modulo N - Cyclic operator-(const Cyclic& h) const { - return (N+i_-h.i_) % N; - } - /// Inverse - Cyclic operator-() const { - return (N-i_) % N; - } -}; - -namespace traits { -/// Define Cyclic to be a model of the Group concept -template struct structure_category > { - typedef group_tag type; -}; -} // \namespace traits - -namespace group { - -template -Cyclic compose(const Cyclic&g, const Cyclic& h) { - return g + h; -} - -template -Cyclic between(const Cyclic&g, const Cyclic& h) { - return h - g; -} - -template -Cyclic inverse(const Cyclic&g) { - return -g; -} - -namespace traits { -/// Define the trait that specifies Cyclic's identity element -template struct identity > { - static const Cyclic value; - typedef Cyclic value_type; -}; -/// Define the trait that asserts Cyclic is an additive group -template struct flavor > { - typedef additive_tag type; -}; -} // \namespace traits -} // \namespace group - -} // \namespace gtsam - -/** - * @file Cyclic.cpp - * @brief Cyclic group implementation - * @author Frank Dellaert - **/ - -namespace gtsam { - -namespace group { -namespace traits { -template -const Cyclic identity >::value = Cyclic(0); -} // \namespace traits -} // \namespace group - -} // \namespace gtsam - /** * @file testCyclic.cpp * @brief Unit tests for cyclic group * @author Frank Dellaert **/ -//#include +#include #include #include