Skip to content

Fix convert_angle to honor non-degree output units (e.g. gon)#14

Open
zhaozhiwen wants to merge 1 commit into
gemc:mainfrom
zhaozhiwen:fix/139-convert-angle-gon
Open

Fix convert_angle to honor non-degree output units (e.g. gon)#14
zhaozhiwen wants to merge 1 commit into
gemc:mainfrom
zhaozhiwen:fix/139-convert-angle-gon

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

convert_angle accepted 'gon' as a valid output unit (it's a key in ANG_TO_RAD) but the return path only special-cased deg/degree, so out='gon' fell through and returned the value in radians — a silently wrong unit for a documented-as-valid output.

Convert generally via the table (val_rad / ANG_TO_RAD[out]), mirroring convert_length. This reduces to the existing deg/rad behavior and yields correct gradians.

Validation: 90*deg converts to 90 deg, π/2 rad, and 100 gon; an unknown unit still raises ValueError (Python 3.12).

Fixes #8

convert_angle accepted 'gon' as a valid output unit (it's a key in
ANG_TO_RAD) but the return path only special-cased deg/degree, so
out='gon' fell through and returned the value in radians — a silently
wrong unit for a documented-as-valid output.

Convert generally via the table (val_rad / ANG_TO_RAD[out]), mirroring
convert_length. This reduces to the existing deg/rad behavior and yields
correct gradians. The redundant extra membership check is dropped since
deg/degree/rad are all already keys in ANG_TO_RAD.

Verified: 90*deg converts to 90 deg, pi/2 rad, and 100 gon; an unknown
unit still raises ValueError (Python 3.12).

Fixes gemc#8
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.

[Low] convert_angle(out='gon') returns radians instead of gradians

1 participant