Accept plane names for the axis argument of Probe.rotate - #461
Open
adityasingh2400 wants to merge 1 commit into
Open
Accept plane names for the axis argument of Probe.rotate#461adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
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.
The docstring of
Probe.rotatedocumentsaxisas one of"xy","yz", or"xz", but passing any of those strings raisesValueError: could not convert string to float: 'xy'. Only a 3-element vector actually works today, so the documented form of the argument has never been usable.The cause is that
rotateforwardsaxisstraight to_rotation_matrix_3d, which immediately doesaxis = axis / np.linalg.norm(axis).np.linalg.normcallsastype(float)on its input, and a string cannot be cast, so the call dies before the rotation matrix is ever built.This adds a small
_axis_to_vectorhelper that normalises the argument before it reaches_rotation_matrix_3d. A plane name maps to the unit vector normal to that plane, so"xy"becomes[0, 0, 1],"yz"becomes[1, 0, 0], and"xz"becomes[0, 1, 0], which is the mapping Alessio suggested in the issue thread. Vectors keep working exactly as before, and anything else now raises aValueErrorthat names the accepted values instead of surfacing a numpy casting error. The type hint and docstring were updated to say that both forms are accepted.Tested with new cases in
tests/test_probe.py. They rotate the same 3D probe twice, once by plane name and once by the equivalent vector, and assert that contact positions and contact plane axes match, plus a check that rotating in the xy plane leaves z untouched and that bad axis values raise. All four new checks fail on main with the numpy casting error and pass with this change. The existing suite still passes, 193 passed and 1 skipped.Fixes #273