Fix convert_angle to honor non-degree output units (e.g. gon)#14
Open
zhaozhiwen wants to merge 1 commit into
Open
Fix convert_angle to honor non-degree output units (e.g. gon)#14zhaozhiwen wants to merge 1 commit into
zhaozhiwen wants to merge 1 commit into
Conversation
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
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.
convert_angleaccepted'gon'as a valid output unit (it's a key inANG_TO_RAD) but the return path only special-caseddeg/degree, soout='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]), mirroringconvert_length. This reduces to the existing deg/rad behavior and yields correct gradians.Validation:
90*degconverts to 90 deg, π/2 rad, and 100 gon; an unknown unit still raisesValueError(Python 3.12).Fixes #8