Skip to content

fix: proper perspective aspect ratio preservation#74

Merged
gselzer merged 3 commits intopyapp-kit:mainfrom
gselzer:zoom-to-fit-perspective-aspect
Apr 24, 2026
Merged

fix: proper perspective aspect ratio preservation#74
gselzer merged 3 commits intopyapp-kit:mainfrom
gselzer:zoom-to-fit-perspective-aspect

Conversation

@gselzer
Copy link
Copy Markdown
Collaborator

@gselzer gselzer commented Apr 23, 2026

Turns out that perspective matrices weren't actually having their aspect ratios preserved. This PR documents what the (newly-renamed) letterbox parameter does, and adds in a test ensuring it behaves as expected.

gselzer added 2 commits April 23, 2026 15:32
Turns out that perspective matrices weren't actually having their aspect
ratios preserved.
We use that term with the ResizePolicy to do very similar things.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.08%. Comparing base (d5236c4) to head (6a5dda8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/scenex/utils/projections.py 89.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
- Coverage   88.09%   88.08%   -0.01%     
==========================================
  Files          64       64              
  Lines        3174     3182       +8     
==========================================
+ Hits         2796     2803       +7     
- Misses        378      379       +1     

☔ 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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes aspect-ratio preservation for zoom_to_fit(..., type="perspective") by introducing/renaming the option to letterbox, documenting its behavior, and adding regression tests to ensure non-square viewports no longer cause anisotropic distortion.

Changes:

  • Renamed preserve_aspect_ratio to letterbox and updated internal logic to apply letterboxing for both orthographic and perspective projections.
  • Added a new perspective letterbox test (and renamed the existing orthographic aspect test) to validate correct NDC mapping for wide/tall canvases.
  • Updated scenex.util.show() to use the new letterbox=True parameter.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/scenex/utils/projections.py Implements letterbox behavior (including perspective aspect correction), updates docstring, and adds _aspect_ratio() helper.
tests/utils/test_projections.py Renames orthographic aspect test and adds a new regression test for perspective letterboxing.
src/scenex/util.py Updates show() to call zoom_to_fit(..., letterbox=True).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/scenex/utils/projections.py Outdated
Comment thread src/scenex/utils/projections.py Outdated
Comment thread src/scenex/utils/projections.py Outdated
Comment thread tests/utils/test_projections.py Outdated
Thanks Copilot!
@gselzer gselzer merged commit 53b9f95 into pyapp-kit:main Apr 24, 2026
37 checks passed
@gselzer gselzer deleted the zoom-to-fit-perspective-aspect branch April 24, 2026 16:47
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