Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix check for normalized quaternion #51

Merged
merged 3 commits into from
Feb 27, 2024
Merged

bugfix: fix check for normalized quaternion #51

merged 3 commits into from
Feb 27, 2024

Conversation

javierggt
Copy link
Contributor

@javierggt javierggt commented Feb 6, 2024

Description

I discovered that the Quaternion can be initialized with an invalid q.

In some places the class assumes that quaternions are normalized, and it tries to enforce that in the q property. However, the check is not correct, and instead it checks that the norm is less than 1. For example, the following does not raise:

from Quaternion import Quat
q = Quat([0, 0, 0, 0.1])

This PR fixes this and adds the corresponding test to catch the issue.

Also, there was one test that was using q=[0, 0, 0, 0], which is useless in all our use cases and can't be normalized. Using q=[0, 0, 0, 0] will raise an exception from now on and the test was fixed.

Interface impacts

A bug was fixed in the constructor that allowed non-normalized quaternions. In particular, it allowed Quat(q=[0, 0, 0, 0]), which might be used (incorrectly) in some places. From now on this will raise an exception.

Testing

Unit tests

  • No unit tests
  • Mac on version 4.3.1.dev4+g2db69e2
  • Linux
  • Windows
(ska3-flight) javierg Quaternion $ pytest Quaternion/
========================================= test session starts =========================================
platform darwin -- Python 3.10.8, pytest-7.2.1, pluggy-1.0.0
rootdir: /Users/javierg/SAO/git, configfile: pytest.ini
plugins: timeout-2.1.0, anyio-3.6.2
collected 72 items                                                                                    

Quaternion/tests/test_all.py ..............................................                     [ 63%]
Quaternion/tests/test_shaped.py ..........................                                      [100%]

========================================= 72 passed in 3.83s ==========================================
(ska3-flight) javierg Quaternion $ python -c "import Quaternion; print(Quaternion.__version__)"
4.3.1.dev4+g2db69e2

Independent check of unit tests by [REVIEWER NAME]

  • [PLATFORM]:

Functional tests

No functional testing.

@taldcroft taldcroft self-requested a review February 8, 2024 11:45
Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

Looks good code-wise. Just update the description to reflect the final PR and add the output of your pytest run and git rev-parse HEAD.

@javierggt
Copy link
Contributor Author

@taldcroft Done

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

LGTM

@javierggt javierggt merged commit 5ae6460 into master Feb 27, 2024
3 checks passed
This was referenced Mar 6, 2024
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.

2 participants