Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arcade/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def rotate_around_point(source: Point2, target: Point2, angle: float):
dx = diff_x * c - diff_y * s
dy = diff_x * s + diff_y * c

return target[0] + dx, target[1] + dy
return source[0] + dx, source[1] + dy


def get_angle_degrees(x1: float, y1: float, x2: float, y2: float) -> float:
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,16 @@ def test_rand_vec_spread_deg():
def test_rand_vec_magnitude():
"""Smoke test"""
rand_vec_magnitude(30.5, 3.3, 4.4)


def test_rotate_around_point():
"""The result is offset from the rotation center, not from the target."""
from arcade.math import rotate_around_point

x, y = rotate_around_point((3.0, 0.0), (5.0, 0.0), 90.0)
assert x == approx(3.0)
assert y == approx(2.0)

# A full turn and a zero-length radius both leave the target where it is.
assert rotate_around_point((3.0, 0.0), (5.0, 0.0), 360.0) == (5.0, 0.0)
assert rotate_around_point((3.0, 0.0), (3.0, 0.0), 90.0) == (3.0, 0.0)