fix(visualization): split lens polygon at NaN boundaries for annular apertures#587
Open
joelvarun wants to merge 1 commit into
Open
Conversation
…apertures When a surface has a RadialAperture with r_min > 0, the aperture clipping injects NaN values into the sag coordinates. These NaN vertices caused undefined fill behavior in matplotlib Polygon patches, producing diagonal line artifacts and missing chunks in the 2D lens layout. Split the vertex array at NaN boundaries into contiguous valid segments and draw a separate polygon for each segment. Refs optiland#538
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
When a surface has a
RadialAperturewithr_min > 0(annular aperture),Surface2D._compute_sag()sets clipped coordinates to NaN. This works correctly for line plots (ax.plot()treats NaN as line breaks), butLens2D._plot_single_lens()passes these NaN-contaminated vertices directly tomatplotlib.patches.Polygon, which has undefined fill behavior with NaN vertices. The result is a spurious diagonal line across the lens body and, when annular and non-annular surfaces share a lens group, missing polygon chunks.Fixes #538
Changes
optiland/visualization/system/lens.py: In_plot_single_lens, detect NaN values in the vertex array. When present, split into contiguous non-NaN segments and create a separatePolygonfor each valid segment. When no NaN values exist, behavior is unchanged.tests/visualization/test_visualization.py: AddTestAnnularApertureVisualizationwith two regression tests that build a lens matching the reproduction case from 2D layout: annular aperture (RadialAperture with r_min) causes polygon fill artifacts in Lens2D #538 and verify that (a) no polygon patch contains NaN vertices, and (b) polygon patches are still rendered.Testing
Baseline (master, before patch):
Patched:
Ruff linting and formatting both pass on the changed files.
Verification log (full pytest output)