Skip to content

Coatings implementation - #57

Open
TacHawkes wants to merge 64 commits into
masterfrom
feature/coatings-implementation
Open

TacHawkes wants to merge 64 commits into
masterfrom
feature/coatings-implementation

Conversation

@TacHawkes

Copy link
Copy Markdown
Collaborator

Abstract

This is a new attempt at coatings and is based on #55 as a prerequisite. It will also render #27 obsolete, as polarizing components can be handled using coatings which results in a much more flexible, modular and extensible API.

This should close #30.


Detailed description: Unified Coatings, Face Partitions, and Polarizing Optics

Overview

This PR implements a unified coatings and dynamic boundary physics pipeline in BeamletOptics.jl. It standardizes boundary interactions (refraction, reflection, splitting) across rays and Gaussian/Astigmatic beamlets, modernizes polarizing components, and optimizes performance to achieve allocation-free tracing.


Key Features

  • Unified Boundary Physics (CoatingBehavior): Introduced traits (Transmissive, Reflective, Splitting) to cleanly dispatch boundary logic.
  • Coating Models: Added support for Uncoated, SimpleARCoating, SimpleHRCoating, SimpleBeamsplitterCoating, JonesCoating, and ThinFilmCoating (multi-layer characteristic matrix calculations).
  • Face-Selective Coatings: Supported named faces (:front, :back, :hypotenuse), direction vectors, and spatial predicates to apply localized coatings.
  • Standardized Splitting: Standardized beamlet splitting (spawning transmitted and reflected children) across components. Added a power_cutoff threshold in solve_system! to prevent infinite loops.
  • Modernized Polarizing Optics: Refactored Waveplate and PolarizingBeamSplitter (plate & cube versions) to sit on top of the coating pipeline. Updated _calculate_global_E0 to use correct 3D polarization projection mapping.

@codecov

codecov Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.33472% with 358 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.08%. Comparing base (28c894b) to head (c503a8f).

Files with missing lines Patch % Lines
src/OpticalComponents/Coatings/CoatedComponents.jl 66.93% 82 Missing ⚠️
...rc/OpticalComponents/Coatings/StandaloneCoating.jl 59.50% 49 Missing ⚠️
src/OpticalComponents/FacePartition.jl 31.70% 28 Missing ⚠️
src/SDFs/AbstractSDF.jl 75.45% 27 Missing ⚠️
ext/RenderObjects.jl 0.00% 24 Missing ⚠️
src/OpticalComponents/Coatings/Models.jl 91.21% 18 Missing ⚠️
src/SDFs/UnionSDF.jl 73.84% 17 Missing ⚠️
src/SDFs/PrimitiveSDF.jl 85.55% 13 Missing ⚠️
ext/RenderPresets.jl 0.00% 9 Missing ⚠️
src/OpticalComponents/Mirrors.jl 74.28% 9 Missing ⚠️
... and 27 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
+ Coverage   73.46%   75.08%   +1.62%     
==========================================
  Files          61       70       +9     
  Lines        3885     5150    +1265     
==========================================
+ Hits         2854     3867    +1013     
- Misses       1031     1283     +252     

☔ View full report in Codecov by Harness.
📢 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b50da79f50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

λ,
from_front
) where {T, R <: Ray{T}}
ndir_t, _ = refraction3d(direction(ray), normal, n_incident, n_transmitted)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle total internal reflection before splitting

When a splitting coating is hit from a higher-index medium above the critical angle, refraction3d returns the reflected direction with the TIR flag set, but this path discards the flag and still creates a transmitted child with n_transmitted and T_coeff. A coated glass-air boundary with behavior = Splitting() will therefore emit a bogus transmitted branch instead of reflecting all power, corrupting traced beam trees in TIR cases.

Useful? React with 👍 / 👎.

zrotate3d!(coating, π)
return RectangularPlateBeamsplitter(substrate, coating)
M = typeof(coating.model)
return RectangularPlateBeamsplitter{typeof(width), M}(substrate, coating)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use promoted dimension type for plate constructors

If callers pass integer dimensions for width while other dimensions or mesh construction promote to floating point, this explicitly instantiates RectangularPlateBeamsplitter{Int64,...} even though substrate and coating are Prism{Float64,...}/Coating{Float64,...}. For inputs like RectangularPlateBeamsplitter(10, 10, 0.2, n) the constructor will fail at runtime; let T be inferred or use promote_type(typeof(width), typeof(height), typeof(thickness)).

Useful? React with 👍 / 👎.

@TacHawkes TacHawkes mentioned this pull request Jul 25, 2026
@TacHawkes

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb6397c429

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +372 to +373
w_dir_t, _ = refraction3d(direction(w_ray), normal, n_incident, n_transmitted)
d_dir_t, _ = refraction3d(direction(d_ray), normal, n_incident, n_transmitted)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle auxiliary beamlet TIR before splitting

When a GaussianBeamlet hits a splitting coating near the critical angle, the chief ray can still refract while the waist or divergence ray is already above critical angle because its direction/normal differs. refraction3d then returns a reflected direction with the TIR flag set, but these lines discard that flag and put the reflected support ray into the transmitted child with n_transmitted, producing an inconsistent split beamlet. Check the component-ray TIR flags before spawning the transmitted branch.

Useful? React with 👍 / 👎.

retardance::Union{Real, Function};
fast_axis_angle::Real=0.0
)
substrate_shape = BoxSDF(width, thickness, height)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Convert waveplate dimensions before constructing BoxSDF

When callers pass integer dimensions to this new rectangular plate constructor, BoxSDF(width, thickness, height) creates a BoxSDF{Int} and stores half-dimensions, so inputs like RectangularPlateWaveplate(10, 10, 1, n, π/2) throw an InexactError before the object is constructed. Promote/convert these dimensions to a floating T before constructing the substrate and coating, matching the updated plate beamsplitter constructors.

Useful? React with 👍 / 👎.

@TacHawkes

Copy link
Copy Markdown
Collaborator Author

Kliebisch, Oliver added 4 commits August 19, 2026 07:24

This branch has not been deployed

No deployments
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.

Polarizing components trait

1 participant