gtsam 4.1.1
gtsam
Cyclic.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
18#include <gtsam/base/Group.h>
19#include <gtsam/base/Testable.h>
20
21#include <cassert>
22#include <iostream> // for cout :-(
23
24namespace gtsam {
25
27template<size_t N>
28class Cyclic {
29 size_t i_;
30public:
32 Cyclic(size_t i) :
33 i_(i) {
34 assert(i < N);
35 }
37 Cyclic():i_(0) {
38 }
39 static Cyclic identity() { return Cyclic();}
40
42 operator size_t() const {
43 return i_;
44 }
46 Cyclic operator+(const Cyclic& h) const {
47 return (i_ + h.i_) % N;
48 }
50 Cyclic operator-(const Cyclic& h) const {
51 return (N + i_ - h.i_) % N;
52 }
54 Cyclic operator-() const {
55 return (N - i_) % N;
56 }
58 void print(const std::string& s = "") const {
59 std::cout << s << i_ << std::endl;
60 }
62 bool equals(const Cyclic& other, double tol = 1e-9) const {
63 return other.i_ == i_;
64 }
65};
66
68template<size_t N>
69struct traits<Cyclic<N> > : internal::AdditiveGroupTraits<Cyclic<N> >, //
70 Testable<Cyclic<N> > {
71};
72
73} // \namespace gtsam
74
Concept check class for variable types with Group properties.
Concept check for values that can be used in unit tests.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:151
Cyclic group of order N.
Definition: Cyclic.h:28
bool equals(const Cyclic &other, double tol=1e-9) const
equals with an tolerance, prints out message if unequal
Definition: Cyclic.h:62
void print(const std::string &s="") const
print with optional string
Definition: Cyclic.h:58
Cyclic()
Default constructor yields identity.
Definition: Cyclic.h:37
Cyclic(size_t i)
Constructor.
Definition: Cyclic.h:32
Cyclic operator-(const Cyclic &h) const
Subtraction modulo N.
Definition: Cyclic.h:50
Cyclic operator+(const Cyclic &h) const
Addition modulo N.
Definition: Cyclic.h:46
Cyclic operator-() const
Inverse.
Definition: Cyclic.h:54