-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlattpoint.cpp
More file actions
128 lines (101 loc) · 2.44 KB
/
lattpoint.cpp
File metadata and controls
128 lines (101 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "lattpoint.h"
#include <stdexcept>
LattPoint::LattPoint(const array<int,4> initX, const int initL) {
L = initL;
for(int i = 0; i < 4; i++)
x[i] = initX[i] % L;
}
LattPoint::LattPoint(const LattPoint& x2) {
x = x2.x;
L = x2.L;
}
LattPoint::LattPoint(const LattPoint&& x2) {
x = x2.x;
L = x2.L;
}
void LattPoint::setX(const array<int,4> newX) {
for(int i = 0; i < 4; i++)
x[i] = newX[i] % L;
}
array<int,4> LattPoint::getX() const {
array<int,4> copyX = x;
return copyX;
}
int LattPoint::getL() const {
return L;
}
LattPoint LattPoint::scale(const int s) {
array<int,4> newX;
for(int i = 0; i < 4; i++)
newX[i] = (x[i] * s) % L;
LattPoint scaled(newX, L);
return scaled;
}
string LattPoint::toString() const {
return "[" + std::to_string(x[0]) + "," + std::to_string(x[1]) + "," + std::to_string(x[2]) + "," + std::to_string(x[3]) + "]";
}
LattPoint LattPoint::operator=(const LattPoint& x2) {
if (this != &x2) {
L = x2.L;
x = x2.x;
}
return *this;
}
LattPoint LattPoint::operator=(const LattPoint&& x2) {
if (this != &x2)
L = x2.L;
x = x2.x;
return *this;
}
LattPoint LattPoint::operator+=(const LattPoint& x2) {
if(L != x2.getL())
throw std::invalid_argument("different lattice size");
array<int,4> x2x = x2.getX();
for(int i = 0; i < 4; i++)
x[i] = (x[i] + x2x[i]) % L;
return *this;
}
LattPoint LattPoint::operator+(const LattPoint& x2) const {
if(L != x2.getL())
throw std::invalid_argument("different lattice size");
array<int,4> sumX;
array<int,4> x2x = x2.getX();
for(int i = 0; i < 4; i++)
sumX[i] = (x[i] + x2x[i]) % L;
LattPoint sum(sumX, L);
return sum;
}
LattPoint LattPoint::operator-=(const LattPoint& x2) {
if(L != x2.getL())
throw std::invalid_argument("different lattice size");
array<int,4> x2x = x2.getX();
for(int i = 0; i < 4; i++) {
x[i] = x[i] - x2x[i];
while(x[i] < 0)
x[i] += L;
x[i] %= L;
}
return *this;
}
LattPoint LattPoint::operator-(const LattPoint& x2) const {
if(L != x2.getL())
throw std::invalid_argument("different lattice size");
array<int,4> diffX;
array<int,4> x2x = x2.getX();
for(int i = 0; i < 4; i++) {
diffX[i] = x[i] - x2x[i];
while(diffX[i] < 0)
diffX[i] += L;
diffX[i] %= L;
}
LattPoint diff(diffX, L);
return diff;
}
bool LattPoint::operator<(const LattPoint& x2) const {
array<int,4> x2x = x2.getX();
for(int i = 0; i < 4; i++) {
if(x[i] < x2x[i]) return true;
else if(x[i] > x2x[i]) return false;
}
return false;
}