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#

The scene overlay draws nothing outside the picture

Alexander Graef2f565c93e835
diff --git a/CLAUDE.md b/CLAUDE.md
index d782850..39b9b52 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -337,7 +337,9 @@ WPF shell as it stands:
of an edited array). The author's format has no rotation; the importer leaves it 0. On the pictures a
composite source carries a **rotation handle** (`MarkerThumb` role `SourceAngle`, id `SourceAngle:<name>`,
the `AngleMarker` style: a bent arrow) on its row axis just beyond the first row (at least 28 px from the
- centre), joined to the centre by a dotted lever line, both shown only while the source is selected (the
+ centre; **clipped to the picture** since 2026-10-16, so a wide array at the border does not put it over the other
+ picture or the menu: it stays on the row axis and what falls outside is cut, `thumb.Clip` set in the arrange
+ pass; a version that pulled it inside and bent the lever was rejected the same day as making no sense), joined to the centre by a dotted lever line, both shown only while the source is selected (the
user's rule; collapsed, the handle is out of the Tab cycle until the source is selected through its
handle or the tree): dragging turns the array to follow the mouse (whole
degrees, Shift snaps to 15), the arrow keys turn it by a degree (ten with Shift), focusing it selects the
@@ -615,7 +617,12 @@ WPF shell as it stands:
four crosshair ticks outside and a gap around the exact pixel; a line probe gets two handles and
a dashed line, a composite source its emitter dots, every item its name). Every stroke, dot, line
and label is drawn over a dark halo first (`HaloThickness`), so the handles read on any picture
- and colour scheme (agreed 2026-10-09 after thin white rings vanished on the intensity picture).
+ and colour scheme (agreed 2026-10-09 after thin white rings vanished on the intensity picture). **What the
+ overlay draws itself is clipped to the picture** (2026-10-16, after a rotated array dragged to the top border
+ put its emitter dots over the menu bar): the dots, the line probes' lines and the rotation lever go through a
+ clip on `SceneOverlay.PictureRect`, the canvas at its uniform scale centred in the element, since the element
+ fills the cell and the picture is letterboxed in it; the handles sit on clamped positions and the labels are
+ kept inside by their placement, so neither needs it.
Dragging writes `Source.X/Y`, `Probe.AX/AY/BX/BY` in canvas pixels; the arrow keys move the
focused handle by one pixel (ten with Shift); grabbing or focusing a handle selects the item
(`PreviewPane.SelectedItem` ↔ `MainWindow.SelectedItem` ↔ the Project tree, both ways); a left click on
diff --git a/WaveDudeNext.WPF/Controls/SceneOverlay.cs b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
index 94108a3..bca8306 100644
--- a/WaveDudeNext.WPF/Controls/SceneOverlay.cs
+++ b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
@@ -347,6 +347,14 @@ public sealed class SceneOverlay : Panel
/// <summary>The centre of canvas pixel (x, y) in this element's coordinates at its current size.</summary>
private Point ToView(int x, int y) => ToView(x, y, RenderSize);
+ /// <summary>The picture's rectangle in this element's coordinates for an element of <paramref name="size"/>: the canvas at its uniform scale, centred (the element fills the cell, the picture is letterboxed in it).</summary>
+ private Rect PictureRect(Size size)
+ {
+ double scale = ScaleFor(size);
+ double width = CanvasWidth * scale, height = CanvasHeight * scale;
+ return new Rect((size.Width - width) / 2, (size.Height - height) / 2, width, height);
+ }
+
/// <summary>
/// Where the rotation handle of a composite source sits, for an element of <paramref name="size"/>: on the
/// array's row axis, turned by its angle (counter-clockwise on the screen), just beyond the first row's
@@ -434,12 +442,22 @@ public sealed class SceneOverlay : Panel
/// <inheritdoc/>
protected override Size ArrangeOverride(Size finalSize)
{
+ Rect picture = PictureRect(finalSize);
foreach (MarkerThumb thumb in Children)
{
(int x, int y) = PointOf(thumb);
Point centre = thumb.Role == MarkerRole.SourceAngle ? AnglePoint((Source)thumb.Item, finalSize) : ToView(x, y, finalSize);
Size size = thumb.DesiredSize;
- thumb.Arrange(new Rect(centre.X - size.Width / 2, centre.Y - size.Height / 2, size.Width, size.Height));
+ var rect = new Rect(centre.X - size.Width / 2, centre.Y - size.Height / 2, size.Width, size.Height);
+ thumb.Arrange(rect);
+ if (thumb.Role == MarkerRole.SourceAngle)
+ {
+ // the rotation handle stays on the row axis, however far out; what falls outside the picture is clipped
+ // (2026-10-16, the user's rule: the lever bending to keep the handle inside made no sense). The other
+ // handles sit on clamped canvas positions and show whole at the edge
+ Rect visible = Rect.Intersect(picture, rect);
+ thumb.Clip = visible == rect ? null : new RectangleGeometry(new Rect(visible.X - rect.X, visible.Y - rect.Y, Math.Max(0, visible.Width), Math.Max(0, visible.Height)));
+ }
}
return finalSize;
}
@@ -453,6 +471,11 @@ public sealed class SceneOverlay : Panel
return;
}
object? selected = SelectedItem;
+ // lines and dots stay within the picture (2026-10-16, after a rotated array dragged to the border put its
+ // emitter dots over the menu bar): an emitter or a line end outside the canvas is clipped here, the handles
+ // are children and sit on clamped positions, and the labels below are kept inside by their placement. The
+ // picture's rectangle, not this element's: the element fills the cell and the picture is letterboxed in it
+ dc.PushClip(new RectangleGeometry(PictureRect(RenderSize)));
foreach (Probe probe in project.Probes)
{
if (probe.Kind != ProbeKind.Line)
@@ -487,6 +510,7 @@ public sealed class SceneOverlay : Panel
dc.DrawEllipse(dots, halo, ToView(element.X, element.Y), ElementDotRadius, ElementDotRadius);
}
}
+ dc.Pop();
foreach (MarkerThumb thumb in Children)
{
if (thumb.Role is MarkerRole.ProbeB or MarkerRole.SourceAngle)