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 new source, probe or part lands at the centre of the canvas the preview shows
Alexander Graef96c8a08bb0bc
diff --git a/CLAUDE.md b/CLAUDE.mdindex a7eb414..9714798 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -169,6 +169,9 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA- **Play means "show me the simulation"**: it starts an automatic run when needed and holds at the newest frameuntil the run catches up. Live follows a running run until the user scrubs; it ends with a last follow to thefinal frame. A replaced project goes to frame 0; a discarded run keeps the position. In/out points are steps.+- **A new source, probe or part lands at the centre of the canvas the preview shows** (2026-10-26, Jeroen's report: one+ at the corner went unnoticed inside the rim); the model's parameterless adders take the scene's size, the window passes+ the shown canvas's centre, which an image scene sizes; a new probe's line end lies 100 px to the right.- **Handles and overlays**: sources, probes, emitter dots and the rotation handle are drawn over the pictures incanvas pixels, over a dark halo, clipped to the picture; a probe's handles and line appear only on the picture ofthe layer it measures (2026-10-18), sources on both; graph boxes lie over every handle and dot, the selecteddiff --git a/WaveDudeNext.WPF/MainWindow.Project.cs b/WaveDudeNext.WPF/MainWindow.Project.csindex 0b1491f..1cddfb2 100644--- a/WaveDudeNext.WPF/MainWindow.Project.cs+++ b/WaveDudeNext.WPF/MainWindow.Project.cs@@ -109,7 +109,10 @@ public partial class MainWindow_ => null,};- private void OnAddSource(object sender, ExecutedRoutedEventArgs e) => Added(Project.AddSource());+ /// <summary>The centre of the canvas the preview shows (an image scene's own size), where a new source, probe or part lands (2026-10-26, Jeroen's report: one at the corner went unnoticed).</summary>+ private (int X, int Y) CanvasCentre => (previewPane.CanvasWidth / 2, previewPane.CanvasHeight / 2);++ private void OnAddSource(object sender, ExecutedRoutedEventArgs e) => Added(Project.AddSource(CanvasCentre.X, CanvasCentre.Y));/// <summary>/// Add part: with an <see cref="OpticalPart"/> subclass as parameter (the menu entries) the part is appended; without one (the@@ -120,7 +123,7 @@ public partial class MainWindow{if (e.Parameter is Type type){- Added(Project.AddPart(type));+ Added(Project.AddPart(type, CanvasCentre.X, CanvasCentre.Y));}else{@@ -139,7 +142,7 @@ public partial class MainWindow}}- private void OnAddProbe(object sender, ExecutedRoutedEventArgs e) => Added(Project.AddProbe());+ private void OnAddProbe(object sender, ExecutedRoutedEventArgs e) => Added(Project.AddProbe(CanvasCentre.X, CanvasCentre.Y));private void CanAdd(object sender, CanExecuteRoutedEventArgs e) =>e.CanExecute = Target(e.Parameter) is NamedCollection folder && ListOf(folder) != null;diff --git a/WaveDudeNext/Model/Project.cs b/WaveDudeNext/Model/Project.csindex 0100565..1d215ab 100644--- a/WaveDudeNext/Model/Project.cs+++ b/WaveDudeNext/Model/Project.cs@@ -331,9 +331,17 @@ public sealed class Project : ObservableObject}/// <summary>Appends a new source named "Source n" with the first free n, and returns it.</summary>- public Source AddSource()+ public Source AddSource() => AddSource(Scene.Width / 2, Scene.Height / 2);++ /// <summary>+ /// Appends a new source named "Source n" at canvas pixel (<paramref name="x"/>, <paramref name="y"/>), its emitters+ /// from the seed, and returns it. New objects land at the centre of the canvas (2026-10-26, Jeroen's report: a source at+ /// the corner went unnoticed, the more so inside the absorbing rim): <see cref="AddSource()"/> takes the scene's size,+ /// the application passes the centre of the canvas it shows, which an image scene sizes.+ /// </summary>+ public Source AddSource(int x, int y){- var source = new Source { Name = NumberedName("Source", Sources.Select(s => s.Name)) };+ var source = new Source { Name = NumberedName("Source", Sources.Select(s => s.Name)), X = x, Y = y };source.GenerateElements(Seed);Sources.Add(source);return source;@@ -342,10 +350,13 @@ public sealed class Project : ObservableObject/// <summary>/// Appends a new part of the concrete <see cref="OpticalPart"/> subclass <paramref name="type"/> (the "+ Part" menu's/// parameter), prepared as new (<see cref="OpticalPart.PrepareNew"/>), named by its <see cref="OpticalPart.NameStem"/>- /// with the first free n ("Lens 1", "Bragg reflector 2"), centred on the canvas (the scene's size; an image scene's own- /// size is not known here), and returns it.+ /// with the first free n ("Lens 1", "Bragg reflector 2"), centred on the scene's size (see <see cref="AddSource()"/>),+ /// and returns it./// </summary>- public OpticalPart AddPart(Type type)+ public OpticalPart AddPart(Type type) => AddPart(type, Scene.Width / 2, Scene.Height / 2);++ /// <summary>Appends a new part as <see cref="AddPart(Type)"/> does, centred on canvas pixel (<paramref name="x"/>, <paramref name="y"/>).</summary>+ public OpticalPart AddPart(Type type, int x, int y){if (!type.IsSubclassOf(typeof(OpticalPart)) || type.IsAbstract){@@ -354,8 +365,8 @@ public sealed class Project : ObservableObjectvar part = (OpticalPart)Activator.CreateInstance(type)!;part.PrepareNew();part.Name = NumberedName(part.NameStem, Parts.Select(p => p.Name));- part.X = Scene.Width / 2;- part.Y = Scene.Height / 2;+ part.X = x;+ part.Y = y;Parts.Add(part);return part;}@@ -364,9 +375,15 @@ public sealed class Project : ObservableObjectpublic T AddPart<T>() where T : OpticalPart, new() => (T)AddPart(typeof(T));/// <summary>Appends a new probe named "Probe n" with the first free n, and returns it.</summary>- public Probe AddProbe()+ public Probe AddProbe() => AddProbe(Scene.Width / 2, Scene.Height / 2);++ /// <summary>+ /// Appends a new probe named "Probe n" with its point at canvas pixel (<paramref name="x"/>, <paramref name="y"/>) and the+ /// end of its line, should it become one, 100 pixels to the right (see <see cref="AddSource(int, int)"/>), and returns it.+ /// </summary>+ public Probe AddProbe(int x, int y){- var probe = new Probe { Name = NumberedName("Probe", Probes.Select(p => p.Name)) };+ var probe = new Probe { Name = NumberedName("Probe", Probes.Select(p => p.Name)), AX = x, AY = y, BX = x + 100, BY = y };Probes.Add(probe);return probe;}diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.csindex d3d53f8..86f2456 100644--- a/_tools/library_check/Program.cs+++ b/_tools/library_check/Program.cs@@ -2835,6 +2835,12 @@ internal static class ProgramType[] partTypes = [.. typeof(OpticalPart).Assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(OpticalPart)) && !type.IsAbstract)];HashSet<Type?> elements = [.. typeof(Project).GetProperty(nameof(Project.Parts))!.GetCustomAttributes<XmlElementAttribute>().Select(element => element.Type)];var adder = new Project();+ var placed = new Project();+ placed.Scene.Width = 400;+ placed.Scene.Height = 300;+ Check(placed.AddSource() is { X: 200, Y: 150 } && placed.AddProbe() is { AX: 200, AY: 150, BX: 300, BY: 150 } && placed.AddPart<LensPart>() is { X: 200, Y: 150 }+ && placed.AddSource(10, 20) is { X: 10, Y: 20, Elements: [{ X: 10, Y: 20 }] } && placed.AddProbe(30, 40) is { AX: 30, AY: 40 } && placed.AddPart(typeof(LensPart), 50, 60) is { X: 50, Y: 60 },+ "a new source, probe or part lands at the scene's centre, or where the application puts it (the canvas it shows); the source's emitter with it");Check(partTypes.Length > 0 && partTypes.All(type => elements.Contains(type) && adder.AddPart(type) is { } added && added.GetType() == type && added.Name == added.NameStem + " 1"),$"each of the {partTypes.Length} part classes has its file element and is added by its type as '<stem> 1'");Check(xml.Contains("<Node X=\"-100\" Y=\"0\" OutX=\"67\" />") && xml.Contains("<Node X=\"100\" Y=\"0\" InX=\"-67\" />"), "a fibre's nodes are sparse Node children: handles only where set, Smooth only when off");