Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.
C#
A lens surface reads flat when its sag at the rim is under half a pixel
Alexander Graefb9af44e71581
diff --git a/CLAUDE.md b/CLAUDE.mdindex f7d294d..bcc0101 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -231,7 +231,9 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDAwhich the tree's rows and toolbar use directly (`PlusBadge` on the add buttons) and which draws in the inherited textcolour, so a disabled row's icon greys with its name through one trigger on the row. A lens row's icon is its ownprofile (2026-10-29, the user's design): nine `IconLens<Left><Right>` drawings, each surface convex, flat or concave by- its radius's sign, chosen by `LensIconConverter` from R1 and R2 in a template scoped to the row's icon, so it follows an+ its sag at the rim (`LensPart.ShapeOf`: flat under half a pixel, 2026-10-29, the user's report: Example 1's mirror of radii+ 14401 on 104 px showed as biconvex), chosen by `LensIconConverter` from R1, R2 and the diameter in a template scoped to+ the row's icon, so it follows anedit; the Part menu's `IconLens` is the lens-and-mirror pair the user drew, a biconvex lens beside a concave mirror with aflat back, which no row shows. The Mirror box renames the part, Lens to Mirror and back(`LensPart.MirrorName`, run by the box's command and never by the setter, so a loaded or undone name stays). Drawings are 16 px, 1 px strokesdiff --git a/OpticalParts.md b/OpticalParts.mdindex e655f9d..feae9f3 100644--- a/OpticalParts.md+++ b/OpticalParts.md@@ -113,7 +113,8 @@ too curved for them is raised to the smallest that fits (`FitRadii`), so the lennever negative (a diameter of 2000 with radii of 300 had given a tiny lens). The form shows the edge thickness, and a"Concave" box flips both radii. A curved mirror is the same shape with `Mirror` on; ticking the box renames the part, Lens to Mirror and back(`LensPart.MirrorName`, applied by the box's command, 2026-10-29, the user's design), and the tree row's icon is the-part's own profile, each surface convex, flat or concave by its radius's sign. On the pictures the size grip+part's own profile, each surface convex, flat or concave by its sag at the rim (`ShapeOf`: flat under half a pixel, so+Example 1's mirror of radii 14401 on 104 px reads flat, the user's report of 2026-10-29). On the pictures the size gripstretches the lens as a rectangle's grip does: across, the diameter with the profile held; along, the whole profilewith its sags and edge, so a thinner lens is the same lens squashed; diagonally, the lens as a whole; the arcs arerefitted as circles through the stretched rim and vertex, and nothing stops the grip (`SetExtents`; 2026-10-26, Jeroen'sdiff --git a/WaveDudeNext.WPF/Converters/LensIconConverter.cs b/WaveDudeNext.WPF/Converters/LensIconConverter.csindex d5f8e8f..3f8d482 100644--- a/WaveDudeNext.WPF/Converters/LensIconConverter.cs+++ b/WaveDudeNext.WPF/Converters/LensIconConverter.cs@@ -22,20 +22,19 @@ using WaveDudeNext.Model;namespace WaveDudeNext.WPF.Converters;/// <summary>-/// The icon drawing of a lens or mirror by its radii (2026-10-29, the user's design): <c>Lens</c> followed by the shape of each-/// surface, <c>Convex</c>, <c>Flat</c> or <c>Concave</c>, the name of the theme's <c>IconLens{left}{right}</c> geometry. The-/// inputs are <see cref="LensPart.R1"/> and <see cref="LensPart.R2"/>, signed as the model signs them: R1 above 0 and R2 below-/// 0 bulge outward, 0 is flat; the fit never changes a sign. The biconvex profile stands in until both arrive (the kind's own-/// symbol, <c>Lens</c>, is the Add part menu's lens-and-mirror pair, which a row never shows).+/// The icon drawing of a lens or mirror by its profile (2026-10-29, the user's design): <c>Lens</c> followed by the shape of+/// each surface as <see cref="LensPart.ShapeOf"/> reads it, <c>Convex</c>, <c>Flat</c> or <c>Concave</c>, the name of the+/// theme's <c>IconLens{left}{right}</c> geometry. The inputs are <see cref="LensPart.R1"/>, <see cref="LensPart.R2"/> and+/// <see cref="LensPart.Diameter"/>: R1 above 0 and R2 below 0 bow outward, and a surface whose sag at the rim is under half a+/// pixel is flat whatever its sign (the user's report: Example 1's mirror of radii 14401 on 104 px showed as biconvex). The+/// biconvex profile stands in until all three arrive (the kind's own symbol, <c>Lens</c>, is the Add part menu's+/// lens-and-mirror pair, which a row never shows)./// </summary>public sealed class LensIconConverter : IMultiValueConverter{/// <inheritdoc/>public object Convert(object[] values, Type targetType, object? parameter, CultureInfo culture) =>- values is [double r1, double r2] ? "Lens" + Shape(r1) + Shape(-r2) : "LensConvexConvex";-- /// <summary>The surface's shape for a radius signed so that positive bulges outward.</summary>- private static string Shape(double outward) => outward > 0.0 ? "Convex" : outward < 0.0 ? "Concave" : "Flat";+ values is [double r1, double r2, int diameter] ? "Lens" + LensPart.ShapeOf(r1, diameter) + LensPart.ShapeOf(-r2, diameter) : "LensConvexConvex";/// <inheritdoc/>public object[] ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture) =>diff --git a/WaveDudeNext.WPF/Panes/ProjectTree.xaml b/WaveDudeNext.WPF/Panes/ProjectTree.xamlindex d03c428..7aa5d0d 100644--- a/WaveDudeNext.WPF/Panes/ProjectTree.xaml+++ b/WaveDudeNext.WPF/Panes/ProjectTree.xaml@@ -372,6 +372,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<MultiBinding Converter="{StaticResource LensIcon}"><Binding Path="R1" /><Binding Path="R2" />+ <Binding Path="Diameter" /></MultiBinding></controls:IconView.Drawing></controls:IconView>diff --git a/WaveDudeNext/Model/OpticalPart.cs b/WaveDudeNext/Model/OpticalPart.csindex 2b8c7d4..76157a2 100644--- a/WaveDudeNext/Model/OpticalPart.cs+++ b/WaveDudeNext/Model/OpticalPart.cs@@ -349,6 +349,17 @@ public abstract class CoatedPart : OpticalPart}}+/// <summary>The shape of one surface of a <see cref="LensPart"/> as it reads: bowing outward, flat, or bowing inward (<see cref="LensPart.ShapeOf"/>).</summary>+public enum SurfaceShape+{+ /// <summary>No bow worth a pixel: a radius of 0, or a sag at the rim under half a pixel.</summary>+ Flat,+ /// <summary>Bowing outward, away from the lens.</summary>+ Convex,+ /// <summary>Bowing inward, into the lens.</summary>+ Concave,+}+/// <summary>/// A lens, or a curved or flat mirror when <see cref="Mirror"/> is set: the strip of <see cref="Diameter"/> across/// the axis between two spherical surfaces of radii <see cref="R1"/> (left, facing -x') and <see cref="R2"/>@@ -585,6 +596,16 @@ public sealed class LensPart : CoatedPart}}+ /// <summary>+ /// The shape of a surface whose radius, signed so that positive bows outward, is <paramref name="outward"/> on a lens of+ /// <paramref name="diameter"/>: flat for 0 or when its sag at the rim is under half a pixel (the rule of+ /// <see cref="SetVertex(int, double, double, double)"/>; 2026-10-29, the user's report: Example 1's mirror of radii 14401+ /// on 104 px, a sag of a tenth of a pixel, showed as biconvex), else convex or concave by the sign. R1 is signed so; R2+ /// bows outward when negative, so it is passed negated.+ /// </summary>+ public static SurfaceShape ShapeOf(double outward, int diameter) =>+ !double.IsFinite(outward) || Sag(outward, Math.Max(2, diameter) / 2.0) < 0.5 ? SurfaceShape.Flat : outward > 0.0 ? SurfaceShape.Convex : SurfaceShape.Concave;+/// <summary>How far a surface of radius <paramref name="radius"/> bows out beyond its vertex at <paramref name="half"/> (half the diameter) from the axis, in pixels; 0 for a flat surface.</summary>public static double Sag(double radius, double half){diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.csindex 6c354f4..f28964d 100644--- a/_tools/library_check/Program.cs+++ b/_tools/library_check/Program.cs@@ -2714,6 +2714,14 @@ internal static class ProgramCheck(LensPart.MirrorName("Lens 1", false) == "Lens 1" && LensPart.MirrorName("Mirror 1", true) == "Mirror 1", "MirrorName: a name that already matches the flag is as given");Check(LensPart.MirrorName("Lensing stage", true) == "Lensing stage" && LensPart.MirrorName("Objective", true) == "Objective" && LensPart.MirrorName("lens 2", true) == "lens 2","MirrorName: whole words in the user's case only; other names are as given");+ // a surface's shape for the row icon (2026-10-29, the user's report: Example 1's mirror of radii 14401 on 104 px showed as+ // biconvex): flat for 0 or a sag at the rim under half a pixel, else by the sign; the threshold on 104 px lies at R = 2704.25+ Check(LensPart.ShapeOf(14401, 104) == SurfaceShape.Flat && LensPart.ShapeOf(-14401, 104) == SurfaceShape.Flat && LensPart.ShapeOf(0, 200) == SurfaceShape.Flat,+ "ShapeOf: a sag under half a pixel is flat, as is a radius of 0");+ Check(LensPart.ShapeOf(300, 200) == SurfaceShape.Convex && LensPart.ShapeOf(-300, 200) == SurfaceShape.Concave && LensPart.ShapeOf(10, 200) == SurfaceShape.Convex,+ "ShapeOf: a sag of a pixel or more goes by the sign, a radius under the half diameter too");+ Check(LensPart.ShapeOf(2704, 104) == SurfaceShape.Convex && LensPart.ShapeOf(2705, 104) == SurfaceShape.Flat,+ "ShapeOf: the half-pixel threshold on 104 px lies between R 2704 and 2705");lens.Diameter = 100;lens.Thickness = 40;lens.R1 = 300;