Skip to content

Measure get_angle_degrees clockwise from up, like get_angle_radians - #2950

Merged
pvcraven merged 1 commit into
developmentfrom
fix/angle-functions
Oct 8, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
fix/angle-functions

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 8, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #2754: get_angle_degrees and get_angle_radians measure angles differently.

Target from (0, 0) get_angle_degrees before get_angle_radians before (as degrees) Both, after
up (0, 1) -90 0 0
right (1, 0) 0 (returned as -0.0) 90 90
down (0, -1) 90 180 180
left (-1, 0) -180 -90 -90

Both functions used to measure clockwise from up. #2157 (June 2024) changed get_angle_degrees to measure clockwise from the right, and missed get_angle_radians.

Both now measure clockwise from straight up, like Sprite.angle: 0 is up and 90 is right. So a sprite whose image points up faces a point with sprite.angle = get_angle_degrees(...), and get_angle_radians is always math.radians of it. Only get_angle_degrees changes, which goes back to its pre-#2157 behavior. The docstrings now say which way the angles go.

Breaking: code using get_angle_degrees gets 90 more than before. The changelog entry is under Unreleased → Breaking Changes, and says to subtract 90 for the old value.

The issue proposes atan2(dy, dx) instead. That's counter-clockwise from the right, so it would have disagreed with Sprite.angle by direction.

Examples

  • sprite_rotate_around_tank is the only user of get_angle_radians in the repo.
    • Its corrected barrel (correct = True) passed swapped arguments and sat 90° off from the mouse: with the mouse to the right, the barrel lay along the top edge of the tank. It now sticks out toward the mouse.
    • The default barrel compensation goes from -90 to -180 to match, and that mode behaves exactly as before.
  • turn_and_move: the image offset and movement math were updated for the new angles.
    • Checked against development for six directions, the sprite faces and moves identically.
    • Its arrival check used <, so a sprite moving straight along an axis never registered arrival and kept turning. It now uses <=, and every direction stops facing the right way.

Tests

New in tests/unit/test_math.py; there were no tests for these functions before:

  • get_angle_degrees returns the angle clockwise from up, for six directions.
  • get_angle_radians matches math.radians(get_angle_degrees(...)).
  • A sprite turned by get_angle_degrees faces its target.

12 of the 20 fail on development.

I compared both examples with development by simulation (barrel angle and offset; sprite angle, heading and arrival), and rendered the tank to check the barrel. Full suite: 1799 passed. ruff, mypy and pyright all pass.

🤖 Generated with Claude Code

get_angle_degrees measured clockwise from the right, while
get_angle_radians measured clockwise from up, so they disagreed by 90
degrees (#2754). #2157 changed get_angle_degrees and missed
get_angle_radians. Both now measure clockwise from up, like
Sprite.angle: 0 is up and 90 is right, so a sprite whose image points
up faces a point with sprite.angle = get_angle_degrees(...).

Examples:
- sprite_rotate_around_tank: the corrected barrel passed swapped
  arguments to get_angle_radians and sat 90 degrees off from the mouse.
  The default barrel compensation goes from -90 to -180.
- turn_and_move: image offset and movement updated for the new angles,
  so it behaves the same. Its arrival check used <, so a sprite moving
  straight along an axis never stopped; now <=.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvcraven
pvcraven merged commit 186960d into development Oct 8, 2026
7 checks passed
@pvcraven
pvcraven deleted the fix/angle-functions branch October 8, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: get_angle_radians function in math.py returns incorrect angle due to swapped atan2 parameters

1 participant