-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpatches_state.py
86 lines (67 loc) · 2.86 KB
/
patches_state.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
"""
Keeping track of the X/Z orientation in this class
"""
from enum import Enum
class XOrientation(Enum):
ORIGINAL = 1
ROTATED = 3
class PatchesState:
def __init__(self):
print("Patches State")
self.the_active_patches = []
self.per_patch_x_orientation = {}
def add_active_patch(self, patch, x_orientation=XOrientation.ORIGINAL):
self.the_active_patches.append(patch)
self.per_patch_x_orientation[patch] = x_orientation
def remove_active_patch(self, patch):
# remove the patch from being tracked
self.the_active_patches.remove(patch)
# remove the stored orientation
del self.per_patch_x_orientation[patch]
def is_patch_active(self, patch):
# if it is in the active ones?
return patch in self.the_active_patches
def get_all_active_patches(self):
return self.the_active_patches
def rotate_patch(self, patch):
if self.is_patch_active(patch):
c_orient = self.per_patch_x_orientation[patch]
if c_orient == XOrientation.ORIGINAL:
self.per_patch_x_orientation[patch] = XOrientation.ROTATED
else:
self.per_patch_x_orientation[patch] = XOrientation.ORIGINAL
else:
print("ERROR! Patch is not active " + str(patch))
"""
The number is a sum of two powers of two
Which stand for the bits from the 6 available of a cube
This number is used by the Javascript to draw the X faces
// build each side of the box geometry
//ORIGINAL is 1 + 2
if((which_faces & 1) == 1)
this.buildPlane(poss, 'z', 'y', 'x', - 1, - 1, depth, height, width); // px
if((which_faces & 2) == 2)
this.buildPlane(poss, 'z', 'y', 'x', 1, - 1, depth, height, - width); // nx
//ROTATED 4 + 8
if((which_faces & 4) == 4)
this.buildPlane(poss, 'x', 'z', 'y', 1, 1, width, depth, height); // py
if((which_faces & 8) == 8)
this.buildPlane(poss, 'x', 'z', 'y', 1, - 1, width, depth, - height); // ny
//pz and nz are not important for lattice surgery, because these are along the time axis
if((which_faces & 16) == 16)
this.buildPlane(poss, 'x', 'y', 'z', 1, - 1, width, height, depth); // pz
if((which_faces & 32) == 32)
this.buildPlane(poss, 'x', 'y', 'z', - 1, - 1, width, height, - depth); // nz
}
"""
def get_patch_orientation_as_number(self, patch):
if self.is_patch_active(patch):
c_orient = self.per_patch_x_orientation[patch]
if c_orient == XOrientation.ORIGINAL:
return (63 - 3) # 1 + 2
else:
return (63 - 12) # 4 + 8
else:
print("ERROR! Patch is not active! " + str(patch))
# HORROR
return -1