Zum Inhalt

FacePosition

An enum describing the different faces of a rubik's cube.

Also (through same-value declaration) provides a mapping from relative to absolute faces.

from_vector(vector) staticmethod

Converts the given vector to the corresponding face.

Conversion is done according to the default definition: BLUE/FRONT -> x+, RED/LEFT -> y+, YELLOW/TOP -> z+

Parameters:

Name Type Description Default
vector ndarray

the vector to convert to a face

required

Returns:

Type Description
FacePosition

the corresponding face

Source code in core/cube/FacePosition.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@staticmethod
def from_vector(vector: np.ndarray) -> 'FacePosition':
    """Converts the given vector to the corresponding face.

    Conversion is done according to the default definition: BLUE/FRONT -> x+, RED/LEFT -> y+, YELLOW/TOP -> z+

    Args:
        vector: the vector to convert to a face

    Returns:
        the corresponding face
    """
    if (vector == np.array([1, 0, 0])).all():
        return FacePosition.FRONT
    if (vector == np.array([-1, 0, 0])).all():
        return FacePosition.BACK
    if (vector == np.array([0, 1, 0])).all():
        return FacePosition.LEFT
    if (vector == np.array([0, -1, 0])).all():
        return FacePosition.RIGHT
    if (vector == np.array([0, 0, 1])).all():
        return FacePosition.TOP
    if (vector == np.array([0, 0, -1])).all():
        return FacePosition.BOTTOM

from_string_notation(string) staticmethod

Returns the internal representation for a given character, swapping left and right because of the different models used.

Note

left and right are swapped because cuber notation uses the point of view of the cuber and our FacePosition uses the point of view of the cube

Returns:

Type Description
FacePosition

the internal representation of the face

Source code in core/cube/FacePosition.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
@staticmethod
def from_string_notation(string: str) -> 'FacePosition':
    """Returns the internal representation for a given character, swapping left and right because of the different models used.

    !!! note
        left and right are swapped because cuber notation uses the point of view
        of the cuber and our `FacePosition` uses the point of view of the cube

    Returns:
        the internal representation of the face
    """
    char = string[0].lower()

    if char == 'f':
        return FacePosition.FRONT
    if char == 'b':
        return FacePosition.BACK
    if char == 'r':
        # left and right are swapped because cuber notation uses the point of view
        # of the cuber and our face position uses the point of view of the cube
        return FacePosition.LEFT
    if char == 'l':
        return FacePosition.RIGHT
    if char == 'u':
        return FacePosition.TOP
    if char == 'd':
        return FacePosition.BOTTOM

    raise ValueError('Cannot infer face from string: {}'.format(repr(string)))

from_tile_color(tile_color) staticmethod

Converts the given color to the corresponding face.

Parameters:

Name Type Description Default
tile_color TileColor

the color of the face

required

Returns:

Type Description
FacePosition

the matching face

Source code in core/cube/FacePosition.py
202
203
204
205
206
207
208
209
210
211
212
@staticmethod
def from_tile_color(tile_color: TileColor) -> 'FacePosition':
    """Converts the given color to the corresponding face.

    Args:
        tile_color: the color of the face

    Returns:
        the matching face
    """
    return FacePosition(tile_color.value)

is_next_to(self, other)

Checks whether the given face is next to this face.

Parameters:

Name Type Description Default
other FacePosition

the possibly neighboring face

required

Returns:

Type Description
bool

whether the given face is a neighbor

Source code in core/cube/FacePosition.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def is_next_to(self, other: 'FacePosition') -> bool:
    """Checks whether the given face is next to this face.

    Args:
        other: the possibly neighboring face

    Returns:
         whether the given face is a neighbor
    """
    neighbours = {
        FacePosition.YELLOW: [FacePosition.BLUE, FacePosition.RED, FacePosition.GREEN, FacePosition.ORANGE],
        FacePosition.WHITE: [FacePosition.BLUE, FacePosition.RED, FacePosition.GREEN, FacePosition.ORANGE],
        FacePosition.GREEN: [FacePosition.YELLOW, FacePosition.WHITE, FacePosition.RED, FacePosition.ORANGE],
        FacePosition.BLUE: [FacePosition.YELLOW, FacePosition.WHITE, FacePosition.RED, FacePosition.ORANGE],
        FacePosition.RED: [FacePosition.YELLOW, FacePosition.BLUE, FacePosition.GREEN, FacePosition.WHITE],
        FacePosition.ORANGE: [FacePosition.YELLOW, FacePosition.BLUE, FacePosition.GREEN, FacePosition.WHITE]
    }
    return other in neighbours[self]

to_vector(self)

Converts the face to its vector representation.

Conversion is done according to the default definition: BLUE/FRONT -> x+, RED/LEFT -> y+, YELLOW/TOP -> z+

Source code in core/cube/FacePosition.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def to_vector(self) -> np.ndarray:
    """Converts the face to its vector representation.

    Conversion is done according to the default definition: BLUE/FRONT -> x+, RED/LEFT -> y+, YELLOW/TOP -> z+
    """
    if self == FacePosition.FRONT:
        return np.array([1, 0, 0])
    if self == FacePosition.BACK:
        return np.array([-1, 0, 0])
    if self == FacePosition.LEFT:
        return np.array([0, 1, 0])
    if self == FacePosition.RIGHT:
        return np.array([0, -1, 0])
    if self == FacePosition.TOP:
        return np.array([0, 0, 1])
    if self == FacePosition.BOTTOM:
        return np.array([0, 0, -1])

to_rotation(self, degrees)

Returns the rotation matching this face axis and the given degrees.

Parameters:

Name Type Description Default
degrees float

the amount of rotation.

required

Returns:

Type Description
Rotation

the rotation

Source code in core/cube/FacePosition.py
 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
def to_rotation(self, degrees: float) -> transform.Rotation:
    """Returns the rotation matching this face axis and the given degrees.

    Args:
        degrees: the amount of rotation.

    Returns:
        the rotation
    """
    axis = None
    if self == FacePosition.FRONT:
        axis = 'x'
    if self == FacePosition.BACK:
        axis = 'x'
        degrees *= -1
    if self == FacePosition.LEFT:
        axis = 'y'
    if self == FacePosition.RIGHT:
        axis = 'y'
        degrees *= -1
    if self == FacePosition.TOP:
        axis = 'z'
    if self == FacePosition.BOTTOM:
        axis = 'z'
        degrees *= -1

    return transform.Rotation.from_euler(axis, degrees, degrees=True)

to_color(self)

Converts this face to its color.

Returns:

Type Description
TileColor

the matching color

Source code in core/cube/FacePosition.py
114
115
116
117
118
119
120
def to_color(self) -> TileColor:
    """Converts this face to its color.

    Returns:
        the matching color
    """
    return TileColor(self.value)

to_string_notation(self)

Returns the cuber notation representation, swapping left and right because of the different models used.

Note

left and right are swapped because cuber notation uses the point of view of the cuber and our FacePosition uses the point of view of the cube

Returns:

Type Description
str

the cuber notation of this face (a letter)

Source code in core/cube/FacePosition.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
def to_string_notation(self) -> str:
    """Returns the cuber notation representation, swapping left and right because of the different models used.

    !!! note
        left and right are swapped because cuber notation uses the point of view
        of the cuber and our `FacePosition` uses the point of view of the cube

    Returns:
        the cuber notation of this face (a letter)
    """
    if self == FacePosition.FRONT:
        return 'F'
    if self == FacePosition.BACK:
        return 'B'
    if self == FacePosition.LEFT:
        # left and right are swapped because cuber notation uses the point of view
        # of the cuber and our face position uses the point of view of the cube
        return 'R'
    if self == FacePosition.RIGHT:
        return 'L'
    if self == FacePosition.TOP:
        return 'U'
    if self == FacePosition.BOTTOM:
        return 'D'