Skip to content

Conversation

@RubenKelevra
Copy link
Contributor

The previous implementation incorrectly normalized angles when using a non-zero startAt parameter. It would first normalize to [0, 360), then attempt to adjust for startAt, which failed for many cases, especially with negative input values.

The new implementation correctly handles all cases by:

  1. Shifting the coordinate system by -startAt
  2. Normalizing to [0, 360)
  3. Shifting back by +startAt

This ensures the result is always in the range [startAt, startAt+360).

Example of the bug: normalizeDegrees(-720.0, 200.0) would return 0 instead of the correct value 360.

Normalize angles by shifting to origin first, then shifting back.
Previous implementation failed for negative inputs with non-zero startAt.
@riQQ
Copy link
Collaborator

riQQ commented Jun 5, 2025

This is the perfect change to add accompanying unit tests.

@westnordost
Copy link
Member

I agree with @riQQ

@RubenKelevra
Copy link
Contributor Author

Was about to add some :)

@westnordost
Copy link
Member

ah, cool!

The test for isRightOf(p0, 270.0) now expects false instead of true, as a point lying exactly on the defined bearing should not be considered to the right of the line. This aligns the test with geometric convention, where "right of" excludes points that are collinear with the line.
@RubenKelevra RubenKelevra marked this pull request as draft June 5, 2025 21:42
Add unit tests for normalizeDegrees and normalizeRadians (Double/Float) to verify correct normalization with different startAt parameters and a variety of input values, including edge cases with negative numbers and offsets.
@RubenKelevra RubenKelevra marked this pull request as ready for review June 5, 2025 21:55
@RubenKelevra
Copy link
Contributor Author

@westnordost ping.

Copy link
Member

@westnordost westnordost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@westnordost westnordost merged commit 2da5871 into streetcomplete:master Jun 6, 2025
@RubenKelevra RubenKelevra deleted the fix_anglemath branch June 6, 2025 20:06
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.

3 participants