8
8
# Module : Pivot
9
9
#
10
10
########################################################
11
+ from random import randrange
11
12
12
13
class Pivot (object ):
13
14
15
+
16
+ def check_two_points (self ,P ,P2 ,P3 ,P4 ,point_dico ):
17
+ point = {}
18
+ if (P2 in point_dico ):
19
+ if (point_dico [P2 ] == point_dico [P ]):
20
+ if (P3 in point_dico ) | (P4 in point_dico ):
21
+ return point
22
+ else :
23
+ coord = randrange (1 ,2 )
24
+ if (coord == 1 ):
25
+ final = P3
26
+ else :
27
+ final = P4
28
+ array = final .split ('_' )
29
+ xf = int (array [0 ])
30
+ yf = int (array [1 ])
31
+ point ['x' ] = xf
32
+ point ['y' ] = yf
33
+
34
+ return point
35
+
36
+ else :
37
+ return point
38
+ elif (P3 in point_dico ):
39
+ if (point_dico [P3 ] == point_dico [P ]):
40
+ if (P2 in point_dico ) | (P4 in point_dico ):
41
+ return point
42
+ else :
43
+ coord = randrange (1 ,2 )
44
+ if (coord == 1 ):
45
+ final = P2
46
+ else :
47
+ final = P4
48
+ array = final .split ('_' )
49
+ xf = int (array [0 ])
50
+ yf = int (array [1 ])
51
+ point ['x' ] = xf
52
+ point ['y' ] = yf
53
+
54
+ return point
55
+
56
+ else :
57
+ return point
58
+ elif (P4 in point_dico ):
59
+ if (point_dico [P4 ] == point_dico [P ]):
60
+ if (P2 in point_dico ) | (P3 in point_dico ):
61
+ return point
62
+ else :
63
+ coord = randrange (1 ,2 )
64
+ if (coord == 1 ):
65
+ final = P2
66
+ else :
67
+ final = P4
68
+ array = final .split ('_' )
69
+ xf = int (array [0 ])
70
+ yf = int (array [1 ])
71
+ point ['x' ] = xf
72
+ point ['y' ] = yf
73
+
74
+ return point
75
+
76
+
77
+ else :
78
+ return point
79
+ else :
80
+ return point
81
+
82
+ def carre (self ,P ,P2 ,P3 ,P4 ,point_dico ):
83
+ if (P2 in point_dico ) & (P3 in point_dico ) & (P4 in point_dico ):
84
+ if (point_dico [P ] == point_dico [P2 ]) & (point_dico [P ] == point_dico [P3 ]) & (point_dico [P ] == point_dico [P4 ]):
85
+ return True
86
+
14
87
#Vérification d'un carré en haut à gauche
15
88
def top_left (self ,x ,y ,space ,point_dico ):
16
89
x2 = x - space
@@ -20,9 +93,7 @@ def top_left(self,x,y,space,point_dico):
20
93
P3 = str (str (x2 )+ '_' + str (y ))
21
94
P4 = str (str (x2 )+ '_' + str (y2 ))
22
95
23
- if (P2 in point_dico ) & (P3 in point_dico ) & (P4 in point_dico ):
24
- if (point_dico [P ] == point_dico [P2 ]) & (point_dico [P ] == point_dico [P3 ]) & (point_dico [P ] == point_dico [P4 ]):
25
- return True
96
+ return self .carre (P ,P2 ,P3 ,P4 ,point_dico )
26
97
27
98
#Vérification d'un carré en haut à droite
28
99
def top_right (self ,x ,y ,space ,point_dico ):
@@ -33,39 +104,29 @@ def top_right(self,x,y,space,point_dico):
33
104
P3 = str (str (x2 )+ '_' + str (y2 ))
34
105
P4 = str (str (x2 )+ '_' + str (y ))
35
106
36
- if (P2 in point_dico ) & (P3 in point_dico ) & (P4 in point_dico ):
37
-
38
- if (point_dico [P ] == point_dico [P2 ]) & (point_dico [P ] == point_dico [P3 ]) & (point_dico [P ] == point_dico [P4 ]):
39
-
40
- return True
107
+ return self .carre (P ,P2 ,P3 ,P4 ,point_dico )
41
108
42
109
#Vérification d'un carré en bas à gauche
43
110
def bottom_left (self ,x ,y ,space ,point_dico ):
44
111
x2 = x - space
45
112
y2 = y + space
46
-
47
113
P = str (str (x )+ '_' + str (y ))
48
114
P2 = str (str (x2 )+ '_' + str (y ))
49
115
P3 = str (str (x2 )+ '_' + str (y2 ))
50
116
P4 = str (str (x )+ '_' + str (y2 ))
51
117
52
- if (P2 in point_dico ) & (P3 in point_dico ) & (P4 in point_dico ):
53
- if (point_dico [P ] == point_dico [P2 ]) & (point_dico [P ] == point_dico [P3 ]) & (point_dico [P ] == point_dico [P4 ]):
54
- return True
118
+ return self .carre (P ,P2 ,P3 ,P4 ,point_dico )
55
119
56
120
#Vérification d'un carré en bas à droit
57
121
def bottom_right (self ,x ,y ,space ,point_dico ):
58
122
x2 = x + space
59
123
y2 = y + space
60
-
61
124
P = str (str (x )+ '_' + str (y ))
62
125
P2 = str (str (x )+ '_' + str (y2 ))
63
126
P3 = str (str (x2 )+ '_' + str (y ))
64
127
P4 = str (str (x2 )+ '_' + str (y2 ))
65
128
66
- if (P2 in point_dico ) & (P3 in point_dico ) & (P4 in point_dico ):
67
- if (point_dico [P ] == point_dico [P2 ]) & (point_dico [P ] == point_dico [P3 ]) & (point_dico [P ] == point_dico [P4 ]):
68
- return True
129
+ return self .carre (P ,P2 ,P3 ,P4 ,point_dico )
69
130
70
131
def get_point_top_left (self ,x ,y ,space ,point_dico ):
71
132
x2 = x - space
@@ -156,4 +217,69 @@ def get_point_bottom_left(self,x,y,space,point_dico):
156
217
else :
157
218
return point
158
219
220
+ def check_three_points_top_left (self ,x ,y ,space ,point_dico ):
221
+ x2 = x - space
222
+ y2 = y - space
223
+ P = str (str (x )+ '_' + str (y ))
224
+ P2 = str (str (x )+ '_' + str (y2 ))
225
+ P3 = str (str (x2 )+ '_' + str (y ))
226
+ P4 = str (str (x2 )+ '_' + str (y2 ))
227
+ point = {}
228
+
229
+ if (P2 in point_dico ) | (P3 in point_dico ) | (P4 in point_dico ):
230
+ return point
231
+ else :
232
+ coord = randrange (1 ,3 )
233
+ if (coord == 1 ):
234
+ xf = x
235
+ yf = y2
236
+ elif (coord == 2 ):
237
+ xf = x2
238
+ yf = y
239
+ else :
240
+ xf = x2
241
+ yf = y2
242
+
243
+ point ['x' ] = xf
244
+ point ['y' ] = yf
245
+ return point
246
+
247
+ def check_two_points_top_left (self ,x ,y ,space ,point_dico ):
248
+ x2 = x - space
249
+ y2 = y - space
250
+ P = str (str (x )+ '_' + str (y ))
251
+ P2 = str (str (x )+ '_' + str (y2 ))
252
+ P3 = str (str (x2 )+ '_' + str (y ))
253
+ P4 = str (str (x2 )+ '_' + str (y2 ))
254
+
255
+ return self .check_two_points (P ,P2 ,P3 ,P4 ,point_dico )
256
+
257
+ def check_two_points_top_right (self ,x ,y ,space ,point_dico ):
258
+ x2 = x + space
259
+ y2 = y - space
260
+ P = str (str (x )+ '_' + str (y ))
261
+ P2 = str (str (x )+ '_' + str (y2 ))
262
+ P3 = str (str (x2 )+ '_' + str (y2 ))
263
+ P4 = str (str (x2 )+ '_' + str (y ))
264
+
265
+ return self .check_two_points (P ,P2 ,P3 ,P4 ,point_dico )
266
+
267
+ def check_two_points_bottom_left (self ,x ,y ,space ,point_dico ):
268
+ x2 = x - space
269
+ y2 = y + space
270
+ P = str (str (x )+ '_' + str (y ))
271
+ P2 = str (str (x2 )+ '_' + str (y ))
272
+ P3 = str (str (x2 )+ '_' + str (y2 ))
273
+ P4 = str (str (x )+ '_' + str (y2 ))
274
+
275
+ return self .check_two_points (P ,P2 ,P3 ,P4 ,point_dico )
276
+
277
+ def check_two_points_bottom_right (self ,x ,y ,space ,point_dico ):
278
+ x2 = x + space
279
+ y2 = y + space
280
+ P = str (str (x )+ '_' + str (y ))
281
+ P2 = str (str (x )+ '_' + str (y2 ))
282
+ P3 = str (str (x2 )+ '_' + str (y ))
283
+ P4 = str (str (x2 )+ '_' + str (y2 ))
159
284
285
+ return self .check_two_points (P ,P2 ,P3 ,P4 ,point_dico )
0 commit comments