Mantid
Loading...
Searching...
No Matches
RotCounter.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <algorithm>
9#include <fstream>
10#include <iterator>
11#include <vector>
12
13namespace Mantid::Geometry {
14std::ostream &operator<<(std::ostream &OX, const RotaryCounter &A)
21{
22 A.write(OX);
23 return OX;
24}
25
26RotaryCounter::RotaryCounter(const int S, const int N)
27 : Rmax(N), RC(S)
34{
35 for (int i = 0; i < S; i++)
36 RC[i] = i;
37}
38
46{
47 if (RC.size() != A.RC.size())
48 return false;
49
50 for (size_t i = 0; i < RC.size(); i++) {
51 if (RC[i] != A.RC[i]) {
52 return false;
53 }
54 }
55 return true;
56}
57
65{
66 const size_t ourSize = RC.size();
67 const size_t theirSize = A.RC.size();
68 const size_t maxI = (theirSize > ourSize) ? ourSize : theirSize;
69 for (size_t i = 0; i < maxI; i++) {
70 if (RC[i] != A.RC[i]) {
71 return RC[i] > A.RC[i];
72 }
73 }
74 if (theirSize != ourSize) {
75 return ourSize > theirSize;
76 }
77 return false;
78}
79
87{
88 const size_t ourSize = RC.size();
89 const size_t theirSize = A.RC.size();
90 const size_t maxI = (theirSize > ourSize) ? ourSize : theirSize;
91 for (size_t i = 0; i < maxI; i++) {
92 if (RC[i] != A.RC[i]) {
93 return RC[i] < A.RC[i];
94 }
95 }
96 if (theirSize != ourSize)
97 return ourSize < theirSize;
98 return false;
99}
100
108{
109 (void)a; // Avoid compiler warning
110 return this->operator++();
111}
112
121{
122 int Npart = Rmax - 1;
123 int I;
124 for (I = static_cast<int>(RC.size()) - 1; I >= 0 && RC[I] == Npart; I--, Npart--)
125 ;
126
127 if (I < 0) {
128 for (int i = 0; i < static_cast<int>(RC.size()); i++)
129 RC[i] = i;
130 return 1;
131 }
132 RC[I]++;
133 for (I++; I < static_cast<int>(RC.size()); I++)
134 RC[I] = RC[I - 1] + 1;
135 return 0;
136}
137
145{
146 (void)a; // Avoid compiler warning
147 return this->operator--();
148}
149
158{
159 const auto Size(static_cast<int>(RC.size()));
160 int I;
161 for (I = Size - 1; I > 0 && RC[I] == RC[I - 1] + 1; I--)
162 ;
163 // Loop case
164 if (!I && !RC[0]) {
165 // In case of loop go to
166 for (int i = 0; i < Size; i++) {
167 RC[i] = Rmax + i - Size;
168 }
169 return 1;
170 }
171
172 RC[I]--;
173 for (I++; I < Size; I++) {
174 RC[I] = Rmax + I - Size;
175 }
176 return 0;
177}
178
179void RotaryCounter::write(std::ostream &OX) const
184{
185 OX << " ";
186 copy(RC.begin(), RC.end() - 1, std::ostream_iterator<int>(OX, ":"));
187 OX << RC.back() << " ";
188}
189} // namespace Mantid::Geometry
Simple multilevel-cyclic counter.
Definition: RotCounter.h:28
int operator++()
Carrys out a rotational addition.
Definition: RotCounter.cpp:113
RotaryCounter(const int S, const int N)
Size,Max.
Definition: RotCounter.cpp:26
int Rmax
Number to over cycle.
Definition: RotCounter.h:32
bool operator<(const RotaryCounter &) const
Determines the precidence of the RotaryCounters Operator works on the 0 to high index.
Definition: RotCounter.cpp:80
std::vector< int > RC
rotation list
Definition: RotCounter.h:33
bool operator==(const RotaryCounter &) const
Chec to find if Counters identical in ALL respects.
Definition: RotCounter.cpp:39
int operator--()
Carrys out a rotational addition.
Definition: RotCounter.cpp:150
bool operator>(const RotaryCounter &) const
Determines the precidence of the RotaryCounters Operator works on the 0 to high index.
Definition: RotCounter.cpp:58
void write(std::ostream &) const
Write out object to a stream.
Definition: RotCounter.cpp:179
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
Definition: PointGroup.cpp:312