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#

Optical logic gates (XOR, AND, OR) and a zone plate as optical parts

Jeroen Vleggaard11ece30dad1
diff --git a/CLAUDE.md b/CLAUDE.md
index aaf393a..72f186a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -190,6 +190,39 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
Enter), a handle plus a rotation lever on the pictures; while selected, the outline as painted in the accent colour,
a size grip on a corner or vertex (rectangle, lens, polygon, triangle, GRIN, Bragg) and a handle per point of an outline
or fibre (2026-10-19); the shape shows through the glowing outline otherwise.
+- **Optical logic** (2026-10-21/22, "+ Part" > Optical logic): `LogicGatePart` with `XorGatePart`, `AndGatePart`,
+ `OrGatePart` (elements `XorGate`, `AndGate`, `OrGate`), one 2 × 2 directional coupler whose phase shift of B over A
+ alone makes the kind: +90° upper a − b (XOR), −90° upper a + b (AND, 4 : 1 at best, a passive linear gate has no truer
+ AND), +30° upper at 120° (OR: ½, ½, ½); the phase section sits in a quarter-period stretch in all three, so they share
+ dimensions and ports (measured 120 × 544 px: XOR 0.01, AND 1.88 against 0.50, OR 0.49 against 0.55). Laid out by
+ `LogicGateDesign` from the design frequency with `WaveguideModes`, a mode solver on the
+ engine's own discrete equations (4th-order stencil, its β matches a simulated guide to 1e-5); smooth S-bends whose radius
+ follows the mode's confinement, a measured coupling excess of 0.07 rad taken off, the cladding's rim and the input ends
+ absorb (`PartShape.AbsorptionShareAt`). The user's choices of 2026-10-22: the design is entered as a source frequency
+ (`DesignFrequency`, default 50; the wavelength is shown, from `Simulation.SourceFrequencyScale`, which the follower hands
+ each gate as `FrequencyScale`); both ends carry an AR band like a lens's (`Coating`, √n of core and cladding, default 6 px,
+ the measured least reflection, 3.4 % against 24 % bare), which replaced an output taper, switchable per end
+ (`InputCoated`, `OutputCoated`, default on; 2026-10-22, the user found a band in a junction keeps the wave from passing
+ from one unit into the next); each output can be switched off
+ (`XorOutputActive`, `SumOutputActive`), an absorber rising over 2 λ in its arm's last stretch (0.03 % reflected, nothing
+ out). The unit is twice the port spacing wide, ports at ¼ and ¾ (the user's request, 2026-10-22, for staggered tiling):
+ the side absorber fills out to there, at least λ/2 (none let 7.6 % through to the XOR output). Defaults core 2.55 in
+ 1.45, the phase section then lowered on arm A: spacing 60, 120 × 544 px, both inputs leave about 1 % at the XOR output,
+ sum 1.9× (the user found 1600 px unacceptable). Both ends are open (2026-10-22, the user's choice: the input termination
+ is gone, sources are to be coupled in from outside by a fibre later), so staggered gates cascade; a source placed in the
+ unit sits half a wavelength in, and its backward wave leaves through the coated input end. The port spacing is raised to the design's minimum; the form's box edits
+ `PortSpacingUsed`, so it shows the spacing used and every step moves the ports. Inputs are ordinary sources on the ports
+ the form lists; `GatePortFollower` (the window keeps one per project) moves a source within 1 px of an input onto the
+ input's new position after any gate edit, and `Movable.MoveAll` moves parts last so a group move does not move it twice.
+- **Zone plate** (2026-10-22, a main part beside the lens, element `ZonePlate`): `ZonePlatePart`, Fresnel zones at
+ rₙ = √(nλf + (nλ/2)²) from a target frequency (`IFrequencyDesigned`, the follower hands it the frequency scale) and focal
+ length, every second zone an absorbing block (the user's choice over mirror or phase blocks; blue only, `PaintsIndex`
+ false), `Inverse` exchanging them; blocks 96 rising over the AR depth from the faces, sharp at the sides (measured: 0.4 %
+ through, 1.0 % back at 64 px thick with a 32 px rise). In 2D a zone plate is cylindrical: the central zone dominates
+ (Cornu spiral), so the inverse plate focuses weakly (about 1 × the free wave); the default plate (800, f 600, 8 zones)
+ 4.6 ×. Light passing outside the diameter pushes the focus on (5 zones +30 %, 8 zones +3 %); the optional absorbing
+ `Mount` (`MountWidth` either side, default off and 200 px, the user's request) stops it (5 zones: +12 % in the check's
+ small canvas, +6 % in a wide one).
- File types `.wdproj` / `.wdscheme` are registered per user at start-up; unsaved edits ask on close.
## Numbers (workstation: 10-core Xeon without AVX2, RTX 2080, 64 GB)
@@ -205,7 +238,7 @@ numbers: no GPU JPEG, no OpenCL colouring at presentation, no `Vector256`, no Di
## Harnesses
-`library_check` (100+ checks: engines, store, renderer, schemes, probes, scratch, reduced preview, importer, export, parts, group move, open edges).
+`library_check` (100+ checks: engines, store, renderer, schemes, probes, scratch, reduced preview, importer, export, parts, group move, open edges, XOR gate).
UI, all on `Common.ps1`, with their check counts: `PreviewCheck` 43, `RunCheck` 71, `LanguageCheck` 11,
`ProbeGraphCheck` 39, `ImportCheck` 10, `ExportCheck` 38, `PreviewQualityCheck` 35, `SceneImageCheck` 8,
`ColorPickerCheck` 13, `KeyboardCheck` 13, `AboutCheck` 18, `SelectionCheck` 10. Test projects `tiny*.wdproj` sit beside them. A harness
diff --git a/WaveDudeNext.WPF/Controls/SceneOverlay.cs b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
index 33c01c2..542d38b 100644
--- a/WaveDudeNext.WPF/Controls/SceneOverlay.cs
+++ b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
@@ -531,8 +531,8 @@ public sealed class SceneOverlay : Panel
};
/// <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
- /// or Bragg stack, the first vertex of a polygon, the second end of a triangle's base; null for a kind without one.
+ /// 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,
+ /// Bragg stack or zone plate, the first vertex of a polygon, the second end of a triangle's base; null for a kind without one.
/// </summary>
private static (double X, double Y)? GripOf(OpticalPart part) => part switch
{
@@ -543,6 +543,7 @@ public sealed class SceneOverlay : Panel
TrianglePart triangle => triangle.Vertices()[1],
GrinLensPart grin => (grin.Length / 2.0, grin.Diameter / 2.0),
BraggReflectorPart bragg => (bragg.Length / 2.0, bragg.Width / 2.0),
+ ZonePlatePart plate => (plate.Thickness / 2.0, plate.Diameter / 2.0),
_ => null,
};
@@ -582,6 +583,10 @@ public sealed class SceneOverlay : Panel
case BraggReflectorPart bragg:
bragg.Width = Math.Max(2, across);
break;
+ case ZonePlatePart plate:
+ plate.Thickness = Math.Max(1, along);
+ plate.Diameter = Math.Max(2, across);
+ break;
}
}
diff --git a/WaveDudeNext.WPF/Converters/LogicGateLayoutConverter.cs b/WaveDudeNext.WPF/Converters/LogicGateLayoutConverter.cs
new file mode 100644
index 0000000..11ded38
--- /dev/null
+++ b/WaveDudeNext.WPF/Converters/LogicGateLayoutConverter.cs
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using System.Globalization;
+using System.Windows.Data;
+using WaveDudeNext.Model;
+using WaveDudeNext.Parts;
+
+namespace WaveDudeNext.WPF.Converters;
+
+/// <summary>
+/// One read-only value of a <see cref="LogicGatePart"/>'s layout as text: the first value is the gate, the others are its
+/// position, angle and design inputs, bound only so the text follows them. The parameter picks the value: "Wavelength"
+/// ("≈ 32.1 px", the design frequency's) and "QuarterWave" (the core's quarter-wave coating), "CoreWidth", "Gap",
+/// "CouplerLength" and "Length" give pixels ("8 px"), "InputA", "InputB", "OutputUpper" and "OutputLower" a port's canvas
+/// pixel ("(131, 103)"). "–" without a design (a core index not above the cladding's).
+/// </summary>
+public sealed class LogicGateLayoutConverter : IMultiValueConverter
+{
+ public object Convert(object?[] values, Type targetType, object? parameter, CultureInfo culture)
+ {
+ if (values.Length < 1 || values[0] is not LogicGatePart gate)
+ {
+ return "–";
+ }
+ if (parameter as string == "Wavelength")
+ {
+ return double.IsFinite(gate.Wavelength) && gate.Wavelength > 0.0 ? string.Format(culture, "≈ {0:0.0} px", gate.Wavelength) : "–";
+ }
+ if (gate.Design is not LogicGateDesign design || gate.Ports() is not { } ports)
+ {
+ return "–";
+ }
+ string Pixels(int value) => string.Format(culture, "{0} px", value);
+ string Port((int X, int Y) port) => string.Format(culture, "({0}, {1})", port.X, port.Y);
+ return (parameter as string) switch
+ {
+ "QuarterWave" => string.Format(culture, "≈ {0:0.0} px", design.QuarterWaveCoating),
+ "CoreWidth" => Pixels(design.CoreWidth),
+ "Gap" => Pixels(design.Gap),
+ "CouplerLength" => Pixels(design.CouplerLength),
+ "Length" => Pixels(design.Length),
+ "InputA" => Port(ports[0]),
+ "InputB" => Port(ports[1]),
+ "OutputUpper" => Port(ports[2]),
+ "OutputLower" => Port(ports[3]),
+ _ => "–",
+ };
+ }
+
+ public object[] ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture) =>
+ throw new NotSupportedException();
+}
diff --git a/WaveDudeNext.WPF/Converters/ZonePlateConverter.cs b/WaveDudeNext.WPF/Converters/ZonePlateConverter.cs
new file mode 100644
index 0000000..cb0ae2d
--- /dev/null
+++ b/WaveDudeNext.WPF/Converters/ZonePlateConverter.cs
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using System.Globalization;
+using System.Windows.Data;
+using WaveDudeNext.Model;
+
+namespace WaveDudeNext.WPF.Converters;
+
+/// <summary>
+/// One read-only value of a <see cref="ZonePlatePart"/> as text: the first value is the plate, the others the inputs the
+/// value depends on, bound only so the text follows them. The parameter picks it: "Wavelength" ("≈ 32.0 px"), "Zones"
+/// (the zone count, "8") or "OuterZone" (the outermost whole zone's width, "≈ 30.6 px"); "–" without a wavelength.
+/// </summary>
+public sealed class ZonePlateConverter : IMultiValueConverter
+{
+ public object Convert(object?[] values, Type targetType, object? parameter, CultureInfo culture)
+ {
+ if (values.Length < 1 || values[0] is not ZonePlatePart plate || !double.IsFinite(plate.Wavelength) || plate.Wavelength <= 0.0)
+ {
+ return "–";
+ }
+ return (parameter as string) switch
+ {
+ "Wavelength" => string.Format(culture, "≈ {0:0.0} px", plate.Wavelength),
+ "Zones" => plate.ZoneCount.ToString(culture),
+ "OuterZone" => string.Format(culture, "≈ {0:0.0} px", plate.OuterZoneWidth),
+ _ => "–",
+ };
+ }
+
+ public object[] ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture) =>
+ throw new NotSupportedException();
+}
diff --git a/WaveDudeNext.WPF/MainWindow.Live.cs b/WaveDudeNext.WPF/MainWindow.Live.cs
index 25265ad..33942f7 100644
--- a/WaveDudeNext.WPF/MainWindow.Live.cs
+++ b/WaveDudeNext.WPF/MainWindow.Live.cs
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
+// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Alexander Graef <[email protected]>
//
// This file is part of WaveDude Next, a 2D wave simulator.
@@ -71,6 +71,8 @@ public partial class MainWindow
nameof(IsPreviewPlaying), typeof(bool), typeof(MainWindow), new PropertyMetadata(false, (d, _) => ((MainWindow)d).OnPreviewPlayingChanged()));
private ProjectWatcher? _watcher;
+ /// <summary>Keeps the sources on a logic gate's inputs there when the gate is edited.</summary>
+ private GatePortFollower? _follower;
private ScratchRunner? _scratch;
private SimulationRun? _pausedForScratch;
private DispatcherTimer? _scratchTimer;
@@ -140,6 +142,8 @@ public partial class MainWindow
SelectedItems.Clear();
_watcher?.Dispose();
_watcher = null;
+ _follower?.Dispose();
+ _follower = null;
_imageCache = null;
_embeddedCache = null;
_composedCache = null;
@@ -157,6 +161,7 @@ public partial class MainWindow
{
_watcher = new ProjectWatcher(project);
_watcher.Changed += OnProjectChanged;
+ _follower = new GatePortFollower(project);
// warm up: the first scratch frame builds the engine (an OpenCL compile), better now than on the first click
ScheduleScratch();
}
@@ -548,5 +553,7 @@ public partial class MainWindow
_scratch = null;
_watcher?.Dispose();
_watcher = null;
+ _follower?.Dispose();
+ _follower = null;
}
}
diff --git a/WaveDudeNext.WPF/Panes/ProjectTree.xaml b/WaveDudeNext.WPF/Panes/ProjectTree.xaml
index 803c55c..34d49ab 100644
--- a/WaveDudeNext.WPF/Panes/ProjectTree.xaml
+++ b/WaveDudeNext.WPF/Panes/ProjectTree.xaml
@@ -1,4 +1,4 @@
-<!--
+<!--
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2026 Alexander Graef <[email protected]>
@@ -94,12 +94,20 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<MenuItem Header="{DynamicResource MenuAddFiber}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Fiber}" AutomationProperties.AutomationId="AddPart:Fiber" />
<MenuItem Header="{DynamicResource MenuAddBraggReflector}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.BraggReflector}" AutomationProperties.AutomationId="AddPart:BraggReflector" />
<MenuItem Header="{DynamicResource MenuAddGrinLens}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.GrinLens}" AutomationProperties.AutomationId="AddPart:GrinLens" />
+ <MenuItem Header="{DynamicResource MenuAddZonePlate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.ZonePlate}" AutomationProperties.AutomationId="AddPart:ZonePlate" />
<Separator />
<MenuItem Header="{DynamicResource MenuAddPolygon}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Polygon}" AutomationProperties.AutomationId="AddPart:Polygon" />
<MenuItem Header="{DynamicResource MenuAddRectangle}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Rectangle}" AutomationProperties.AutomationId="AddPart:Rectangle" />
<MenuItem Header="{DynamicResource MenuAddEllipse}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Ellipse}" AutomationProperties.AutomationId="AddPart:Ellipse" />
<MenuItem Header="{DynamicResource MenuAddTriangle}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Triangle}" AutomationProperties.AutomationId="AddPart:Triangle" />
<MenuItem Header="{DynamicResource MenuAddOutline}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Outline}" AutomationProperties.AutomationId="AddPart:Outline" />
+ <Separator />
+ <!-- optical logic: one entry per gate (2026-10-21 and 22, the user's requests: XOR, then AND and OR) -->
+ <MenuItem Header="{DynamicResource MenuAddOpticalLogic}" AutomationProperties.AutomationId="AddPart:OpticalLogic">
+ <MenuItem Header="{DynamicResource MenuAddXorGate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.XorGate}" AutomationProperties.AutomationId="AddPart:XorGate" />
+ <MenuItem Header="{DynamicResource MenuAddAndGate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.AndGate}" AutomationProperties.AutomationId="AddPart:AndGate" />
+ <MenuItem Header="{DynamicResource MenuAddOrGate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.OrGate}" AutomationProperties.AutomationId="AddPart:OrGate" />
+ </MenuItem>
</ContextMenu>
</UserControl.Resources>
@@ -167,12 +175,19 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<MenuItem Header="{DynamicResource MenuAddFiber}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Fiber}" />
<MenuItem Header="{DynamicResource MenuAddBraggReflector}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.BraggReflector}" />
<MenuItem Header="{DynamicResource MenuAddGrinLens}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.GrinLens}" />
+ <MenuItem Header="{DynamicResource MenuAddZonePlate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.ZonePlate}" />
<Separator />
<MenuItem Header="{DynamicResource MenuAddPolygon}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Polygon}" />
<MenuItem Header="{DynamicResource MenuAddRectangle}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Rectangle}" />
<MenuItem Header="{DynamicResource MenuAddEllipse}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Ellipse}" />
<MenuItem Header="{DynamicResource MenuAddTriangle}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Triangle}" />
<MenuItem Header="{DynamicResource MenuAddOutline}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.Outline}" />
+ <Separator />
+ <MenuItem Header="{DynamicResource MenuAddOpticalLogic}">
+ <MenuItem Header="{DynamicResource MenuAddXorGate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.XorGate}" />
+ <MenuItem Header="{DynamicResource MenuAddAndGate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.AndGate}" />
+ <MenuItem Header="{DynamicResource MenuAddOrGate}" Command="{x:Static commands:ProjectCommands.AddPart}" CommandParameter="{x:Static model:PartKind.OrGate}" />
+ </MenuItem>
</MenuItem>
<MenuItem Header="{DynamicResource MenuProjectAddProbe}" Command="{x:Static commands:ProjectCommands.AddProbe}" />
<Separator />
diff --git a/WaveDudeNext.WPF/Panes/PropertiesPane.xaml b/WaveDudeNext.WPF/Panes/PropertiesPane.xaml
index 8865557..2418e78 100644
--- a/WaveDudeNext.WPF/Panes/PropertiesPane.xaml
+++ b/WaveDudeNext.WPF/Panes/PropertiesPane.xaml
@@ -70,6 +70,18 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<DataTemplate DataType="{x:Type model:GrinLensPart}">
<views:GrinLensPartView />
</DataTemplate>
+ <DataTemplate DataType="{x:Type model:ZonePlatePart}">
+ <views:ZonePlatePartView />
+ </DataTemplate>
+ <DataTemplate DataType="{x:Type model:XorGatePart}">
+ <views:LogicGatePartView />
+ </DataTemplate>
+ <DataTemplate DataType="{x:Type model:AndGatePart}">
+ <views:LogicGatePartView />
+ </DataTemplate>
+ <DataTemplate DataType="{x:Type model:OrGatePart}">
+ <views:LogicGatePartView />
+ </DataTemplate>
<DataTemplate DataType="{x:Type model:Probe}">
<views:ProbeView />
</DataTemplate>
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index 927de06..f42e6ed 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -1,4 +1,4 @@
-<!--
+<!--
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2026 Alexander Graef <[email protected]>
@@ -123,6 +123,11 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddFiber">_Faser</s:String>
<s:String x:Key="MenuAddBraggReflector">_Bragg-Reflektor</s:String>
<s:String x:Key="MenuAddGrinLens">_GRIN-Linse</s:String>
+ <s:String x:Key="MenuAddZonePlate">_Zonenplatte</s:String>
+ <s:String x:Key="MenuAddOpticalLogic">_Optische Logik</s:String>
+ <s:String x:Key="MenuAddXorGate">_XOR (Mach-Zehnder)</s:String>
+ <s:String x:Key="MenuAddAndGate">_AND</s:String>
+ <s:String x:Key="MenuAddOrGate">_OR</s:String>
<s:String x:Key="MenuProjectToggleEnabled">_Aktiv</s:String>
<s:String x:Key="MenuProjectDuplicate">_Duplizieren</s:String>
<s:String x:Key="MenuProjectRemove">_Entfernen</s:String>
@@ -266,6 +271,25 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="SectionCore">Kern</s:String>
<s:String x:Key="SectionCladding">Mantel</s:String>
<s:String x:Key="SectionLayers">Schichten</s:String>
+ <s:String x:Key="SectionDesign">Entwurf</s:String>
+ <s:String x:Key="SectionLayout">Aufbau</s:String>
+ <s:String x:Key="SectionPorts">Anschlüsse</s:String>
+ <s:String x:Key="SectionOutputs">Aktive Ausgänge</s:String>
+ <s:String x:Key="TipGateWavelength">Die Wellenlänge, die die Entwurfsfrequenz in einem Medium mit Index 1 ergibt, bei der Quellfrequenzskala der Simulation</s:String>
+ <s:String x:Key="LabelQuarterWave">Viertelwellen-Schicht</s:String>
+ <s:String x:Key="TipQuarterWave">Die Dicke der am wenigsten reflektierenden Schicht auf dem Kern, λ / (4 √n)</s:String>
+ <s:String x:Key="LabelCoreWidth">Kernbreite</s:String>
+ <s:String x:Key="LabelCouplerGap">Koppelspalt</s:String>
+ <s:String x:Key="LabelCouplerLength">Koppellänge</s:String>
+ <s:String x:Key="LabelGateLength">Gesamtlänge</s:String>
+ <s:String x:Key="TipGateLayout">Aus der Entwurfswellenlänge und den Indizes mit der eigenen Wellengleichung des Simulators berechnet (dem Laplace-Operator 4. Ordnung)</s:String>
+ <s:String x:Key="LabelInputA">Eingang A</s:String>
+ <s:String x:Key="LabelInputB">Eingang B</s:String>
+ <s:String x:Key="TipGatePorts">Canvas-Pixel. Die Eingänge mit gleichen Wellen speisen (gleiche Frequenz, Amplitude und Phase); eine fehlende Welle ist eine logische 0. Die Ausgänge liegen auf den Eingängen von Gattern, die einen Anschlussabstand höher und tiefer eine Länge weiter stehen</s:String>
+ <s:String x:Key="SectionZones">Zonen</s:String>
+ <s:String x:Key="LabelZoneCount">Anzahl der Zonen</s:String>
+ <s:String x:Key="LabelOuterZone">Äußerste Zone</s:String>
+ <s:String x:Key="TipZones">Die Zonen, die die Platte innerhalb ihres Durchmessers bekommt, und die Breite der äußersten ganzen Zone, die das Gitter auflösen muss (mindestens einige Pixel)</s:String>
<s:String x:Key="SectionPoints">Punkte</s:String>
<s:String x:Key="HintPolygonPoints">Eckpunkte des Umrisses relativ zum Mittelpunkt, vor der Drehung. Leer: das regelmäßige Polygon oben wird verwendet.</s:String>
<s:String x:Key="HintFiberPoints">Stützpunkte des Pfads relativ zum Mittelpunkt, vor der Drehung.</s:String>
@@ -627,6 +651,44 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.GrinLensPart.EdgeIndex">Brechungsindex am Rand, 1,00 bis 2,55 in Schritten von 0,01. Das Profil zwischen Achse und Rand ist parabolisch.</s:String>
<s:String x:Key="Label.GrinLensPart.Coating">Entspiegelung</s:String>
<s:String x:Key="Hint.GrinLensPart.Coating">Dicke in Pixeln des entspiegelnden Bands direkt innerhalb des Umrisses mit dem Index √n; 0 für keines.</s:String>
+ <s:String x:Key="Label.LogicGatePart.DesignFrequency">Entwurfsfrequenz</s:String>
+ <s:String x:Key="Hint.LogicGatePart.DesignFrequency">Die Quellfrequenz, für die das Gatter entworfen ist, auf derselben Skala wie die Frequenz einer Quelle: die Frequenz der speisenden Quellen. Die Wellenlänge und daraus Kernbreite, Koppler und Phasenabschnitt folgen daraus, das Gatter arbeitet also nur bei dieser Frequenz.</s:String>
+ <s:String x:Key="Label.LogicGatePart.Coating">Entspiegelung</s:String>
+ <s:String x:Key="Hint.LogicGatePart.Coating">Dicke in Pixeln des entspiegelnden Bands an den unten angekreuzten Enden mit dem Index √n von Kern und Mantel; 0 für keines. Ein Viertelwellenband, das am wenigsten reflektiert, ist λ / (4 √n) Pixel dick; das Formular zeigt es für den Kern.</s:String>
+ <s:String x:Key="Label.LogicGatePart.InputCoated">Entspiegelung am Eingang</s:String>
+ <s:String x:Key="Hint.LogicGatePart.InputCoated">Das entspiegelnde Band an das Eingangsende legen. Dort ausschalten, wo das Gatter sein Licht von einem Gatter davor erhält, damit die Welle durch die Verbindung geht.</s:String>
+ <s:String x:Key="Label.LogicGatePart.OutputCoated">Entspiegelung am Ausgang</s:String>
+ <s:String x:Key="Hint.LogicGatePart.OutputCoated">Das entspiegelnde Band an das Ausgangsende legen. Dort ausschalten, wo das Gatter sein Licht an ein Gatter danach weitergibt, damit die Welle durch die Verbindung geht.</s:String>
+ <s:String x:Key="Label.LogicGatePart.UpperOutputActive">Oberer Ausgang</s:String>
+ <s:String x:Key="Hint.LogicGatePart.UpperOutputActive">Das Licht des oberen Ausgangs aus dem Gatter lassen. Ausgeschaltet nimmt ein sanft ansteigender Absorber es im letzten Stück des Arms auf.</s:String>
+ <s:String x:Key="Label.LogicGatePart.LowerOutputActive">Unterer Ausgang</s:String>
+ <s:String x:Key="Hint.LogicGatePart.LowerOutputActive">Das Licht des unteren Ausgangs aus dem Gatter lassen. Ausgeschaltet nimmt ein sanft ansteigender Absorber es im letzten Stück des Arms auf.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.DesignFrequency">Zielfrequenz</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.DesignFrequency">Die Quellfrequenz, für die die Platte entworfen ist, auf derselben Skala wie die Frequenz einer Quelle. Die Zonen folgen aus der Wellenlänge, die sie ergibt, also fokussiert die Platte diese Frequenz in der Brennweite; andere Frequenzen anderswo.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.FocalLength">Brennweite</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.FocalLength">Abstand in Pixeln von der Platte bis zum Brennpunkt, für eine ebene Welle entlang der Achse.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Inverse">Invertiert</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Inverse">Die Zonen tauschen: Die mittlere Zone wird ein Block, der erste Ring offen und so weiter. Der Brennpunkt bleibt, wo er ist.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Diameter">Durchmesser</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Diameter">Ausdehnung quer zur Achse in Pixeln; die Zonen füllen sie.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Thickness">Dicke</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Thickness">Ausdehnung entlang der Achse in Pixeln: die Tiefe der Blöcke. Sie sollte Raum für den entspiegelnden Anstieg an beiden Seiten lassen.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Coating">Entspiegelung</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Coating">Tiefe in Pixeln, über die die Absorption eines Blocks von null an den Seitenflächen bis zur vollen Stärke ansteigt, damit die Blöcke wenig reflektieren; höchstens die halbe Dicke zählt.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Mount">Fassung</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Mount">Die Platte mit einer absorbierenden Fassung umgeben, damit kein Licht außerhalb ihres Durchmessers vorbeigeht. Ohne sie trifft dieses Licht auf der Achse das fokussierte Licht und schiebt den Brennpunkt weiter hinaus, umso mehr, je weniger Zonen die Platte hat.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.MountWidth">Breite der Fassung</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.MountWidth">Breite in Pixeln der absorbierenden Fassung auf jeder Seite, außerhalb des Durchmessers.</s:String>
+ <s:String x:Key="Enum.GateOutput.Xor">XOR: dunkel mit beiden an</s:String>
+ <s:String x:Key="Enum.GateOutput.And">AND: 4-mal so hell mit beiden an</s:String>
+ <s:String x:Key="Enum.GateOutput.Or">OR: für einen so hell wie für zwei</s:String>
+ <s:String x:Key="Enum.GateOutput.Remainder">Rest: 3-mal mit beiden an</s:String>
+ <s:String x:Key="Label.LogicGatePart.CoreIndex">Kernindex</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CoreIndex">Brechungsindex der Wellenleiterkerne, 1,00 bis 2,55 in Schritten von 0,01. Er muss über dem des Mantels liegen; je größer der Unterschied, desto schmaler die Kerne und desto enger die Biegungen.</s:String>
+ <s:String x:Key="Label.LogicGatePart.CladdingIndex">Mantelindex</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CladdingIndex">Brechungsindex des Mantels um die Kerne, 1,00 bis 2,55 in Schritten von 0,01.</s:String>
+ <s:String x:Key="Label.LogicGatePart.PortSpacing">Anschlussabstand</s:String>
+ <s:String x:Key="Hint.LogicGatePart.PortSpacing">Abstand zwischen den beiden Eingängen und zwischen den beiden Ausgängen in Pixeln. Ein Wert unter dem, was der Entwurf braucht, um die Arme getrennt zu halten, wird darauf angehoben, und das Feld zeigt den verwendeten Abstand.</s:String>
<s:String x:Key="Enum.PartKind.Lens">Linse oder Spiegel</s:String>
<s:String x:Key="Enum.PartKind.Polygon">Polygon</s:String>
<s:String x:Key="Enum.PartKind.Rectangle">Rechteck</s:String>
@@ -636,6 +698,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Enum.PartKind.Fiber">Faser</s:String>
<s:String x:Key="Enum.PartKind.BraggReflector">Bragg-Reflektor</s:String>
<s:String x:Key="Enum.PartKind.GrinLens">GRIN-Linse</s:String>
+ <s:String x:Key="Enum.PartKind.XorGate">XOR-Gatter</s:String>
+ <s:String x:Key="Enum.PartKind.AndGate">AND-Gatter</s:String>
+ <s:String x:Key="Enum.PartKind.OrGate">OR-Gatter</s:String>
+ <s:String x:Key="Enum.PartKind.ZonePlate">Zonenplatte</s:String>
<s:String x:Key="Enum.TriangleType.Equilateral">Gleichseitig</s:String>
<s:String x:Key="Enum.TriangleType.RightIsosceles">Rechtwinklig-gleichschenklig (45°)</s:String>
<s:String x:Key="Enum.TriangleType.ThirtySixtyNinety">30-60-90</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index 2767c88..46c565e 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -1,4 +1,4 @@
-<!--
+<!--
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2026 Alexander Graef <[email protected]>
@@ -125,6 +125,11 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddFiber">_Fibre</s:String>
<s:String x:Key="MenuAddBraggReflector">_Bragg reflector</s:String>
<s:String x:Key="MenuAddGrinLens">_GRIN lens</s:String>
+ <s:String x:Key="MenuAddZonePlate">_Zone plate</s:String>
+ <s:String x:Key="MenuAddOpticalLogic">Opt_ical logic</s:String>
+ <s:String x:Key="MenuAddXorGate">_XOR (Mach-Zehnder)</s:String>
+ <s:String x:Key="MenuAddAndGate">_AND</s:String>
+ <s:String x:Key="MenuAddOrGate">_OR</s:String>
<s:String x:Key="MenuProjectToggleEnabled">_Enabled</s:String>
<s:String x:Key="MenuProjectDuplicate">_Duplicate</s:String>
<s:String x:Key="MenuProjectRemove">_Remove</s:String>
@@ -268,6 +273,25 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="SectionCore">Core</s:String>
<s:String x:Key="SectionCladding">Cladding</s:String>
<s:String x:Key="SectionLayers">Layers</s:String>
+ <s:String x:Key="SectionDesign">Design</s:String>
+ <s:String x:Key="SectionLayout">Layout</s:String>
+ <s:String x:Key="SectionPorts">Ports</s:String>
+ <s:String x:Key="SectionOutputs">Outputs active</s:String>
+ <s:String x:Key="TipGateWavelength">The wavelength the design frequency gives in a medium of index 1, with the simulation's source frequency scale</s:String>
+ <s:String x:Key="LabelQuarterWave">Quarter-wave coating</s:String>
+ <s:String x:Key="TipQuarterWave">The thickness of the least reflecting coating on the core, λ / (4 √n)</s:String>
+ <s:String x:Key="LabelCoreWidth">Core width</s:String>
+ <s:String x:Key="LabelCouplerGap">Coupler gap</s:String>
+ <s:String x:Key="LabelCouplerLength">Coupler length</s:String>
+ <s:String x:Key="LabelGateLength">Total length</s:String>
+ <s:String x:Key="TipGateLayout">Computed from the design wavelength and the indices with the simulator's own wave equation (the 4th-order Laplacian)</s:String>
+ <s:String x:Key="LabelInputA">Input A</s:String>
+ <s:String x:Key="LabelInputB">Input B</s:String>
+ <s:String x:Key="TipGatePorts">Canvas pixels. Feed the inputs with equal waves (the same frequency, amplitude and phase); a missing wave is a logical 0. The outputs line up with the inputs of gates set a port spacing above and below, one length on</s:String>
+ <s:String x:Key="SectionZones">Zones</s:String>
+ <s:String x:Key="LabelZoneCount">Number of zones</s:String>
+ <s:String x:Key="LabelOuterZone">Outermost zone</s:String>
+ <s:String x:Key="TipZones">The zones the plate gets within its diameter, and the width of the outermost whole one, which the grid must resolve (a few pixels at least)</s:String>
<s:String x:Key="SectionPoints">Points</s:String>
<s:String x:Key="HintPolygonPoints">Vertices of the outline relative to the centre, before rotation. Empty: the regular polygon above is used.</s:String>
<s:String x:Key="HintFiberPoints">Vertices of the path relative to the centre, before rotation.</s:String>
@@ -629,6 +653,44 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.GrinLensPart.EdgeIndex">Refractive index at the edge, 1.00 to 2.55 in steps of 0.01. The profile between the axis and the edge is parabolic.</s:String>
<s:String x:Key="Label.GrinLensPart.Coating">AR coating</s:String>
<s:String x:Key="Hint.GrinLensPart.Coating">Thickness in pixels of the anti-reflection band just inside the outline, with the index √n; 0 for none.</s:String>
+ <s:String x:Key="Label.LogicGatePart.DesignFrequency">Design frequency</s:String>
+ <s:String x:Key="Hint.LogicGatePart.DesignFrequency">The source frequency the gate is designed for, on the same scale as a source's frequency: the frequency of the sources that drive it. The wavelength, and from it the core width, the coupler and the phase section, follow from it, so the gate works at this frequency only.</s:String>
+ <s:String x:Key="Label.LogicGatePart.Coating">AR coating</s:String>
+ <s:String x:Key="Hint.LogicGatePart.Coating">Thickness in pixels of the anti-reflection band at the ends ticked below, with the index √n of the core and of the cladding; 0 for none. A quarter-wave band, the least reflecting, is λ / (4 √n) pixels thick; the form shows it for the core.</s:String>
+ <s:String x:Key="Label.LogicGatePart.InputCoated">AR on input side</s:String>
+ <s:String x:Key="Hint.LogicGatePart.InputCoated">Put the anti-reflection band on the input end. Switch it off where the gate takes its light from a gate before it, so the wave passes through the junction.</s:String>
+ <s:String x:Key="Label.LogicGatePart.OutputCoated">AR on output side</s:String>
+ <s:String x:Key="Hint.LogicGatePart.OutputCoated">Put the anti-reflection band on the output end. Switch it off where the gate hands its light to a gate after it, so the wave passes through the junction.</s:String>
+ <s:String x:Key="Label.LogicGatePart.UpperOutputActive">Upper output</s:String>
+ <s:String x:Key="Hint.LogicGatePart.UpperOutputActive">Let the upper output's light leave the gate. Switched off, an absorber with a soft rise takes it in the last stretch of the arm.</s:String>
+ <s:String x:Key="Label.LogicGatePart.LowerOutputActive">Lower output</s:String>
+ <s:String x:Key="Hint.LogicGatePart.LowerOutputActive">Let the lower output's light leave the gate. Switched off, an absorber with a soft rise takes it in the last stretch of the arm.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.DesignFrequency">Target frequency</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.DesignFrequency">The source frequency the plate is designed for, on the same scale as a source&apos;s frequency. The zones follow from the wavelength it gives, so the plate focuses this frequency at the focal length; other frequencies focus elsewhere.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.FocalLength">Focal length</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.FocalLength">Distance in pixels from the plate to its focus, for a plane wave arriving along the axis.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Inverse">Inverse</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Inverse">Exchange the zones: the central zone becomes a block, the first ring open, and so on. The focus stays where it is.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Diameter">Diameter</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Diameter">Extent across the axis in pixels; the zones fill it.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Thickness">Thickness</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Thickness">Extent along the axis in pixels: the depth of the blocks. It should leave room for the anti-reflection rise on both faces.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Coating">Anti-reflection</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Coating">Depth in pixels over which a block&apos;s absorption rises from nothing at its faces to its full strength, so the blocks reflect little; at most half the thickness takes effect.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Mount">Mount</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Mount">Surround the plate with an absorbing mount, so no light passes outside its diameter. Without it, that light meets the focused light on the axis and moves the focus further out, the more so the fewer zones the plate has.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.MountWidth">Mount width</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.MountWidth">Width in pixels of the absorbing mount on either side, beyond the diameter.</s:String>
+ <s:String x:Key="Enum.GateOutput.Xor">XOR: dark with both on</s:String>
+ <s:String x:Key="Enum.GateOutput.And">AND: 4 × as bright with both on</s:String>
+ <s:String x:Key="Enum.GateOutput.Or">OR: as bright for one as for two</s:String>
+ <s:String x:Key="Enum.GateOutput.Remainder">Remainder: 3 × with both on</s:String>
+ <s:String x:Key="Label.LogicGatePart.CoreIndex">Core index</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CoreIndex">Refractive index of the waveguide cores, 1.00 to 2.55 in steps of 0.01. It must be above the cladding's; the larger the difference, the narrower the cores and the tighter the bends.</s:String>
+ <s:String x:Key="Label.LogicGatePart.CladdingIndex">Cladding index</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CladdingIndex">Refractive index of the cladding around the cores, 1.00 to 2.55 in steps of 0.01.</s:String>
+ <s:String x:Key="Label.LogicGatePart.PortSpacing">Port spacing</s:String>
+ <s:String x:Key="Hint.LogicGatePart.PortSpacing">Distance between the two inputs, and between the two outputs, in pixels. A value below what the design needs to keep the arms apart is raised to it, and the box shows the spacing used.</s:String>
<s:String x:Key="Enum.PartKind.Lens">Lens or mirror</s:String>
<s:String x:Key="Enum.PartKind.Polygon">Polygon</s:String>
<s:String x:Key="Enum.PartKind.Rectangle">Rectangle</s:String>
@@ -638,6 +700,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Enum.PartKind.Fiber">Fibre</s:String>
<s:String x:Key="Enum.PartKind.BraggReflector">Bragg reflector</s:String>
<s:String x:Key="Enum.PartKind.GrinLens">GRIN lens</s:String>
+ <s:String x:Key="Enum.PartKind.XorGate">XOR gate</s:String>
+ <s:String x:Key="Enum.PartKind.AndGate">AND gate</s:String>
+ <s:String x:Key="Enum.PartKind.OrGate">OR gate</s:String>
+ <s:String x:Key="Enum.PartKind.ZonePlate">Zone plate</s:String>
<s:String x:Key="Enum.TriangleType.Equilateral">Equilateral</s:String>
<s:String x:Key="Enum.TriangleType.RightIsosceles">Right isosceles (45°)</s:String>
<s:String x:Key="Enum.TriangleType.ThirtySixtyNinety">30-60-90</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index 72f2958..3da68c8 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -1,4 +1,4 @@
-<!--
+<!--
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2026 Alexander Graef <[email protected]>
@@ -123,6 +123,11 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddFiber">_Fibre</s:String>
<s:String x:Key="MenuAddBraggReflector">Réflecteur de _Bragg</s:String>
<s:String x:Key="MenuAddGrinLens">Lentille _GRIN</s:String>
+ <s:String x:Key="MenuAddZonePlate">Lame à _zones</s:String>
+ <s:String x:Key="MenuAddOpticalLogic">Log_ique optique</s:String>
+ <s:String x:Key="MenuAddXorGate">_XOR (Mach-Zehnder)</s:String>
+ <s:String x:Key="MenuAddAndGate">_AND (ET)</s:String>
+ <s:String x:Key="MenuAddOrGate">_OR (OU)</s:String>
<s:String x:Key="MenuProjectToggleEnabled">_Activé</s:String>
<s:String x:Key="MenuProjectDuplicate">_Dupliquer</s:String>
<s:String x:Key="MenuProjectRemove">_Supprimer</s:String>
@@ -266,6 +271,25 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="SectionCore">Cœur</s:String>
<s:String x:Key="SectionCladding">Gaine</s:String>
<s:String x:Key="SectionLayers">Couches</s:String>
+ <s:String x:Key="SectionDesign">Conception</s:String>
+ <s:String x:Key="SectionLayout">Disposition</s:String>
+ <s:String x:Key="SectionPorts">Ports</s:String>
+ <s:String x:Key="SectionOutputs">Sorties actives</s:String>
+ <s:String x:Key="TipGateWavelength">La longueur d'onde que donne la fréquence de conception dans un milieu d'indice 1, avec l'échelle de fréquence des sources de la simulation</s:String>
+ <s:String x:Key="LabelQuarterWave">Traitement quart d'onde</s:String>
+ <s:String x:Key="TipQuarterWave">L'épaisseur du traitement le moins réfléchissant sur le cœur, λ / (4 √n)</s:String>
+ <s:String x:Key="LabelCoreWidth">Largeur du cœur</s:String>
+ <s:String x:Key="LabelCouplerGap">Écart du coupleur</s:String>
+ <s:String x:Key="LabelCouplerLength">Longueur du coupleur</s:String>
+ <s:String x:Key="LabelGateLength">Longueur totale</s:String>
+ <s:String x:Key="TipGateLayout">Calculé à partir de la longueur d'onde de conception et des indices avec l'équation d'onde du simulateur lui-même (le laplacien du 4e ordre)</s:String>
+ <s:String x:Key="LabelInputA">Entrée A</s:String>
+ <s:String x:Key="LabelInputB">Entrée B</s:String>
+ <s:String x:Key="TipGatePorts">Pixels du canevas. Alimentez les entrées avec des ondes identiques (même fréquence, amplitude et phase) ; une onde absente est un 0 logique. Les sorties tombent sur les entrées des portes placées un écart de ports plus haut et plus bas, une longueur plus loin</s:String>
+ <s:String x:Key="SectionZones">Zones</s:String>
+ <s:String x:Key="LabelZoneCount">Nombre de zones</s:String>
+ <s:String x:Key="LabelOuterZone">Zone la plus externe</s:String>
+ <s:String x:Key="TipZones">Les zones que la lame reçoit dans son diamètre, et la largeur de la dernière zone entière, que la grille doit résoudre (au moins quelques pixels)</s:String>
<s:String x:Key="SectionPoints">Points</s:String>
<s:String x:Key="HintPolygonPoints">Sommets du contour par rapport au centre, avant rotation. Vide : le polygone régulier ci-dessus est utilisé.</s:String>
<s:String x:Key="HintFiberPoints">Sommets du trajet par rapport au centre, avant rotation.</s:String>
@@ -627,6 +651,44 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.GrinLensPart.EdgeIndex">Indice de réfraction au bord, de 1,00 à 2,55 par pas de 0,01. Le profil entre l'axe et le bord est parabolique.</s:String>
<s:String x:Key="Label.GrinLensPart.Coating">Traitement antireflet</s:String>
<s:String x:Key="Hint.GrinLensPart.Coating">Épaisseur en pixels de la bande antireflet juste à l'intérieur du contour, d'indice √n ; 0 pour aucune.</s:String>
+ <s:String x:Key="Label.LogicGatePart.DesignFrequency">Fréquence de conception</s:String>
+ <s:String x:Key="Hint.LogicGatePart.DesignFrequency">La fréquence de source pour laquelle la porte est conçue, sur la même échelle que la fréquence d'une source : celle des sources qui l'alimentent. La longueur d'onde, et d'elle la largeur des cœurs, le coupleur et la section de phase, en découlent ; la porte ne fonctionne donc qu'à cette fréquence.</s:String>
+ <s:String x:Key="Label.LogicGatePart.Coating">Traitement antireflet</s:String>
+ <s:String x:Key="Hint.LogicGatePart.Coating">Épaisseur en pixels de la bande antireflet aux extrémités cochées ci-dessous, d'indice √n du cœur et de la gaine ; 0 pour aucune. Une bande quart d'onde, la moins réfléchissante, a une épaisseur de λ / (4 √n) pixels ; le formulaire l'affiche pour le cœur.</s:String>
+ <s:String x:Key="Label.LogicGatePart.InputCoated">Antireflet côté entrée</s:String>
+ <s:String x:Key="Hint.LogicGatePart.InputCoated">Mettre la bande antireflet à l'extrémité d'entrée. La désactiver là où la porte reçoit sa lumière d'une porte précédente, pour que l'onde traverse la jonction.</s:String>
+ <s:String x:Key="Label.LogicGatePart.OutputCoated">Antireflet côté sortie</s:String>
+ <s:String x:Key="Hint.LogicGatePart.OutputCoated">Mettre la bande antireflet à l'extrémité de sortie. La désactiver là où la porte transmet sa lumière à une porte suivante, pour que l'onde traverse la jonction.</s:String>
+ <s:String x:Key="Label.LogicGatePart.UpperOutputActive">Sortie haute</s:String>
+ <s:String x:Key="Hint.LogicGatePart.UpperOutputActive">Laisser la lumière de la sortie haute quitter la porte. Désactivée, un absorbeur à montée douce la prend dans le dernier tronçon du bras.</s:String>
+ <s:String x:Key="Label.LogicGatePart.LowerOutputActive">Sortie basse</s:String>
+ <s:String x:Key="Hint.LogicGatePart.LowerOutputActive">Laisser la lumière de la sortie basse quitter la porte. Désactivée, un absorbeur à montée douce la prend dans le dernier tronçon du bras.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.DesignFrequency">Fréquence cible</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.DesignFrequency">La fréquence de source pour laquelle la lame est conçue, sur la même échelle que la fréquence d&apos;une source. Les zones découlent de la longueur d&apos;onde qu&apos;elle donne ; la lame focalise donc cette fréquence à la distance focale, les autres ailleurs.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.FocalLength">Distance focale</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.FocalLength">Distance en pixels de la lame à son foyer, pour une onde plane arrivant le long de l&apos;axe.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Inverse">Inversée</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Inverse">Échanger les zones : la zone centrale devient un bloc, le premier anneau ouvert, et ainsi de suite. Le foyer reste en place.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Diameter">Diamètre</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Diameter">Étendue perpendiculaire à l&apos;axe en pixels ; les zones la remplissent.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Thickness">Épaisseur</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Thickness">Étendue le long de l&apos;axe en pixels : la profondeur des blocs. Elle doit laisser la place à la montée antireflet sur les deux faces.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Coating">Antireflet</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Coating">Profondeur en pixels sur laquelle l&apos;absorption d&apos;un bloc monte de rien sur ses faces à sa pleine force, pour que les blocs réfléchissent peu ; au plus la moitié de l&apos;épaisseur compte.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Mount">Monture</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Mount">Entourer la lame d&apos;une monture absorbante, pour qu&apos;aucune lumière ne passe hors de son diamètre. Sans elle, cette lumière rencontre la lumière focalisée sur l&apos;axe et repousse le foyer, d&apos;autant plus que la lame a peu de zones.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.MountWidth">Largeur de la monture</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.MountWidth">Largeur en pixels de la monture absorbante de chaque côté, au-delà du diamètre.</s:String>
+ <s:String x:Key="Enum.GateOutput.Xor">XOR : sombre avec les deux</s:String>
+ <s:String x:Key="Enum.GateOutput.And">AND : 4 fois plus avec les deux</s:String>
+ <s:String x:Key="Enum.GateOutput.Or">OR : pareil pour une ou deux</s:String>
+ <s:String x:Key="Enum.GateOutput.Remainder">Reste : 3 fois avec les deux</s:String>
+ <s:String x:Key="Label.LogicGatePart.CoreIndex">Indice du cœur</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CoreIndex">Indice de réfraction des cœurs des guides, de 1,00 à 2,55 par pas de 0,01. Il doit dépasser celui de la gaine ; plus l'écart est grand, plus les cœurs sont étroits et les courbes serrées.</s:String>
+ <s:String x:Key="Label.LogicGatePart.CladdingIndex">Indice de la gaine</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CladdingIndex">Indice de réfraction de la gaine autour des cœurs, de 1,00 à 2,55 par pas de 0,01.</s:String>
+ <s:String x:Key="Label.LogicGatePart.PortSpacing">Écart des ports</s:String>
+ <s:String x:Key="Hint.LogicGatePart.PortSpacing">Distance entre les deux entrées, et entre les deux sorties, en pixels. Une valeur inférieure à ce que la conception exige pour garder les bras séparés y est relevée, et la case affiche l'écart utilisé.</s:String>
<s:String x:Key="Enum.PartKind.Lens">Lentille ou miroir</s:String>
<s:String x:Key="Enum.PartKind.Polygon">Polygone</s:String>
<s:String x:Key="Enum.PartKind.Rectangle">Rectangle</s:String>
@@ -636,6 +698,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Enum.PartKind.Fiber">Fibre</s:String>
<s:String x:Key="Enum.PartKind.BraggReflector">Réflecteur de Bragg</s:String>
<s:String x:Key="Enum.PartKind.GrinLens">Lentille GRIN</s:String>
+ <s:String x:Key="Enum.PartKind.XorGate">Porte XOR</s:String>
+ <s:String x:Key="Enum.PartKind.AndGate">Porte AND</s:String>
+ <s:String x:Key="Enum.PartKind.OrGate">Porte OR</s:String>
+ <s:String x:Key="Enum.PartKind.ZonePlate">Lame à zones</s:String>
<s:String x:Key="Enum.TriangleType.Equilateral">Équilatéral</s:String>
<s:String x:Key="Enum.TriangleType.RightIsosceles">Rectangle isocèle (45°)</s:String>
<s:String x:Key="Enum.TriangleType.ThirtySixtyNinety">30-60-90</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index 5526038..58494d3 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -1,4 +1,4 @@
-<!--
+<!--
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2026 Alexander Graef <[email protected]>
@@ -123,6 +123,11 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddFiber">_Vezel</s:String>
<s:String x:Key="MenuAddBraggReflector">_Bragg-reflector</s:String>
<s:String x:Key="MenuAddGrinLens">_GRIN-lens</s:String>
+ <s:String x:Key="MenuAddZonePlate">_Zoneplaat</s:String>
+ <s:String x:Key="MenuAddOpticalLogic">Optische log_ica</s:String>
+ <s:String x:Key="MenuAddXorGate">_XOR (Mach-Zehnder)</s:String>
+ <s:String x:Key="MenuAddAndGate">_AND</s:String>
+ <s:String x:Key="MenuAddOrGate">_OR</s:String>
<s:String x:Key="MenuProjectToggleEnabled">_Ingeschakeld</s:String>
<s:String x:Key="MenuProjectDuplicate">_Dupliceren</s:String>
<s:String x:Key="MenuProjectRemove">_Verwijderen</s:String>
@@ -266,6 +271,25 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="SectionCore">Kern</s:String>
<s:String x:Key="SectionCladding">Mantel</s:String>
<s:String x:Key="SectionLayers">Lagen</s:String>
+ <s:String x:Key="SectionDesign">Ontwerp</s:String>
+ <s:String x:Key="SectionLayout">Indeling</s:String>
+ <s:String x:Key="SectionPorts">Poorten</s:String>
+ <s:String x:Key="SectionOutputs">Actieve uitgangen</s:String>
+ <s:String x:Key="TipGateWavelength">De golflengte die de ontwerpfrequentie geeft in een medium met index 1, bij de bronfrequentieschaal van de simulatie</s:String>
+ <s:String x:Key="LabelQuarterWave">Kwartgolf-coating</s:String>
+ <s:String x:Key="TipQuarterWave">De dikte van de minst reflecterende coating op de kern, λ / (4 √n)</s:String>
+ <s:String x:Key="LabelCoreWidth">Kernbreedte</s:String>
+ <s:String x:Key="LabelCouplerGap">Spleet van de koppelaar</s:String>
+ <s:String x:Key="LabelCouplerLength">Lengte van de koppelaar</s:String>
+ <s:String x:Key="LabelGateLength">Totale lengte</s:String>
+ <s:String x:Key="TipGateLayout">Berekend uit de ontwerpgolflengte en de indices met de eigen golfvergelijking van de simulator (de 4e-orde-Laplaciaan)</s:String>
+ <s:String x:Key="LabelInputA">Ingang A</s:String>
+ <s:String x:Key="LabelInputB">Ingang B</s:String>
+ <s:String x:Key="TipGatePorts">Canvaspixels. Voed de ingangen met gelijke golven (dezelfde frequentie, amplitude en fase); een ontbrekende golf is een logische 0. De uitgangen liggen in lijn met de ingangen van poorten die een poortafstand hoger en lager staan, één lengte verder</s:String>
+ <s:String x:Key="SectionZones">Zones</s:String>
+ <s:String x:Key="LabelZoneCount">Aantal zones</s:String>
+ <s:String x:Key="LabelOuterZone">Buitenste zone</s:String>
+ <s:String x:Key="TipZones">De zones die de plaat binnen zijn diameter krijgt, en de breedte van de buitenste hele zone, die het rooster moet kunnen oplossen (minstens een paar pixels)</s:String>
<s:String x:Key="SectionPoints">Punten</s:String>
<s:String x:Key="HintPolygonPoints">Hoekpunten van de omtrek ten opzichte van het middelpunt, vóór rotatie. Leeg: de regelmatige veelhoek hierboven wordt gebruikt.</s:String>
<s:String x:Key="HintFiberPoints">Punten van het pad ten opzichte van het middelpunt, vóór rotatie.</s:String>
@@ -627,6 +651,44 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.GrinLensPart.EdgeIndex">Brekingsindex aan de rand, 1,00 tot 2,55 in stappen van 0,01. Het profiel tussen de as en de rand is parabolisch.</s:String>
<s:String x:Key="Label.GrinLensPart.Coating">AR-coating</s:String>
<s:String x:Key="Hint.GrinLensPart.Coating">Dikte in pixels van de antireflectieband net binnen de omtrek, met index √n; 0 voor geen.</s:String>
+ <s:String x:Key="Label.LogicGatePart.DesignFrequency">Ontwerpfrequentie</s:String>
+ <s:String x:Key="Hint.LogicGatePart.DesignFrequency">De bronfrequentie waarvoor de poort is ontworpen, op dezelfde schaal als de frequentie van een bron: de frequentie van de bronnen die hem voeden. De golflengte, en daaruit de kernbreedte, de koppelaar en de fasesectie, volgen eruit, dus de poort werkt alleen bij deze frequentie.</s:String>
+ <s:String x:Key="Label.LogicGatePart.Coating">AR-coating</s:String>
+ <s:String x:Key="Hint.LogicGatePart.Coating">Dikte in pixels van de antireflectieband aan de hieronder aangevinkte uiteinden, met index √n van de kern en van de mantel; 0 voor geen. Een kwartgolfband, de minst reflecterende, is λ / (4 √n) pixels dik; het formulier toont die voor de kern.</s:String>
+ <s:String x:Key="Label.LogicGatePart.InputCoated">AR aan ingangszijde</s:String>
+ <s:String x:Key="Hint.LogicGatePart.InputCoated">Breng de antireflectieband aan op het ingangsuiteinde. Schakel hem uit waar de poort haar licht van een voorgaande poort krijgt, zodat de golf door de overgang gaat.</s:String>
+ <s:String x:Key="Label.LogicGatePart.OutputCoated">AR aan uitgangszijde</s:String>
+ <s:String x:Key="Hint.LogicGatePart.OutputCoated">Breng de antireflectieband aan op het uitgangsuiteinde. Schakel hem uit waar de poort haar licht aan een volgende poort doorgeeft, zodat de golf door de overgang gaat.</s:String>
+ <s:String x:Key="Label.LogicGatePart.UpperOutputActive">Bovenste uitgang</s:String>
+ <s:String x:Key="Hint.LogicGatePart.UpperOutputActive">Laat het licht van de bovenste uitgang de poort verlaten. Uitgeschakeld neemt een geleidelijk oplopende absorber het op in het laatste stuk van de arm.</s:String>
+ <s:String x:Key="Label.LogicGatePart.LowerOutputActive">Onderste uitgang</s:String>
+ <s:String x:Key="Hint.LogicGatePart.LowerOutputActive">Laat het licht van de onderste uitgang de poort verlaten. Uitgeschakeld neemt een geleidelijk oplopende absorber het op in het laatste stuk van de arm.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.DesignFrequency">Doelfrequentie</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.DesignFrequency">De bronfrequentie waarvoor de plaat is ontworpen, op dezelfde schaal als de frequentie van een bron. De zones volgen uit de golflengte die ze geeft, dus de plaat focust deze frequentie op de brandpuntsafstand; andere frequenties elders.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.FocalLength">Brandpuntsafstand</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.FocalLength">Afstand in pixels van de plaat tot het brandpunt, voor een vlakke golf die langs de as binnenkomt.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Inverse">Omgekeerd</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Inverse">Wissel de zones om: de middelste zone wordt een blok, de eerste ring open, enzovoort. Het brandpunt blijft op zijn plaats.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Diameter">Diameter</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Diameter">Afmeting dwars op de as in pixels; de zones vullen die.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Thickness">Dikte</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Thickness">Afmeting langs de as in pixels: de diepte van de blokken. Laat ruimte voor de antireflectie-oploop aan beide zijden.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Coating">Antireflectie</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Coating">Diepte in pixels waarover de absorptie van een blok oploopt van niets aan de zijvlakken tot de volle sterkte, zodat de blokken weinig reflecteren; hoogstens de halve dikte telt.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.Mount">Houder</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.Mount">Omgeef de plaat met een absorberende houder, zodat er geen licht buiten de diameter langs gaat. Zonder houder ontmoet dat licht het gefocuste licht op de as en schuift het brandpunt verder weg, sterker naarmate de plaat minder zones heeft.</s:String>
+ <s:String x:Key="Label.ZonePlatePart.MountWidth">Breedte van de houder</s:String>
+ <s:String x:Key="Hint.ZonePlatePart.MountWidth">Breedte in pixels van de absorberende houder aan elke kant, buiten de diameter.</s:String>
+ <s:String x:Key="Enum.GateOutput.Xor">XOR: donker met beide aan</s:String>
+ <s:String x:Key="Enum.GateOutput.And">AND: 4 × zo helder met beide aan</s:String>
+ <s:String x:Key="Enum.GateOutput.Or">OR: even helder voor één als twee</s:String>
+ <s:String x:Key="Enum.GateOutput.Remainder">Rest: 3 × met beide aan</s:String>
+ <s:String x:Key="Label.LogicGatePart.CoreIndex">Kernindex</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CoreIndex">Brekingsindex van de golfgeleiderkernen, 1,00 tot 2,55 in stappen van 0,01. Moet boven die van de mantel liggen; hoe groter het verschil, hoe smaller de kernen en hoe krapper de bochten.</s:String>
+ <s:String x:Key="Label.LogicGatePart.CladdingIndex">Mantelindex</s:String>
+ <s:String x:Key="Hint.LogicGatePart.CladdingIndex">Brekingsindex van de mantel rond de kernen, 1,00 tot 2,55 in stappen van 0,01.</s:String>
+ <s:String x:Key="Label.LogicGatePart.PortSpacing">Poortafstand</s:String>
+ <s:String x:Key="Hint.LogicGatePart.PortSpacing">Afstand tussen de twee ingangen, en tussen de twee uitgangen, in pixels. Een waarde onder wat het ontwerp nodig heeft om de armen gescheiden te houden, wordt daartoe verhoogd, en het vak toont de gebruikte afstand.</s:String>
<s:String x:Key="Enum.PartKind.Lens">Lens of spiegel</s:String>
<s:String x:Key="Enum.PartKind.Polygon">Polygoon</s:String>
<s:String x:Key="Enum.PartKind.Rectangle">Rechthoek</s:String>
@@ -636,6 +698,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Enum.PartKind.Fiber">Vezel</s:String>
<s:String x:Key="Enum.PartKind.BraggReflector">Bragg-reflector</s:String>
<s:String x:Key="Enum.PartKind.GrinLens">GRIN-lens</s:String>
+ <s:String x:Key="Enum.PartKind.XorGate">XOR-poort</s:String>
+ <s:String x:Key="Enum.PartKind.AndGate">AND-poort</s:String>
+ <s:String x:Key="Enum.PartKind.OrGate">OR-poort</s:String>
+ <s:String x:Key="Enum.PartKind.ZonePlate">Zoneplaat</s:String>
<s:String x:Key="Enum.TriangleType.Equilateral">Gelijkzijdig</s:String>
<s:String x:Key="Enum.TriangleType.RightIsosceles">Rechthoekig-gelijkbenig (45°)</s:String>
<s:String x:Key="Enum.TriangleType.ThirtySixtyNinety">30-60-90</s:String>
diff --git a/WaveDudeNext.WPF/Views/LogicGatePartView.xaml b/WaveDudeNext.WPF/Views/LogicGatePartView.xaml
new file mode 100644
index 0000000..f0f409f
--- /dev/null
+++ b/WaveDudeNext.WPF/Views/LogicGatePartView.xaml
@@ -0,0 +1,196 @@
+<!--
+SPDX-License-Identifier: GPL-3.0-or-later
+Copyright (C) 2026 Alexander Graef <[email protected]>
+
+This file is part of WaveDude Next, a 2D wave simulator.
+
+Based on the work of
+ Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+ <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+ 0x23 (Diffraction Limited), author of WaveSimulator2D
+ <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+
+WaveDude Next is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+<https://www.gnu.org/licenses/>.
+-->
+
+<UserControl x:Class="WaveDudeNext.WPF.Views.LogicGatePartView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:controls="clr-namespace:WaveDudeNext.WPF.Controls"
+ xmlns:converters="clr-namespace:WaveDudeNext.WPF.Converters"
+ xmlns:meta="clr-namespace:WaveDudeNext.WPF.Markup"
+ xmlns:localization="clr-namespace:WaveDudeNext.WPF.Localization"
+ xmlns:views="clr-namespace:WaveDudeNext.WPF.Views"
+ xmlns:model="clr-namespace:WaveDudeNext.Model;assembly=WaveDudeNext">
+
+ <UserControl.Resources>
+ <converters:LogicGateLayoutConverter x:Key="Layout" />
+ <converters:EnumNameConverter x:Key="EnumName" />
+ <!-- a read-only value beside its label; the layout values bind the gate plus every input they depend on, so the text follows them -->
+ <Style x:Key="LayoutText" TargetType="{x:Type TextBlock}">
+ <Setter Property="VerticalAlignment" Value="Center" />
+ </Style>
+ </UserControl.Resources>
+
+ <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
+ <StackPanel Margin="8">
+ <views:PartCommonView />
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionDesign}" />
+ <controls:FormPanel>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.DesignFrequency}" />
+ <controls:NumberBox Text="{Binding DesignFrequency}" Minimum="1" Maximum="255" DragStep="0.1" Decimals="2" ToolTip="{meta:Hint model:LogicGatePart.DesignFrequency}" AutomationProperties.AutomationId="PartDesignFrequency" />
+
+ <!-- read-only: the wavelength the frequency gives with the project's frequency scale -->
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelWavelength}" />
+ <TextBlock Style="{StaticResource LayoutText}" ToolTip="{DynamicResource TipGateWavelength}" AutomationProperties.AutomationId="PartWavelength">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="Wavelength">
+ <Binding /><Binding Path="Wavelength" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+ </controls:FormPanel>
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionMaterial}" />
+ <controls:FormPanel>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.CoreIndex}" />
+ <controls:NumberBox Text="{Binding CoreIndex}" Minimum="1" Maximum="2.55" Increment="0.01" ToolTip="{meta:Hint model:LogicGatePart.CoreIndex}" AutomationProperties.AutomationId="PartCoreIndex" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.CladdingIndex}" />
+ <controls:NumberBox Text="{Binding CladdingIndex}" Minimum="1" Maximum="2.55" Increment="0.01" ToolTip="{meta:Hint model:LogicGatePart.CladdingIndex}" AutomationProperties.AutomationId="PartCladdingIndex" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.Coating}" />
+ <controls:NumberBox Text="{Binding Coating}" Minimum="0" Maximum="50" ToolTip="{meta:Hint model:LogicGatePart.Coating}" AutomationProperties.AutomationId="PartCoating" />
+
+ <!-- per end, so a junction between staggered gates can go without a band -->
+ <CheckBox controls:FormPanel.FullWidth="True" Content="{meta:Label model:LogicGatePart.InputCoated}"
+ IsChecked="{Binding InputCoated}" ToolTip="{meta:Hint model:LogicGatePart.InputCoated}" AutomationProperties.AutomationId="PartInputCoated" />
+ <CheckBox controls:FormPanel.FullWidth="True" Content="{meta:Label model:LogicGatePart.OutputCoated}"
+ IsChecked="{Binding OutputCoated}" ToolTip="{meta:Hint model:LogicGatePart.OutputCoated}" AutomationProperties.AutomationId="PartOutputCoated" />
+
+ <!-- read-only: the quarter-wave thickness for the core, the least reflecting band -->
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelQuarterWave}" />
+ <TextBlock Style="{StaticResource LayoutText}" ToolTip="{DynamicResource TipQuarterWave}" AutomationProperties.AutomationId="PartQuarterWave">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="QuarterWave">
+ <Binding /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+ </controls:FormPanel>
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionShape}" />
+ <controls:FormPanel>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.PortSpacing}" />
+ <!-- the spacing the design uses, so each step moves the ports; a value below the minimum springs back to it -->
+ <controls:NumberBox Text="{Binding PortSpacingUsed}" Minimum="2" Maximum="2000" Increment="2" ToolTip="{meta:Hint model:LogicGatePart.PortSpacing}" AutomationProperties.AutomationId="PartPortSpacing" />
+ </controls:FormPanel>
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionOutputs}" />
+ <controls:FormPanel>
+ <!-- each output by its place, ticked to let its light out; the box names what the output gives for this kind of gate -->
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.UpperOutputActive}" />
+ <CheckBox IsChecked="{Binding UpperOutputActive}" ToolTip="{meta:Hint model:LogicGatePart.UpperOutputActive}" AutomationProperties.AutomationId="PartUpperOutputActive">
+ <CheckBox.Content>
+ <MultiBinding Converter="{StaticResource EnumName}">
+ <Binding Path="UpperOutput" />
+ <Binding Path="Current" Source="{x:Static localization:LanguageController.Instance}" />
+ </MultiBinding>
+ </CheckBox.Content>
+ </CheckBox>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.LowerOutputActive}" />
+ <CheckBox IsChecked="{Binding LowerOutputActive}" ToolTip="{meta:Hint model:LogicGatePart.LowerOutputActive}" AutomationProperties.AutomationId="PartLowerOutputActive">
+ <CheckBox.Content>
+ <MultiBinding Converter="{StaticResource EnumName}">
+ <Binding Path="LowerOutput" />
+ <Binding Path="Current" Source="{x:Static localization:LanguageController.Instance}" />
+ </MultiBinding>
+ </CheckBox.Content>
+ </CheckBox>
+ </controls:FormPanel>
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionLayout}" />
+ <controls:FormPanel ToolTip="{DynamicResource TipGateLayout}">
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelCoreWidth}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartCoreWidth">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="CoreWidth">
+ <Binding /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelCouplerGap}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartCouplerGap">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="Gap">
+ <Binding /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelCouplerLength}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartCouplerLength">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="CouplerLength">
+ <Binding /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelGateLength}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartGateLength">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="Length">
+ <Binding /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+ </controls:FormPanel>
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionPorts}" />
+ <controls:FormPanel ToolTip="{DynamicResource TipGatePorts}">
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelInputA}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartInputA">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="InputA">
+ <Binding /><Binding Path="X" /><Binding Path="Y" /><Binding Path="Angle" /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelInputB}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartInputB">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="InputB">
+ <Binding /><Binding Path="X" /><Binding Path="Y" /><Binding Path="Angle" /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.UpperOutputActive}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartOutputUpper">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="OutputUpper">
+ <Binding /><Binding Path="X" /><Binding Path="Y" /><Binding Path="Angle" /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LogicGatePart.LowerOutputActive}" />
+ <TextBlock Style="{StaticResource LayoutText}" AutomationProperties.AutomationId="PartOutputLower">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Layout}" ConverterParameter="OutputLower">
+ <Binding /><Binding Path="X" /><Binding Path="Y" /><Binding Path="Angle" /><Binding Path="Wavelength" /><Binding Path="CoreIndex" /><Binding Path="CladdingIndex" /><Binding Path="PortSpacing" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+ </controls:FormPanel>
+ </StackPanel>
+ </ScrollViewer>
+</UserControl>
diff --git a/WaveDudeNext.WPF/Views/LogicGatePartView.xaml.cs b/WaveDudeNext.WPF/Views/LogicGatePartView.xaml.cs
new file mode 100644
index 0000000..a3c4815
--- /dev/null
+++ b/WaveDudeNext.WPF/Views/LogicGatePartView.xaml.cs
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using System.Windows.Controls;
+
+namespace WaveDudeNext.WPF.Views;
+
+/// <summary>Editor for a logic gate (<see cref="WaveDudeNext.Model.LogicGatePart"/>: XOR, AND, OR): the design wavelength, the indices, the port spacing, and the computed layout and ports, read-only.</summary>
+public partial class LogicGatePartView : UserControl
+{
+ public LogicGatePartView()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/WaveDudeNext.WPF/Views/ZonePlatePartView.xaml b/WaveDudeNext.WPF/Views/ZonePlatePartView.xaml
new file mode 100644
index 0000000..cedc662
--- /dev/null
+++ b/WaveDudeNext.WPF/Views/ZonePlatePartView.xaml
@@ -0,0 +1,104 @@
+<!--
+SPDX-License-Identifier: GPL-3.0-or-later
+Copyright (C) 2026 Alexander Graef <[email protected]>
+
+This file is part of WaveDude Next, a 2D wave simulator.
+
+Based on the work of
+ Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+ <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+ 0x23 (Diffraction Limited), author of WaveSimulator2D
+ <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+
+WaveDude Next is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+<https://www.gnu.org/licenses/>.
+-->
+
+<UserControl x:Class="WaveDudeNext.WPF.Views.ZonePlatePartView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:controls="clr-namespace:WaveDudeNext.WPF.Controls"
+ xmlns:converters="clr-namespace:WaveDudeNext.WPF.Converters"
+ xmlns:meta="clr-namespace:WaveDudeNext.WPF.Markup"
+ xmlns:views="clr-namespace:WaveDudeNext.WPF.Views"
+ xmlns:model="clr-namespace:WaveDudeNext.Model;assembly=WaveDudeNext">
+
+ <UserControl.Resources>
+ <converters:ZonePlateConverter x:Key="Plate" />
+ <!-- a read-only value beside its label; it binds the plate plus every input it depends on, so the text follows them -->
+ <Style x:Key="ReadoutText" TargetType="{x:Type TextBlock}">
+ <Setter Property="VerticalAlignment" Value="Center" />
+ </Style>
+ </UserControl.Resources>
+
+ <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
+ <StackPanel Margin="8">
+ <views:PartCommonView />
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionDesign}" />
+ <controls:FormPanel>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ZonePlatePart.DesignFrequency}" />
+ <controls:NumberBox Text="{Binding DesignFrequency}" Minimum="1" Maximum="255" DragStep="0.1" Decimals="2" ToolTip="{meta:Hint model:ZonePlatePart.DesignFrequency}" AutomationProperties.AutomationId="PartDesignFrequency" />
+
+ <!-- read-only: the wavelength the frequency gives with the project's frequency scale -->
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelWavelength}" />
+ <TextBlock Style="{StaticResource ReadoutText}" ToolTip="{DynamicResource TipGateWavelength}" AutomationProperties.AutomationId="PartWavelength">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Plate}" ConverterParameter="Wavelength">
+ <Binding /><Binding Path="Wavelength" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ZonePlatePart.FocalLength}" />
+ <controls:NumberBox Text="{Binding FocalLength}" Minimum="1" Increment="10" ToolTip="{meta:Hint model:ZonePlatePart.FocalLength}" AutomationProperties.AutomationId="PartFocalLength" />
+
+ <CheckBox controls:FormPanel.FullWidth="True" Content="{meta:Label model:ZonePlatePart.Inverse}"
+ IsChecked="{Binding Inverse}" ToolTip="{meta:Hint model:ZonePlatePart.Inverse}" AutomationProperties.AutomationId="PartInverse" />
+ </controls:FormPanel>
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionShape}" />
+ <controls:FormPanel>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ZonePlatePart.Diameter}" />
+ <controls:NumberBox Text="{Binding Diameter}" Minimum="2" Increment="10" ToolTip="{meta:Hint model:ZonePlatePart.Diameter}" AutomationProperties.AutomationId="PartDiameter" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ZonePlatePart.Thickness}" />
+ <controls:NumberBox Text="{Binding Thickness}" Minimum="1" ToolTip="{meta:Hint model:ZonePlatePart.Thickness}" AutomationProperties.AutomationId="PartThickness" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ZonePlatePart.Coating}" />
+ <controls:NumberBox Text="{Binding Coating}" Minimum="0" Maximum="400" ToolTip="{meta:Hint model:ZonePlatePart.Coating}" AutomationProperties.AutomationId="PartCoating" />
+
+ <CheckBox controls:FormPanel.FullWidth="True" Content="{meta:Label model:ZonePlatePart.Mount}"
+ IsChecked="{Binding Mount}" ToolTip="{meta:Hint model:ZonePlatePart.Mount}" AutomationProperties.AutomationId="PartMount" />
+
+ <!-- the mount's width, only while there is a mount -->
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ZonePlatePart.MountWidth}" />
+ <controls:NumberBox Text="{Binding MountWidth}" Minimum="1" Increment="10" IsEnabled="{Binding Mount}" ToolTip="{meta:Hint model:ZonePlatePart.MountWidth}" AutomationProperties.AutomationId="PartMountWidth" />
+ </controls:FormPanel>
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionZones}" />
+ <controls:FormPanel ToolTip="{DynamicResource TipZones}">
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelZoneCount}" />
+ <TextBlock Style="{StaticResource ReadoutText}" AutomationProperties.AutomationId="PartZoneCount">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Plate}" ConverterParameter="Zones">
+ <Binding /><Binding Path="ZoneCount" /><Binding Path="Diameter" /><Binding Path="FocalLength" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{DynamicResource LabelOuterZone}" />
+ <TextBlock Style="{StaticResource ReadoutText}" AutomationProperties.AutomationId="PartOuterZone">
+ <TextBlock.Text>
+ <MultiBinding Converter="{StaticResource Plate}" ConverterParameter="OuterZone">
+ <Binding /><Binding Path="ZoneCount" /><Binding Path="Diameter" /><Binding Path="FocalLength" />
+ </MultiBinding>
+ </TextBlock.Text>
+ </TextBlock>
+ </controls:FormPanel>
+ </StackPanel>
+ </ScrollViewer>
+</UserControl>
diff --git a/WaveDudeNext.WPF/Views/ZonePlatePartView.xaml.cs b/WaveDudeNext.WPF/Views/ZonePlatePartView.xaml.cs
new file mode 100644
index 0000000..58ce63a
--- /dev/null
+++ b/WaveDudeNext.WPF/Views/ZonePlatePartView.xaml.cs
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using System.Windows.Controls;
+
+namespace WaveDudeNext.WPF.Views;
+
+/// <summary>Editor for a <see cref="WaveDudeNext.Model.ZonePlatePart"/>: the target frequency and focal length, the inverse switch, the plate's size and anti-reflection rise, and the zones it gets, read-only.</summary>
+public partial class ZonePlatePartView : UserControl
+{
+ public ZonePlatePartView()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/WaveDudeNext/Model/IFrequencyDesigned.cs b/WaveDudeNext/Model/IFrequencyDesigned.cs
new file mode 100644
index 0000000..bbc55e0
--- /dev/null
+++ b/WaveDudeNext/Model/IFrequencyDesigned.cs
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+namespace WaveDudeNext.Model;
+
+/// <summary>
+/// A part laid out for a source frequency (a logic gate, a zone plate): it turns its design frequency into a wavelength
+/// with the simulation's <see cref="Simulation.SourceFrequencyScale"/>, which the window's
+/// <see cref="Parts.GatePortFollower"/> hands it as <see cref="FrequencyScale"/>. UI thread, like the model.
+/// </summary>
+public interface IFrequencyDesigned
+{
+ /// <summary>The simulation's source frequency scale; not stored with the part.</summary>
+ double FrequencyScale { get; set; }
+}
diff --git a/WaveDudeNext/Model/IMovable.cs b/WaveDudeNext/Model/IMovable.cs
index ce42b06..ed43212 100644
--- a/WaveDudeNext/Model/IMovable.cs
+++ b/WaveDudeNext/Model/IMovable.cs
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
+// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Alexander Graef <[email protected]>
//
// This file is part of WaveDude Next, a 2D wave simulator.
@@ -65,14 +65,18 @@ public static class Movable
return (dx, dy);
}
- /// <summary>Moves every item by the same delta; nothing happens for a zero delta.</summary>
+ /// <summary>
+ /// Moves every item by the same delta; nothing happens for a zero delta. The optical parts move last: a source on an
+ /// logic gate's input follows the gate by itself (<see cref="Parts.GatePortFollower"/>), so a source moved with the group
+ /// must have left the old port before the gate moves, or it would be moved twice.
+ /// </summary>
public static void MoveAll(IEnumerable<IMovable> items, int dx, int dy)
{
if (dx == 0 && dy == 0)
{
return;
}
- foreach (IMovable item in items)
+ foreach (IMovable item in items.OrderBy(item => item is OpticalPart ? 1 : 0))
{
item.MoveBy(dx, dy);
}
diff --git a/WaveDudeNext/Model/OpticalPart.cs b/WaveDudeNext/Model/OpticalPart.cs
index 70e458d..aef9823 100644
--- a/WaveDudeNext/Model/OpticalPart.cs
+++ b/WaveDudeNext/Model/OpticalPart.cs
@@ -18,6 +18,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml.Serialization;
+using WaveDudeNext.Parts;
namespace WaveDudeNext.Model;
@@ -42,6 +43,14 @@ public enum PartKind
BraggReflector,
/// <summary>A gradient-index lens (<see cref="GrinLensPart"/>).</summary>
GrinLens,
+ /// <summary>An optical XOR gate: two waveguides and a directional coupler designed for one wavelength (<see cref="XorGatePart"/>).</summary>
+ XorGate,
+ /// <summary>An optical AND gate, the same coupler with the in-phase sum on the upper output (<see cref="AndGatePart"/>).</summary>
+ AndGate,
+ /// <summary>An optical OR gate, the same coupler with the waves meeting at 120° on the upper output (<see cref="OrGatePart"/>).</summary>
+ OrGate,
+ /// <summary>A Fresnel zone plate, a diffractive lens of absorbing zones (<see cref="ZonePlatePart"/>).</summary>
+ ZonePlate,
}
/// <summary>
@@ -1506,3 +1515,675 @@ public sealed class GrinLensPart : OpticalPart
/// <inheritdoc/>
public override OpticalPart Clone() => ShallowClone<GrinLensPart>();
}
+
+/// <summary>What one output of a <see cref="LogicGatePart"/> gives, in powers relative to one input's for the inputs 00, 10, 01, 11.</summary>
+public enum GateOutput
+{
+ /// <summary>0, ½, ½, 0: exclusive or, the waves cancel when both are on.</summary>
+ Xor,
+ /// <summary>0, ½, ½, 2: the sum in phase; read as AND with a threshold between ½ and 2 (4 : 1, the most a passive linear gate gives).</summary>
+ And,
+ /// <summary>0, ½, ½, ½: or, the waves meet at 120° and two give what one gives.</summary>
+ Or,
+ /// <summary>0, ½, ½, 1½: what the OR gate's coupler sends the other way, the waves meeting at 60°.</summary>
+ Remainder,
+}
+
+/// <summary>
+/// An optical logic gate, the interferometric logic of a Mach-Zehnder's combining half (the user's choice, 2026-10-21: a
+/// 2 × 2 directional coupler): two single-mode waveguides, input A above the axis and input B below, a phase section that
+/// puts wave B <see cref="PhaseShift"/> ahead of wave A, and a 3 dB coupler whose upper output carries (a + i·b) / √2 and
+/// lower output (i·a + b) / √2 of two coherent inputs (equal waves of the same frequency and phase). The phase shift alone
+/// makes the gate (the user's request, 2026-10-22, for AND and OR in the same dimensions as the XOR): +90° gives the upper
+/// output a − b (<see cref="XorGatePart"/>), −90° a + b (<see cref="AndGatePart"/>), +30° a + e^{i120°}·b
+/// (<see cref="OrGatePart"/>); the phase section sits in a stretch of the same length in all three, so they share their
+/// dimensions and ports and tile together. The whole layout follows from <see cref="DesignFrequency"/> (through
+/// <see cref="Wavelength"/>) and the indices (<see cref="LogicGateDesign"/>): the core width, the cladding, the gap, the
+/// coupler and phase-section lengths are computed with the engines' own discrete wave equation (the 4th-order stencil;
+/// the 9-point stencil's waves are slower and miss the design). Both ends are open and carry an anti-reflection band
+/// (<see cref="Coating"/>) unless switched off per end (<see cref="InputCoated"/>, <see cref="OutputCoated"/>), so light
+/// comes in from a fibre or a gate before and leaves into the next, and each output can
+/// be switched off by an absorber in its arm (<see cref="UpperOutputActive"/>, <see cref="LowerOutputActive"/>). The gate
+/// is passive; its inputs can be ordinary sources placed on <see cref="Ports"/>.
+/// </summary>
+public abstract class LogicGatePart : OpticalPart, IFrequencyDesigned
+{
+ /// <summary>Default <see cref="DesignFrequency"/>: level 50, a wavelength of 32 px at the default solver settings, the user's wavelength (2026-10-21); twelve pixels a period in the core, so the grid resolves the guide well.</summary>
+ public const double DefaultFrequency = 50.0;
+ /// <summary>Lowest <see cref="DesignFrequency"/>.</summary>
+ public const double MinFrequency = 1.0;
+ /// <summary>Shortest <see cref="Wavelength"/> the design accepts, in pixels.</summary>
+ public const double MinWavelength = 6.0;
+ /// <summary>Longest <see cref="Wavelength"/> the design accepts, in pixels.</summary>
+ public const double MaxWavelength = 200.0;
+ /// <summary>
+ /// Default <see cref="Coating"/> in pixels, the least reflecting band on the default gate, measured from the standing wave
+ /// in an output arm (2026-10-22): 0, 3, 5, 6, 7, 8 and 9 px reflected 24, 16, 5.5, 3.4, 3.9, 7.5 and 11 % of the power.
+ /// A little above the quarter wave λ / (4 √n) = 5.0 px of the core, as the mode runs partly in the cladding.
+ /// </summary>
+ public const int DefaultCoating = 6;
+ /// <summary>
+ /// Default <see cref="CoreIndex"/>, the largest: the strongest contrast to the cladding holds the mode tightest, so the
+ /// bends and the coupler are shortest. Measured at λ 32 (2026-10-21): cores of 2.0, 2.3 and 2.55 made gates of 726, 588
+ /// and 539 px whose XOR output kept 1.4, 1.9 and 1.1 % with both inputs on; a core of 1.6 at λ 16 made 1100 px.
+ /// </summary>
+ public const double DefaultCoreIndex = 2.55;
+ /// <summary>Default <see cref="CladdingIndex"/>.</summary>
+ public const double DefaultCladdingIndex = 1.45;
+ /// <summary>Default <see cref="PortSpacing"/> in pixels: as close as the design allows (it raises any smaller value); 60 px at the defaults, a unit 120 px wide.</summary>
+ public const int DefaultPortSpacing = 2;
+ /// <summary>Largest <see cref="PortSpacing"/> in pixels.</summary>
+ public const int MaxPortSpacing = 2000;
+
+ private double _designFrequency = DefaultFrequency;
+ private double _frequencyScale = Simulation.DefaultSourceFrequencyScale;
+ private double _coreIndex = DefaultCoreIndex;
+ private double _claddingIndex = DefaultCladdingIndex;
+ private int _portSpacing = DefaultPortSpacing;
+ private int _coating = DefaultCoating;
+ private bool _inputCoated = true;
+ private bool _outputCoated = true;
+ private bool _upperOutputActive = true;
+ private bool _lowerOutputActive = true;
+
+ /// <summary>How far wave B leads wave A into the coupler, in degrees; fixed per kind.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public abstract double PhaseShift { get; }
+
+ /// <summary>What the upper output gives; fixed per kind.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public abstract GateOutput UpperOutput { get; }
+
+ /// <summary>What the lower output gives; fixed per kind.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public abstract GateOutput LowerOutput { get; }
+
+ /// <summary>
+ /// The source frequency the gate is designed for, as a source level (the scale of <see cref="Source.Frequency"/>): the
+ /// frequency of the sources that drive it (the user's point, 2026-10-22: every source input is a frequency, so the
+ /// gate takes one too and shows the wavelength). The layout follows from the <see cref="Wavelength"/> it gives.
+ /// </summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultFrequency)]
+ [Category("Design")]
+ [DisplayName("Design frequency")]
+ [Description("The source frequency the gate is designed for, on the same scale as a source's frequency: the frequency of the sources that drive it. The wavelength, and from it the core width, the coupler and the phase section, follow from it, so the gate works at this frequency only.")]
+ public double DesignFrequency
+ {
+ get => _designFrequency;
+ set
+ {
+ if (SetProperty(ref _designFrequency, value))
+ {
+ OnDesignChanged();
+ }
+ }
+ }
+
+ /// <summary>
+ /// The simulation's <see cref="Simulation.SourceFrequencyScale"/>, which turns <see cref="DesignFrequency"/> into an
+ /// angular frequency; kept current by the window's <see cref="Parts.GatePortFollower"/>, the default scale until then.
+ /// Not stored: the project's simulation settings hold it. UI thread.
+ /// </summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public double FrequencyScale
+ {
+ get => _frequencyScale;
+ set
+ {
+ if (SetProperty(ref _frequencyScale, value))
+ {
+ OnDesignChanged();
+ }
+ }
+ }
+
+ /// <summary>
+ /// The wavelength in pixels in a medium of index 1 that <see cref="DesignFrequency"/> gives: λ = 2π / ω with
+ /// ω = level / 255 × 0.5 × <see cref="FrequencyScale"/> radians per step and the engines' speed of 1 pixel per step at
+ /// index 1 (<see cref="Simulation.Wavelength"/> with that speed); NaN for a frequency that gives none.
+ /// </summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public double Wavelength => Simulation.Wavelength(DesignFrequency, 1.0, FrequencyScale);
+
+ /// <summary>Thickness in pixels of the anti-reflection band at the ends <see cref="InputCoated"/> and <see cref="OutputCoated"/> select, with the index √n of the core and of the cladding; 0 for none. A quarter-wave band is λ / (4 √n) thick.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultCoating)]
+ [Category("Material")]
+ [DisplayName("AR coating")]
+ [Description("Thickness in pixels of the anti-reflection band at the ends ticked below, with the index √n of the core and of the cladding; 0 for none. A quarter-wave band, the least reflecting, is λ / (4 √n) pixels thick; the form shows it for the core.")]
+ public int Coating
+ {
+ get => _coating;
+ set => SetProperty(ref _coating, value);
+ }
+
+ /// <summary>
+ /// Whether the input end carries the anti-reflection band (<see cref="Coating"/>). Off where the gate takes its light
+ /// from a gate before it (the user's request, 2026-10-22: a band in the junction keeps the wave from passing from one
+ /// unit into the next).
+ /// </summary>
+ [XmlAttribute]
+ [DefaultValue(true)]
+ [Category("Material")]
+ [DisplayName("AR on input side")]
+ [Description("Put the anti-reflection band on the input end. Switch it off where the gate takes its light from a gate before it, so the wave passes through the junction.")]
+ public bool InputCoated
+ {
+ get => _inputCoated;
+ set => SetProperty(ref _inputCoated, value);
+ }
+
+ /// <summary>Whether the output end carries the anti-reflection band (<see cref="Coating"/>); off where the gate hands its light to a gate after it (see <see cref="InputCoated"/>).</summary>
+ [XmlAttribute]
+ [DefaultValue(true)]
+ [Category("Material")]
+ [DisplayName("AR on output side")]
+ [Description("Put the anti-reflection band on the output end. Switch it off where the gate hands its light to a gate after it, so the wave passes through the junction.")]
+ public bool OutputCoated
+ {
+ get => _outputCoated;
+ set => SetProperty(ref _outputCoated, value);
+ }
+
+ /// <summary>Whether the upper output (<see cref="UpperOutput"/>) lets its light out; switched off, an absorber in the blue channel takes it in the arm's last stretch.</summary>
+ [XmlAttribute]
+ [DefaultValue(true)]
+ [Category("Outputs")]
+ [DisplayName("Upper output")]
+ [Description("Let the upper output's light leave the gate. Switched off, an absorber with a soft rise takes it in the last stretch of the arm.")]
+ public bool UpperOutputActive
+ {
+ get => _upperOutputActive;
+ set => SetProperty(ref _upperOutputActive, value);
+ }
+
+ /// <summary>Whether the lower output (<see cref="LowerOutput"/>) lets its light out; switched off, an absorber in the blue channel takes it in the arm's last stretch.</summary>
+ [XmlAttribute]
+ [DefaultValue(true)]
+ [Category("Outputs")]
+ [DisplayName("Lower output")]
+ [Description("Let the lower output's light leave the gate. Switched off, an absorber with a soft rise takes it in the last stretch of the arm.")]
+ public bool LowerOutputActive
+ {
+ get => _lowerOutputActive;
+ set => SetProperty(ref _lowerOutputActive, value);
+ }
+
+ /// <summary>Tells the form that the values derived from the design follow an edit of a design input.</summary>
+ private void OnDesignChanged()
+ {
+ OnPropertyChanged(nameof(Wavelength));
+ OnPropertyChanged(nameof(PortSpacingUsed));
+ }
+
+ /// <summary>Refractive index of the waveguide cores, 1.00 to 2.55; above the cladding's for guiding.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultCoreIndex)]
+ [Category("Material")]
+ [DisplayName("Core index")]
+ [Description("Refractive index of the waveguide cores, 1.00 to 2.55 in steps of 0.01. It must be above the cladding's; the larger the difference, the narrower the cores and the tighter the bends.")]
+ public double CoreIndex
+ {
+ get => _coreIndex;
+ set
+ {
+ if (SetProperty(ref _coreIndex, value))
+ {
+ OnPropertyChanged(nameof(PortSpacingUsed));
+ }
+ }
+ }
+
+ /// <summary>Refractive index of the cladding around the cores, 1.00 to 2.55.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultCladdingIndex)]
+ [Category("Material")]
+ [DisplayName("Cladding index")]
+ [Description("Refractive index of the cladding around the cores, 1.00 to 2.55 in steps of 0.01.")]
+ public double CladdingIndex
+ {
+ get => _claddingIndex;
+ set
+ {
+ if (SetProperty(ref _claddingIndex, value))
+ {
+ OnPropertyChanged(nameof(PortSpacingUsed));
+ }
+ }
+ }
+
+ /// <summary>Distance between the two inputs (and the two outputs) in pixels, centre to centre, as typed; the design raises a value below what it needs to keep the arms apart (<see cref="PortSpacingUsed"/>).</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultPortSpacing)]
+ [Category("Shape")]
+ [DisplayName("Port spacing")]
+ [Description("Distance between the two inputs, and between the two outputs, in pixels. A value below what the design needs to keep the arms apart is raised to it.")]
+ public int PortSpacing
+ {
+ get => _portSpacing;
+ set
+ {
+ if (SetProperty(ref _portSpacing, value))
+ {
+ OnPropertyChanged(nameof(PortSpacingUsed));
+ }
+ }
+ }
+
+ /// <summary>
+ /// The port spacing the design uses, what the form shows and edits: <see cref="PortSpacing"/> raised to the design's
+ /// minimum (60 px at the defaults), so every step of the box moves the ports (the user's report, 2026-10-21: the box
+ /// stood at 2 and its steps up to the minimum changed nothing). Setting it sets <see cref="PortSpacing"/>. Not stored.
+ /// </summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public int PortSpacingUsed
+ {
+ get => Design?.PortSpacing ?? PortSpacing;
+ set => PortSpacing = value;
+ }
+
+ /// <summary>The layout for the current values (guarded as the painter guards them), or null when the cores guide nothing. Any thread; cached.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public LogicGateDesign? Design => double.IsFinite(Wavelength) && Wavelength > 0.0
+ ? LogicGateDesign.For(Math.Round(Math.Clamp(Wavelength, MinWavelength, MaxWavelength), 3), NormalizeIndex(CoreIndex), NormalizeIndex(CladdingIndex), Math.Clamp(PortSpacing, 2, MaxPortSpacing), PhaseShift)
+ : null;
+
+ /// <inheritdoc/>
+ public override double AxisReach => (Design?.Length ?? 0) / 2.0;
+
+ /// <summary>The outer edge of the claddings: along the upper arm's top, back along the lower arm's bottom; a closed outline of the gate's extent.</summary>
+ public override (double X, double Y)[] Outline()
+ {
+ if (Design is not { } design)
+ {
+ return [];
+ }
+ const int steps = 64;
+ double outer = design.CoreWidth / 2.0 + design.CladdingThickness + design.AbsorberWidth;
+ var points = new (double X, double Y)[2 * (steps + 1)];
+ for (int i = 0; i <= steps; i++)
+ {
+ double x = design.Left + (double)design.Length * i / steps;
+ double offset = design.ArmOffset(x) + outer;
+ points[i] = (x, -offset);
+ points[2 * steps + 1 - i] = (x, offset);
+ }
+ return points;
+ }
+
+ /// <summary>The ports in canvas pixels (rounded to the pixel a source would sit on): input A, input B, the upper output and the lower output; null without a design.</summary>
+ public (int X, int Y)[]? Ports()
+ {
+ if (Design is not { } design)
+ {
+ return null;
+ }
+ double half = design.PortSpacing / 2.0;
+ (int, int) At(double x, double y)
+ {
+ (double cx, double cy) = ToCanvas(x, y);
+ return ((int)Math.Floor(cx), (int)Math.Floor(cy));
+ }
+ return [At(design.InputX, -half), At(design.InputX, half), At(design.OutputX, -half), At(design.OutputX, half)];
+ }
+
+ /// <inheritdoc/>
+ public override void Normalize()
+ {
+ base.Normalize();
+ DesignFrequency = double.IsFinite(DesignFrequency) ? Math.Round(Math.Clamp(DesignFrequency, MinFrequency, Source.MaxLevel), 2) : DefaultFrequency;
+ CoreIndex = NormalizeIndex(CoreIndex);
+ CladdingIndex = NormalizeIndex(CladdingIndex);
+ PortSpacing = Math.Clamp(PortSpacing, 2, MaxPortSpacing);
+ Coating = Math.Clamp(Coating, 0, MaxCoating);
+ }
+}
+
+/// <summary>
+/// An XOR gate: wave B leads by 90°, so the upper output carries (a − b) / √2, dark when both inputs are on, and the lower
+/// the in-phase sum (the 2026-10-21 design, measured: with both inputs on the upper output keeps about 1 % of one input's
+/// power, the lower 1.9×).
+/// </summary>
+public sealed class XorGatePart : LogicGatePart
+{
+ /// <inheritdoc/>
+ public override PartKind Kind => PartKind.XorGate;
+
+ /// <inheritdoc/>
+ public override double PhaseShift => 90.0;
+
+ /// <inheritdoc/>
+ public override GateOutput UpperOutput => GateOutput.Xor;
+
+ /// <inheritdoc/>
+ public override GateOutput LowerOutput => GateOutput.And;
+
+ /// <inheritdoc/>
+ public override OpticalPart Clone() => ShallowClone<XorGatePart>();
+}
+
+/// <summary>
+/// An AND gate in the only sense a passive linear gate has one: wave A leads by 90°, so the upper output carries the in-phase
+/// sum (a + b) / √2, half an input's power for one input and twice it for two, 4 : 1, to be read with a threshold between;
+/// the lower output carries the XOR. The XOR gate with its outputs exchanged.
+/// </summary>
+public sealed class AndGatePart : LogicGatePart
+{
+ /// <inheritdoc/>
+ public override PartKind Kind => PartKind.AndGate;
+
+ /// <inheritdoc/>
+ public override double PhaseShift => -90.0;
+
+ /// <inheritdoc/>
+ public override GateOutput UpperOutput => GateOutput.And;
+
+ /// <inheritdoc/>
+ public override GateOutput LowerOutput => GateOutput.Xor;
+
+ /// <inheritdoc/>
+ public override OpticalPart Clone() => ShallowClone<AndGatePart>();
+}
+
+/// <summary>
+/// An OR gate: wave B leads by 30°, so the waves meet at 120° in the upper output, a + e^{i120°}·b over √2, and one input or
+/// two give the same half an input's power (1 + 1 + 2 cos 120° = 1); the lower output, where they meet at 60°, gives ½, ½ and 1½.
+/// </summary>
+public sealed class OrGatePart : LogicGatePart
+{
+ /// <inheritdoc/>
+ public override PartKind Kind => PartKind.OrGate;
+
+ /// <inheritdoc/>
+ public override double PhaseShift => 30.0;
+
+ /// <inheritdoc/>
+ public override GateOutput UpperOutput => GateOutput.Or;
+
+ /// <inheritdoc/>
+ public override GateOutput LowerOutput => GateOutput.Remainder;
+
+ /// <inheritdoc/>
+ public override OpticalPart Clone() => ShallowClone<OrGatePart>();
+}
+
+/// <summary>
+/// A Fresnel zone plate (the user's request, 2026-10-22), a diffractive lens: a plate of <see cref="Thickness"/> along the
+/// axis and <see cref="Diameter"/> across it, cut into zones at the radii rₙ = √(n·λ·f + (n·λ/2)²) from the axis, λ the
+/// <see cref="Wavelength"/> of <see cref="DesignFrequency"/> and f the <see cref="FocalLength"/>; every second zone is a
+/// block that absorbs (the user's choice of material), the central zone open, or a block when <see cref="Inverse"/>. The
+/// waves through the open zones arrive at the focus a whole number of periods apart and add there. The blocks are painted
+/// into the blue channel only, the refractive index left as it is: full at their middle, rising quadratically over
+/// <see cref="Coating"/> from the faces the wave meets and leaves, so they reflect little; their sides toward the
+/// neighbouring zones stay sharp, as the outer zones are narrow (about λ·f / <see cref="Diameter"/>). Light passes freely
+/// outside the diameter unless the absorbing <see cref="Mount"/> is on. Positions and lengths are canvas pixels.
+/// </summary>
+public sealed class ZonePlatePart : OpticalPart, IFrequencyDesigned
+{
+ /// <summary>Default <see cref="Diameter"/> in pixels.</summary>
+ public const int DefaultDiameter = 800;
+ /// <summary>Default <see cref="Thickness"/> in pixels: two wavelengths at the default frequency, room for the rise on both faces (see <see cref="BlockAbsorption"/>).</summary>
+ public const int DefaultThickness = 64;
+ /// <summary>Default <see cref="Coating"/> in pixels: a wavelength at the default frequency (see <see cref="BlockAbsorption"/>).</summary>
+ public const int DefaultCoating = 32;
+ /// <summary>Default <see cref="DesignFrequency"/>: level 50, a wavelength of 32 px at the default solver settings, as the logic gates.</summary>
+ public const double DefaultFrequency = 50.0;
+ /// <summary>Default <see cref="FocalLength"/> in pixels.</summary>
+ public const int DefaultFocalLength = 600;
+ /// <summary>
+ /// The absorption (blue) in the middle of a block. Measured on a block of the whole diameter with a plane wave at λ 32
+ /// (2026-10-22, transmitted / reflected power): 255 over a 16 px rise in 48 px 0.4 / 10.7 %, over 24 px 0.3 / 4.9 %;
+ /// 128 over 24 px 0.3 / 2.2 %; 64 over 24 px 2.7 / 0.9 %; in 64 px over 32 px, 64 1.0 / 0.7 %, 96 0.4 / 1.0 %, 128
+ /// 0.3 / 1.2 %. A block that stops all and reflects nothing does not exist: a strong absorber is a wall of its own.
+ /// </summary>
+ public const int BlockAbsorption = 96;
+
+ private int _diameter = DefaultDiameter;
+ private int _thickness = DefaultThickness;
+ private int _coating = DefaultCoating;
+ private double _designFrequency = DefaultFrequency;
+ private double _frequencyScale = Simulation.DefaultSourceFrequencyScale;
+ private int _focalLength = DefaultFocalLength;
+ private bool _inverse;
+ private bool _mount;
+ private int _mountWidth = DefaultMountWidth;
+
+ /// <summary>Default <see cref="MountWidth"/> in pixels.</summary>
+ public const int DefaultMountWidth = 200;
+
+ /// <inheritdoc/>
+ public override PartKind Kind => PartKind.ZonePlate;
+
+ /// <summary>
+ /// Whether an absorbing mount surrounds the plate (the user's request, 2026-10-22): a band of <see cref="MountWidth"/>
+ /// on either side beyond the diameter, the plate's thickness and absorption, so no light passes outside the zones (which
+ /// otherwise meets the focused light on the axis and pushes the focus on).
+ /// </summary>
+ [XmlAttribute]
+ [DefaultValue(false)]
+ [Category("Shape")]
+ [Description("Surround the plate with an absorbing mount, so no light passes outside its diameter. Without it, that light meets the focused light on the axis and moves the focus further out, the more so the fewer zones the plate has.")]
+ public bool Mount
+ {
+ get => _mount;
+ set => SetProperty(ref _mount, value);
+ }
+
+ /// <summary>Width in pixels of the mount on either side, beyond the diameter.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultMountWidth)]
+ [Category("Shape")]
+ [DisplayName("Mount width")]
+ [Description("Width in pixels of the absorbing mount on either side, beyond the diameter.")]
+ public int MountWidth
+ {
+ get => _mountWidth;
+ set => SetProperty(ref _mountWidth, value);
+ }
+
+ /// <summary>Half the plate's outer extent across the axis in pixels: half the diameter, plus the mount when it is on.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public double OuterHalfWidth => Math.Max(2, Diameter) / 2.0 + (Mount ? Math.Max(1, MountWidth) : 0);
+
+ /// <summary>Extent across the axis in pixels.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultDiameter)]
+ [Category("Shape")]
+ [Description("Extent across the axis in pixels; the zones fill it.")]
+ public int Diameter
+ {
+ get => _diameter;
+ set
+ {
+ if (SetProperty(ref _diameter, value))
+ {
+ OnPropertyChanged(nameof(ZoneCount));
+ }
+ }
+ }
+
+ /// <summary>Extent along the axis in pixels, the blocks' depth.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultThickness)]
+ [Category("Shape")]
+ [Description("Extent along the axis in pixels: the depth of the blocks. It should leave room for the anti-reflection rise on both faces.")]
+ public int Thickness
+ {
+ get => _thickness;
+ set => SetProperty(ref _thickness, value);
+ }
+
+ /// <summary>Depth in pixels over which a block's absorption rises from nothing at the faces the wave meets and leaves to its full strength; at most half the thickness takes effect.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultCoating)]
+ [Category("Shape")]
+ [DisplayName("Anti-reflection")]
+ [Description("Depth in pixels over which a block's absorption rises from nothing at its faces to its full strength, so the blocks reflect little; at most half the thickness takes effect.")]
+ public int Coating
+ {
+ get => _coating;
+ set => SetProperty(ref _coating, value);
+ }
+
+ /// <summary>The source frequency the plate is designed for, as a source level (the scale of <see cref="Source.Frequency"/>).</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultFrequency)]
+ [Category("Design")]
+ [DisplayName("Target frequency")]
+ [Description("The source frequency the plate is designed for, on the same scale as a source's frequency. The zones follow from the wavelength it gives, so the plate focuses this frequency at the focal length; other frequencies focus elsewhere.")]
+ public double DesignFrequency
+ {
+ get => _designFrequency;
+ set
+ {
+ if (SetProperty(ref _designFrequency, value))
+ {
+ OnDesignChanged();
+ }
+ }
+ }
+
+ /// <inheritdoc/>
+ [XmlIgnore]
+ [Browsable(false)]
+ public double FrequencyScale
+ {
+ get => _frequencyScale;
+ set
+ {
+ if (SetProperty(ref _frequencyScale, value))
+ {
+ OnDesignChanged();
+ }
+ }
+ }
+
+ /// <summary>Distance in pixels from the plate's centre to the focus along the axis (+x'), for a plane wave arriving along it.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultFocalLength)]
+ [Category("Design")]
+ [DisplayName("Focal length")]
+ [Description("Distance in pixels from the plate to its focus, for a plane wave arriving along the axis.")]
+ public int FocalLength
+ {
+ get => _focalLength;
+ set
+ {
+ if (SetProperty(ref _focalLength, value))
+ {
+ OnPropertyChanged(nameof(ZoneCount));
+ }
+ }
+ }
+
+ /// <summary>Whether the zones are exchanged: the central zone a block and the first ring open, and so on.</summary>
+ [XmlAttribute]
+ [DefaultValue(false)]
+ [Category("Design")]
+ [Description("Exchange the zones: the central zone becomes a block, the first ring open, and so on. The focus stays where it is.")]
+ public bool Inverse
+ {
+ get => _inverse;
+ set => SetProperty(ref _inverse, value);
+ }
+
+ /// <summary>The wavelength in pixels in a medium of index 1 that <see cref="DesignFrequency"/> gives with <see cref="FrequencyScale"/> (the engines' speed of 1 pixel per step); NaN for none.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public double Wavelength => Simulation.Wavelength(DesignFrequency, 1.0, FrequencyScale);
+
+ /// <summary>How many zones, open and blocked, fit within half the diameter (the last one cut by the rim); 0 without a wavelength.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public int ZoneCount
+ {
+ get
+ {
+ double half = Math.Max(2, Diameter) / 2.0;
+ return ZoneAt(half) is { } zone ? zone + 1 : 0;
+ }
+ }
+
+ /// <summary>
+ /// The zone, counted from 0 at the axis, that the distance <paramref name="r"/> from the axis falls in: the n with
+ /// rₙ ≤ r &lt; rₙ₊₁, from rₙ² = n·λ·f + (n·λ/2)², a quadratic in n; null without a wavelength or a focal length.
+ /// </summary>
+ public int? ZoneAt(double r)
+ {
+ double lambda = Wavelength;
+ double f = Math.Max(1, FocalLength);
+ if (!double.IsFinite(lambda) || lambda <= 0.0)
+ {
+ return null;
+ }
+ // (λ²/4)·n² + λf·n − r² = 0
+ double a = lambda * lambda / 4.0;
+ double b = lambda * f;
+ double n = (-b + Math.Sqrt(b * b + 4.0 * a * r * r)) / (2.0 * a);
+ return (int)Math.Floor(n);
+ }
+
+ /// <summary>Whether the distance <paramref name="r"/> from the axis falls in a block: the odd zones, or the even ones when inverse.</summary>
+ public bool IsBlockAt(double r) => ZoneAt(Math.Abs(r)) is { } zone && (zone % 2 == 1) != Inverse;
+
+ /// <summary>The width in pixels of the outermost whole zone within the diameter, rₙ − rₙ₋₁; what the grid must resolve.</summary>
+ [XmlIgnore]
+ [Browsable(false)]
+ public double OuterZoneWidth
+ {
+ get
+ {
+ double lambda = Wavelength;
+ int count = ZoneCount;
+ if (count < 2)
+ {
+ return Math.Max(2, Diameter) / 2.0;
+ }
+ double f = Math.Max(1, FocalLength);
+ double Radius(int n) => Math.Sqrt(n * lambda * f + n * lambda / 2.0 * (n * lambda / 2.0));
+ return Radius(count - 1) - Radius(count - 2);
+ }
+ }
+
+ /// <summary>Tells the form that the values derived from the wavelength follow an edit.</summary>
+ private void OnDesignChanged()
+ {
+ OnPropertyChanged(nameof(Wavelength));
+ OnPropertyChanged(nameof(ZoneCount));
+ }
+
+ /// <inheritdoc/>
+ public override double AxisReach => Math.Max(1, Thickness) / 2.0;
+
+ /// <summary>The plate's rectangle, the mount included when it is on.</summary>
+ public override (double X, double Y)[] Outline()
+ {
+ double t = Math.Max(1, Thickness) / 2.0;
+ double d = OuterHalfWidth;
+ return [(-t, -d), (t, -d), (t, d), (-t, d)];
+ }
+
+ /// <inheritdoc/>
+ public override void Normalize()
+ {
+ base.Normalize();
+ MountWidth = Math.Max(1, MountWidth);
+ Diameter = Math.Max(2, Diameter);
+ Thickness = Math.Max(1, Thickness);
+ Coating = Math.Clamp(Coating, 0, MaxAbsorptionRamp);
+ DesignFrequency = double.IsFinite(DesignFrequency) ? Math.Round(Math.Clamp(DesignFrequency, LogicGatePart.MinFrequency, Source.MaxLevel), 2) : DefaultFrequency;
+ FocalLength = Math.Max(1, FocalLength);
+ }
+
+ /// <inheritdoc/>
+ public override OpticalPart Clone() => ShallowClone<ZonePlatePart>();
+}
diff --git a/WaveDudeNext/Model/Project.cs b/WaveDudeNext/Model/Project.cs
index 12251c0..05ac3b2 100644
--- a/WaveDudeNext/Model/Project.cs
+++ b/WaveDudeNext/Model/Project.cs
@@ -147,7 +147,7 @@ public sealed class Project : ObservableObject
}
/// <summary>
- /// Optical parts (lenses, mirrors, polygons, rectangles, ellipses, triangles, outlines, fibres, Bragg reflectors, GRIN lenses), in the order they appear in
+ /// Optical parts (lenses, mirrors, polygons, rectangles, ellipses, triangles, outlines, fibres, Bragg reflectors, GRIN lenses, XOR, AND and OR gates, zone plates), in the order they appear in
/// the project tree, which is the order they are painted in: a later part paints over an earlier one. One element
/// name per kind in the file (2026-10-18, the user's choice, so a schema can say what each element needs).
/// Observable; always present, empty in a new project.
@@ -161,6 +161,10 @@ public sealed class Project : ObservableObject
[XmlElement("Fiber", typeof(FiberPart))]
[XmlElement("BraggReflector", typeof(BraggReflectorPart))]
[XmlElement("GrinLens", typeof(GrinLensPart))]
+ [XmlElement("XorGate", typeof(XorGatePart))]
+ [XmlElement("AndGate", typeof(AndGatePart))]
+ [XmlElement("OrGate", typeof(OrGatePart))]
+ [XmlElement("ZonePlate", typeof(ZonePlatePart))]
[Browsable(false)]
public ObservableCollection<OpticalPart> Parts
{
@@ -336,7 +340,7 @@ public sealed class Project : ObservableObject
/// <summary>
/// Appends a new part of <paramref name="kind"/>, named "Lens n", "Polygon n", "Rectangle n", "Ellipse n", "Triangle n", "Outline n",
- /// "Fiber n", "Bragg reflector n" or "GRIN lens n" with the first free n, centred on the canvas (the scene's size; an image scene's own size is not
+ /// "Fiber n", "Bragg reflector n", "GRIN lens n", "XOR gate n", "AND gate n", "OR gate n" or "Zone plate n" with the first free n, centred on the canvas (the scene's size; an image scene's own size is not
/// known here), and returns it.
/// </summary>
public OpticalPart AddPart(PartKind kind)
@@ -352,6 +356,10 @@ public sealed class Project : ObservableObject
PartKind.Fiber => new FiberPart { Points = FiberPart.DefaultPath() },
PartKind.BraggReflector => new BraggReflectorPart(),
PartKind.GrinLens => new GrinLensPart(),
+ PartKind.XorGate => new XorGatePart(),
+ PartKind.AndGate => new AndGatePart(),
+ PartKind.OrGate => new OrGatePart(),
+ PartKind.ZonePlate => new ZonePlatePart(),
_ => throw new ArgumentOutOfRangeException(nameof(kind)),
};
part.Name = NumberedName(PartStem(kind), Parts.Select(p => p.Name));
@@ -373,6 +381,10 @@ public sealed class Project : ObservableObject
PartKind.Fiber => "Fiber",
PartKind.BraggReflector => "Bragg reflector",
PartKind.GrinLens => "GRIN lens",
+ PartKind.XorGate => "XOR gate",
+ PartKind.AndGate => "AND gate",
+ PartKind.OrGate => "OR gate",
+ PartKind.ZonePlate => "Zone plate",
_ => "Part",
};
diff --git a/WaveDudeNext/Parts/GatePortFollower.cs b/WaveDudeNext/Parts/GatePortFollower.cs
new file mode 100644
index 0000000..8a57c99
--- /dev/null
+++ b/WaveDudeNext/Parts/GatePortFollower.cs
@@ -0,0 +1,170 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using System.Collections.Specialized;
+using System.ComponentModel;
+using NLog;
+using WaveDudeNext.Model;
+
+namespace WaveDudeNext.Parts;
+
+/// <summary>
+/// Keeps the sources that drive a <see cref="LogicGatePart"/> on its inputs (the user's request, 2026-10-21): a source on an
+/// input port (within <see cref="Reach"/> pixels) is moved onto the port's new position whenever an edit of the gate moves
+/// the port: its position, angle, port spacing, or a design value that changes the layout. Remembers each gate's input
+/// ports after every edit, so it knows where they were. A group move that takes the sources along moves them before the
+/// gate (<see cref="Movable.MoveAll"/>), so they have left the old ports by then and are not moved twice. It also hands every
+/// gate, and every other part laid out for a frequency (<see cref="IFrequencyDesigned"/>, a zone plate), the simulation's
+/// <see cref="Simulation.SourceFrequencyScale"/>, which turns its design frequency into its wavelength. UI thread, like the model.
+/// </summary>
+public sealed class GatePortFollower : IDisposable
+{
+ private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
+
+ /// <summary>How far, in canvas pixels on either axis, a source may stand from an input port and still count as on it.</summary>
+ public const int Reach = 1;
+
+ private readonly Project _project;
+ private readonly Dictionary<LogicGatePart, (int X, int Y)[]?> _inputs = [];
+ private INotifyCollectionChanged? _parts;
+ private Simulation? _simulation;
+
+ /// <param name="project">The project whose gates to follow for its lifetime (or until <see cref="Dispose"/>).</param>
+ public GatePortFollower(Project project)
+ {
+ _project = project;
+ project.PropertyChanged += OnProjectPropertyChanged;
+ Resubscribe();
+ }
+
+ /// <summary>Stops following.</summary>
+ public void Dispose()
+ {
+ _project.PropertyChanged -= OnProjectPropertyChanged;
+ Unsubscribe();
+ }
+
+ private void OnProjectPropertyChanged(object? sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName is nameof(Project.Parts) or nameof(Project.Simulation))
+ {
+ Resubscribe();
+ }
+ }
+
+ private void OnPartsChanged(object? sender, NotifyCollectionChangedEventArgs e) => Resubscribe();
+
+ /// <summary>A new frequency scale: every part laid out for a frequency gets it (and a gate's sources follow the ports it moves).</summary>
+ private void OnSimulationChanged(object? sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == nameof(Simulation.SourceFrequencyScale))
+ {
+ foreach (IFrequencyDesigned part in _project.Parts.OfType<IFrequencyDesigned>())
+ {
+ part.FrequencyScale = _project.Simulation.SourceFrequencyScale;
+ }
+ }
+ }
+
+ /// <summary>Subscribes to every gate in the parts list, keeping what is known of gates still there and noting the ports of new ones.</summary>
+ private void Resubscribe()
+ {
+ Dictionary<LogicGatePart, (int X, int Y)[]?> known = new(_inputs);
+ Unsubscribe();
+ _parts = _project.Parts;
+ _parts.CollectionChanged += OnPartsChanged;
+ _simulation = _project.Simulation;
+ _simulation.PropertyChanged += OnSimulationChanged;
+ foreach (LogicGatePart gate in _project.Parts.OfType<LogicGatePart>())
+ {
+ if (!_inputs.ContainsKey(gate))
+ {
+ // a gate seen before keeps its remembered ports, so its sources follow the scale handed over now; a new one starts at it
+ if (known.TryGetValue(gate, out (int X, int Y)[]? ports))
+ {
+ _inputs[gate] = ports;
+ gate.PropertyChanged += OnGateChanged;
+ gate.FrequencyScale = _project.Simulation.SourceFrequencyScale;
+ }
+ else
+ {
+ gate.FrequencyScale = _project.Simulation.SourceFrequencyScale;
+ _inputs[gate] = Inputs(gate);
+ gate.PropertyChanged += OnGateChanged;
+ }
+ }
+ }
+ // the other parts laid out for a frequency (a zone plate) have no ports to follow, only the scale
+ foreach (IFrequencyDesigned part in _project.Parts.OfType<IFrequencyDesigned>().Where(part => part is not LogicGatePart))
+ {
+ part.FrequencyScale = _project.Simulation.SourceFrequencyScale;
+ }
+ }
+
+ private void Unsubscribe()
+ {
+ if (_parts != null)
+ {
+ _parts.CollectionChanged -= OnPartsChanged;
+ _parts = null;
+ }
+ if (_simulation != null)
+ {
+ _simulation.PropertyChanged -= OnSimulationChanged;
+ _simulation = null;
+ }
+ foreach (LogicGatePart gate in _inputs.Keys)
+ {
+ gate.PropertyChanged -= OnGateChanged;
+ }
+ _inputs.Clear();
+ }
+
+ /// <summary>Moves the sources on the gate's old input ports onto the new ones, then remembers the new ones.</summary>
+ private void OnGateChanged(object? sender, PropertyChangedEventArgs e)
+ {
+ if (sender is not LogicGatePart gate || !_inputs.TryGetValue(gate, out (int X, int Y)[]? before))
+ {
+ return;
+ }
+ (int X, int Y)[]? after = Inputs(gate);
+ _inputs[gate] = after;
+ if (before == null || after == null)
+ {
+ return;
+ }
+ for (int i = 0; i < before.Length; i++)
+ {
+ if (before[i] == after[i])
+ {
+ continue;
+ }
+ foreach (Source source in _project.Sources)
+ {
+ if (Math.Abs(source.X - before[i].X) <= Reach && Math.Abs(source.Y - before[i].Y) <= Reach)
+ {
+ Logger.Debug("Source '{Source}' follows input {Port} of '{Gate}' ({Property}): ({X0}, {Y0}) to ({X1}, {Y1})",
+ source.Name, i == 0 ? "A" : "B", gate.Name, e.PropertyName, source.X, source.Y, after[i].X, after[i].Y);
+ source.MoveBy(after[i].X - source.X, after[i].Y - source.Y);
+ }
+ }
+ }
+ }
+
+ /// <summary>The gate's two input ports in canvas pixels, or null without a design.</summary>
+ private static (int X, int Y)[]? Inputs(LogicGatePart gate) => gate.Ports() is { } ports ? [ports[0], ports[1]] : null;
+}
diff --git a/WaveDudeNext/Parts/LogicGateDesign.cs b/WaveDudeNext/Parts/LogicGateDesign.cs
new file mode 100644
index 0000000..3f432d7
--- /dev/null
+++ b/WaveDudeNext/Parts/LogicGateDesign.cs
@@ -0,0 +1,379 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using NLog;
+
+namespace WaveDudeNext.Parts;
+
+/// <summary>
+/// The layout of a logic gate (<see cref="Model.LogicGatePart"/>) designed for one wavelength and one phase shift: two
+/// single-mode waveguides, input A above (−y') and input B below (+y'), <see cref="PortSpacing"/> apart; a phase section
+/// whose core is <see cref="PhaseIndexStep"/> higher or lower over <see cref="PhaseLength"/>, within a stretch of a quarter
+/// period's length (<see cref="PhaseRegionLength"/>) whatever the shift, so every gate kind has the same dimensions;
+/// smooth S-bends (<see cref="BendShare"/>) that bring the arms <see cref="CoupledSpacing"/> apart; a 3 dB directional
+/// coupler; S-bends back out; straight outputs, where a switched-off output's absorber sits. Both ends are open, so gates
+/// cascade; the anti-reflection bands on them belong to the part, not the design (they do not change the layout).
+/// A coupler of total coupling ∫κ dz = π/4 sends (a + i·b) / √2 to the upper output and (i·a + b) / √2 to the lower; with
+/// b a quarter period ahead (b → i·b) the upper output carries (a − b) / √2, the XOR of two equal coherent inputs, and
+/// the lower i·(a + b) / √2, their sum; with b a quarter period behind the two change places (AND on top), and with b 30°
+/// ahead the waves meet at 120° on top (OR). κ = (β_even − β_odd) / 2 comes from <see cref="WaveguideModes"/> at every
+/// spacing, so the bends' share of the coupling is counted and the straight coupler takes the rest.
+/// All lengths are pixels along the axis x', the part frame's origin at the gate's centre. Immutable; any thread.
+/// </summary>
+public sealed class LogicGateDesign
+{
+ private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
+
+ /// <summary>How much higher the phase section's core index is than the core's.</summary>
+ public const double PhaseIndexStep = 0.1;
+
+ /// <summary>
+ /// The bend's radiation exponent: the smallest radius R of the S-bends makes (2/3)·γ³R / β² this large, the exponent of
+ /// a bent guide's radiation loss (Marcuse), γ being the mode's decay constant in the cladding and β its propagation
+ /// constant. So a guide that holds its mode tighter bends tighter. Measured on a core of 1.6 in 1.45 at λ 16
+ /// (2026-10-21): an exponent of 5.6 (R = 30 λ) let the bends radiate about 7 % into the other arm, 11 (60 λ) left a floor
+ /// of 1.3 % at the XOR output.
+ /// </summary>
+ public const double BendLossExponent = 11.0;
+
+ /// <summary>
+ /// The narrowest absorbing band outside the clear cladding, in wavelengths. Measured on the default gate (2026-10-22, both
+ /// inputs on): bands of 64, 32, 16 and 8 px left 2.1, 3.4, 1.5 and 3.1 % at the XOR output, none 7.6 % (the cladding
+ /// then guides the stray light to the outputs); half a wavelength keeps a margin over the quarter that still worked.
+ /// </summary>
+ public const double MinAbsorber = 0.5;
+
+ /// <summary>The absorption (blue) at the rim of the cladding's absorbing band; a strength that reflected little in the measurements of OpticalParts.md 6a.</summary>
+ public const int Absorption = 64;
+
+ /// <summary>
+ /// The largest share of the coupler's π/4 the two S-bends may give; the gap is widened until the straight coupler carries
+ /// the rest. Measured on the default gate (2026-10-21, bends of 60 λ): at 0.6 (gap 12 px, 1161 px long) the XOR output
+ /// kept 2.3 % of one input's power with both inputs on, at 0.25 (gap 16 px, 1621 px long) 1.3 %. The light the bends
+ /// radiate into the other arm, not the coupling model, sets that floor: the solver's κ matched the straight coupler to 1 %.
+ /// 0.6, the shorter gate, is the user's choice (2026-10-21).
+ /// </summary>
+ public const double BendShareLimit = 0.6;
+
+ /// <summary>
+ /// What the simulated couplers coupled beyond the model's ∫κ dz, in radians, taken off the straight coupler: 0.06 to 0.08
+ /// on gates with cores of 1.6 to 2.2 in 1.45 at λ 16 (2026-10-21, one input split 43/57 instead of 50/50); with it
+ /// taken off, the split came out 50/51 and the XOR output's floor fell from 4.2 % to 2.9 % (core 2.0). It held with the
+ /// output taper and at λ 32 (cores of 2.0 and 2.55: without it 42/58 and 2.3 to 2.5 %, with it 48/52 and 1.1 to 1.4 %).
+ /// </summary>
+ public const double CouplingExcess = 0.07;
+
+ /// <summary>Points per S-bend at which the coupling is evaluated.</summary>
+ private const int BendSamples = 24;
+
+ private static readonly Dictionary<(double, double, double, int, double), LogicGateDesign?> Cache = [];
+ private static readonly Lock CacheGate = new();
+
+ private LogicGateDesign()
+ {
+ }
+
+ /// <summary>The design wavelength in pixels (in a medium of index 1).</summary>
+ public double Wavelength { get; private init; }
+ /// <summary>Refractive index of the cores.</summary>
+ public double CoreIndex { get; private init; }
+ /// <summary>Refractive index of the cladding around the cores.</summary>
+ public double CladdingIndex { get; private init; }
+ /// <summary>Width of each core in pixels: nine tenths of the single-mode cut-off λ / (2 NA), at least 2.</summary>
+ public int CoreWidth { get; private init; }
+ /// <summary>Thickness of the clear cladding around each core in pixels: three decay lengths of the mode.</summary>
+ public int CladdingThickness { get; private init; }
+ /// <summary>
+ /// Thickness in pixels of the absorbing band outside the clear cladding (cladding index, absorption rising to the rim):
+ /// whatever is left out to half the port spacing past the ports, at least <see cref="MinAbsorber"/> wavelengths.
+ /// </summary>
+ public double AbsorberWidth => PortSpacing / 2.0 - CoreWidth / 2.0 - CladdingThickness;
+ /// <summary>Distance between the cores' centres at the ports in pixels, even.</summary>
+ public int PortSpacing { get; private init; }
+ /// <summary>Distance between the cores' centres in the coupler in pixels, even.</summary>
+ public int CoupledSpacing { get; private init; }
+ /// <summary>Gap between the cores in the coupler in pixels.</summary>
+ public int Gap => CoupledSpacing - CoreWidth;
+ /// <summary>
+ /// Length of the straight input stretch before the port in pixels, half a wavelength. The input end is open, coated like
+ /// the output end, so light from a fibre or a gate before it comes in (the user's choice, 2026-10-22, which removed an
+ /// absorbing termination that took the light arriving from a gate before); the sources are to be coupled in from outside.
+ /// </summary>
+ public int InputLength { get; private init; }
+ /// <summary>Length of the straight stretches from the port to the phase section and from it to the bend in pixels, a wavelength each.</summary>
+ public int LeadLength { get; private init; }
+ /// <summary>Length of the stretch that holds the phase section in pixels: what a quarter-period shift needs, for every gate kind.</summary>
+ public int PhaseRegionLength { get; private init; }
+ /// <summary>Length of the phase section in pixels, from the start of its stretch: the shift's share of a quarter period.</summary>
+ public int PhaseLength { get; private init; }
+ /// <summary>How far wave B leads wave A into the coupler, in degrees.</summary>
+ public double PhaseShift { get; private init; }
+ /// <summary>Length of each S-bend in pixels.</summary>
+ public int BendLength { get; private init; }
+ /// <summary>Length of the straight coupler in pixels.</summary>
+ public int CouplerLength { get; private init; }
+ /// <summary>
+ /// Length of the straight output stretch in pixels, three wavelengths: the output ports a half wavelength in, then the
+ /// <see cref="OutputRampLength"/> where a switched-off output's absorber rises, up to the coated end.
+ /// </summary>
+ public int OutputLength { get; private init; }
+ /// <summary>Length in pixels over which a switched-off output's absorber rises to its full strength at the right end, two wavelengths (a soft rise reflects little, OpticalParts.md 6a; measured on the default gate, 2026-10-22: 0.03 % of the power came back, nothing left past the end).</summary>
+ public int OutputRampLength { get; private init; }
+ /// <summary>
+ /// Whether the phase section sits on arm A rather than arm B: on the arm to be put ahead, raised by
+ /// <see cref="PhaseIndexStep"/>, or, for a core within the step of the largest index, on the other arm, lowered.
+ /// </summary>
+ public bool PhaseOnArmA { get; private init; }
+ /// <summary>Refractive index of the phase section's core.</summary>
+ public double PhaseIndex { get; private init; }
+ /// <summary>Propagation constant of a single guide in radians per pixel.</summary>
+ public double Beta { get; private init; }
+ /// <summary>Coupling constant κ in the straight coupler in radians per pixel.</summary>
+ public double Kappa { get; private init; }
+ /// <summary>The coupling both S-bends add, ∫κ dz in radians.</summary>
+ public double BendCoupling { get; private init; }
+
+ /// <summary>Total length along the axis in pixels.</summary>
+ public int Length => InputLength + LeadLength + PhaseRegionLength + LeadLength + 2 * BendLength + CouplerLength + OutputLength;
+
+ /// <summary>Where the input arms start, x' of the left end.</summary>
+ public double Left => -Length / 2.0;
+
+ /// <summary>x' of the input ports, half a wavelength in from the open input end: where a source placed in the unit drives an arm.</summary>
+ public double InputX => Left + InputLength;
+
+ /// <summary>x' where a switched-off output's absorber starts to rise.</summary>
+ public double OutputRampStart => Length / 2.0 - OutputRampLength;
+
+ /// <summary>x' of the output ports, a half wavelength into the straight output stretch.</summary>
+ public double OutputX => Length / 2.0 - OutputLength + Math.Round(Wavelength / 2.0);
+
+ /// <summary>The thickness in pixels of a quarter-wave anti-reflection band on the core, λ / (4 √n).</summary>
+ public double QuarterWaveCoating => Wavelength / (4.0 * Math.Sqrt(CoreIndex));
+
+ /// <summary>Where the phase section starts and ends along x'.</summary>
+ public (double Start, double End) PhaseSection => (InputX + LeadLength, InputX + LeadLength + PhaseLength);
+
+ /// <summary>
+ /// The S-bend's offset profile from the far end (t = 0, share 0) to the near end (t = 1, share 1): t − sin(2πt) / 2π,
+ /// whose slope and curvature are both 0 at the ends, so the bend joins the straight stretches without a kink in
+ /// direction or in curvature (the user's point, 2026-10-21: bends must be smooth). Its curvature peaks at
+ /// 2π·Δ / L² in the middle third, Δ being the offset and L the length.
+ /// </summary>
+ public static double BendShare(double t) => t - Math.Sin(2.0 * Math.PI * t) / (2.0 * Math.PI);
+
+ /// <summary>
+ /// Half the outer width of the gate across the axis, at the ports: the port spacing itself, so the unit is twice the
+ /// port spacing wide with its ports at a quarter and three quarters of its width (the user's request, 2026-10-22). Gates
+ /// then tile in staggered columns: a gate's outputs meet one input each of two gates set a port spacing above and below
+ /// it, which touch without overlapping.
+ /// </summary>
+ public double HalfWidth => PortSpacing;
+
+ /// <summary>
+ /// The design for the given inputs, from a cache shared by every gate with the same values; null when the core
+ /// guides nothing at this wavelength (a core index not above the cladding's).
+ /// </summary>
+ public static LogicGateDesign? For(double wavelength, double coreIndex, double claddingIndex, int portSpacing, double phaseShift)
+ {
+ var key = (wavelength, coreIndex, claddingIndex, portSpacing, phaseShift);
+ lock (CacheGate)
+ {
+ if (Cache.TryGetValue(key, out LogicGateDesign? cached))
+ {
+ return cached;
+ }
+ }
+ LogicGateDesign? design = Create(wavelength, coreIndex, claddingIndex, portSpacing, phaseShift);
+ lock (CacheGate)
+ {
+ if (Cache.Count > 64)
+ {
+ Cache.Clear();
+ }
+ Cache[key] = design;
+ }
+ return design;
+ }
+
+ /// <summary>The distance of each arm's centre from the axis at <paramref name="x"/>: half the port spacing at the ports, half the coupled spacing in the coupler, the smooth S-bend (<see cref="BendShare"/>) between.</summary>
+ public double ArmOffset(double x)
+ {
+ (double offset, _) = ArmOffsetAndSlope(x);
+ return offset;
+ }
+
+ /// <summary>The arm's offset from the axis at <paramref name="x"/> and its slope d(offset)/dx.</summary>
+ public (double Offset, double Slope) ArmOffsetAndSlope(double x)
+ {
+ double far = PortSpacing / 2.0;
+ double near = CoupledSpacing / 2.0;
+ double bendIn = InputX + 2 * LeadLength + PhaseRegionLength;
+ double couplerStart = bendIn + BendLength;
+ double bendOut = couplerStart + CouplerLength;
+ if (x <= bendIn || x >= bendOut + BendLength)
+ {
+ return (far, 0.0);
+ }
+ if (x >= couplerStart && x <= bendOut)
+ {
+ return (near, 0.0);
+ }
+ // along the bend from the far end (t = 0) to the near end (t = 1)
+ double t = x < couplerStart ? (x - bendIn) / BendLength : 1.0 - (x - bendOut) / BendLength;
+ double sign = x < couplerStart ? 1.0 : -1.0;
+ double offset = far - (far - near) * BendShare(t);
+ double slope = -sign * (far - near) * (1.0 - Math.Cos(2.0 * Math.PI * t)) / BendLength;
+ return (offset, slope);
+ }
+
+ private static LogicGateDesign? Create(double wavelength, double coreIndex, double claddingIndex, int portSpacing, double phaseShift)
+ {
+ if (!(wavelength > 0.0) || !(coreIndex > claddingIndex))
+ {
+ Logger.Debug("Logic gate: no guided mode for λ {Wavelength} px, core {Core}, cladding {Cladding}", wavelength, coreIndex, claddingIndex);
+ return null;
+ }
+ double omega = WaveguideModes.Omega(wavelength);
+ // single mode: the slab's cut-off of the second mode is at w = λ / (2 NA); stay at nine tenths of it, in whole pixels
+ double aperture = Math.Sqrt(coreIndex * coreIndex - claddingIndex * claddingIndex);
+ int width = Math.Max(2, (int)Math.Floor(0.9 * wavelength / (2.0 * aperture)));
+ double? single = SingleBeta(wavelength, omega, coreIndex, claddingIndex, width, 0);
+ if (single is not { } beta)
+ {
+ Logger.Debug("Logic gate: a {Width} px core guides nothing at λ {Wavelength} px", width, wavelength);
+ return null;
+ }
+ // the cladding reaches three decay lengths past the core: the field decays as e^(−γ|y|), γ² ≈ μ − Ω n_cl² for slow decay
+ double mu = Mu(beta);
+ double gamma = Math.Sqrt(Math.Max(1e-9, mu - omega * claddingIndex * claddingIndex));
+ int cladding = Math.Max(2, (int)Math.Ceiling(3.0 / gamma));
+ int absorber = Math.Max(2, (int)Math.Ceiling(MinAbsorber * wavelength));
+ // the modes see the cladding index out to the narrowest absorbing band's rim (its damping is left out: the field there is
+ // e^-3 of the core's); a wider band, from a wider port spacing, changes them by nothing that counts
+ int outer = cladding + absorber;
+ // the phase section: the leading arm's core raised by the step, or, where that would pass the largest index, the other
+ // arm's lowered by it; either way the leading wave gains the shift on the other
+ bool lowered = coreIndex + PhaseIndexStep > Model.OpticalPart.MaxIndex + 1e-9;
+ bool bLeads = phaseShift >= 0.0;
+ bool phaseOnA = bLeads == lowered;
+ double phaseIndex = Math.Round(lowered ? coreIndex - PhaseIndexStep : coreIndex + PhaseIndexStep, 2);
+ double singleBeta = SingleBeta(wavelength, omega, coreIndex, claddingIndex, width, outer) ?? beta;
+ double phaseBeta = phaseIndex > claddingIndex ? SingleBeta(wavelength, omega, phaseIndex, claddingIndex, width, outer) ?? singleBeta : singleBeta;
+ double phaseStep = Math.Abs(phaseBeta - singleBeta);
+ if (phaseStep < 1e-6)
+ {
+ Logger.Debug("Logic gate: a phase section of index {Index} shifts nothing at λ {Wavelength} px", phaseIndex, wavelength);
+ return null;
+ }
+ int regionLength = Math.Max(1, (int)Math.Round(Math.PI / 2.0 / phaseStep));
+ int phaseLength = Math.Min(regionLength, (int)Math.Round(Math.Abs(phaseShift) * Math.PI / 180.0 / phaseStep));
+ double radius = BendLossExponent * 1.5 * singleBeta * singleBeta / (gamma * gamma * gamma);
+ // the gap: from one decay length up, in steps of two pixels (the coupled spacing stays even), until the bends' share of
+ // the coupling is at most BendShareLimit; the straight coupler, whose κ the solver gives exactly, takes the rest
+ int gap = Math.Max(2, (int)Math.Round(1.0 / gamma));
+ gap += (width + gap) % 2;
+ int coupled, spacing, bendLength;
+ double kappa, bend;
+ while (true)
+ {
+ coupled = width + gap;
+ // the arms' claddings apart at the ports, and room for the narrowest absorbing band out to half the spacing past them
+ spacing = Math.Max(portSpacing, Math.Max(coupled + width + 2 * cladding + 2, (int)Math.Ceiling(width + 2.0 * (cladding + absorber))));
+ spacing += spacing % 2;
+ // the S-bend's smallest radius L² / (2π Δ) is the radius above
+ bendLength = Math.Max(1, (int)Math.Ceiling(Math.Sqrt(2.0 * Math.PI * radius * (spacing - coupled) / 2.0)));
+ kappa = KappaAt(coupled, omega, coreIndex, claddingIndex, width, outer);
+ bend = BendKappa(coupled, spacing, bendLength, omega, coreIndex, claddingIndex, width, outer);
+ if (2.0 * bend <= BendShareLimit * Math.PI / 4.0 || gap >= 2 * cladding)
+ {
+ break;
+ }
+ gap += 2;
+ }
+ int couplerLength = kappa > 0.0 ? Math.Max(0, (int)Math.Round((Math.PI / 4.0 - CouplingExcess - 2.0 * bend) / kappa)) : 0;
+ Logger.Debug("Logic gate for λ {Wavelength} px, shift {Shift}°: core {Width} px, cladding {Cladding} px, gap {Gap} px, β {Beta:0.00000}, κ {Kappa:0.00000}/px, bends add {Bend:0.000} rad, coupler {Coupler} px, phase section {Phase} of {Region} px on arm {Arm}, bends {BendLength} px of radius {Radius:0} px",
+ wavelength, phaseShift, width, cladding, gap, singleBeta, kappa, 2.0 * bend, couplerLength, phaseLength, regionLength, phaseOnA ? "A" : "B", bendLength, radius);
+ return new LogicGateDesign
+ {
+ Wavelength = wavelength,
+ CoreIndex = coreIndex,
+ CladdingIndex = claddingIndex,
+ CoreWidth = width,
+ CladdingThickness = cladding,
+ PortSpacing = spacing,
+ CoupledSpacing = coupled,
+ InputLength = (int)Math.Round(wavelength / 2.0),
+ LeadLength = (int)Math.Round(wavelength),
+ PhaseRegionLength = regionLength,
+ PhaseLength = phaseLength,
+ PhaseShift = phaseShift,
+ BendLength = bendLength,
+ CouplerLength = couplerLength,
+ OutputLength = (int)Math.Round(3.0 * wavelength),
+ OutputRampLength = (int)Math.Round(2.0 * wavelength),
+ PhaseOnArmA = phaseOnA,
+ PhaseIndex = phaseIndex,
+ Beta = singleBeta,
+ Kappa = kappa,
+ BendCoupling = 2.0 * bend,
+ };
+ }
+
+ /// <summary>The coupling one S-bend adds, ∫κ dz over its spacing profile from <paramref name="spacing"/> to <paramref name="coupled"/> (Simpson).</summary>
+ private static double BendKappa(int coupled, int spacing, int bendLength, double omega, double coreIndex, double claddingIndex, int width, int outer)
+ {
+ double sum = 0.0;
+ for (int i = 0; i <= BendSamples; i++)
+ {
+ double t = (double)i / BendSamples;
+ double distance = spacing - (spacing - coupled) * BendShare(t);
+ double weight = i == 0 || i == BendSamples ? 1.0 : i % 2 == 1 ? 4.0 : 2.0;
+ sum += weight * KappaAt(distance, omega, coreIndex, claddingIndex, width, outer);
+ }
+ return sum * bendLength / (3.0 * BendSamples);
+ }
+
+ /// <summary>The longitudinal stencil term μ(β) = cos(2β) / 6 − 8 cos(β) / 3 + 5 / 2.</summary>
+ private static double Mu(double beta) => Math.Cos(2.0 * beta) / 6.0 - 8.0 * Math.Cos(beta) / 3.0 + 2.5;
+
+ /// <summary>β of one core of <paramref name="width"/> and <paramref name="coreIndex"/> in its cladding (a band of the cladding index wide enough when <paramref name="cladding"/> is 0), index 1 beyond.</summary>
+ private static double? SingleBeta(double wavelength, double omega, double coreIndex, double claddingIndex, int width, int cladding)
+ {
+ double reach = cladding > 0 ? cladding : 2.0 * wavelength;
+ int half = (int)Math.Ceiling(width / 2.0 + reach + 8);
+ double[] rows = WaveguideModes.Rows(-half, 2 * half, y =>
+ Math.Abs(y) <= width / 2.0 ? coreIndex : Math.Abs(y) <= width / 2.0 + reach ? claddingIndex : 1.0);
+ return WaveguideModes.Beta(rows, omega, false);
+ }
+
+ /// <summary>κ = (β_even − β_odd) / 2 of the two cores <paramref name="distance"/> apart (centre to centre), each in its cladding, index 1 beyond.</summary>
+ private static double KappaAt(double distance, double omega, double coreIndex, double claddingIndex, int width, int cladding)
+ {
+ double core = width / 2.0;
+ double outer = core + cladding;
+ int half = (int)Math.Ceiling(distance / 2.0 + outer + 8);
+ double[] rows = WaveguideModes.Rows(-half, 2 * half, y =>
+ {
+ double nearest = Math.Min(Math.Abs(y - distance / 2.0), Math.Abs(y + distance / 2.0));
+ return nearest <= core ? coreIndex : nearest <= outer ? claddingIndex : 1.0;
+ });
+ double? even = WaveguideModes.Beta(rows, omega, false);
+ double? odd = WaveguideModes.Beta(rows, omega, true);
+ return even is { } e && odd is { } o ? Math.Max(0.0, (e - o) / 2.0) : 0.0;
+ }
+}
diff --git a/WaveDudeNext/Parts/PartPainter.cs b/WaveDudeNext/Parts/PartPainter.cs
index 2664796..0c6d401 100644
--- a/WaveDudeNext/Parts/PartPainter.cs
+++ b/WaveDudeNext/Parts/PartPainter.cs
@@ -115,6 +115,10 @@ public static class PartPainter
{
PaintAbsorption(bgra, stride, shape, x0, y0, x1, y1);
}
+ if (!shape.PaintsIndex)
+ {
+ return;
+ }
if (shape.IsMirror)
{
Parallel.For(y0, y1 + 1, y =>
@@ -185,7 +189,8 @@ public static class PartPainter
/// <summary>
/// Paints a part's absorption into the blue channel: at a pixel whose centre lies at depth δ inside the outline,
- /// round(<see cref="PartShape.Absorption"/> × <see cref="PartShape.AbsorptionProfile"/>(δ / ramp)), the ramp being
+ /// round(<see cref="PartShape.Absorption"/> × <see cref="PartShape.AbsorptionProfile"/>(δ / ramp)) (or the shape's own
+ /// <see cref="PartShape.AbsorptionShareAt"/>), the ramp being
/// the part's, shortened to the deepest pixel centre when the part is thinner than twice it (so a thin part still
/// reaches its full absorption in its middle). The larger of that and the blue already there is kept, so a part
/// never lowers the damping of the image or of an earlier part. The profile is continuous and 0 at the outline, so
@@ -226,7 +231,7 @@ public static class PartPainter
if (depth >= 0f)
{
int offset = y * stride + x * 4;
- int blue = (int)Math.Round(full * PartShape.AbsorptionProfile(ramp > 0.0 ? depth / ramp : 1.0));
+ int blue = (int)Math.Round(full * shape.AbsorptionShareAt(x + 0.5, y + 0.5, depth, ramp));
bgra[offset] = (byte)Math.Max(bgra[offset], blue);
}
}
diff --git a/WaveDudeNext/Parts/PartShape.cs b/WaveDudeNext/Parts/PartShape.cs
index 6bf0f45..90e17ec 100644
--- a/WaveDudeNext/Parts/PartShape.cs
+++ b/WaveDudeNext/Parts/PartShape.cs
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
+// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Alexander Graef <[email protected]>
//
// This file is part of WaveDude Next, a 2D wave simulator.
@@ -58,6 +58,8 @@ public abstract class PartShape
FiberPart fiber => fiber.Points.Count < 2 ? null : new FiberShape(fiber),
BraggReflectorPart bragg => new BraggShape(bragg),
GrinLensPart grin => new GrinShape(grin),
+ LogicGatePart gate => gate.Design is { } design ? new LogicGateShape(gate, design) : null,
+ ZonePlatePart plate => double.IsFinite(plate.Wavelength) && plate.Wavelength > 0.0 ? new ZonePlateShape(plate) : null,
_ => null,
};
}
@@ -91,6 +93,18 @@ public abstract class PartShape
return t * t;
}
+ /// <summary>
+ /// The share of <see cref="Absorption"/> the painter gives the canvas point (<paramref name="canvasX"/>,
+ /// <paramref name="canvasY"/>), which lies <paramref name="depth"/> pixels inside the outline: by default
+ /// <see cref="AbsorptionProfile"/> of the depth over <paramref name="ramp"/>, rising inward. A shape that absorbs at
+ /// its rim instead (a logic gate's cladding) overrides it.
+ /// </summary>
+ public virtual double AbsorptionShareAt(double canvasX, double canvasY, double depth, double ramp) =>
+ AbsorptionProfile(ramp > 0.0 ? depth / ramp : 1.0);
+
+ /// <summary>Whether the part paints a refractive index into the red channel; false for a part that only absorbs (a zone plate), whose red stays as it was.</summary>
+ public virtual bool PaintsIndex => true;
+
/// <summary>
/// Whether the index steps somewhere inside the outline (a Bragg stack's layers), so a pixel well inside still
/// needs its samples; false where the inside is one index or varies smoothly (the GRIN profile).
@@ -392,4 +406,141 @@ public abstract class PartShape
return _centreIndex - (_centreIndex - _edgeIndex) * t * t;
}
}
+
+ /// <summary>
+ /// A zone plate (<see cref="ZonePlatePart"/>): the plate's rectangle, its blocks absorbing and nothing painted into the
+ /// red channel. A block's absorption rises from nothing at the faces across the axis (x' = ±thickness / 2) over the
+ /// anti-reflection depth, shortened to half the thickness; its sides toward the open zones are sharp. The mount, when on,
+ /// is a block beyond the diameter out to the outer half-width.
+ /// </summary>
+ private sealed class ZonePlateShape : PartShape
+ {
+ private readonly ZonePlatePart _plate;
+ private readonly double _halfThickness;
+ private readonly double _halfDiameter;
+ private readonly double _outerHalfWidth;
+ private readonly double _ramp;
+
+ public ZonePlateShape(ZonePlatePart plate) : base(plate)
+ {
+ // a copy, so the painter's threads read values that do not change under them
+ _plate = (ZonePlatePart)plate.Clone();
+ _halfThickness = Math.Max(1, plate.Thickness) / 2.0;
+ _halfDiameter = Math.Max(2, plate.Diameter) / 2.0;
+ _outerHalfWidth = plate.OuterHalfWidth;
+ _ramp = Math.Min(Math.Max(0, plate.Coating), _halfThickness);
+ }
+
+ public override bool IsMirror => false;
+ protected override int Coating => 0;
+ public override bool PaintsIndex => false;
+ public override int Absorption => ZonePlatePart.BlockAbsorption;
+ public override int AbsorptionRamp => Math.Max(1, (int)Math.Ceiling(_ramp));
+ protected override double Extent => Math.Sqrt(_halfThickness * _halfThickness + _outerHalfWidth * _outerHalfWidth);
+ protected override double Depth(double x, double y) => Math.Min(_halfThickness - Math.Abs(x), _outerHalfWidth - Math.Abs(y));
+ protected override double BodyIndex(double x, double y) => 1.0;
+
+ /// <summary>Nothing in an open zone; in a block or the mount, rising quadratically from the faces across the axis over the ramp.</summary>
+ public override double AbsorptionShareAt(double canvasX, double canvasY, double depth, double ramp)
+ {
+ (double x, double y) = ToFrame(canvasX, canvasY);
+ double across = Math.Abs(y);
+ if (across > _outerHalfWidth || across <= _halfDiameter && !_plate.IsBlockAt(y))
+ {
+ return 0.0;
+ }
+ double inside = _halfThickness - Math.Abs(x);
+ return _ramp > 0.0 ? AbsorptionProfile(inside / _ramp) : 1.0;
+ }
+ }
+
+ /// <summary>
+ /// A logic gate (<see cref="LogicGateDesign"/>): two arms mirrored about the axis, each a core in its cladding, cut square at
+ /// both ends; the distance from an arm is the offset across the axis times the cosine of the arm's slope, the first-order
+ /// distance to the curve (exact on the straight stretches, within a few percent of a pixel in the gentle bends). The
+ /// cladding's outer band absorbs, rising toward the rim (<see cref="LogicGateDesign.AbsorberWidth"/>), so light the
+ /// sources and the bends send into the cladding is not guided along it by the step to the scene outside. Each square
+ /// end the part selects carries its anti-reflection band (√n of the core and of the cladding, as a lens's coating), and
+ /// a switched-off output's arm absorbs over its last stretch.
+ /// </summary>
+ private sealed class LogicGateShape : PartShape
+ {
+ private readonly LogicGateDesign _design;
+ private readonly double _halfLength;
+ private readonly double _core;
+ private readonly double _outer;
+ private readonly double _coreIndex;
+ private readonly double _phaseIndex;
+ private readonly double _claddingIndex;
+ private readonly (double Start, double End) _phase;
+ private readonly int _endCoating;
+ private readonly bool _inputCoated;
+ private readonly bool _outputCoated;
+ private readonly bool _xorActive;
+ private readonly bool _sumActive;
+
+ public LogicGateShape(LogicGatePart gate, LogicGateDesign design) : base(gate)
+ {
+ _design = design;
+ _halfLength = design.Length / 2.0;
+ _core = design.CoreWidth / 2.0;
+ _outer = _core + design.CladdingThickness + design.AbsorberWidth;
+ _coreIndex = design.CoreIndex;
+ _phaseIndex = design.PhaseIndex;
+ _claddingIndex = design.CladdingIndex;
+ _phase = design.PhaseSection;
+ _endCoating = GuardCoating(gate.Coating);
+ _inputCoated = gate.InputCoated;
+ _outputCoated = gate.OutputCoated;
+ _xorActive = gate.UpperOutputActive;
+ _sumActive = gate.LowerOutputActive;
+ }
+
+ public override bool IsMirror => false;
+ protected override int Coating => 0;
+ public override int Absorption => LogicGateDesign.Absorption;
+ public override int AbsorptionRamp => Math.Max(1, (int)Math.Ceiling(_design.AbsorberWidth));
+ public override bool HasInnerEdges => true;
+ protected override double Extent => Math.Sqrt(_halfLength * _halfLength + _design.HalfWidth * _design.HalfWidth);
+
+ /// <summary>
+ /// Full at the cladding's side rim, falling quadratically to nothing <see cref="AbsorptionRamp"/> pixels in; and in the
+ /// arm of a switched-off output, rising quadratically from nothing over the output ramp to full at the right end. The
+ /// input ends and an active output do not absorb, so light comes in and goes out.
+ /// </summary>
+ public override double AbsorptionShareAt(double canvasX, double canvasY, double depth, double ramp)
+ {
+ (double x, double y) = ToFrame(canvasX, canvasY);
+ (double distance, bool armB) = Nearest(x, y);
+ double inside = _outer - distance;
+ if (inside < 0.0 || Math.Abs(x) > _halfLength)
+ {
+ return 0.0;
+ }
+ double side = AbsorptionProfile(1.0 - inside / _design.AbsorberWidth);
+ double output = (armB ? _sumActive : _xorActive) ? 0.0 : AbsorptionProfile((x - _design.OutputRampStart) / _design.OutputRampLength);
+ return Math.Max(side, output);
+ }
+
+ /// <summary>The distance from the nearer arm's centre line, and whether that arm is B (below the axis).</summary>
+ private (double Distance, bool ArmB) Nearest(double x, double y)
+ {
+ (double offset, double slope) = _design.ArmOffsetAndSlope(x);
+ double cos = 1.0 / Math.Sqrt(1.0 + slope * slope);
+ return (Math.Abs(Math.Abs(y) - offset) * cos, y > 0.0);
+ }
+
+ protected override double Depth(double x, double y) => Math.Min(_halfLength - Math.Abs(x), _outer - Nearest(x, y).Distance);
+
+ /// <summary>The core, the phase section on its arm, or the cladding; within the coating's thickness of a coated end (the input at −x, the output at +x), √n of it rounded to 0.01.</summary>
+ protected override double BodyIndex(double x, double y)
+ {
+ (double distance, bool armB) = Nearest(x, y);
+ double index = distance > _core ? _claddingIndex
+ : armB != _design.PhaseOnArmA && x >= _phase.Start && x < _phase.End ? _phaseIndex
+ : _coreIndex;
+ bool coated = x < 0.0 ? _inputCoated : _outputCoated;
+ return coated && _endCoating > 0 && _halfLength - Math.Abs(x) < _endCoating ? Math.Round(Math.Sqrt(index), 2) : index;
+ }
+ }
}
diff --git a/WaveDudeNext/Parts/WaveguideModes.cs b/WaveDudeNext/Parts/WaveguideModes.cs
new file mode 100644
index 0000000..4a4d8ec
--- /dev/null
+++ b/WaveDudeNext/Parts/WaveguideModes.cs
@@ -0,0 +1,238 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 Alexander Graef <[email protected]>
+//
+// This file is part of WaveDude Next, a 2D wave simulator.
+//
+// Based on the work of
+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
+// 0x23 (Diffraction Limited), author of WaveSimulator2D
+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
+//
+// WaveDude Next is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation, either version 3 of the License, or (at your option) any later
+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
+// <https://www.gnu.org/licenses/>.
+
+using WaveDudeNext.Engine;
+
+namespace WaveDudeNext.Parts;
+
+/// <summary>
+/// The guided modes of a straight waveguide as the engines see it: the transverse index profile is one value per
+/// pixel row, and the mode is a solution of the engine's own discrete equations, not of the continuous wave
+/// equation, so a design built on it holds on the grid. A mode u(x, y, t) = φ(y)·e^{i(βx − ωt)} of the 4th-order
+/// stencil (<see cref="Model.Simulation.FourthOrderLaplacian"/>) with the leapfrog's sub-steps satisfies
+/// L_y φ + Ω n²(y) φ = μ(β) φ, where L_y is the stencil's transverse part, Ω = 4S² sin²(ω / 2S) the leapfrog's
+/// frequency term for S sub-steps per step, and μ(β) = cos(2β) / 6 − 8 cos(β) / 3 + 5 / 2 the stencil's
+/// longitudinal part. The largest eigenvalue μ of the given symmetry is the fundamental mode. Units: pixels, steps,
+/// radians. Pure arithmetic; any thread.
+/// </summary>
+public static class WaveguideModes
+{
+ /// <summary>
+ /// The leapfrog's frequency term Ω = 4S² sin²(ω / 2S) of a wave of <paramref name="wavelength"/> pixels in a medium
+ /// of index 1 (ω = 2π / λ radians per step, the source form's nominal wavelength), with the sub-step count the
+ /// engines use on a scene whose fastest pixel has index 1.
+ /// </summary>
+ public static double Omega(double wavelength)
+ {
+ int subSteps = WaveSimulator.ComputeSubSteps(1f);
+ double s = Math.Sin(2.0 * Math.PI / wavelength / (2.0 * subSteps));
+ return 4.0 * subSteps * subSteps * s * s;
+ }
+
+ /// <summary>
+ /// The propagation constant β (radians per pixel) of the fundamental even (<paramref name="odd"/> false) or odd mode
+ /// of the index profile <paramref name="index"/>, one value per pixel row, the field 0 beyond both ends; null when no
+ /// mode of that symmetry is guided (its μ does not exceed the edge rows' Ω n²). The symmetry is about the middle of
+ /// the array: row j mirrors row length − 1 − j, so the profile should be symmetric for an odd mode to mean anything.
+ /// </summary>
+ public static double? Beta(double[] index, double omega, bool odd)
+ {
+ int n = index.Length;
+ double[] potential = new double[n];
+ double top = 0.0;
+ for (int j = 0; j < n; j++)
+ {
+ potential[j] = omega * index[j] * index[j];
+ top = Math.Max(top, potential[j]);
+ }
+ // A = L_y + diag(Ω n²) is at most max Ω n² (L_y is negative semi-definite), so σI − A is positive definite
+ // and inverse iteration with it converges on the largest eigenvalue of the chosen symmetry
+ double sigma = top + 1e-9;
+ (double[] l0, double[] l1, double[] l2) = Cholesky(potential, sigma);
+ double[] x = new double[n];
+ for (int j = 0; j < n; j++)
+ {
+ double t = (j + 0.5) / n - 0.5;
+ x[j] = odd ? t : 1.0 - t * t;
+ }
+ double mu = double.NaN;
+ for (int iteration = 0; iteration < 400; iteration++)
+ {
+ Symmetrise(x, odd);
+ Normalise(x);
+ double next = Rayleigh(x, potential);
+ if (Math.Abs(next - mu) < 1e-15)
+ {
+ mu = next;
+ break;
+ }
+ mu = next;
+ Solve(l0, l1, l2, x);
+ }
+ double edge = Math.Max(potential[0], potential[n - 1]);
+ if (!(mu > edge))
+ {
+ return null;
+ }
+ return BetaOf(mu);
+ }
+
+ /// <summary>The β in (0, π) whose longitudinal stencil term cos(2β) / 6 − 8 cos(β) / 3 + 5 / 2 is <paramref name="mu"/> (rising monotonically from 0 to 16/3).</summary>
+ public static double BetaOf(double mu)
+ {
+ double low = 0.0;
+ double high = Math.PI;
+ for (int i = 0; i < 100; i++)
+ {
+ double mid = (low + high) / 2.0;
+ if (Math.Cos(2.0 * mid) / 6.0 - 8.0 * Math.Cos(mid) / 3.0 + 2.5 < mu)
+ {
+ low = mid;
+ }
+ else
+ {
+ high = mid;
+ }
+ }
+ return (low + high) / 2.0;
+ }
+
+ /// <summary>
+ /// The index of each pixel row as the painter paints a horizontal band structure: <paramref name="profile"/> sampled
+ /// at the four sub-rows of each row, averaged and rounded to 0.01 (red = index × 100). Row j spans
+ /// [<paramref name="first"/> + j, <paramref name="first"/> + j + 1) in the part frame.
+ /// </summary>
+ public static double[] Rows(int first, int count, Func<double, double> profile)
+ {
+ double[] rows = new double[count];
+ for (int j = 0; j < count; j++)
+ {
+ double sum = 0.0;
+ for (int k = 0; k < PartPainter.Supersample; k++)
+ {
+ sum += profile(first + j + (k + 0.5) / PartPainter.Supersample);
+ }
+ rows[j] = Math.Round(sum / PartPainter.Supersample, 2);
+ }
+ return rows;
+ }
+
+ /// <summary>Banded Cholesky factor of σI − A (A = L_y + diag(potential)), the bands of L: the diagonal, the first and the second sub-diagonal.</summary>
+ private static (double[] L0, double[] L1, double[] L2) Cholesky(double[] potential, double sigma)
+ {
+ int n = potential.Length;
+ double[] l0 = new double[n];
+ double[] l1 = new double[n];
+ double[] l2 = new double[n];
+ // σI − A: diagonal σ + 5/2 − Ω n², first off-diagonal −4/3, second +1/12
+ const double near = -4.0 / 3.0;
+ const double far = 1.0 / 12.0;
+ for (int j = 0; j < n; j++)
+ {
+ if (j >= 2)
+ {
+ l2[j] = far / l0[j - 2];
+ }
+ if (j >= 1)
+ {
+ double sum = near - (j >= 2 ? l2[j] * l1[j - 1] : 0.0);
+ l1[j] = sum / l0[j - 1];
+ }
+ double diagonal = sigma + 2.5 - potential[j] - l1[j] * l1[j] - l2[j] * l2[j];
+ l0[j] = Math.Sqrt(diagonal);
+ }
+ return (l0, l1, l2);
+ }
+
+ /// <summary>Overwrites <paramref name="x"/> with (L Lᵀ)⁻¹ x.</summary>
+ private static void Solve(double[] l0, double[] l1, double[] l2, double[] x)
+ {
+ int n = x.Length;
+ for (int j = 0; j < n; j++)
+ {
+ double sum = x[j];
+ if (j >= 1)
+ {
+ sum -= l1[j] * x[j - 1];
+ }
+ if (j >= 2)
+ {
+ sum -= l2[j] * x[j - 2];
+ }
+ x[j] = sum / l0[j];
+ }
+ for (int j = n - 1; j >= 0; j--)
+ {
+ double sum = x[j];
+ if (j + 1 < n)
+ {
+ sum -= l1[j + 1] * x[j + 1];
+ }
+ if (j + 2 < n)
+ {
+ sum -= l2[j + 2] * x[j + 2];
+ }
+ x[j] = sum / l0[j];
+ }
+ }
+
+ /// <summary>xᵀ A x for a unit x.</summary>
+ private static double Rayleigh(double[] x, double[] potential)
+ {
+ int n = x.Length;
+ double sum = 0.0;
+ for (int j = 0; j < n; j++)
+ {
+ double at(int k) => k >= 0 && k < n ? x[k] : 0.0;
+ double ax = -(at(j - 2) + at(j + 2)) / 12.0 + 4.0 * (at(j - 1) + at(j + 1)) / 3.0 - 2.5 * x[j] + potential[j] * x[j];
+ sum += x[j] * ax;
+ }
+ return sum;
+ }
+
+ /// <summary>Projects <paramref name="x"/> onto the even or odd vectors about the middle of the array.</summary>
+ private static void Symmetrise(double[] x, bool odd)
+ {
+ int n = x.Length;
+ for (int j = 0; j < n / 2; j++)
+ {
+ double a = x[j];
+ double b = x[n - 1 - j];
+ x[j] = odd ? (a - b) / 2.0 : (a + b) / 2.0;
+ x[n - 1 - j] = odd ? -x[j] : x[j];
+ }
+ if (n % 2 == 1 && odd)
+ {
+ x[n / 2] = 0.0;
+ }
+ }
+
+ /// <summary>Scales <paramref name="x"/> to unit length.</summary>
+ private static void Normalise(double[] x)
+ {
+ double sum = 0.0;
+ foreach (double v in x)
+ {
+ sum += v * v;
+ }
+ double scale = 1.0 / Math.Sqrt(sum);
+ for (int j = 0; j < x.Length; j++)
+ {
+ x[j] *= scale;
+ }
+ }
+}
diff --git a/Wave_Dude_Examples/logical_elements_example.wdproj b/Wave_Dude_Examples/logical_elements_example.wdproj
new file mode 100644
index 0000000..7c35901
--- /dev/null
+++ b/Wave_Dude_Examples/logical_elements_example.wdproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project Version="2" Seed="1083267589">
+ <Simulation Steps="7000" />
+ <Display>
+ <Field ColorScheme="Default field" BlackLevel="-0.05" Preview="false" />
+ <Intensity ColorScheme="Default intensity" Brightness="3" />
+ </Display>
+ <Source Name="Source 1" X="367" Y="663" Frequency="50" Mode="Pulsed" PulseShape="SmoothedSquare" />
+ <Source Name="Source 2" X="367" Y="723" Frequency="50" Mode="Pulsed" PulseShape="SmoothedSquare" PulseWidth="20" OffWidth="20" />
+ <Source Name="Source 3" X="367" Y="542" Frequency="50" PulseShape="SmoothedSquare" />
+ <Source Name="Source 4" X="366" Y="603" Frequency="50" Mode="Pulsed" PulseShape="SmoothedSquare" OffWidth="20" />
+ <XorGate Name="XOR gate 1" X="629" Y="574" Coating="0" OutputCoated="false" UpperOutputActive="false" />
+ <Rectangle Name="Rectangle 1" X="322" Y="643" Absorption="255" Length="74" Width="274" />
+ <Rectangle Name="Rectangle 1 copy" X="1440" Y="645" Absorption="255" Length="74" Width="274" />
+ <AndGate Name="AND gate 2" X="626" Y="694" OutputCoated="false" LowerOutputActive="false" />
+ <XorGate Name="XOR gate 2" X="1161" Y="634" Coating="0" InputCoated="false" />
+ <Probe Name="Probe 1" Layer="Intensity" Measurement="Value" AX="1363" AY="663" BoxSize="ExtraLarge" BoxX="1092" BoxY="25" AutoScaleY="false" YMin="0" YMax="0.2" Window="1500" />
+ <Probe Name="Probe 1 copy" Layer="Intensity" Measurement="Value" AX="823" AY="722" BoxSize="ExtraLarge" BoxX="247" BoxY="24" AutoScaleY="false" YMin="0" YMax="0.05" Window="1500" />
+</Project>
\ No newline at end of file
diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.cs
index 190e338..57c8444 100644
--- a/_tools/library_check/Program.cs
+++ b/_tools/library_check/Program.cs
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
+// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Alexander Graef <[email protected]>
//
// This file is part of WaveDude Next, a 2D wave simulator.
@@ -266,6 +266,8 @@ internal static class Program
CheckImport();
CheckParts();
CheckAbsorbingParts();
+ CheckXorGate();
+ CheckZonePlate();
CheckBrightnessFit();
CheckRun();
ExportChecks.Run(Check);
@@ -2131,6 +2133,7 @@ internal static class Program
OpticalPart copy = project.Duplicate(reflector);
Check(copy is BraggReflectorPart { Name: "Bragg reflector 1 copy", Angle: 45, Index2: 2.2 } && project.Parts.IndexOf(copy) == 8 && project.Parts.Count == 10, "Duplicate: a deep copy right after the original, named '… copy'");
Check(project.Remove(copy) && project.Move(reflector, 0) && project.Parts[0] == reflector && project.Parts.Count == 9, "Remove and Move work on the parts list");
+ ((XorGatePart)project.AddPart(PartKind.XorGate)).DesignFrequency = 80;
string xml;
using (var stream = new MemoryStream())
{
@@ -2143,13 +2146,15 @@ internal static class Program
"an outline's points are Point children");
Check(xml.Contains("<Polygon Name=\"Polygon 1\" X=\"100\" Y=\"60\" />") && xml.Contains("<Rectangle Name=\"Rectangle 1\" X=\"100\" Y=\"60\" Width=\"7\" />") && xml.Contains("<Ellipse Name=\"Ellipse 1\" X=\"100\" Y=\"60\" Length=\"9\" Width=\"9\" Linked=\"true\" />") && xml.Contains("<Triangle Name=\"Triangle 1\" X=\"100\" Y=\"60\" Type=\"RightIsosceles\" AngleA=\"45\" AngleB=\"45\" />"),
"the polygon, rectangle, ellipse and triangle elements, sparse");
+ Check(xml.Contains("<XorGate Name=\"XOR gate 1\" X=\"100\" Y=\"60\" DesignFrequency=\"80\" />"), "the XOR gate element, sparse");
Check(xml.IndexOf("<Source", StringComparison.Ordinal) < 0 && xml.IndexOf("<Lens", StringComparison.Ordinal) < xml.IndexOf("<Probe", StringComparison.Ordinal) || !xml.Contains("<Probe"), "the parts sit between the sources and the probes");
Project back;
using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xml)))
{
back = Project.Load(stream);
}
- Check(back.Parts.Count == 9 && back.Parts.Select(p => p.Kind).SequenceEqual([PartKind.BraggReflector, PartKind.Lens, PartKind.Outline, PartKind.Polygon, PartKind.Rectangle, PartKind.Ellipse, PartKind.Triangle, PartKind.Fiber, PartKind.GrinLens]), "the nine kinds load back in order");
+ Check(back.Parts.Count == 10 && back.Parts.Select(p => p.Kind).SequenceEqual([PartKind.BraggReflector, PartKind.Lens, PartKind.Outline, PartKind.Polygon, PartKind.Rectangle, PartKind.Ellipse, PartKind.Triangle, PartKind.Fiber, PartKind.GrinLens, PartKind.XorGate])
+ && back.Parts[9] is XorGatePart { DesignFrequency: 80 }, "the ten kinds load back in order");
Check(back.Parts[7] is FiberPart { Points.Count: 2 } loaded && loaded.Points[0].X == -100 && loaded.Points[1].X == 100, "a loaded fibre has its two points, not the default path on top of them");
Check(back.Parts[2] is OutlinePart { Mirror: true, Points.Count: 1 } && back.Parts[0] is BraggReflectorPart { Angle: 45, Index2: 2.2, Pairs: 10 } && back.Parts[4] is RectanglePart { Width: 7, Length: 60 } && back.Parts[5] is EllipsePart { Width: 9, Length: 9, Linked: true } && back.Parts[6] is TrianglePart { Type: TriangleType.RightIsosceles, AngleB: 45 },
"a loaded outline keeps its point and mirror flag, the reflector its angle and index, the rectangle its width, the triangle its type");
@@ -2165,6 +2170,334 @@ internal static class Program
private static int BlueAt(ScenePixels pixels, int x, int y) => pixels.Bgra[y * pixels.StrideBytes + x * 4];
+ /// <summary>
+ /// The XOR gate (2026-10-21): the mode solver against a measured straight guide, the design scaling with the wavelength,
+ /// the painted layout, and the gate itself driven by sources on its inputs (on the GPU when there is one, the CPU is
+ /// slow at this size): one input splits about evenly, both cancel at the XOR output and double at the sum output.
+ /// </summary>
+ private static void CheckXorGate()
+ {
+ Console.WriteLine("--- XOR gate");
+ // β of a straight guide (core 1.6, 8 px, cladding 1.45 with an absorbing rim, as the gate paints it), solver and engine
+ const double lambda = 16.0;
+ {
+ int w = 600, h = 120, cy = 60;
+ var clad = new RectanglePart { Name = "k", X = w / 2, Y = cy, Length = w + 40, Width = 8 + 2 * 49, RefractiveIndex = 1.45 };
+ var core = new RectanglePart { Name = "c", X = w / 2, Y = cy, Length = w + 40, Width = 8, RefractiveIndex = 1.6 };
+ ScenePixels px = PartPainter.Paint(null, w, h, 1.0, [clad, core])!;
+ for (int y = 0; y < h; y++)
+ {
+ double depth = Math.Abs(y + 0.5 - cy) - 21.0;
+ for (int x = 0; x < w && depth > 0 && depth < 32; x++)
+ {
+ px.Bgra[y * px.StrideBytes + x * 4] = (byte)Math.Round(64 * (depth / 32) * (depth / 32));
+ }
+ }
+ var source = Make(20, cy, 0, 1.0) with { Level = 255.0 * 4.0 * Math.PI / (lambda * 2.0) };
+ var sim = new WaveSimulator(SceneData.FromBgra(px.Bgra, w, h, px.StrideBytes, false, 0, true), new EngineOptions(2.0, 1.0, false, true, 10.0, 1.0), [source]);
+ double omega = 2.0 * Math.PI / lambda;
+ var lockIn = new System.Numerics.Complex[2];
+ int steps = 1100, window = 320;
+ for (int s = 0; s < steps; s++)
+ {
+ sim.AdvanceOneStep();
+ if (s >= steps - window)
+ {
+ sim.PrepareFrame(true, false);
+ var phase = System.Numerics.Complex.FromPolarCoordinates(1.0, omega * s);
+ lockIn[0] += sim.FieldData[(cy + 1) * (w + 2) + 150 + 1] * phase;
+ lockIn[1] += sim.FieldData[(cy + 1) * (w + 2) + 450 + 1] * phase;
+ }
+ }
+ // the phase grows by β per pixel along the guide; 300 px of it, known up to whole turns, the β near 0.6
+ double turn = 2.0 * Math.PI / 300.0;
+ double measured = (lockIn[1].Phase - lockIn[0].Phase) / 300.0;
+ measured += turn * Math.Round((0.6 - measured) / turn);
+ double[] rows = WaveguideModes.Rows(-57, 114, y => Math.Abs(y) <= 4 ? 1.6 : Math.Abs(y) <= 53 ? 1.45 : 1.0);
+ double? solved = WaveguideModes.Beta(rows, WaveguideModes.Omega(lambda), false);
+ Check(solved is { } beta && Math.Abs(beta - measured) < 2e-3, $"the mode solver's β {solved:0.00000} matches the engine's guide, {measured:0.00000} rad/px");
+ }
+
+ // the design follows the wavelength
+ LogicGateDesign? short_ = LogicGateDesign.For(12, 1.6, 1.45, 64, 90), standard = LogicGateDesign.For(16, 1.6, 1.45, 64, 90), long_ = LogicGateDesign.For(32, 1.6, 1.45, 64, 90);
+ Check(short_ != null && standard != null && long_ != null && short_.CoreWidth < standard.CoreWidth && standard.CoreWidth < long_.CoreWidth
+ && new[] { short_, standard, long_ }.All(d => d.PortSpacing % 2 == 0 && d.CoupledSpacing % 2 == 0 && d.CouplerLength > 0)
+ && long_.Length > standard.Length && long_.PortSpacing > 64,
+ $"the core widens with the wavelength ({short_?.CoreWidth}, {standard?.CoreWidth}, {long_?.CoreWidth} px at 12, 16, 32), even spacings, the ports pushed apart when the design needs it");
+ Check(new XorGatePart().Design is { Length: < 650 } && new XorGatePart { DesignFrequency = 100, CoreIndex = 2.0 }.Design is { Length: < 500 },
+ $"the gate is short: {new XorGatePart().Design?.Length} px by default (frequency 50, λ 32, core 2.55), {new XorGatePart { DesignFrequency = 100, CoreIndex = 2.0 }.Design?.Length} px at frequency 100 (λ 16) with a core of 2.0");
+ Check(Math.Abs(new XorGatePart().Wavelength - Simulation.Wavelength(50, 1.0, 2.0)) < 1e-12 && Math.Abs(new XorGatePart { FrequencyScale = 4.0 }.Wavelength - new XorGatePart().Wavelength / 2.0) < 1e-9,
+ $"the wavelength follows from the design frequency and the frequency scale: {new XorGatePart().Wavelength:0.00} px at 50, half at twice the scale");
+ Check(LogicGateDesign.For(16, 1.45, 1.45, 64, 90) == null && new XorGatePart { CoreIndex = 1.4 }.Ports() == null, "no design when the core does not guide (core index not above the cladding's)");
+ Check(LogicGateDesign.For(32, 2.55, 1.45, 2, 90) is { PhaseOnArmA: true, PhaseIndex: 2.45, PhaseLength: > 0 and < 200 } && LogicGateDesign.For(32, 2.0, 1.45, 2, 90) is { PhaseOnArmA: false, PhaseIndex: 2.1 },
+ "a core at the largest index puts its phase section on arm A, lowered; below it the section raises arm B");
+ Check(new[] { new XorGatePart(), new XorGatePart { PortSpacing = 120 }, new XorGatePart { DesignFrequency = 100, CoreIndex = 2.0 } }
+ .All(g => g.Design is { } d && d.HalfWidth == d.PortSpacing && Math.Abs(g.Outline().Max(p => Math.Abs(p.Y)) - d.PortSpacing) < 1e-9 && d.AbsorberWidth >= LogicGateDesign.MinAbsorber * d.Wavelength - 1e-9),
+ $"the unit is twice the port spacing wide, its ports at a quarter and three quarters ({new XorGatePart().Design!.PortSpacing} px spacing, {2 * new XorGatePart().Design!.PortSpacing} px wide by default)");
+ {
+ // staggered tiling: two gates a port spacing above and below, one length on, take one output each, and touch
+ var first = new XorGatePart { X = 400, Y = 300 };
+ int s = first.Design!.PortSpacing, length = first.Design.Length;
+ var upper = new XorGatePart { X = 400 + length, Y = 300 - s };
+ var lower = new XorGatePart { X = 400 + length, Y = 300 + s };
+ Check(first.Ports()![2].Y == upper.Ports()![1].Y && first.Ports()![3].Y == lower.Ports()![0].Y
+ && upper.Outline().Max(p => upper.ToCanvas(p.X, p.Y).Y) == lower.Outline().Min(p => lower.ToCanvas(p.X, p.Y).Y),
+ "gates set a port spacing above and below the next column: the XOR output meets the upper gate's input B, the sum output the lower gate's input A, and the two touch");
+ }
+ Check(new XorGatePart { PortSpacing = 20 }.Design!.PortSpacing == new XorGatePart().Design!.PortSpacing && new XorGatePart { PortSpacing = 120 }.Design!.PortSpacing == 120,
+ $"a port spacing below the design's minimum ({new XorGatePart().Design!.PortSpacing} px) is raised to it, a larger one is used as typed");
+ Check(LogicGateDesign.BendShare(0) == 0 && Math.Abs(LogicGateDesign.BendShare(1) - 1) < 1e-12 && Math.Abs(LogicGateDesign.BendShare(0.5) - 0.5) < 1e-12,
+ "the S-bend runs from the ports' offset to the coupler's, symmetric about its middle");
+
+ // the painted layout of the default gate (core 2.55, cladding 1.45, λ 32; the phase section lowered on arm A)
+ var gate = new XorGatePart { Name = "g" };
+ LogicGateDesign design = gate.Design!;
+ // room on both sides: the open input ends let a source's backward wave out, and the canvas edge must not send it back
+ int width = design.Length + 400, height = (int)(2 * design.HalfWidth) + 200;
+ gate.X = width / 2;
+ gate.Y = height / 2;
+ ScenePixels painted = PartPainter.Paint(null, width, height, 1.0, [gate])!;
+ (int X, int Y)[] ports = gate.Ports()!;
+ int phaseX = gate.X + (int)((design.PhaseSection.Start + design.PhaseSection.End) / 2);
+ int end = gate.X + design.Length / 2 - 1;
+ Check(RedAt(painted, ports[0].X + 2, ports[0].Y) == 255 && RedAt(painted, ports[0].X + 2, ports[0].Y - design.CoreWidth / 2 - 3) == 145
+ && RedAt(painted, phaseX, ports[0].Y) == 245 && RedAt(painted, phaseX, ports[1].Y) == 255 && RedAt(painted, ports[2].X, ports[2].Y) == 255 && RedAt(painted, gate.X, 2) == 100,
+ "cores of 2.55 in a cladding of 1.45, the phase section of 2.45 on arm A only, the scene untouched beyond");
+ int start = gate.X - design.Length / 2 + 1;
+ Check(RedAt(painted, end, ports[2].Y) == 160 && RedAt(painted, end, ports[2].Y - design.CoreWidth / 2 - 3) == 120 && RedAt(painted, start, ports[0].Y) == 160
+ && RedAt(painted, end - gate.Coating - 1, ports[2].Y) == 255,
+ "both ends carry the AR band: √2.55 on the cores, √1.45 on the cladding, the coating's thickness deep");
+ gate.UpperOutputActive = false;
+ ScenePixels switched = PartPainter.Paint(null, width, height, 1.0, [gate])!;
+ gate.UpperOutputActive = true;
+ Check(BlueAt(switched, end, ports[2].Y) > 50 && BlueAt(switched, end, ports[3].Y) == 0 && BlueAt(switched, ports[2].X, ports[2].Y) == 0
+ && BlueAt(switched, end - design.OutputRampLength / 2, ports[2].Y) is > 5 and < 30,
+ $"a switched-off XOR output absorbs in its arm's last stretch, rising softly ({BlueAt(switched, end - design.OutputRampLength / 2, ports[2].Y)} halfway, {BlueAt(switched, end, ports[2].Y)} at the end); the sum arm and the port stay clear");
+ Check(BlueAt(painted, ports[0].X + 2, ports[0].Y) == 0 && BlueAt(painted, gate.X, gate.Y) == 0 && BlueAt(painted, ports[2].X, ports[2].Y) == 0
+ && BlueAt(painted, gate.X - design.Length / 2 + 1, ports[0].Y) == 0 && BlueAt(painted, ports[2].X, ports[2].Y - (int)(design.HalfWidth - design.PortSpacing / 2.0) + 1) > 50,
+ "no absorption along the cores, the coupler, the outputs or the open input ends; the cladding's rim absorbs");
+
+ // driven by sources on its inputs
+ SceneData scene = SceneData.FromBgra(painted.Bgra, width, height, painted.StrideBytes, false, 0, true);
+ double level = gate.DesignFrequency;
+ (double Xor, double Sum, double Past) Outputs(List<Emitter> emitters, SceneData? other = null)
+ {
+ SceneData run = other ?? scene;
+ var options = new EngineOptions(2.0, 1.0, false, true, 10.0, 1.0);
+ IWaveEngine engine = GpuWaveSimulator.TryCreate(run, options, emitters, out _) is { } gpu ? gpu : new WaveSimulator(run, options, emitters);
+ // the wave crosses the gate in about 1.6 steps a pixel; the rest lets it settle into a steady state; ten periods averaged
+ int lambda = (int)Math.Round(design.Wavelength);
+ int steps = 2 * design.Length + 60 * lambda, window = 10 * lambda, half = design.CoreWidth / 2 + 2;
+ int beyond = end + lambda;
+ double xor = 0, sum = 0, past = 0;
+ for (int s = 0; s < steps; s++)
+ {
+ engine.AdvanceOneStep();
+ if (s >= steps - window)
+ {
+ engine.PrepareFrame(true, false);
+ float[] u = engine.FieldData;
+ // over the core and half a wavelength along it
+ for (int dx = -lambda / 2; dx < lambda / 2; dx++)
+ {
+ for (int dy = -half; dy <= half; dy++)
+ {
+ float a = u[(ports[2].Y + dy + 1) * (width + 2) + ports[2].X + dx + 1];
+ float b = u[(ports[3].Y + dy + 1) * (width + 2) + ports[3].X + dx + 1];
+ xor += a * a;
+ sum += b * b;
+ }
+ }
+ // what leaves the outputs: a column a wavelength past the right end, a quarter of the unit's width about each
+ // output (the open input ends let a source's backward wave into the scene, which passes the gate outside)
+ foreach (int py in new[] { ports[2].Y, ports[3].Y })
+ {
+ for (int y = py - design.PortSpacing / 2; y < py + design.PortSpacing / 2; y++)
+ {
+ float c = u[(y + 1) * (width + 2) + beyond + 1];
+ past += c * c;
+ }
+ }
+ }
+ }
+ (engine as IDisposable)?.Dispose();
+ return (xor, sum, past);
+ }
+ var sw = System.Diagnostics.Stopwatch.StartNew();
+ (double xorA, double sumA, double pastA) = Outputs([Make(ports[0].X, ports[0].Y, 0, 1.0) with { Level = level }]);
+ (double xorAB, double sumAB, _) = Outputs([Make(ports[0].X, ports[0].Y, 0, 1.0) with { Level = level }, Make(ports[1].X, ports[1].Y, 0, 1.0) with { Level = level }]);
+ double single = xorA + sumA;
+ Check(Math.Abs(xorA / single - 0.5) < 0.1, $"one input splits about evenly: {xorA / single:0.000} to the XOR output");
+ CheckGatePortFollower();
+ Check(xorAB / single < 0.03 && sumAB / single > 1.8, $"both inputs: the XOR output keeps {xorAB / single:0.000} of one input's power, the sum output {sumAB / single:0.00}× ({sw.ElapsedMilliseconds} ms)");
+ gate.UpperOutputActive = false;
+ gate.LowerOutputActive = false;
+ ScenePixels closed = PartPainter.Paint(null, width, height, 1.0, [gate])!;
+ gate.UpperOutputActive = true;
+ gate.LowerOutputActive = true;
+ (_, _, double pastClosed) = Outputs([Make(ports[0].X, ports[0].Y, 0, 1.0) with { Level = level }], SceneData.FromBgra(closed.Bgra, width, height, closed.StrideBytes, false, 0, true));
+ Check(pastClosed < 0.01 * pastA, $"both outputs switched off: {pastClosed / pastA:0.0000} of the light that left the open gate gets out");
+
+ // AND and OR (2026-10-22): the same unit with another phase shift, the same dimensions and ports
+ foreach (LogicGatePart other in new LogicGatePart[] { new AndGatePart { X = gate.X, Y = gate.Y }, new OrGatePart { X = gate.X, Y = gate.Y } })
+ {
+ Check(other.Design!.Length == design.Length && other.Design.PortSpacing == design.PortSpacing && other.Ports()!.SequenceEqual(ports),
+ $"the {other.Kind} has the XOR gate's dimensions and ports ({2 * other.Design.PortSpacing} × {other.Design.Length} px; phase section {other.Design.PhaseLength} of {other.Design.PhaseRegionLength} px on arm {(other.Design.PhaseOnArmA ? "A" : "B")})");
+ ScenePixels otherPixels = PartPainter.Paint(null, width, height, 1.0, [other])!;
+ SceneData otherScene = SceneData.FromBgra(otherPixels.Bgra, width, height, otherPixels.StrideBytes, false, 0, true);
+ (double upperA, double lowerA, _) = Outputs([Make(ports[0].X, ports[0].Y, 0, 1.0) with { Level = level }], otherScene);
+ (double upperAB, double lowerAB, _) = Outputs([Make(ports[0].X, ports[0].Y, 0, 1.0) with { Level = level }, Make(ports[1].X, ports[1].Y, 0, 1.0) with { Level = level }], otherScene);
+ double one = upperA + lowerA;
+ string table = $"one input {upperA / one:0.00} up / {lowerA / one:0.00} down, both {upperAB / one:0.00} up / {lowerAB / one:0.00} down";
+ if (other is AndGatePart)
+ {
+ Check(upperAB > 3.0 * upperA && lowerAB < 0.03 * one, "AND: the upper output 3 to 4 × as bright with both inputs as with one, the lower (XOR) dark: " + table);
+ }
+ else
+ {
+ Check(upperAB > 0.8 * upperA && upperAB < 1.2 * upperA && lowerAB > 2.4 * lowerA, "OR: the upper output as bright with both inputs as with one, the lower about 3 ×: " + table);
+ }
+ }
+ }
+
+ /// <summary>
+ /// The zone plate (2026-10-22): the zone radii, the painted blocks (blue only, rising from the faces, sharp at the sides),
+ /// the inverse, the frequency scale handed over, the file element, and a plane wave focused near the focal length (on the
+ /// GPU when there is one).
+ /// </summary>
+ private static void CheckZonePlate()
+ {
+ Console.WriteLine("--- zone plate");
+ var plate = new ZonePlatePart { Name = "z", Diameter = 480, FocalLength = 360 };
+ double lambda = plate.Wavelength, f = plate.FocalLength;
+ double Radius(int n) => Math.Sqrt(n * lambda * f + n * lambda / 2.0 * (n * lambda / 2.0));
+ Check(plate.ZoneAt(Radius(1) - 0.5) == 0 && plate.ZoneAt(Radius(1) + 0.5) == 1 && plate.ZoneAt(Radius(3) + 0.5) == 3
+ && !plate.IsBlockAt(0) && plate.IsBlockAt(Radius(1) + 1) && !plate.IsBlockAt(Radius(2) + 1) && plate.ZoneCount == plate.ZoneAt(240) + 1,
+ $"the zones change at rₙ = √(nλf + (nλ/2)²) ({Radius(1):0.0}, {Radius(2):0.0}, {Radius(3):0.0} px), the central one open, {plate.ZoneCount} within the diameter");
+ plate.Inverse = true;
+ Check(plate.IsBlockAt(0) && !plate.IsBlockAt(Radius(1) + 1), "inverse: the central zone a block, the first ring open");
+ plate.Inverse = false;
+
+ const int width = 960, height = 640, cx = 240, cy = 320;
+ plate.X = cx;
+ plate.Y = cy;
+ ScenePixels painted = PartPainter.Paint(null, width, height, 1.0, [plate])!;
+ int blockY = cy + (int)Math.Round((Radius(1) + Radius(2)) / 2.0);
+ Check(BlueAt(painted, cx, blockY) >= ZonePlatePart.BlockAbsorption - 4 && BlueAt(painted, cx, cy) == 0 && BlueAt(painted, cx - plate.Thickness / 2, blockY) < 10
+ && BlueAt(painted, cx - plate.Thickness / 4, blockY) is > 10 and < 60 && RedAt(painted, cx, blockY) == 100 && BlueAt(painted, cx, cy + (int)Radius(1) - 2) == 0 && BlueAt(painted, cx, cy + (int)Radius(1) + 2) > 50,
+ $"a block absorbs {ZonePlatePart.BlockAbsorption} in its middle, rising from its faces ({BlueAt(painted, cx - plate.Thickness / 4, blockY)} halfway in), sharp at its sides, the index untouched; the central zone clear");
+
+ var project = new Project();
+ project.Parts.Add(plate);
+ using (new GatePortFollower(project))
+ {
+ project.Simulation.SourceFrequencyScale = 4.0;
+ Check(plate.FrequencyScale == 4.0 && Math.Abs(plate.Wavelength - lambda / 2.0) < 1e-9, "the simulation's frequency scale reaches the zone plate, halving its wavelength at twice the scale");
+ project.Simulation.SourceFrequencyScale = 2.0;
+ }
+ string xml;
+ using (var stream = new MemoryStream())
+ {
+ project.Save(stream);
+ xml = System.Text.Encoding.UTF8.GetString(stream.ToArray());
+ }
+ Check(xml.Contains("<ZonePlate Name=\"z\" X=\"240\" Y=\"320\" Diameter=\"480\" FocalLength=\"360\" />"), "the zone plate element, sparse");
+
+ // a plane wave from a line of emitters, focused behind the plate
+ var emitters = new List<Emitter>();
+ for (int y = 10; y < height - 10; y++)
+ {
+ emitters.Add(Make(60, y, 0, 0.05) with { Level = plate.DesignFrequency });
+ }
+ double[] Axis(ScenePixels? pixels)
+ {
+ SceneData scene = pixels != null ? SceneData.FromBgra(pixels.Bgra, width, height, pixels.StrideBytes, false, 0, true) : SceneData.Empty(width, height, 0, 1.0, true);
+ var options = new EngineOptions(2.0, 1.0, false, true, 10.0, 1.0);
+ IWaveEngine engine = GpuWaveSimulator.TryCreate(scene, options, emitters, out _) is { } gpu ? gpu : new WaveSimulator(scene, options, emitters);
+ int steps = 1600, window = (int)Math.Round(10 * lambda);
+ var lockIn = new System.Numerics.Complex[width];
+ for (int s = 0; s < steps; s++)
+ {
+ engine.AdvanceOneStep();
+ if (s >= steps - window)
+ {
+ engine.PrepareFrame(true, false);
+ var phase = System.Numerics.Complex.FromPolarCoordinates(1.0, 2.0 * Math.PI / lambda * s);
+ for (int x = 0; x < width; x++)
+ {
+ lockIn[x] += engine.FieldData[(cy + 1) * (width + 2) + x + 1] * phase;
+ }
+ }
+ }
+ (engine as IDisposable)?.Dispose();
+ return [.. lockIn.Select(c => c.Magnitude * c.Magnitude)];
+ }
+ var sw = System.Diagnostics.Stopwatch.StartNew();
+ double[] focused = Axis(painted), free = Axis(null);
+ int peak = Enumerable.Range(cx + 100, width - cx - 140).MaxBy(x => focused[x]);
+ // the light that passes outside the diameter meets the focused light on the axis and pushes the peak on: measured
+ // 2026-10-22, 5 zones 30 % beyond the focal length, 8 zones 3 %; an absorbing surround brought the 5 back to 6 %
+ Check(peak - cx > 0.95 * f && peak - cx < 1.35 * f && focused[peak] > 2.0 * free[peak],
+ $"a plane wave comes to a focus {peak - cx} px behind the plate (focal length {f}; the light passing outside pushes it on), {focused[peak] / free[peak]:0.0} × as bright as without it ({sw.ElapsedMilliseconds} ms)");
+
+ // the mount: absorbing beyond the diameter, so the focus comes back toward the focal length
+ Check(BlueAt(painted, cx, cy + 240 + 30) == 0 && plate.Outline().Max(p => p.Y) == 240, "without a mount nothing absorbs beyond the diameter");
+ plate.Mount = true;
+ plate.MountWidth = 120;
+ ScenePixels mounted = PartPainter.Paint(null, width, height, 1.0, [plate])!;
+ Check(BlueAt(mounted, cx, cy + 240 + 30) >= ZonePlatePart.BlockAbsorption - 4 && BlueAt(mounted, cx, cy - 240 - 30) >= ZonePlatePart.BlockAbsorption - 4
+ && BlueAt(mounted, cx, cy) == 0 && plate.Outline().Max(p => p.Y) == 360,
+ "the mount absorbs on both sides beyond the diameter, the outline grown by its width");
+ double[] withMount = Axis(mounted);
+ int mountedPeak = Enumerable.Range(cx + 100, width - cx - 140).MaxBy(x => withMount[x]);
+ Check(Math.Abs(mountedPeak - cx - f) < Math.Abs(peak - cx - f) && mountedPeak - cx < 1.15 * f && withMount[mountedPeak] > 2.0 * free[mountedPeak],
+ $"with the mount the focus lies {mountedPeak - cx} px behind the plate (focal length {f}), {withMount[mountedPeak] / free[mountedPeak]:0.0} × as bright as without a plate");
+ using (var stream = new MemoryStream())
+ {
+ project.Save(stream);
+ xml = System.Text.Encoding.UTF8.GetString(stream.ToArray());
+ }
+ Check(xml.Contains("<ZonePlate Name=\"z\" X=\"240\" Y=\"320\"") && xml.Contains(" Mount=\"true\"") && xml.Contains(" MountWidth=\"120\""), "the mount in the file");
+ }
+
+ /// <summary>Sources on a gate's inputs follow the gate (2026-10-21): spacing, position, angle, a group move, a gate added later; others stay.</summary>
+ private static void CheckGatePortFollower()
+ {
+ var project = new Project();
+ var gate = (XorGatePart)project.AddPart(PartKind.XorGate);
+ (int X, int Y)[] ports = gate.Ports()!;
+ var a = new Source { Name = "A", X = ports[0].X, Y = ports[0].Y };
+ var b = new Source { Name = "B", X = ports[1].X + 1, Y = ports[1].Y - 1 };
+ var away = new Source { Name = "away", X = 100, Y = 100 };
+ project.Sources.Add(a);
+ project.Sources.Add(b);
+ project.Sources.Add(away);
+ bool OnInputs() => gate.Ports() is { } p && (a.X, a.Y) == p[0] && (b.X, b.Y) == p[1];
+ using (new GatePortFollower(project))
+ {
+ gate.PortSpacing = 100;
+ Check(OnInputs() && gate.Ports()![1].Y - gate.Ports()![0].Y == 100 && (away.X, away.Y) == (100, 100),
+ "a wider port spacing takes the sources on the inputs along (one a pixel off its port), not the one elsewhere");
+ gate.X += 40;
+ gate.Angle = 90;
+ gate.DesignFrequency = 70;
+ Check(OnInputs(), $"they follow a move, a turn and a new design frequency: A ({a.X}, {a.Y}), B ({b.X}, {b.Y})");
+ project.Simulation.SourceFrequencyScale = 2.5;
+ Check(gate.FrequencyScale == 2.5 && OnInputs(), "the simulation's frequency scale reaches the gate, and the sources follow the ports it moves");
+ (int X, int Y) bBefore = (b.X, b.Y);
+ Movable.MoveAll([gate, a], 7, -3);
+ Check(OnInputs() && (b.X, b.Y) == (bBefore.X + 7, bBefore.Y - 3), "a group move of the gate with A moves A once, and B follows the gate");
+ var second = (XorGatePart)project.AddPart(PartKind.XorGate);
+ second.Y = 200;
+ var c = new Source { Name = "C", X = second.Ports()![0].X, Y = second.Ports()![0].Y };
+ project.Sources.Add(c);
+ second.PortSpacing = 80;
+ Check((c.X, c.Y) == second.Ports()![0], "a gate added later is followed too");
+ }
+ gate.PortSpacing = 140;
+ Check(!OnInputs(), "after Dispose nothing follows");
+ }
+
private static void CheckAbsorbingParts()
{
Console.WriteLine("--- absorbing parts");