From 3fdb941d97b72ed6da62ce2dae48fa4e1eabec77 Mon Sep 17 00:00:00 2001 From: Dearex Date: Sun, 24 Aug 2025 09:48:47 +0200 Subject: [PATCH] =?UTF-8?q?fixed=20rotations=20>60=C2=B0,=20small=20cleanu?= =?UTF-8?q?ps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit as hex._rotate_clockwise doesnt change the hex but returns a value, the rotation was only ever done once. the step-calculation yielded wrong steps for counterclockwise rotation. --- hexpex/hex.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hexpex/hex.py b/hexpex/hex.py index 07c78af..1b0462f 100644 --- a/hexpex/hex.py +++ b/hexpex/hex.py @@ -195,17 +195,16 @@ def rotate(self: T, hexes: Iterable[T], angle: int) -> set[T]: if angle % 60 != 0: raise ValueError("argument of 'angle' must be in 60 degree increments.") - rotated = set() + rotated = list() + # Negative angles return the step count for clockwise rotation so no differntiation needed steps = abs((angle % 360) // 60) for hex in hexes: vector = hex - self - if angle > 0: - *_, vector = (hex._rotate_clockwise() for _ in range(steps)) - elif angle < 0: - *_, vector = (hex._rotate_counterclockwise() for _ in range(steps)) - rotated.add(self + vector) - return rotated + for _ in range(steps): + vector = vector._rotate_clockwise() + rotated.append(self + vector) + return tuple(rotated) def to_tuple(self) -> tuple[int, ...]: """Convert self to tuple representation."""