Skip to content

Feature/boundary physics - #61

Open
TacHawkes wants to merge 15 commits into
masterfrom
feature/boundary-physics
Open

TacHawkes wants to merge 15 commits into
masterfrom
feature/boundary-physics

Conversation

@TacHawkes

@TacHawkes TacHawkes commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Part 2 of 3: Physical Boundary Interactions & Wave Propagation

Note: Builds upon PR #60 (feature/intersection-handling).

This PR introduces the physical boundary interaction engine:

  • Modular BoundaryPhysics.jl implementing Snell's law, Fresnel coefficients, and Total Internal Reflection (TIR).
  • Ray splitting (Splitting behavior) generating transmitted and reflected child rays.
  • S/P-basis polarization transformations with Poynting flux impedance scaling.

@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: a214dbc956

ℹ️ 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 +207 to +210
if hasfield(T, :n)
return (Base.typename(T).wrapper)(s, obj.n, c_tuple)
else
return (Base.typename(T).wrapper)(s, c_tuple)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add constructible coated wrappers

When with_coatings is called on the existing optics advertised in the examples, this fallback calls the original type constructor with an extra coatings tuple, e.g. Lens(s, obj.n, c_tuple) or Mirror(s, c_tuple). Those structs in this commit still only have shape,n or shape fields and no matching constructors, so the public coating API throws a MethodError before any coated component can be created.

Useful? React with 👍 / 👎.


Default fallback implementation checking if an object has refractive properties. Returns `false`.
"""
is_refractive(::AbstractObject) = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Mark refractive optics as refractive

For standalone coatings or coincident coated boundaries adjacent to a Lens/Prism, this new predicate is the only applicable method because no is_refractive(::AbstractRefractiveOptic) override is added. The boundary resolver therefore treats refractive substrates as ambient media, chooses the system index instead of the glass index, and returns no substrate hint, so coated or standalone interfaces next to lenses trace as air-to-air boundaries.

Useful? React with 👍 / 👎.


Refer to e.g. [`DiscreteRefractiveIndex`](@ref), [`SellmeierEquation`](@ref), [`AbsorbingMedium`](@ref), and [`GainMedium`](@ref).
"""
const RefractiveIndex = Union{Function, DiscreteRefractiveIndex, SellmeierEquation, AbsorbingMedium, GainMedium}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove Float64-only refractive index returns

Adding AbsorbingMedium and GainMedium to RefractiveIndex makes Lens/Prism accept media whose call returns n + imκ, but the existing refractive_index(::AbstractRefractiveOptic{<:Any,<:RefractiveIndex}, λ)::Float64 method still forces that complex value into Float64. Any nonzero absorption or gain therefore throws before the new attenuation code can run; the refractive optic accessor needs to return Number/the actual complex value.

Useful? React with 👍 / 👎.

Comment thread src/Rays.jl
end
end

Ray{T}(pos, dir, int, λ, n) where {T} = Ray{T}(pos, dir, int, λ, n, one(T))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve ray weights across legacy interactions

This compatibility overload keeps old Ray{T}(pos, dir, int, λ, n) call sites compiling by silently resetting the new power weight to 1. Existing interactions such as ordinary lenses and mirrors still use that signature, so a ray that was split or attenuated by the new coating physics regains full power at the next uncoated optic, making optical_power and power_cutoff incorrect; those call sites need to pass through weight(ray).

Useful? React with 👍 / 👎.

Comment thread src/SDFs/PrimitiveSDF.jl Outdated
end

function bounding_sphere(s::CylinderSDF{T}) where T
return (Point3{T}(0), sqrt(s.radius^2 + (s.height / 2)^2))

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 the full cylinder half-extent in culling

CylinderSDF.sdf treats height as the y half-extent via abs(y) - cylinder.height, but the new bounding sphere only includes height / 2. For tall cylinders, off-axis rays aimed at an end cap can be fast-forwarded past the real cap hit into the volume, after which _raymarch_outside may never report the intersection; the sphere radius should use sqrt(radius^2 + height^2) to enclose the actual SDF.

Useful? React with 👍 / 👎.

if is_reflected
return SPBasis(-rs, 0, 0, rp)
else
return SPBasis(ts, 0, 0, tp)

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 Fresnel field coefficients to power

For Uncoated boundaries with n1 != n2, these are field Fresnel transmission coefficients, but coating_transmittance later treats abs2(ts/tp) as transmitted power without the admittance factor n2*cos(θt)/(n1*cos(θi)). At normal incidence from air to glass this reports 0.64 instead of the physical 0.96, so unpolarized Ray weights through bare or thin-film transmissive boundaries are corrupted.

Useful? React with 👍 / 👎.

…ix surface_tag fallback and numeric_gradient step
@TacHawkes
TacHawkes force-pushed the feature/boundary-physics branch from a214dbc to 888cac1 Compare August 19, 2026 05:24
@TacHawkes
TacHawkes force-pushed the feature/boundary-physics branch from 888cac1 to 6c67176 Compare August 19, 2026 05:27
Kliebisch, Oliver added 2 commits August 19, 2026 07:40
…SDF surface_tags to :top/:bottom, and make Aqua test conditional
@TacHawkes
TacHawkes force-pushed the feature/boundary-physics branch from 6c67176 to 7edcf60 Compare August 19, 2026 05:41

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.

1 participant