From 870555f569bc63fecdc7c0b16e72e4e002f21c13 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 26 Jul 2018 13:06:54 -0400 Subject: all the R_t have been objectified --- lib/dihedral.h | 112 +++++++++++++++++++++------------------------------------ 1 file changed, 41 insertions(+), 71 deletions(-) (limited to 'lib/dihedral.h') diff --git a/lib/dihedral.h b/lib/dihedral.h index 8238835..5588afa 100644 --- a/lib/dihedral.h +++ b/lib/dihedral.h @@ -4,76 +4,46 @@ #include "types.h" #include "potts.h" -template -struct dihedral_t { bool is_reflection; T x; }; - -template -void init(dihedral_t *ptr) { - ptr->is_reflection = false; - ptr->x = (T)0; -} - -template -dihedral_t copy(dihedral_t r) { - return r; -} - -template -void free_spin(dihedral_t r) { - // do nothing! -} - -template -potts_t act(dihedral_t r, potts_t s) { - potts_t s2; - if (r.is_reflection) { - s2.x = ((q + r.x) - s.x) % q; - } else { - s2.x = (r.x + s.x) % q; - } - - return s2; -} - -template -dihedral_t act(dihedral_t r1, dihedral_t r2) { - dihedral_t r3; - - if (r1.is_reflection) { - r3.is_reflection = !(r2.is_reflection); - r3.x = ((q + r1.x) - r2.x) % q; - } else { - r3.is_reflection = r2.is_reflection; - r3.x = (r1.x + r2.x) % q; - } - - return r3; -} - -template -potts_t act_inverse(dihedral_t r, potts_t s) { - potts_t s2; - if (r.is_reflection) { - s2.x = ((r.x + q) - s.x) % q; - } else { - s2.x = ((s.x + q) - r.x) % q; - } - - return s2; -} - template -dihedral_t act_inverse(dihedral_t r1, dihedral_t r2) { - dihedral_t r3; - - if (r1.is_reflection) { - r3.is_reflection = !(r2.is_reflection); - r3.x = ((r1.x + q) - r2.x) % q; - } else { - r3.is_reflection = r2.is_reflection; - r3.x = ((r2.x + q) - r1.x) % q; - } - - return r3; -} +class dihedral_t { + public: + bool is_reflection; + q_t x; + + dihedral_t() : is_reflection(false), x(0) {} + dihedral_t(bool x, q_t y) : is_reflection(x), x(y) {} + + potts_t act(const potts_t& s) const { + if (this->is_reflection) { + return potts_t(((q + this->x) - s.x) % q); + } else { + return potts_t((this->x + s.x) % q); + } + } + + + dihedral_t act(dihedral_t r) const { + if (this->is_reflection) { + return dihedral_t(!(r.is_reflection), ((q + this->x) - r.x) % q); + } else { + return dihedral_t(r.is_reflection, (this->x + r.x) % q); + } + } + + potts_t act_inverse(potts_t s) const { + if (this->is_reflection) { + return this->act(s); + } else { + return potts_t(((s.x + q) - this->x) % q); + } + } + + dihedral_t act_inverse(dihedral_t r) const { + if (this->is_reflection) { + return this->act(r); + } else { + return dihedral_t(r.is_reflection, ((r.x + q) - this->x) % q); + } + } +}; -- cgit v1.2.3-70-g09d2