Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Fix geometry rotation (#97)
Browse files Browse the repository at this point in the history
Lib: Fix geometry rotation
  • Loading branch information
mawildoer authored Oct 23, 2024
1 parent 1899839 commit c18574a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/faebryk/libs/geometry/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,11 @@ def rotate(
R = np.array(((c, -s), (s, c)))

return cls.translate(
(-axis[0], -axis[1]),
[tuple(R @ np.array(point)) for point in cls.translate(axis, structure)],
axis,
[
tuple(R @ np.array(point))
for point in cls.translate((-axis[0], -axis[1]), structure)
],
)

C = TypeVar("C", tuple[float, float], tuple[float, float, float])
Expand Down
21 changes: 21 additions & 0 deletions test/libs/geometry/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from faebryk.libs.geometry.basic import Geometry


@pytest.mark.parametrize(
"structure, axis, angle, expected",
[
# around origin
((1, 0), (0, 0), 90, (0, 1)),
((1, 2), (0, 0), 90, (-2, 1)),
((1, 2), (0, 0), 180, (-1, -2)),
# around point
((0, 0), (1, 0), 180, (2, 0)),
((4, 0), (3, 0), 180, (2, 0)),
],
)
def test_rotate(structure, axis, angle, expected):
rotated = Geometry.rotate(axis, [structure], angle)
# rotated = tuple(map(float, rotated[0]))
assert rotated[0] == pytest.approx(expected, abs=1e-6)

0 comments on commit c18574a

Please sign in to comment.