-
Notifications
You must be signed in to change notification settings - Fork 7
/
Misc.cpp
57 lines (54 loc) · 1.06 KB
/
Misc.cpp
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
#include "Misc.h"
XYPos DirFlip::trans(XYPos pos, int size)
{
size = size - 1;
switch (dir)
{
case DIRECTION_N:
break;
case DIRECTION_E:
pos = XYPos(size - pos.y, pos.x);
break;
case DIRECTION_S:
pos = XYPos(size - pos.x,size - pos.y);
break;
case DIRECTION_W:
pos = XYPos(pos.y, size - pos.x);
break;
}
if (flp)
pos.y = size - pos.y;
return pos;
}
XYPos DirFlip::trans_inv(XYPos pos, int size)
{
size = size - 1;
if (flp)
pos.y = size - pos.y;
switch (dir)
{
case DIRECTION_N:
break;
case DIRECTION_E:
pos = XYPos(pos.y, size - pos.x);
break;
case DIRECTION_S:
pos = XYPos(size - pos.x,size - pos.y);
break;
case DIRECTION_W:
pos = XYPos(size - pos.y, pos.x);
break;
}
return pos;
}
uint64_t checksum(std::string s)
{
uint64_t rep = 0;
for (char& c : s)
{
rep ^= (rep & 1) << 62;
rep >>= 1;
rep ^= uint8_t(c);
}
return rep;
}