Fix rotate_around_point to rotate about the source point - #2878
Open
uttam12331 wants to merge 1 commit into
Open
Fix rotate_around_point to rotate about the source point#2878uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
rotate_around_point computes the source->target vector, rotates it, then adds it back to `target` instead of the center of rotation `source`. This places the result at the wrong location and does not preserve the point's distance from the center. For example, rotating (1, 0) around (0, 0) by 90 degrees returned (1, 1) (distance sqrt(2) from the center) instead of the expected (0, 1). Add the rotated offset to `source` so the point orbits the center, and add regression tests asserting the distance from source is preserved and that a 180 degree rotation reflects the target through the source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
arcade.math.rotate_around_point(source, target, angle)rotatestargetaroundsource, but it adds the rotated offset back totargetinstead of to the center of rotationsource. As a result the returned point is placed incorrectly and its distance from the center is not preserved.Reproduction
Any rotation where the source and target differ lands on the wrong point.
Fix
The offset
(dx, dy)is the rotatedsource -> targetvector, so it must be added to the center of rotationsource, not totarget:Tests
Added two regression tests in
tests/unit/test_math.pythat are independent of the clockwise/counter-clockwise convention:sourcefor several angles, andtargetthroughsource.Both fail on the previous behavior and pass with the fix.