Skip to content

Fix operator precedence in SegmentText rotation calculation#104

Closed
leofernandezg wants to merge 1 commit intocdelker:masterfrom
leofernandezg:fix/rotation-operator-precedence
Closed

Fix operator precedence in SegmentText rotation calculation#104
leofernandezg wants to merge 1 commit intocdelker:masterfrom
leofernandezg:fix/rotation-operator-precedence

Conversation

@leofernandezg
Copy link
Copy Markdown

Summary

  • Adds missing parentheses in rotation calculation on lines 342 and 408 of segments.py

Problem

rotation + transform.theta % 360 is evaluated as rotation + (transform.theta % 360) due to Python operator precedence, instead of (rotation + transform.theta) % 360. This produces rotation values exceeding 360 degrees.

Test results

Branch Passed Failed
master 470 0
this branch 473 0

Fixes #100

The expression `rotation + transform.theta % 360` was evaluated as
`rotation + (transform.theta % 360)` due to Python operator precedence,
instead of the intended `(rotation + transform.theta) % 360`.

This could produce rotation values exceeding 360 degrees (e.g. 395
instead of 35 when rotation=350 and theta=45).

Added parentheses on both occurrences (xform and draw methods) and
test/test_rotation.py to verify.

Fixes cdelker#100
@cdelker cdelker closed this Apr 11, 2026
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.

Operator precedence bug in SegmentText rotation calculation

2 participants