-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformations.py
150 lines (137 loc) · 2.09 KB
/
transformations.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import numpy as np
# Tested in BlacklistParser_test
class MMult:
def get_suffix(self):
return self.suffix
def perform(self, coords):
return [(np.array(c) * self.r).getA1().tolist() for c in coords]
class L90(MMult):
def __init__(self):
self.suffix = 'L90'
self.r = np.matrix([[0, -1],[1, 0]])
class L180(MMult):
def __init__(self):
self.suffix = 'L180'
self.r = np.matrix([[0, -1],[1, 0]]) * np.matrix([[0, -1],[1, 0]])
class R90(MMult):
def __init__(self):
self.suffix = 'R90'
self.r = np.matrix([[0, 1],[-1, 0]])
class R180(MMult):
def __init__(self):
self.suffix = 'R180'
self.r = np.matrix([[0, 1],[-1, 0]]) * np.matrix([[0, 1],[-1, 0]])
class Mirror(MMult):
def __init__(self):
self.suffix = 'Mirror'
self.r = np.matrix([[-1, 0],[0, 1]])
class ML90(MMult):
def __init__(self):
self.suffix = 'ML90'
self.r = np.matrix([[-1, 0],[0, 1]]) * np.matrix([[0, -1],[1, 0]])
class ML180(MMult):
def __init__(self):
self.suffix = 'ML180'
self.r = np.matrix([[-1, 0],[0, 1]]) * np.matrix([[0, -1],[1, 0]]) * np.matrix([[0, -1],[1, 0]])
class MR90(MMult):
def __init__(self):
self.suffix = 'MR90'
self.r = np.matrix([[-1, 0],[0, 1]]) * np.matrix([[0, 1],[-1, 0]])
class MR180(MMult):
def __init__(self):
self.suffix = 'MR180'
self.r = np.matrix([[-1, 0],[0, 1]]) * np.matrix([[0, 1],[-1, 0]]) * np.matrix([[0, 1],[-1, 0]])
# Rotation examples
#
# ------
# Pattern:
# xx..
# ..xx
#
# - L
# .x
# .x
# x.
# x.
#
# - R (same)
# .x
# .x
# x.
# x.
#
# - M
# ..xx
# xx..
#
# - F (Mirror, then rot 180)
# 1 M
# ..xx
# xx..
#
# 2 R90
# x.
# x.
# .x
# .x
#
# 3 R90
# ..xx
# xx..
#
# - LM (Rotate 90 left then mirror)
# x.
# x.
# .x
# .x
#
# - RM (Rotate 90 right then mirror) (same)
# x.
# x.
# .x
# .x
#
#
# ----------
#
# Shape:
# x..
# xxx
#
# - L
# .x
# .x
# xx
#
# - R
# xx
# x.
# x.
#
# - M
# ..x
# xxx
#
# - F
# 1 M
# ..x
# xxx
#
# 1 R90
# x
# x
# xx
#
# 2 R90
# xxx
# x
#
# - LM
# x
# x
# xx
#
# - RF
# xx
# .x
# .x