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 #include <iostream> // for cout :-(
21 
22 namespace gtsam {
23 
25 template<size_t N>
26 class Cyclic {
27  size_t i_;
28 public:
30  Cyclic(size_t i) :
31  i_(i) {
32  assert(i < N);
33  }
35  Cyclic():i_(0) {
36  }
37  static Cyclic identity() { return Cyclic();}
38 
40  operator size_t() const {
41  return i_;
42  }
44  Cyclic operator+(const Cyclic& h) const {
45  return (i_ + h.i_) % N;
46  }
48  Cyclic operator-(const Cyclic& h) const {
49  return (N + i_ - h.i_) % N;
50  }
52  Cyclic operator-() const {
53  return (N - i_) % N;
54  }
56  void print(const std::string& s = "") const {
57  std::cout << s << i_ << std::endl;
58  }
60  bool equals(const Cyclic& other, double tol = 1e-9) const {
61  return other.i_ == i_;
62  }
63 };
64 
66 template<size_t N>
67 struct traits<Cyclic<N> > : internal::AdditiveGroupTraits<Cyclic<N> >, //
68  Testable<Cyclic<N> > {
69 };
70 
71 } // \namespace gtsam
72 
Concept check for values that can be used in unit tests.
Concept check class for variable types with Group properties.
static Cyclic identity()
Definition: Cyclic.h:37
#define N
Definition: gksort.c:12
Cyclic group of order N.
Definition: Cyclic.h:26
Cyclic operator-(const Cyclic &h) const
Subtraction modulo N.
Definition: Cyclic.h:48
bool equals(const Cyclic &other, double tol=1e-9) const
equals with an tolerance, prints out message if unequal
Definition: Cyclic.h:60
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Cyclic(size_t i)
Constructor.
Definition: Cyclic.h:30
traits
Definition: chartTesting.h:28
const double h
size_t i_
we just use an unsigned int
Definition: Cyclic.h:27
Cyclic operator-() const
Inverse.
Definition: Cyclic.h:52
const G double tol
Definition: Group.h:83
void print(const std::string &s="") const
print with optional string
Definition: Cyclic.h:56
Cyclic()
Default constructor yields identity.
Definition: Cyclic.h:35
Cyclic operator+(const Cyclic &h) const
Addition modulo N.
Definition: Cyclic.h:44


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:56