Skip to content

[Maintenance] Refactor issue 113 - offset-rotation procedure to _transformations.py#166

Open
20086080 wants to merge 8 commits intocamUrban:mainfrom
20086080:Refactor_Issue_113
Open

[Maintenance] Refactor issue 113 - offset-rotation procedure to _transformations.py#166
20086080 wants to merge 8 commits intocamUrban:mainfrom
20086080:Refactor_Issue_113

Conversation

@20086080
Copy link
Copy Markdown

@20086080 20086080 commented May 1, 2026

Description

Refactor rotation handling in CoreWingMovement and add targeted unit tests to validate the rotation-point offset transformation logic.

This improves clarity and correctness of how offset-based rotations are applied, and introduces focused tests to validate transformation behavior in a controlled and reproducible way. The rotation handling logic can now be reused elsewhere as required.

I am a a first-time contributor and will add myself to the list of contributors in the README. Thank you.

Motivation

The rotation-point offset logic in WingMovement (though actually in the _core super class in generate_wing_at_time_step method) is mathematically non-trivial and previously untested in isolation. This makes it a difficult task to confidently refactor or extend and has a level of complexity which I took on as a challenge.

Additionally, the transformation logic relies on _transformations.generate_rot_T, so ensuring correctness requires validating both:

  • the transformation construction, and
  • its downstream application in WingMovement.

Relevant Issues

Closes #113.

Changes

Refactor

  • Clarified the rotation offset application logic in WingMovement.generate_wing_at_time_step.
  • Improved readability of the transformation workflow:
    • Explicit extraction of rotation matrix from transformation matrix.
    • Clear separation of rotation computation and offset adjustment.
  • Retained existing behavior while making the math easier to reason about and test independently.

New Tests

  • Added unit tests in test_transformations.py to validate transformation behavior.

    • test_identity_rotation - Identity rotation should produce zero adjustment
    • test_zero_offset - Zero offset should always produce zero adjustment
    • test_known_rotation - Test adjustment for a known rotation (90° about z-axis)
  • Introduced tests (class TestComputeOffsetRotationAdjustment) specifically targeting:

    • Correct construction of rotation matrices via generate_rot_T.
    • Correct application of rotation to vectors.
    • Numerical validation of offset-based rotation adjustment: Verifies (I - R) @ offset produces expected translation.
  • Used numpy.testing.assert_allclose with tight tolerances (atol=1e-14) to ensure numerical precision.

Testing Methodology

  • Tests are property-based and physics-aligned, not just structural:
  • Validate invariants (e.g., identity cases, zero rotation behavior).
  • Validate known analytical results for simple rotations.
  • Focus on deterministic inputs (fixed angles, offsets) to ensure reproducibility.

Validation

  • Ran the full test suite locally to ensure no regressions.
  • All existing tests pass.

Dependency Updates

None.

Change Magnitude

Minor: Small refactor with added tests to improve scalability, correctness and maintainability.

Checklist (check each item when completed or not applicable)

  • I am familiar with the current contribution guidelines.
  • PR description links all relevant issues and follows this template.
  • My branch is up to date with the upstream main branch.
  • All calculations use S.I. units.
  • Code is formatted with black (line length = 88).
  • Code is well documented with block comments where appropriate.
  • Any external code, algorithms, or equations used have been cited in comments or docstrings.
  • All new modules, classes, functions, and methods have docstrings in reStructuredText format, and are formatted using docformatter (--in-place --black). See the style guide for type hints and docstrings for more details.
  • All new classes, functions, and methods in the pterasoftware package use type hints. See the style guide for type hints and docstrings for more details.
  • If any major functionality was added or significantly changed, I have added or updated tests in the tests package.
  • Code locally passes all tests in the tests package.
  • This PR passes the ReadTheDocs build check (this runs automatically with the other workflows).
  • This PR passes the black, codespell, and isort GitHub actions.
  • This PR passes the mypy GitHub action.
  • This PR passes all the tests GitHub actions.

@20086080 20086080 requested a review from camUrban as a code owner May 1, 2026 05:22
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.71%. Comparing base (899cfa1) to head (e4b377a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #166   +/-   ##
=======================================
  Coverage   91.71%   91.71%           
=======================================
  Files          35       35           
  Lines        6828     6830    +2     
=======================================
+ Hits         6262     6264    +2     
  Misses        566      566           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Owner

@camUrban camUrban left a comment

Choose a reason for hiding this comment

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

Hi @20086080, thanks so much for this PR. It looks great. I especially appreciate the tests you added. I've left a few small comments below.

Comment thread .idea/misc.xml Outdated
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this change was committed accidentally. You might want to rename your PyCharm project to "PteraSoftware" to match the project default, or add this file to your personal .git/info/exclude file.

Comment thread .idea/PteraSoftware.iml Outdated
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this change was committed accidentally. You might want to rename your PyCharm project to "PteraSoftware" to match the project default, or add this file to your personal .git/info/exclude file.

Comment thread .idea/vcs.xml Outdated
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this change was committed accidentally. You might want to add this file to your personal .git/info/exclude file.

Comment thread pterasoftware/_transformations.py Outdated
:return: A (3,) ndarray representing the position adjustment.
"""

return (np.eye(3, dtype=float) - rotation_matrix) @ offset
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think you can fix the mypy warning here by wrapping this in np.asarray(..., dtype=float). Then, double-check you don't get any warnings by running mypy pterasoftware.

Comment thread pterasoftware/_transformations.py Outdated
When a rotation is applied about a point other than the origin, the effective
position must be adjusted. This function computes that adjustment vector.

The adjustment is given by: (I - R) @ offset
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You can drop the extra white space after the colon here.

Comment thread tests/unit/test_transformations.py Outdated
npt.assert_allclose(adjustment, np.zeros(3), atol=1e-14)

def test_known_rotation(self):
"""Test adjustment for a known rotation (90° about z-axis)."""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Replace with "90 deg" (we try to avoid any characters that aren't in the set of 95 printable-ASCII characters).

Comment thread tests/unit/test_transformations.py Outdated


class TestComputeOffsetRotationAdjustment(unittest.TestCase):
"""Tests for compute_offset_rotation_adjustment function."""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Add "the" to "Tests for compute_..."

@camUrban camUrban added the maintenance Improvements or additions to documentation, testing, or robustness label May 1, 2026
@camUrban
Copy link
Copy Markdown
Owner

camUrban commented May 1, 2026

Also, don't forget to add yourself to the list of contributors in the README! 😄

@20086080
Copy link
Copy Markdown
Author

20086080 commented May 2, 2026

@camUrban Hi. Thank you for all the comments and suggestions. I have made the requested changes. Let me know if anything additional on this. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Improvements or additions to documentation, testing, or robustness

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract offset-rotation procedure to _transformations.py

2 participants