Skip to content

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's grip stretches it, and a handle on each surface's vertex sets its radius

Alexander Graef7329d687477b
diff --git a/OpticalParts.md b/OpticalParts.md
index d90cc40..aa3e014 100644
--- a/OpticalParts.md
+++ b/OpticalParts.md
@@ -81,7 +81,16 @@ left surface) and `R2` −300 (R1 > 0 and R2 < 0 bulge outward, 0 is flat), `Ref
x'₂ = t/2 + s₂(y'), the sag s(y') = R − sign(R)·√(R² − y'²). The diameter and the centre thickness are the bulk: a radius
too curved for them is raised to the smallest that fits (`FitRadii`), so the lens fills its diameter and the edge is
never 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.
+"Concave" box flips both radii. A curved mirror is the same shape with `Mirror` on. On the pictures the size grip
+stretches the lens as a rectangle's grip does: across, the diameter with the profile held; along, the whole profile
+with its sags and edge, so a thinner lens is the same lens squashed; diagonally, the lens as a whole; the arcs are
+refitted as circles through the stretched rim and vertex, and nothing stops the grip (`SetExtents`; 2026-10-26, Jeroen's
+report: a grip dragged a little inward had the radii fitted flat and the lens was a rectangle, and held sags made a
+stretched lens a slab). A handle on each surface's vertex sets its radius
+(`SetVertex`, Jeroen's proposal): dragged along the axis with the rim and the other surface held, the sag at the rim
+gives the radius by the sagitta, outward bulging, through the rim plane flat, then concave, a hemisphere at most; the
+centre thickness follows and the position moves to the new centre. A drag holds the rim and the other vertex as it
+found them (`MarkerThumb.DragAnchors`), so the position's rounding never creeps into them.
**Shapes** (`ShapePart`: `Mirror`, `RefractiveIndex` 1.50, `Coating`, `Absorption`, `AbsorptionRamp` 40, over an
outline each kind generates). One class per shape, not a shape mode inside one class (the user's point, 2026-10-18: a
@@ -167,9 +176,10 @@ the check's small canvas, +6 % in a wide one).
the canvas, named "<stem> n".
- **Pictures**: a handle at the centre and a rotation lever; while selected, the outline as painted in the accent
colour, a size grip (a rectangle's or ellipse's corner, the lens's thickness and diameter, a GRIN lens, Bragg stack or
- zone plate corner, a polygon's first vertex, the second end of a triangle's base), a handle per outline point
- (2026-10-19) and per fibre node with its two Bézier handles on dotted lines (2026-10-22); otherwise the shape shows
- through the glowing outline. Arrows nudge, Escape during a drag puts things back.
+ zone plate corner, a polygon's first vertex, the second end of a triangle's base), a lens's two vertex handles for
+ the radii (2026-10-26), a handle per outline point (2026-10-19) and per fibre node with its two Bézier handles on
+ dotted lines (2026-10-22); otherwise the shape shows through the glowing outline. Arrows nudge, Escape during a drag
+ puts things back.
- **Examples**: `Wave_Dude_Examples/logical_elements_example.wdproj` (Jeroen's, 2026-10-22: XOR and AND gates cascaded
with pulsed sources and probes).
diff --git a/WaveDudeNext.WPF/Controls/MarkerThumb.cs b/WaveDudeNext.WPF/Controls/MarkerThumb.cs
index 1ee6db9..456ad46 100644
--- a/WaveDudeNext.WPF/Controls/MarkerThumb.cs
+++ b/WaveDudeNext.WPF/Controls/MarkerThumb.cs
@@ -17,6 +17,7 @@
using System.Windows;
using System.Windows.Controls.Primitives;
+using System.Windows.Input;
namespace WaveDudeNext.WPF.Controls;
@@ -35,6 +36,8 @@ public enum MarkerRole
PartGrip,
/// <summary>One point of an outline's list, or one node of a fibre's path (<see cref="MarkerThumb.Index"/> says which).</summary>
PartPoint,
+ /// <summary>The vertex of a lens surface (<see cref="MarkerThumb.Index"/> 1 or 2): moves along the axis and sets the surface's radius, the rim held (2026-10-26, Jeroen's proposal).</summary>
+ PartSurface,
/// <summary>The in-handle of a node of a fibre's path: the Bézier handle of the segment arriving there (<see cref="MarkerThumb.Index"/> says which node; 2026-10-22).</summary>
FiberIn,
/// <summary>The out-handle of a node of a fibre's path: the Bézier handle of the segment leaving there.</summary>
@@ -131,4 +134,14 @@ public sealed class MarkerThumb : Thumb
/// <summary>For the Bézier handle of a smooth node: the other handle's length when the drag or key press began, which it keeps while it turns (canvas pixels); null otherwise.</summary>
internal double? MirrorLength { get; set; }
+
+ /// <summary>Canvas points captured as a drag or a run of keyboard steps starts, which it holds still: a lens surface's rim and the other surface's vertex (2026-10-26); null for a handle without any. Forgotten when the focus leaves.</summary>
+ internal (double X, double Y)[]? DragAnchors { get; set; }
+
+ /// <inheritdoc/>
+ protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
+ {
+ base.OnLostKeyboardFocus(e);
+ DragAnchors = null;
+ }
}
diff --git a/WaveDudeNext.WPF/Controls/SceneOverlay.cs b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
index c71c199..2d3ab4c 100644
--- a/WaveDudeNext.WPF/Controls/SceneOverlay.cs
+++ b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
@@ -367,6 +367,12 @@ public sealed class SceneOverlay : Panel
{
AddThumb(part, MarkerRole.PartGrip, GripStyle, part.Name, "PartGrip:" + part.Name, "TipGripFormat");
}
+ if (part is LensPart)
+ {
+ // a handle on each surface's vertex, which sets its radius (2026-10-26, Jeroen's proposal)
+ AddThumb(part, MarkerRole.PartSurface, HandleStyle, part.Name, $"PartSurface:{part.Name}:1", "TipSurfaceFormat", 1);
+ AddThumb(part, MarkerRole.PartSurface, HandleStyle, part.Name, $"PartSurface:{part.Name}:2", "TipSurfaceFormat", 2);
+ }
if (PointsOf(part) is { } points)
{
// the list and its points: a point added, removed or moved rebuilds or re-arranges
@@ -588,8 +594,14 @@ public sealed class SceneOverlay : Panel
/// <summary>Whether a handle is shown for the current item alone: a rotation handle, a grip, a point, node or Bézier handle.</summary>
private static bool IsDetail(MarkerRole role) => role is MarkerRole.SourceAngle or MarkerRole.PartAngle || HasCanvasPosition(role);
- /// <summary>Whether a handle sits on a continuous canvas position of its own (<see cref="CanvasOf"/>): a grip, a point, node or Bézier handle.</summary>
- private static bool HasCanvasPosition(MarkerRole role) => role is MarkerRole.PartGrip or MarkerRole.PartPoint or MarkerRole.FiberIn or MarkerRole.FiberOut;
+ /// <summary>Whether a handle sits on a continuous canvas position of its own (<see cref="CanvasOf"/>): a grip, a point, node, Bézier handle or lens vertex.</summary>
+ private static bool HasCanvasPosition(MarkerRole role) => role is MarkerRole.PartGrip or MarkerRole.PartPoint or MarkerRole.PartSurface or MarkerRole.FiberIn or MarkerRole.FiberOut;
+
+ /// <summary>What a drag of a handle holds still (<see cref="MarkerThumb.DragAnchors"/>): a lens vertex's rim and the other vertex, in canvas pixels; null for the other handles.</summary>
+ private static (double X, double Y)[]? AnchorsOf(MarkerThumb thumb) =>
+ thumb is { Item: LensPart lens, Role: MarkerRole.PartSurface }
+ ? [lens.ToCanvas(lens.RimX(thumb.Index), 0.0), lens.ToCanvas(lens.VertexX(thumb.Index == 1 ? 2 : 1), 0.0)]
+ : null;
/// <summary>
/// Where a part's size grip sits in the part frame: the corner of a rectangle or an ellipse's box, lens (thickness, diameter), GRIN lens,
@@ -627,8 +639,8 @@ public sealed class SceneOverlay : Panel
ellipse.Width = Math.Max(1, ellipse.Linked ? Math.Max(along, across) : across);
break;
case LensPart lens:
- lens.Thickness = Math.Max(1, along);
- lens.Diameter = Math.Max(2, across);
+ // stretched like a rectangle: across the diameter, along the whole profile, the arcs refitted (2026-10-26)
+ lens.SetExtents(across, along);
break;
case PolygonPart polygon:
// the vertex stays on its ray; its distance is the circumradius
@@ -655,6 +667,7 @@ public sealed class SceneOverlay : Panel
private static (double X, double Y)? CanvasOf(MarkerThumb thumb) => (thumb.Item, thumb.Role) switch
{
(OpticalPart part, MarkerRole.PartGrip) when GripOf(part) is { } grip => part.ToCanvas(grip.X, grip.Y),
+ (LensPart lens, MarkerRole.PartSurface) => lens.ToCanvas(lens.VertexX(thumb.Index), 0.0),
(OpticalPart part, MarkerRole.PartPoint) when PointsOf(part) is { } points && thumb.Index >= 0 && thumb.Index < points.Count => part.ToCanvas(points[thumb.Index].X, points[thumb.Index].Y),
(FiberPart fiber, MarkerRole.PartPoint) when NodeOf(thumb) is { } node => fiber.ToCanvas(node.X, node.Y),
(FiberPart fiber, MarkerRole.FiberIn) when NodeOf(thumb) is { } node => fiber.ToCanvas(node.In.X, node.In.Y),
@@ -746,6 +759,18 @@ public sealed class SceneOverlay : Panel
case (OpticalPart part, MarkerRole.PartGrip):
SetGrip(part, x, y);
break;
+ case (LensPart lens, MarkerRole.PartSurface):
+ // along the axis: the mouse's place in the part frame, its x alone; the rim and the other vertex as the drag found them
+ (double axisX, _) = lens.ToFrame(x, y);
+ if (thumb.DragAnchors is [var rim, var other])
+ {
+ lens.SetVertex(thumb.Index, axisX, lens.ToFrame(rim.X, rim.Y).X, lens.ToFrame(other.X, other.Y).X);
+ }
+ else
+ {
+ lens.SetVertex(thumb.Index, axisX);
+ }
+ break;
case (FiberPart fiber, MarkerRole.PartPoint):
// a node moves with its handles, which are offsets from it
if (NodeOf(thumb) is { } moved)
@@ -1172,6 +1197,7 @@ public sealed class SceneOverlay : Panel
thumb.GrabOffsetX = mouseX - handle.X;
thumb.GrabOffsetY = mouseY - handle.Y;
thumb.MirrorLength = MirrorLengthOf(thumb);
+ thumb.DragAnchors = AnchorsOf(thumb);
}
if (MovesWhole(thumb.Role) && SelectedItems is { } set)
{
@@ -1328,6 +1354,9 @@ public sealed class SceneOverlay : Panel
return;
}
thumb.MirrorLength = MirrorLengthOf(thumb);
+ // held from the first step while the handle keeps the focus, as a drag holds them (recomputed each step, the
+ // position's rounding let the other surface creep)
+ thumb.DragAnchors ??= AnchorsOf(thumb);
(int x, int y) = PointOf(thumb);
SetPoint(thumb, x + dx, y + dy);
e.Handled = true;
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index 2cbaf73..61af08d 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -204,6 +204,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="TipMarkerFormat">{0}: zum Verschieben ziehen; mit Tastaturfokus bewegen die Pfeiltasten um ein Pixel, mit Umschalt um zehn</s:String>
<s:String x:Key="TipAngleMarkerFormat">{0}: zum Drehen des Rasters ziehen (Umschalt rastet auf 15 Grad ein); mit Tastaturfokus drehen die Pfeiltasten um ein Grad, mit Umschalt um zehn</s:String>
<s:String x:Key="TipGripFormat">{0}: zum Ändern der Größe ziehen; mit Tastaturfokus bewegen die Pfeiltasten den Griff um ein Pixel, mit Umschalt um zehn</s:String>
+ <s:String x:Key="TipSurfaceFormat">{0}, Fläche {1}: entlang der Achse ziehen, um sie zu wölben; nach außen wölbt, nach innen ebnet und höhlt; der Rand bleibt. Mit Tastaturfokus bewegen die Pfeiltasten sie um ein Pixel, mit Umschalt um zehn</s:String>
<s:String x:Key="TipPointFormat">{0}, Punkt {1}: zum Verschieben ziehen; mit Tastaturfokus bewegen die Pfeiltasten um ein Pixel, mit Umschalt um zehn</s:String>
<s:String x:Key="TipNodeFormat">{0}, Knoten {1}: zum Verschieben mit seinen Griffen ziehen; mit Tastaturfokus bewegen die Pfeiltasten um ein Pixel, mit Umschalt um zehn</s:String>
<s:String x:Key="TipInHandleFormat">{0}, Knoten {1}, Eingangsgriff: Ziehen formt das hier ankommende Segment; ein glatter Knoten dreht den Ausgangsgriff mit. Mit Tastaturfokus bewegen die Pfeiltasten um ein Pixel, mit Umschalt um zehn</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index a7e7428..fdaee38 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -206,6 +206,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="TipMarkerFormat">{0}: drag to move; with keyboard focus the arrow keys move it by a pixel, ten with Shift</s:String>
<s:String x:Key="TipAngleMarkerFormat">{0}: drag to turn the array (Shift snaps to 15 degrees); with keyboard focus the arrow keys turn it by a degree, ten with Shift</s:String>
<s:String x:Key="TipGripFormat">{0}: drag to resize; with keyboard focus the arrow keys move the grip by a pixel, ten with Shift</s:String>
+ <s:String x:Key="TipSurfaceFormat">{0}, surface {1}: drag along the axis to curve it, outward bulges, inward flattens and then hollows; the rim stays. With keyboard focus the arrow keys move it by a pixel, ten with Shift</s:String>
<s:String x:Key="TipPointFormat">{0}, point {1}: drag to move it; with keyboard focus the arrow keys move it by a pixel, ten with Shift</s:String>
<s:String x:Key="TipNodeFormat">{0}, node {1}: drag to move it with its handles; with keyboard focus the arrow keys move it by a pixel, ten with Shift</s:String>
<s:String x:Key="TipInHandleFormat">{0}, node {1}, in-handle: drag to shape the segment arriving here; a smooth node turns the out-handle with it. With keyboard focus the arrow keys move it by a pixel, ten with Shift</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index 3853847..e6a25cd 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -204,6 +204,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="TipMarkerFormat">{0} : glisser pour déplacer ; avec le focus clavier, les flèches déplacent d'un pixel, de dix avec Maj</s:String>
<s:String x:Key="TipAngleMarkerFormat">{0} : glisser pour tourner la grille (Maj aligne sur 15 degrés) ; avec le focus clavier, les flèches la tournent d'un degré, de dix avec Maj</s:String>
<s:String x:Key="TipGripFormat">{0} : glisser pour redimensionner ; avec le focus clavier, les flèches déplacent la poignée d'un pixel, de dix avec Maj</s:String>
+ <s:String x:Key="TipSurfaceFormat">{0}, surface {1} : glisser le long de l'axe pour la courber, vers l'extérieur elle bombe, vers l'intérieur elle s'aplatit puis se creuse ; le bord reste. Avec le focus clavier, les flèches la déplacent d'un pixel, de dix avec Maj</s:String>
<s:String x:Key="TipPointFormat">{0}, point {1} : glisser pour déplacer ; avec le focus clavier, les flèches déplacent d'un pixel, de dix avec Maj</s:String>
<s:String x:Key="TipNodeFormat">{0}, nœud {1} : glisser pour le déplacer avec ses poignées ; avec le focus clavier, les flèches le déplacent d'un pixel, de dix avec Maj</s:String>
<s:String x:Key="TipInHandleFormat">{0}, nœud {1}, poignée d'entrée : glisser pour former le segment qui arrive ici ; un nœud lisse entraîne la poignée de sortie. Avec le focus clavier, les flèches la déplacent d'un pixel, de dix avec Maj</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index 0a64755..0d33014 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -204,6 +204,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="TipMarkerFormat">{0}: slepen om te verplaatsen; met toetsenbordfocus verplaatsen de pijltoetsen één pixel, tien met Shift</s:String>
<s:String x:Key="TipAngleMarkerFormat">{0}: slepen om het raster te draaien (Shift klikt vast op 15 graden); met toetsenbordfocus draaien de pijltoetsen het één graad, tien met Shift</s:String>
<s:String x:Key="TipGripFormat">{0}: slepen om de grootte te wijzigen; met toetsenbordfocus verplaatsen de pijltoetsen de greep één pixel, tien met Shift</s:String>
+ <s:String x:Key="TipSurfaceFormat">{0}, oppervlak {1}: langs de as slepen om het te krommen, naar buiten bolt het, naar binnen wordt het vlak en dan hol; de rand blijft. Met toetsenbordfocus verplaatsen de pijltoetsen het één pixel, tien met Shift</s:String>
<s:String x:Key="TipPointFormat">{0}, punt {1}: slepen om te verplaatsen; met toetsenbordfocus verplaatsen de pijltoetsen één pixel, tien met Shift</s:String>
<s:String x:Key="TipNodeFormat">{0}, knooppunt {1}: slepen om het met zijn grepen te verplaatsen; met toetsenbordfocus verplaatsen de pijltoetsen één pixel, tien met Shift</s:String>
<s:String x:Key="TipInHandleFormat">{0}, knooppunt {1}, ingaande greep: slepen vormt het segment dat hier aankomt; een glad knooppunt draait de uitgaande greep mee. Met toetsenbordfocus verplaatsen de pijltoetsen één pixel, tien met Shift</s:String>
diff --git a/WaveDudeNext/Model/OpticalPart.cs b/WaveDudeNext/Model/OpticalPart.cs
index 3eea211..be7ffd5 100644
--- a/WaveDudeNext/Model/OpticalPart.cs
+++ b/WaveDudeNext/Model/OpticalPart.cs
@@ -507,7 +507,8 @@ public sealed class LensPart : OpticalPart
double sag2 = Sag(r2, half);
double convex = (r1 > 0.0 ? sag1 : 0.0) + (r2 < 0.0 ? sag2 : 0.0);
double budget = Math.Max(1, thickness) + (r1 < 0.0 ? sag1 : 0.0) + (r2 > 0.0 ? sag2 : 0.0);
- if (convex > budget)
+ // a hair over the budget (the floating point of a stretched lens's sags) is no case for a refit
+ if (convex > budget + 1e-9)
{
double scale = budget / convex;
if (r1 > 0.0)
@@ -525,6 +526,103 @@ public sealed class LensPart : OpticalPart
/// <summary>The radius whose sag at <paramref name="half"/> from the axis is <paramref name="sag"/>, (h² + s²) / 2s, rounded up to a whole pixel (a flatter surface still fits).</summary>
private static double RadiusForSag(double half, double sag) => Math.Ceiling((half * half + sag * sag) / (2.0 * sag));
+ /// <summary>
+ /// Sets the diameter and the centre thickness the size grip stands for by stretching the lens as a rectangle's or an
+ /// ellipse's grip stretches theirs (2026-10-26, Jeroen's report and the user's rule after it: a grip dragged a little inward
+ /// had the radii fitted flat and the lens was a rectangle; held sags made a stretched lens a slab): the diameter stretches
+ /// the lens across, the profile along the axis held; the thickness stretches the whole profile along the axis, the sags
+ /// and the edge with it, so a thinner lens is the same lens squashed and never a slab; pulled out diagonally the lens
+ /// scales as a whole, its shape kept. The surfaces are refitted as circles through the stretched rim and vertex (a sag
+ /// beyond the half diameter is a hemisphere's). Nothing stops the grip but a thickness of 1. Typed values are fitted as
+ /// before.
+ /// </summary>
+ /// <param name="diameter">The diameter asked for, in pixels.</param>
+ /// <param name="thickness">The centre thickness asked for, in pixels.</param>
+ public void SetExtents(int diameter, int thickness)
+ {
+ (double r1, double r2) = FitRadii(Diameter, Thickness, R1, R2);
+ double half = Math.Max(2, Diameter) / 2.0;
+ double grown = Math.Max(2, diameter) / 2.0;
+ double along = Math.Max(1, thickness) / (double)Math.Max(1, Thickness);
+ if (grown == half && along == 1.0)
+ {
+ return;
+ }
+ // the sags signed as the radii are: surface 1 convex is positive, surface 2 convex is negative
+ double sag1 = Math.Clamp(SurfaceSag(r1, half) * along, -grown, grown);
+ double sag2 = Math.Clamp(SurfaceSag(r2, half) * along, -grown, grown);
+ // the thicker value first, so no state in between has the radii fitted
+ if (thickness > Thickness)
+ {
+ Thickness = Math.Max(1, thickness);
+ }
+ Diameter = Math.Max(2, diameter);
+ R1 = RadiusOfSag(grown, sag1);
+ R2 = RadiusOfSag(grown, sag2);
+ Thickness = Math.Max(1, thickness);
+ }
+
+ /// <summary>The radius, signed as <paramref name="sag"/> is, whose surface has that sag at <paramref name="half"/> from the axis: the sagitta (h² + s²) / 2s; 0 for no sag.</summary>
+ private static double RadiusOfSag(double half, double sag) =>
+ sag == 0.0 ? 0.0 : Math.CopySign((half * half + sag * sag) / (2.0 * Math.Abs(sag)), sag);
+
+ /// <summary>Where the vertex of surface <paramref name="surface"/> (1 the left, 2 the right) sits on the axis in the part frame: ∓<see cref="Thickness"/> / 2.</summary>
+ public double VertexX(int surface) => (surface == 1 ? -1 : 1) * Math.Max(1, Thickness) / 2.0;
+
+ /// <summary>Where surface <paramref name="surface"/> meets the rim, on the axis in the part frame: its vertex plus its sag at the half diameter, the radii as fitted.</summary>
+ public double RimX(int surface)
+ {
+ (double r1, double r2) = FitRadii(Diameter, Thickness, R1, R2);
+ return VertexX(surface) + SurfaceSag(surface == 1 ? r1 : r2, Math.Max(2, Diameter) / 2.0);
+ }
+
+ /// <summary>
+ /// Moves the vertex of surface <paramref name="surface"/> to <paramref name="x"/> on the axis (part frame), the surface's
+ /// rim and the other surface held (2026-10-26, Jeroen's proposal, a handle on each vertex): the sag at the rim changes and
+ /// with it the radius; pulled outward the surface bulges, pushed through the rim plane it is flat (within half a pixel),
+ /// then concave, a hemisphere at most either way. The centre thickness follows, a whole pixel of at least 1, and the
+ /// part's position moves to the new centre, rounded to a pixel. <paramref name="rim"/> and <paramref name="other"/> are
+ /// where the rim and the other vertex are (a drag captures them as it starts, so the position's rounding never creeps
+ /// into them).
+ /// </summary>
+ public void SetVertex(int surface, double x, double rim, double other)
+ {
+ double half = Math.Max(2, Diameter) / 2.0;
+ int side = surface == 1 ? -1 : 1;
+ int thickness = Math.Max(1, (int)Math.Round(side * (x - other)));
+ x = other + side * thickness;
+ double sag = Math.Clamp(side * (x - rim), -half, half);
+ if (Math.Abs(sag) < 0.5)
+ {
+ sag = 0.0;
+ }
+ // the sagitta: surface 1 bulging left is R1 > 0, surface 2 bulging right is R2 < 0
+ double radius = RadiusOfSag(half, -side * sag);
+ bool thicker = thickness > Thickness;
+ if (thicker)
+ {
+ Thickness = thickness;
+ }
+ if (surface == 1)
+ {
+ R1 = radius;
+ }
+ else
+ {
+ R2 = radius;
+ }
+ if (!thicker)
+ {
+ Thickness = thickness;
+ }
+ (double cx, double cy) = ToCanvas((x + other) / 2.0, 0.0);
+ X = (int)Math.Round(cx);
+ Y = (int)Math.Round(cy);
+ }
+
+ /// <summary>Moves a vertex as <see cref="SetVertex(int, double, double, double)"/> does, the rim and the other vertex where they are now (a keyboard step).</summary>
+ public void SetVertex(int surface, double x) => SetVertex(surface, x, RimX(surface), VertexX(surface == 1 ? 2 : 1));
+
/// <summary>A radius of at least <paramref name="half"/> in magnitude, its sign kept; a non-finite or zero one is flat.</summary>
private static double GuardRadius(double radius, double half) =>
!double.IsFinite(radius) || radius == 0.0 ? 0.0 : Math.Abs(radius) < half ? Math.CopySign(half, radius) : radius;
diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.cs
index 86f2456..2218e6f 100644
--- a/_tools/library_check/Program.cs
+++ b/_tools/library_check/Program.cs
@@ -2518,6 +2518,36 @@ internal static class Program
lens.R2 = -300;
lens.Normalize();
Check(Math.Abs(lens.R1 - 25010) < 1e-9 && Math.Abs(lens.R2 + 25010) < 1e-9 && Math.Abs(lens.EdgeThickness) < 1e-9, "the user's case: a 2000 × 40 lens gets radii of 25010 and fills its diameter");
+ // the size grip stretches the lens (2026-10-26): across with the profile held, along with the whole profile scaled, so a
+ // diagonal pull scales the lens as a whole; nothing stops it
+ var gripped = new LensPart { Diameter = 100, Thickness = 20, R1 = 130, R2 = -130 };
+ gripped.SetExtents(400, 20);
+ Check(Math.Abs(gripped.R1 - 2005) < 1e-9 && Math.Abs(gripped.R2 + 2005) < 1e-9 && gripped.Diameter == 400 && gripped.Thickness == 20 && Math.Abs(gripped.EdgeThickness) < 1e-9,
+ $"dragged wider alone the sags of 10 stay and the radii follow the diameter ({gripped.R1}), the thickness and the edge as they were");
+ gripped = new LensPart { Diameter = 100, Thickness = 20, R1 = 130, R2 = -130 };
+ gripped.SetExtents(100, 60);
+ Check(Math.Abs(gripped.R1 - 3400.0 / 60.0) < 1e-9 && gripped.Thickness == 60 && gripped.Diameter == 100 && Math.Abs(gripped.EdgeThickness) < 1e-9,
+ $"dragged thicker alone the whole profile scales: sags of 30, R {gripped.R1}, the edge still zero");
+ gripped = new LensPart { Diameter = 100, Thickness = 20, R1 = 130, R2 = -130 };
+ gripped.SetExtents(200, 40);
+ Check(Math.Abs(gripped.R1 - 260) < 1e-9 && Math.Abs(gripped.R2 + 260) < 1e-9, $"pulled out diagonally the lens scales as a whole: the radii doubled to {gripped.R1}");
+ gripped.SetExtents(200, 4);
+ Check(gripped.Thickness == 4 && Math.Abs(gripped.R1 - (10000 + 4) / 4.0) < 1e-9 && Math.Abs(gripped.EdgeThickness) < 1e-9, $"squashed to 4 thick it is the same lens squashed, sags of 2, R {gripped.R1}, never a slab");
+ gripped.SetExtents(100, 400);
+ Check(gripped.R1 == 50 && gripped.R2 == -50 && gripped.Thickness == 400, "stretched thicker than its surfaces can take at that diameter, they are hemispheres on a slab");
+ // a surface handle: the vertex moves on the axis, the rim and the other surface stay; the position follows the centre
+ var shaped = new LensPart { X = 500, Y = 300, Diameter = 100, Thickness = 20, R1 = 0, R2 = 0 };
+ shaped.SetVertex(1, -30.0);
+ Check(Math.Abs(shaped.R1 - 72.5) < 1e-9 && shaped.R2 == 0 && shaped.Thickness == 40 && shaped.X == 490 && Math.Abs(shaped.ToCanvas(shaped.RimX(1), 0).X - 490) < 1e-9 && Math.Abs(shaped.ToCanvas(shaped.VertexX(2), 0).X - 510) < 1e-9,
+ $"the left vertex pulled 20 px out of a flat slab: R1 {shaped.R1} (the sagitta of 20 at 50), 40 thick, the centre at {shaped.X}, the rim and the other vertex where they were");
+ shaped.SetVertex(1, 0.0);
+ Check(shaped.R1 == 0 && shaped.Thickness == 20 && shaped.X == 500, "pushed back to the rim plane it is flat again, the slab as before");
+ shaped.SetVertex(1, 5.0);
+ Check(Math.Abs(shaped.R1 + 2725.0 / 30.0) < 1e-9 && shaped.Thickness == 5 && shaped.X == 508 && Math.Abs(shaped.EdgeThickness - 20) < 1e-9, $"pushed 15 px past the rim plane it is concave, R1 {shaped.R1} (the sagitta of 15), 5 thick at the centre, the edge still 20");
+ shaped.SetVertex(2, 1000.0);
+ Check(shaped.R2 == -50 && shaped.Thickness > 500, $"the right vertex pulled far out stops at a hemisphere, R2 {shaped.R2}");
+ shaped.SetVertex(2, -2000.0);
+ Check(shaped.Thickness == 1, "pushed through the other surface it stops a pixel short of it");
lens.Diameter = 100;
lens.Thickness = 40;
lens.R1 = 300;