-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlattpoint.cpp
More file actions
136 lines (109 loc) · 2.52 KB
/
lattpoint.cpp
File metadata and controls
136 lines (109 loc) · 2.52 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
129
130
131
132
133
134
135
136
#include "lattpoint.h"
#include <stdexcept>
LattPoint::LattPoint(int* initX, int initL) {
L = initL;
for(int i = 0; i < 4; i++)
x[i] = initX[i] % L;
}
LattPoint::LattPoint(const LattPoint& x2) {
L = x2.L;
for(int i = 0; i < 4; i++)
x[i] = x2.x[i];
}
LattPoint::LattPoint(const LattPoint&& x2) {
L = x2.L;
for(int i = 0; i < 4; i++)
x[i] = x2.x[i];
}
void LattPoint::setX(const int* newX) {
for(int i = 0; i < 4; i++)
x[i] = newX[i] % L;
}
void LattPoint::getX(int* targetX) const {
for(int i = 0; i < 4; i++)
targetX[i] = x[i];
}
int LattPoint::getL() const {
return L;
}
LattPoint LattPoint::scale(const int s) {
int newX[4];
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;
for(int i = 0; i < 4; i++)
x[i] = x2.x[i];
}
return *this;
}
LattPoint LattPoint::operator=(const LattPoint&& x2) {
if (this != &x2)
for(int i = 0; i < 4; i++)
x[i] = x2.x[i];
return *this;
}
LattPoint LattPoint::operator+=(const LattPoint& x2) {
if(L != x2.getL())
throw std::invalid_argument("different lattice size");
int x2x[4];
x2.getX(x2x);
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");
int sumX[4];
int x2x[4];
x2.getX(x2x);
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");
int x2x[4];
x2.getX(x2x);
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");
int diffX[4];
int x2x[4];
x2.getX(x2x);
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 {
int x2x[4];
x2.getX(x2x);
for(int i = 0; i < 4; i++) {
if(x[i] < x2x[i]) return true;
else if(x[i] > x2x[i]) return false;
}
return false;
}