fix clockwise_twist
This commit is contained in:
parent
9a92a1e922
commit
5b972eb737
@ -161,36 +161,43 @@ def test_rotation_permutations(p: CornerRotPermutation):
|
|||||||
MID_DIR_INCREMENT: dict[MidRotState, MidRotState] = {"Y": "O", "R": "Y", "O": "R"}
|
MID_DIR_INCREMENT: dict[MidRotState, MidRotState] = {"Y": "O", "R": "Y", "O": "R"}
|
||||||
|
|
||||||
|
|
||||||
def clockwise_twist(s: Skewb, twist: Axis) -> Skewb:
|
def clockwise_twist(s: Skewb, axis: Axis) -> Skewb:
|
||||||
rot_before, rot_after = {"G": (0, 0), "O": (3, 1), "B": (2, 2), "R": (1, 3)}[twist]
|
"""Applies a clockwise twist to the axis.
|
||||||
|
|
||||||
|
Coordinate frame is define as follows:
|
||||||
|
- axis goes through the `top` of a solved cube of a given color
|
||||||
|
- the axis-top is on top and faces away from the observer twisting it,
|
||||||
|
- clockwise is twisting the bottom when looking up from diagonally-below the skewb
|
||||||
|
"""
|
||||||
|
rot_before, rot_after = {"G": (0, 0), "O": (3, 1), "B": (2, 2), "R": (1, 3)}[axis]
|
||||||
for _ in range(rot_before):
|
for _ in range(rot_before):
|
||||||
s = rotate_everything_about_W(s)
|
s = rotate_everything_about_W(s)
|
||||||
s = Skewb(
|
s = Skewb(
|
||||||
top=(
|
top=(
|
||||||
s.top[0],
|
s.top[0],
|
||||||
s.top[1],
|
s.top[1],
|
||||||
Corner((c := s.bot[3]).col, BOT_LEFT_TO_TOP[c.rot]),
|
Corner((c := s.bot[0]).col, BOT_LEFT_TO_TOP[c.rot]),
|
||||||
s.top[3],
|
s.top[3],
|
||||||
),
|
),
|
||||||
bot=(
|
bot=(
|
||||||
s.bot[0],
|
Corner((c := s.bot[2]).col, BOT_RIGHT_TO_BOT_LEFT[c.rot]),
|
||||||
|
s.bot[1],
|
||||||
Corner((c := s.top[2]).col, TOP_TO_BOT_RIGHT[c.rot]),
|
Corner((c := s.top[2]).col, TOP_TO_BOT_RIGHT[c.rot]),
|
||||||
Corner((c := s.bot[2]).col, ROTATE_CORNER_CLOCKWISE[c.rot]),
|
Corner((c := s.bot[3]).col, ROTATE_CORNER_CLOCKWISE[c.rot]),
|
||||||
Corner((c := s.bot[1]).col, BOT_RIGHT_TO_BOT_LEFT[c.rot]),
|
|
||||||
),
|
),
|
||||||
mids=(
|
mids=(
|
||||||
s.mids[0],
|
s.mids[0],
|
||||||
|
s.mids[1],
|
||||||
Middle(
|
Middle(
|
||||||
(m := s.mids[2]).col,
|
(m := s.mids[3]).col,
|
||||||
"Y" if m.col == "Y" else MID_DIR_INCREMENT[m.rot],
|
"Y" if m.col == "Y" else MID_DIR_INCREMENT[m.rot],
|
||||||
),
|
),
|
||||||
Middle(
|
Middle(
|
||||||
(m := s.mids[4]).col,
|
(m := s.mids[4]).col,
|
||||||
"Y" if m.col == "Y" else MID_DIR_INCREMENT[m.rot],
|
"Y" if m.col == "Y" else MID_DIR_INCREMENT[m.rot],
|
||||||
),
|
),
|
||||||
s.mids[3],
|
|
||||||
Middle(
|
Middle(
|
||||||
(m := s.mids[1]).col,
|
(m := s.mids[2]).col,
|
||||||
"Y" if m.col == "Y" else ("O" if m.rot == "Y" else "R"),
|
"Y" if m.col == "Y" else ("O" if m.rot == "Y" else "R"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -200,6 +207,22 @@ def clockwise_twist(s: Skewb, twist: Axis) -> Skewb:
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"axis, want",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"O",
|
||||||
|
Skewb(
|
||||||
|
top=(G0, O0, B0, O2), bot=(G1, R2, B0, R2), mids=(YY, OY, BY, GR, RR)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_clockwise_twist_from_solved(axis: Axis, want: Skewb):
|
||||||
|
want.assert_valid()
|
||||||
|
assert clockwise_twist(solved_skewb, axis) == want
|
||||||
|
|
||||||
|
|
||||||
def anticlockwise_twist(s: Skewb, twist: Axis) -> Skewb:
|
def anticlockwise_twist(s: Skewb, twist: Axis) -> Skewb:
|
||||||
return clockwise_twist(clockwise_twist(s, twist), twist)
|
return clockwise_twist(clockwise_twist(s, twist), twist)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user