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#

An ellipse part, and a chain that keeps a rectangle's or ellipse's width and length equal

Alexander Graef32dc59d26376
diff --git a/CLAUDE.md b/CLAUDE.md
index 59fed15..78756da 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -175,7 +175,9 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
brightness, outline or boxes; a sink that `WantsHalves` gets the plane from the job unrendered. Harness
hooks: `WAVEDUDE_EXPORT_PATH`, `WAVEDUDE_DISCARD_EDITS=1`.
- **Optical parts** (2026-10-18, stages 1 and 2 of `OpticalParts.md`): `OpticalPart` subclasses `LensPart` (mirror flag),
- the shapes under `ShapePart` (`PolygonPart` regular, `RectanglePart`, `TrianglePart` by base and base angles with presets, `OutlinePart` by points), `FiberPart`, `BraggReflectorPart`, `GrinLensPart` in `Project.Parts`, one XML element
+ the shapes under `ShapePart` (`PolygonPart` regular, `RectanglePart`, `EllipsePart` as a polygon of a vertex per 3 px of
+ circumference, 2026-10-20; both carry a `Linked` flag, the chain toggle between width and length of the image editors,
+ which keeps them equal through the boxes, the grip and the file, `TrianglePart` by base and base angles with presets, `OutlinePart` by points), `FiberPart`, `BraggReflectorPart`, `GrinLensPart` in `Project.Parts`, one XML element
per kind; painted into the scene's red channel (4 × 4 supersampled, a mirror by the pixel-centre test as red 0, a
coating band of √n, later parts over earlier ones; a part's centre is the corner of pixel (X, Y), so even sizes cover
whole pixels). A part edit is a simulation edit. Tree folder "Parts", "+ Part" opens a menu of kinds (Space, arrows,
diff --git a/OpticalParts.md b/OpticalParts.md
index c297a4c..02fc008 100644
--- a/OpticalParts.md
+++ b/OpticalParts.md
@@ -12,7 +12,7 @@ corner of pixel (X, Y), not its middle, so even sizes (every default) cover whol
values guarded instead of normalising the model from inside the painter. After the user's review (a side length alone made every
rectangle a square; a shape mode inside one class would be the kind combo we rejected): the polygon became four classes
under `ShapePart` (mirror, index, coating), each its own kind, element and form: `PolygonPart` (regular, side count and
-side length, a face centred on -x'), `RectanglePart` (length, width, a Square button), `TrianglePart` (base across the
+side length, a face centred on -x'), `RectanglePart` (length, width, a chain toggle that keeps them equal: a square), `EllipsePart` (length, width, the same chain: a circle; outlined as a polygon of a vertex per 3 px of circumference), `TrianglePart` (base across the
axis toward -x', two base angles, a type preset: equilateral, right isosceles, 30-60-90, isosceles, custom; the apex angle
shown), `OutlinePart` (points). The "+ Part" menu lists the optics, a separator, the shapes. The handle glyph is the
source's circular crosshair with an inner ring (a lens-shaped glyph read as squashed). A lens's diameter and centre
diff --git a/WaveDudeNext.WPF/Commands/PartCommands.cs b/WaveDudeNext.WPF/Commands/PartCommands.cs
index 0c5c665..ee420a5 100644
--- a/WaveDudeNext.WPF/Commands/PartCommands.cs
+++ b/WaveDudeNext.WPF/Commands/PartCommands.cs
@@ -19,12 +19,9 @@ using System.Windows.Input;
namespace WaveDudeNext.WPF.Commands;
-/// <summary>Commands of the part editors, bound on the views themselves: the point list of an outline or fibre (<c>Views/PartPointsView</c>), the rectangle's Square button.</summary>
+/// <summary>Commands of the part editors, bound on the views themselves: the point list of an outline or fibre (<c>Views/PartPointsView</c>), nothing else since the chain toggle replaced the Square and Circle buttons (2026-10-20).</summary>
public static class PartCommands
{
- /// <summary>Makes a rectangle square: its width becomes its length.</summary>
- public static readonly RoutedUICommand MakeSquare = new("Square", nameof(MakeSquare), typeof(PartCommands));
-
/// <summary>Appends a point after the last one.</summary>
public static readonly RoutedUICommand AddPoint = new("Add point", nameof(AddPoint), typeof(PartCommands));
diff --git a/WaveDudeNext.WPF/Controls/SceneOverlay.cs b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
index 2a5a6b4..33c01c2 100644
--- a/WaveDudeNext.WPF/Controls/SceneOverlay.cs
+++ b/WaveDudeNext.WPF/Controls/SceneOverlay.cs
@@ -531,12 +531,13 @@ public sealed class SceneOverlay : Panel
};
/// <summary>
- /// Where a part's size grip sits in the part frame: the corner of a rectangle, lens (thickness, diameter), GRIN lens
+ /// 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.
/// </summary>
private static (double X, double Y)? GripOf(OpticalPart part) => part switch
{
RectanglePart rectangle => (rectangle.Length / 2.0, rectangle.Width / 2.0),
+ EllipsePart ellipse => (ellipse.Length / 2.0, ellipse.Width / 2.0),
LensPart lens => (lens.Thickness / 2.0, lens.Diameter / 2.0),
PolygonPart polygon => polygon.Vertices()[0],
TrianglePart triangle => triangle.Vertices()[1],
@@ -554,8 +555,14 @@ public sealed class SceneOverlay : Panel
switch (part)
{
case RectanglePart rectangle:
- rectangle.Length = Math.Max(1, along);
- rectangle.Width = Math.Max(1, across);
+ // linked (a square): the farther of the two coordinates sets both
+ rectangle.Length = Math.Max(1, rectangle.Linked ? Math.Max(along, across) : along);
+ rectangle.Width = Math.Max(1, rectangle.Linked ? Math.Max(along, across) : across);
+ break;
+ case EllipsePart ellipse:
+ // the grip sits on the corner of the bounding box, as the rectangle's does
+ ellipse.Length = Math.Max(1, ellipse.Linked ? Math.Max(along, across) : along);
+ ellipse.Width = Math.Max(1, ellipse.Linked ? Math.Max(along, across) : across);
break;
case LensPart lens:
lens.Thickness = Math.Max(1, along);
diff --git a/WaveDudeNext.WPF/Panes/ProjectTree.xaml b/WaveDudeNext.WPF/Panes/ProjectTree.xaml
index 4cdbbec..803c55c 100644
--- a/WaveDudeNext.WPF/Panes/ProjectTree.xaml
+++ b/WaveDudeNext.WPF/Panes/ProjectTree.xaml
@@ -97,6 +97,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<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" />
</ContextMenu>
@@ -169,6 +170,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<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}" />
</MenuItem>
diff --git a/WaveDudeNext.WPF/Panes/PropertiesPane.xaml b/WaveDudeNext.WPF/Panes/PropertiesPane.xaml
index 38d5afa..8865557 100644
--- a/WaveDudeNext.WPF/Panes/PropertiesPane.xaml
+++ b/WaveDudeNext.WPF/Panes/PropertiesPane.xaml
@@ -52,6 +52,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<DataTemplate DataType="{x:Type model:RectanglePart}">
<views:RectanglePartView />
</DataTemplate>
+ <DataTemplate DataType="{x:Type model:EllipsePart}">
+ <views:EllipsePartView />
+ </DataTemplate>
<DataTemplate DataType="{x:Type model:TrianglePart}">
<views:TrianglePartView />
</DataTemplate>
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index d6da445..cffc894 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -113,6 +113,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddLens">_Linse oder Spiegel</s:String>
<s:String x:Key="MenuAddPolygon">_Polygon</s:String>
<s:String x:Key="MenuAddRectangle">_Rechteck</s:String>
+ <s:String x:Key="MenuAddEllipse">_Ellipse</s:String>
<s:String x:Key="MenuAddTriangle">_Dreieck</s:String>
<s:String x:Key="MenuAddOutline">_Umriss</s:String>
<s:String x:Key="MenuAddFiber">_Faser</s:String>
@@ -267,8 +268,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ButtonAddPoint">Punkt hinzufügen</s:String>
<s:String x:Key="TipAddPoint">Punkt nach dem letzten anfügen</s:String>
<s:String x:Key="TipRemovePoint">Diesen Punkt entfernen</s:String>
- <s:String x:Key="ButtonSquare">Quadrat</s:String>
- <s:String x:Key="TipSquare">Die Breite gleich der Länge setzen</s:String>
<s:String x:Key="LabelApexAngle">Winkel an der Spitze</s:String>
<s:String x:Key="TipApexAngle">Der Winkel an der Spitze: 180° minus die beiden Grundwinkel</s:String>
<s:String x:Key="LabelEdgeThickness">Randdicke</s:String>
@@ -558,6 +557,14 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.RectanglePart.Length">Ausdehnung entlang der Achse in Pixeln.</s:String>
<s:String x:Key="Label.RectanglePart.Width">Breite</s:String>
<s:String x:Key="Hint.RectanglePart.Width">Ausdehnung quer zur Achse in Pixeln.</s:String>
+ <s:String x:Key="Label.RectanglePart.Linked">Verkettet</s:String>
+ <s:String x:Key="Hint.RectanglePart.Linked">Die Breite gleich der Länge halten: ein Quadrat.</s:String>
+ <s:String x:Key="Label.EllipsePart.Length">Länge</s:String>
+ <s:String x:Key="Hint.EllipsePart.Length">Durchmesser entlang der Achse in Pixeln.</s:String>
+ <s:String x:Key="Label.EllipsePart.Width">Breite</s:String>
+ <s:String x:Key="Hint.EllipsePart.Width">Durchmesser quer zur Achse in Pixeln.</s:String>
+ <s:String x:Key="Label.EllipsePart.Linked">Verkettet</s:String>
+ <s:String x:Key="Hint.EllipsePart.Linked">Die Breite gleich der Länge halten: ein Kreis.</s:String>
<s:String x:Key="Label.TrianglePart.Base">Grundseite</s:String>
<s:String x:Key="Hint.TrianglePart.Base">Länge der Grundseite in Pixeln; sie liegt quer zur Achse, einer Quelle links zugewandt.</s:String>
<s:String x:Key="Label.TrianglePart.Type">Typ</s:String>
@@ -605,6 +612,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<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>
+ <s:String x:Key="Enum.PartKind.Ellipse">Ellipse</s:String>
<s:String x:Key="Enum.PartKind.Triangle">Dreieck</s:String>
<s:String x:Key="Enum.PartKind.Outline">Umriss</s:String>
<s:String x:Key="Enum.PartKind.Fiber">Faser</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index c3fdd6c..001a033 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -115,6 +115,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddLens">_Lens or mirror</s:String>
<s:String x:Key="MenuAddPolygon">_Polygon</s:String>
<s:String x:Key="MenuAddRectangle">_Rectangle</s:String>
+ <s:String x:Key="MenuAddEllipse">_Ellipse</s:String>
<s:String x:Key="MenuAddTriangle">_Triangle</s:String>
<s:String x:Key="MenuAddOutline">_Outline</s:String>
<s:String x:Key="MenuAddFiber">_Fibre</s:String>
@@ -269,8 +270,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ButtonAddPoint">Add point</s:String>
<s:String x:Key="TipAddPoint">Append a point after the last one</s:String>
<s:String x:Key="TipRemovePoint">Remove this point</s:String>
- <s:String x:Key="ButtonSquare">Square</s:String>
- <s:String x:Key="TipSquare">Make the width equal to the length</s:String>
<s:String x:Key="LabelApexAngle">Apex angle</s:String>
<s:String x:Key="TipApexAngle">The angle at the apex: 180° minus the two base angles</s:String>
<s:String x:Key="LabelEdgeThickness">Edge thickness</s:String>
@@ -560,6 +559,14 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.RectanglePart.Length">Extent along the axis in pixels.</s:String>
<s:String x:Key="Label.RectanglePart.Width">Width</s:String>
<s:String x:Key="Hint.RectanglePart.Width">Extent across the axis in pixels.</s:String>
+ <s:String x:Key="Label.RectanglePart.Linked">Linked</s:String>
+ <s:String x:Key="Hint.RectanglePart.Linked">Keep the width equal to the length: a square.</s:String>
+ <s:String x:Key="Label.EllipsePart.Length">Length</s:String>
+ <s:String x:Key="Hint.EllipsePart.Length">Diameter along the axis in pixels.</s:String>
+ <s:String x:Key="Label.EllipsePart.Width">Width</s:String>
+ <s:String x:Key="Hint.EllipsePart.Width">Diameter across the axis in pixels.</s:String>
+ <s:String x:Key="Label.EllipsePart.Linked">Linked</s:String>
+ <s:String x:Key="Hint.EllipsePart.Linked">Keep the width equal to the length: a circle.</s:String>
<s:String x:Key="Label.TrianglePart.Base">Base</s:String>
<s:String x:Key="Hint.TrianglePart.Base">Length of the base in pixels; the base lies across the axis, toward a source on the left.</s:String>
<s:String x:Key="Label.TrianglePart.Type">Type</s:String>
@@ -607,6 +614,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<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>
+ <s:String x:Key="Enum.PartKind.Ellipse">Ellipse</s:String>
<s:String x:Key="Enum.PartKind.Triangle">Triangle</s:String>
<s:String x:Key="Enum.PartKind.Outline">Outline</s:String>
<s:String x:Key="Enum.PartKind.Fiber">Fibre</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index 22f447a..31cbf06 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -113,6 +113,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddLens">_Lentille ou miroir</s:String>
<s:String x:Key="MenuAddPolygon">_Polygone</s:String>
<s:String x:Key="MenuAddRectangle">_Rectangle</s:String>
+ <s:String x:Key="MenuAddEllipse">_Ellipse</s:String>
<s:String x:Key="MenuAddTriangle">_Triangle</s:String>
<s:String x:Key="MenuAddOutline">C_ontour</s:String>
<s:String x:Key="MenuAddFiber">_Fibre</s:String>
@@ -267,8 +268,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ButtonAddPoint">Ajouter un point</s:String>
<s:String x:Key="TipAddPoint">Ajouter un point après le dernier</s:String>
<s:String x:Key="TipRemovePoint">Supprimer ce point</s:String>
- <s:String x:Key="ButtonSquare">Carré</s:String>
- <s:String x:Key="TipSquare">Rendre la largeur égale à la longueur</s:String>
<s:String x:Key="LabelApexAngle">Angle au sommet</s:String>
<s:String x:Key="TipApexAngle">L'angle au sommet : 180° moins les deux angles à la base</s:String>
<s:String x:Key="LabelEdgeThickness">Épaisseur au bord</s:String>
@@ -558,6 +557,14 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.RectanglePart.Length">Étendue le long de l'axe en pixels.</s:String>
<s:String x:Key="Label.RectanglePart.Width">Largeur</s:String>
<s:String x:Key="Hint.RectanglePart.Width">Étendue perpendiculaire à l'axe en pixels.</s:String>
+ <s:String x:Key="Label.RectanglePart.Linked">Liées</s:String>
+ <s:String x:Key="Hint.RectanglePart.Linked">Garder la largeur égale à la longueur : un carré.</s:String>
+ <s:String x:Key="Label.EllipsePart.Length">Longueur</s:String>
+ <s:String x:Key="Hint.EllipsePart.Length">Diamètre le long de l'axe en pixels.</s:String>
+ <s:String x:Key="Label.EllipsePart.Width">Largeur</s:String>
+ <s:String x:Key="Hint.EllipsePart.Width">Diamètre perpendiculaire à l'axe en pixels.</s:String>
+ <s:String x:Key="Label.EllipsePart.Linked">Liées</s:String>
+ <s:String x:Key="Hint.EllipsePart.Linked">Garder la largeur égale à la longueur : un cercle.</s:String>
<s:String x:Key="Label.TrianglePart.Base">Base</s:String>
<s:String x:Key="Hint.TrianglePart.Base">Longueur de la base en pixels ; elle est perpendiculaire à l'axe, tournée vers une source à gauche.</s:String>
<s:String x:Key="Label.TrianglePart.Type">Type</s:String>
@@ -605,6 +612,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<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>
+ <s:String x:Key="Enum.PartKind.Ellipse">Ellipse</s:String>
<s:String x:Key="Enum.PartKind.Triangle">Triangle</s:String>
<s:String x:Key="Enum.PartKind.Outline">Contour</s:String>
<s:String x:Key="Enum.PartKind.Fiber">Fibre</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index 1a946fb..dfedadb 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -113,6 +113,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="MenuAddLens">_Lens of spiegel</s:String>
<s:String x:Key="MenuAddPolygon">_Polygoon</s:String>
<s:String x:Key="MenuAddRectangle">_Rechthoek</s:String>
+ <s:String x:Key="MenuAddEllipse">_Ellips</s:String>
<s:String x:Key="MenuAddTriangle">_Driehoek</s:String>
<s:String x:Key="MenuAddOutline">_Omtrek</s:String>
<s:String x:Key="MenuAddFiber">_Vezel</s:String>
@@ -267,8 +268,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ButtonAddPoint">Punt toevoegen</s:String>
<s:String x:Key="TipAddPoint">Punt na het laatste toevoegen</s:String>
<s:String x:Key="TipRemovePoint">Dit punt verwijderen</s:String>
- <s:String x:Key="ButtonSquare">Vierkant</s:String>
- <s:String x:Key="TipSquare">De breedte gelijk aan de lengte maken</s:String>
<s:String x:Key="LabelApexAngle">Tophoek</s:String>
<s:String x:Key="TipApexAngle">De hoek aan de top: 180° min de twee basishoeken</s:String>
<s:String x:Key="LabelEdgeThickness">Randdikte</s:String>
@@ -558,6 +557,14 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Hint.RectanglePart.Length">Afmeting langs de as in pixels.</s:String>
<s:String x:Key="Label.RectanglePart.Width">Breedte</s:String>
<s:String x:Key="Hint.RectanglePart.Width">Afmeting dwars op de as in pixels.</s:String>
+ <s:String x:Key="Label.RectanglePart.Linked">Gekoppeld</s:String>
+ <s:String x:Key="Hint.RectanglePart.Linked">De breedte gelijk aan de lengte houden: een vierkant.</s:String>
+ <s:String x:Key="Label.EllipsePart.Length">Lengte</s:String>
+ <s:String x:Key="Hint.EllipsePart.Length">Diameter langs de as in pixels.</s:String>
+ <s:String x:Key="Label.EllipsePart.Width">Breedte</s:String>
+ <s:String x:Key="Hint.EllipsePart.Width">Diameter dwars op de as in pixels.</s:String>
+ <s:String x:Key="Label.EllipsePart.Linked">Gekoppeld</s:String>
+ <s:String x:Key="Hint.EllipsePart.Linked">De breedte gelijk aan de lengte houden: een cirkel.</s:String>
<s:String x:Key="Label.TrianglePart.Base">Basis</s:String>
<s:String x:Key="Hint.TrianglePart.Base">Lengte van de basis in pixels; ze ligt dwars op de as, naar een bron links gekeerd.</s:String>
<s:String x:Key="Label.TrianglePart.Type">Type</s:String>
@@ -605,6 +612,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<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>
+ <s:String x:Key="Enum.PartKind.Ellipse">Ellips</s:String>
<s:String x:Key="Enum.PartKind.Triangle">Driehoek</s:String>
<s:String x:Key="Enum.PartKind.Outline">Omtrek</s:String>
<s:String x:Key="Enum.PartKind.Fiber">Vezel</s:String>
diff --git a/WaveDudeNext.WPF/Themes/Editors.xaml b/WaveDudeNext.WPF/Themes/Editors.xaml
index 77fb686..514949c 100644
--- a/WaveDudeNext.WPF/Themes/Editors.xaml
+++ b/WaveDudeNext.WPF/Themes/Editors.xaml
@@ -553,6 +553,42 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
</Style>
+
+ <!-- the chain between two number boxes that keeps them equal (a rectangle's or ellipse's width and length,
+ 2026-10-20, the user's request after the image editors): a toggle showing two linked rings, parted when off -->
+ <StreamGeometry x:Key="ChainLinkedGeometry">M8,1 h2 a3,3 0 0 1 3,3 v2 a3,3 0 0 1 -3,3 h-2 a3,3 0 0 1 -3,-3 v-2 a3,3 0 0 1 3,-3 z M8,7 h2 a3,3 0 0 1 3,3 v2 a3,3 0 0 1 -3,3 h-2 a3,3 0 0 1 -3,-3 v-2 a3,3 0 0 1 3,-3 z</StreamGeometry>
+ <StreamGeometry x:Key="ChainPartedGeometry">M8,0 h2 a3,3 0 0 1 3,3 v1 a3,3 0 0 1 -3,3 h-2 a3,3 0 0 1 -3,-3 v-1 a3,3 0 0 1 3,-3 z M8,9 h2 a3,3 0 0 1 3,3 v1 a3,3 0 0 1 -3,3 h-2 a3,3 0 0 1 -3,-3 v-1 a3,3 0 0 1 3,-3 z</StreamGeometry>
+ <Style x:Key="LinkToggle" TargetType="{x:Type ToggleButton}">
+ <Setter Property="Width" Value="22" />
+ <Setter Property="Height" Value="22" />
+ <Setter Property="Foreground" Value="{DynamicResource GrayText}" />
+ <Setter Property="FocusVisualStyle" Value="{x:Null}" />
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="{x:Type ToggleButton}">
+ <Border x:Name="Bd" Background="Transparent" BorderBrush="Transparent" BorderThickness="1" SnapsToDevicePixels="True">
+ <Path x:Name="Glyph" Data="{StaticResource ChainPartedGeometry}" Stroke="{TemplateBinding Foreground}" StrokeThickness="1.3"
+ Width="18" Height="16" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" />
+ </Border>
+ <ControlTemplate.Triggers>
+ <Trigger Property="IsChecked" Value="True">
+ <Setter TargetName="Glyph" Property="Data" Value="{StaticResource ChainLinkedGeometry}" />
+ <Setter Property="Foreground" Value="{DynamicResource Accent}" />
+ </Trigger>
+ <Trigger Property="IsMouseOver" Value="True">
+ <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ButtonHover}" />
+ </Trigger>
+ <Trigger Property="IsKeyboardFocused" Value="True">
+ <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Accent}" />
+ </Trigger>
+ <Trigger Property="IsEnabled" Value="False">
+ <Setter Property="Opacity" Value="0.5" />
+ </Trigger>
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
<Style x:Key="FormValue" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{DynamicResource GrayText}" />
<Setter Property="VerticalAlignment" Value="Center" />
diff --git a/WaveDudeNext.WPF/Views/EllipsePartView.xaml b/WaveDudeNext.WPF/Views/EllipsePartView.xaml
new file mode 100644
index 0000000..39314b5
--- /dev/null
+++ b/WaveDudeNext.WPF/Views/EllipsePartView.xaml
@@ -0,0 +1,59 @@
+<!--
+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.EllipsePartView"
+ 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:meta="clr-namespace:WaveDudeNext.WPF.Markup"
+ xmlns:views="clr-namespace:WaveDudeNext.WPF.Views"
+ xmlns:model="clr-namespace:WaveDudeNext.Model;assembly=WaveDudeNext">
+
+ <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
+ <StackPanel Margin="8">
+ <views:PartCommonView />
+ <views:ShapeMaterialView />
+
+ <Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionShape}" />
+ <controls:FormPanel>
+ <!-- the two sizes with the chain beside them spanning both rows, as the image editors draw it; one row of the
+ form, laid out to the form's label column -->
+ <Grid controls:FormPanel.FullWidth="True">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="{Binding LabelWidth, RelativeSource={RelativeSource AncestorType={x:Type controls:FormPanel}}}" />
+ <ColumnDefinition Width="8" />
+ <ColumnDefinition Width="*" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="4" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:EllipsePart.Length}" />
+ <controls:NumberBox Grid.Column="2" Text="{Binding Length}" Minimum="1" Increment="10" ToolTip="{meta:Hint model:EllipsePart.Length}" AutomationProperties.AutomationId="PartLength" />
+ <TextBlock Grid.Row="2" Style="{StaticResource FormLabel}" Text="{meta:Label model:EllipsePart.Width}" />
+ <controls:NumberBox Grid.Row="2" Grid.Column="2" Text="{Binding Width}" Minimum="1" Increment="10" ToolTip="{meta:Hint model:EllipsePart.Width}" AutomationProperties.AutomationId="PartWidth" />
+ <ToggleButton Grid.Column="3" Grid.RowSpan="3" Style="{StaticResource LinkToggle}" Margin="4,0,0,0" VerticalAlignment="Center"
+ IsChecked="{Binding Linked}" ToolTip="{meta:Hint model:EllipsePart.Linked}" AutomationProperties.Name="{meta:Label model:EllipsePart.Linked}" AutomationProperties.AutomationId="PartLinked" />
+ </Grid>
+ </controls:FormPanel>
+ </StackPanel>
+ </ScrollViewer>
+</UserControl>
diff --git a/WaveDudeNext.WPF/Views/EllipsePartView.xaml.cs b/WaveDudeNext.WPF/Views/EllipsePartView.xaml.cs
new file mode 100644
index 0000000..53887b3
--- /dev/null
+++ b/WaveDudeNext.WPF/Views/EllipsePartView.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="Model.EllipsePart"/>: length and width, with the chain that keeps them equal.</summary>
+public partial class EllipsePartView : UserControl
+{
+ public EllipsePartView()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/WaveDudeNext.WPF/Views/RectanglePartView.xaml b/WaveDudeNext.WPF/Views/RectanglePartView.xaml
index 27302ad..4305172 100644
--- a/WaveDudeNext.WPF/Views/RectanglePartView.xaml
+++ b/WaveDudeNext.WPF/Views/RectanglePartView.xaml
@@ -21,15 +21,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
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:commands="clr-namespace:WaveDudeNext.WPF.Commands"
xmlns:meta="clr-namespace:WaveDudeNext.WPF.Markup"
xmlns:views="clr-namespace:WaveDudeNext.WPF.Views"
xmlns:model="clr-namespace:WaveDudeNext.Model;assembly=WaveDudeNext">
- <UserControl.CommandBindings>
- <CommandBinding Command="{x:Static commands:PartCommands.MakeSquare}" CanExecute="CanMakeSquare" Executed="OnMakeSquare" />
- </UserControl.CommandBindings>
-
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<StackPanel Margin="8">
<views:PartCommonView />
@@ -37,15 +32,27 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionShape}" />
<controls:FormPanel>
- <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:RectanglePart.Length}" />
- <controls:NumberBox Text="{Binding Length}" Minimum="1" Increment="10" ToolTip="{meta:Hint model:RectanglePart.Length}" AutomationProperties.AutomationId="PartLength" />
-
- <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:RectanglePart.Width}" />
- <controls:NumberBox Text="{Binding Width}" Minimum="1" Increment="10" ToolTip="{meta:Hint model:RectanglePart.Width}" AutomationProperties.AutomationId="PartWidth" />
-
- <!-- the Square button (the user's request, 2026-10-18): the width takes the length -->
- <Button controls:FormPanel.FullWidth="True" HorizontalAlignment="Left" Padding="8,2" Margin="0,2,0,0" Content="{DynamicResource ButtonSquare}" ToolTip="{DynamicResource TipSquare}"
- Command="{x:Static commands:PartCommands.MakeSquare}" AutomationProperties.AutomationId="PartSquare" />
+ <!-- the two sizes with the chain beside them spanning both rows, as the image editors draw it; one row of the
+ form, laid out to the form's label column -->
+ <Grid controls:FormPanel.FullWidth="True">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="{Binding LabelWidth, RelativeSource={RelativeSource AncestorType={x:Type controls:FormPanel}}}" />
+ <ColumnDefinition Width="8" />
+ <ColumnDefinition Width="*" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="4" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:RectanglePart.Length}" />
+ <controls:NumberBox Grid.Column="2" Text="{Binding Length}" Minimum="1" Increment="10" ToolTip="{meta:Hint model:RectanglePart.Length}" AutomationProperties.AutomationId="PartLength" />
+ <TextBlock Grid.Row="2" Style="{StaticResource FormLabel}" Text="{meta:Label model:RectanglePart.Width}" />
+ <controls:NumberBox Grid.Row="2" Grid.Column="2" Text="{Binding Width}" Minimum="1" Increment="10" ToolTip="{meta:Hint model:RectanglePart.Width}" AutomationProperties.AutomationId="PartWidth" />
+ <ToggleButton Grid.Column="3" Grid.RowSpan="3" Style="{StaticResource LinkToggle}" Margin="4,0,0,0" VerticalAlignment="Center"
+ IsChecked="{Binding Linked}" ToolTip="{meta:Hint model:RectanglePart.Linked}" AutomationProperties.Name="{meta:Label model:RectanglePart.Linked}" AutomationProperties.AutomationId="PartLinked" />
+ </Grid>
</controls:FormPanel>
</StackPanel>
</ScrollViewer>
diff --git a/WaveDudeNext.WPF/Views/RectanglePartView.xaml.cs b/WaveDudeNext.WPF/Views/RectanglePartView.xaml.cs
index de3b05d..fbcb151 100644
--- a/WaveDudeNext.WPF/Views/RectanglePartView.xaml.cs
+++ b/WaveDudeNext.WPF/Views/RectanglePartView.xaml.cs
@@ -16,27 +16,14 @@
// <https://www.gnu.org/licenses/>.
using System.Windows.Controls;
-using System.Windows.Input;
-using WaveDudeNext.Model;
namespace WaveDudeNext.WPF.Views;
-/// <summary>Editor for a <see cref="RectanglePart"/>: length, width and a Square button that copies the length into the width.</summary>
+/// <summary>Editor for a <see cref="Model.RectanglePart"/>: length and width, with the chain that keeps them equal.</summary>
public partial class RectanglePartView : UserControl
{
public RectanglePartView()
{
InitializeComponent();
}
-
- private void CanMakeSquare(object sender, CanExecuteRoutedEventArgs e) =>
- e.CanExecute = DataContext is RectanglePart rectangle && rectangle.Width != rectangle.Length;
-
- private void OnMakeSquare(object sender, ExecutedRoutedEventArgs e)
- {
- if (DataContext is RectanglePart rectangle)
- {
- rectangle.Width = rectangle.Length;
- }
- }
}
diff --git a/WaveDudeNext/Model/OpticalPart.cs b/WaveDudeNext/Model/OpticalPart.cs
index 73b9406..0f53648 100644
--- a/WaveDudeNext/Model/OpticalPart.cs
+++ b/WaveDudeNext/Model/OpticalPart.cs
@@ -30,6 +30,8 @@ public enum PartKind
Polygon,
/// <summary>A rectangle (<see cref="RectanglePart"/>).</summary>
Rectangle,
+ /// <summary>An ellipse or circle (<see cref="EllipsePart"/>).</summary>
+ Ellipse,
/// <summary>A triangle shaped by its base angles (<see cref="TrianglePart"/>).</summary>
Triangle,
/// <summary>A free outline from a point list (<see cref="OutlinePart"/>).</summary>
@@ -665,6 +667,7 @@ public sealed class RectanglePart : ShapePart
private int _length = DefaultSize;
private int _width = DefaultSize;
+ private bool _linked;
/// <inheritdoc/>
public override PartKind Kind => PartKind.Rectangle;
@@ -677,7 +680,13 @@ public sealed class RectanglePart : ShapePart
public int Length
{
get => _length;
- set => SetProperty(ref _length, value);
+ set
+ {
+ if (SetProperty(ref _length, value) && Linked)
+ {
+ Width = value;
+ }
+ }
}
/// <summary>Extent across the axis in pixels.</summary>
@@ -688,7 +697,31 @@ public sealed class RectanglePart : ShapePart
public int Width
{
get => _width;
- set => SetProperty(ref _width, value);
+ set
+ {
+ if (SetProperty(ref _width, value) && Linked)
+ {
+ Length = value;
+ }
+ }
+ }
+
+ /// <summary>Keeps <see cref="Width"/> equal to <see cref="Length"/> (a square): a change of either sets the other, and the size grip moves both (2026-10-20, the user's request: the chain between width and height of the image editors).</summary>
+ [XmlAttribute]
+ [DefaultValue(false)]
+ [Category("Shape")]
+ [DisplayName("Linked")]
+ [Description("Keep the width equal to the length.")]
+ public bool Linked
+ {
+ get => _linked;
+ set
+ {
+ if (SetProperty(ref _linked, value) && value)
+ {
+ Width = Length;
+ }
+ }
}
/// <inheritdoc/>
@@ -711,6 +744,121 @@ public sealed class RectanglePart : ShapePart
public override OpticalPart Clone() => ShallowClone<RectanglePart>();
}
+/// <summary>
+/// An ellipse of <see cref="Length"/> along the axis and <see cref="Width"/> across, centred; a circle when the two are
+/// equal, which <see cref="Linked"/> keeps (2026-10-20, the user's request). Painted and outlined as a polygon of enough vertices for the chord error to
+/// stay far below a pixel: a vertex every three pixels of circumference, 24 at least, 180 at most.
+/// </summary>
+public sealed class EllipsePart : ShapePart
+{
+ /// <summary>Default <see cref="Length"/> and <see cref="Width"/> in pixels.</summary>
+ public const int DefaultSize = 60;
+
+ /// <summary>Fewest vertices of the outline.</summary>
+ public const int MinVertices = 24;
+
+ /// <summary>Most vertices of the outline: a 1000 px circle still has a chord sag under 0.2 px.</summary>
+ public const int MaxVertices = 180;
+
+ private int _length = DefaultSize;
+ private int _width = DefaultSize;
+ private bool _linked;
+
+ /// <inheritdoc/>
+ public override PartKind Kind => PartKind.Ellipse;
+
+ /// <summary>Diameter along the axis in pixels.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultSize)]
+ [Category("Shape")]
+ [Description("Diameter along the axis in pixels.")]
+ public int Length
+ {
+ get => _length;
+ set
+ {
+ if (SetProperty(ref _length, value) && Linked)
+ {
+ Width = value;
+ }
+ }
+ }
+
+ /// <summary>Diameter across the axis in pixels.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultSize)]
+ [Category("Shape")]
+ [Description("Diameter across the axis in pixels.")]
+ public int Width
+ {
+ get => _width;
+ set
+ {
+ if (SetProperty(ref _width, value) && Linked)
+ {
+ Length = value;
+ }
+ }
+ }
+
+ /// <summary>Keeps <see cref="Width"/> equal to <see cref="Length"/> (a circle): a change of either sets the other, and the size grip moves both (2026-10-20, the user's request: the chain between width and height of the image editors).</summary>
+ [XmlAttribute]
+ [DefaultValue(false)]
+ [Category("Shape")]
+ [DisplayName("Linked")]
+ [Description("Keep the width equal to the length.")]
+ public bool Linked
+ {
+ get => _linked;
+ set
+ {
+ if (SetProperty(ref _linked, value) && value)
+ {
+ Width = Length;
+ }
+ }
+ }
+
+ /// <summary>How many vertices the outline gets: one per three pixels of circumference (Ramanujan's estimate), within the limits.</summary>
+ public int VertexCount
+ {
+ get
+ {
+ double a = Math.Max(1, Length) / 2.0;
+ double b = Math.Max(1, Width) / 2.0;
+ double h = (a - b) * (a - b) / ((a + b) * (a + b));
+ double circumference = Math.PI * (a + b) * (1 + 3 * h / (10 + Math.Sqrt(4 - 3 * h)));
+ return Math.Clamp((int)Math.Round(circumference / 3.0), MinVertices, MaxVertices);
+ }
+ }
+
+ /// <inheritdoc/>
+ public override (double X, double Y)[] Vertices()
+ {
+ double a = Math.Max(1, Length) / 2.0;
+ double b = Math.Max(1, Width) / 2.0;
+ int n = VertexCount;
+ var vertices = new (double X, double Y)[n];
+ for (int k = 0; k < n; k++)
+ {
+ double theta = 2.0 * Math.PI * k / n;
+ vertices[k] = (a * Math.Cos(theta), b * Math.Sin(theta));
+ }
+ return vertices;
+ }
+
+ /// <inheritdoc/>
+ public override void Normalize()
+ {
+ base.Normalize();
+ Length = Math.Max(1, Length);
+ Width = Math.Max(1, Width);
+ }
+
+ /// <inheritdoc/>
+ public override OpticalPart Clone() => ShallowClone<EllipsePart>();
+}
+
/// <summary>The presets of a <see cref="TrianglePart"/>: which base angles are fixed.</summary>
public enum TriangleType
{
diff --git a/WaveDudeNext/Model/Project.cs b/WaveDudeNext/Model/Project.cs
index 8fd484c..12251c0 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, 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), 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.
@@ -155,6 +155,7 @@ public sealed class Project : ObservableObject
[XmlElement("Lens", typeof(LensPart))]
[XmlElement("Polygon", typeof(PolygonPart))]
[XmlElement("Rectangle", typeof(RectanglePart))]
+ [XmlElement("Ellipse", typeof(EllipsePart))]
[XmlElement("Triangle", typeof(TrianglePart))]
[XmlElement("Outline", typeof(OutlinePart))]
[XmlElement("Fiber", typeof(FiberPart))]
@@ -334,7 +335,7 @@ public sealed class Project : ObservableObject
}
/// <summary>
- /// Appends a new part of <paramref name="kind"/>, named "Lens n", "Polygon n", "Rectangle n", "Triangle n", "Outline n",
+ /// 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
/// known here), and returns it.
/// </summary>
@@ -345,6 +346,7 @@ public sealed class Project : ObservableObject
PartKind.Lens => new LensPart(),
PartKind.Polygon => new PolygonPart(),
PartKind.Rectangle => new RectanglePart(),
+ PartKind.Ellipse => new EllipsePart(),
PartKind.Triangle => new TrianglePart(),
PartKind.Outline => new OutlinePart(),
PartKind.Fiber => new FiberPart { Points = FiberPart.DefaultPath() },
@@ -365,6 +367,7 @@ public sealed class Project : ObservableObject
PartKind.Lens => "Lens",
PartKind.Polygon => "Polygon",
PartKind.Rectangle => "Rectangle",
+ PartKind.Ellipse => "Ellipse",
PartKind.Triangle => "Triangle",
PartKind.Outline => "Outline",
PartKind.Fiber => "Fiber",
diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.cs
index c81f6f0..74ed7c6 100644
--- a/_tools/library_check/Program.cs
+++ b/_tools/library_check/Program.cs
@@ -1918,6 +1918,36 @@ internal static class Program
Check(Math.Abs(area - 1200.0) < 2.0 && RedAt(painted, 100 - 30, 60) == 150 && RedAt(painted, 100 - 31, 60) == 100 && RedAt(painted, 100 + 29, 60) == 150 && RedAt(painted, 100, 60 + 9) == 150 && RedAt(painted, 100, 60 + 10) == 100,
$"a rectangle of length 60 and width 20 lies square to the axis, x = 70..129, y = 50..69 ({area:F1} px)");
project.Parts.Clear();
+ var ellipse = (EllipsePart)project.AddPart(PartKind.Ellipse);
+ ellipse.X = 100;
+ ellipse.Y = 60;
+ ellipse.Length = 60;
+ ellipse.Width = 40;
+ painted = PartPainter.Paint(null, W, H, 1.0, project.Parts)!;
+ area = PaintedArea(painted, 1.5);
+ expected = Math.PI * 30 * 20;
+ Check(Math.Abs(area - expected) < 0.01 * expected && RedAt(painted, 100 + 28, 60) == 150 && RedAt(painted, 100 + 31, 60) == 100 && RedAt(painted, 100, 60 + 18) == 150 && RedAt(painted, 100, 60 + 21) == 100,
+ $"an ellipse of 60 by 40 covers {area:F1} px against π·30·20 = {expected:F1}, reaching 30 px along the axis and 20 across");
+ ellipse.Width = 60;
+ (double X, double Y)[] round = ellipse.Vertices();
+ Check(round.Length == ellipse.VertexCount && round.Length == 63 && round.All(v => Math.Abs(Math.Sqrt(v.X * v.X + v.Y * v.Y) - 30) < 1e-9) && Math.Abs(ellipse.AxisReach - 30) < 1e-9,
+ "a circle of 60: one vertex per three pixels of circumference (63), all 30 px from the centre");
+ Check(new EllipsePart { Length = 4, Width = 4 }.VertexCount == EllipsePart.MinVertices && new EllipsePart { Length = 2000, Width = 2000 }.VertexCount == EllipsePart.MaxVertices, "the vertex count stays within its limits");
+ // the chain: linking takes the length into the width, then either side moves the other
+ var linked = new RectanglePart { Length = 50, Width = 20 };
+ linked.Linked = true;
+ bool follows = linked.Width == 50;
+ linked.Length = 70;
+ follows &= linked.Width == 70;
+ linked.Width = 30;
+ follows &= linked.Length == 30;
+ linked.Linked = false;
+ linked.Length = 80;
+ Check(follows && linked.Width == 30, "a linked rectangle keeps width and length equal, an unlinked one not");
+ ellipse.Width = 10;
+ ellipse.Linked = true;
+ Check(ellipse.Width == 60 && ellipse.Vertices().All(v => Math.Abs(Math.Sqrt(v.X * v.X + v.Y * v.Y) - 30) < 1e-9), "a linked ellipse is a circle");
+ project.Parts.Clear();
var triangle = (TrianglePart)project.AddPart(PartKind.Triangle);
triangle.X = 100;
triangle.Y = 60;
@@ -2057,6 +2087,9 @@ internal static class Program
polygon.Mirror = true;
project.AddPart(PartKind.Polygon);
((RectanglePart)project.AddPart(PartKind.Rectangle)).Width = 7;
+ var roundOne = (EllipsePart)project.AddPart(PartKind.Ellipse);
+ roundOne.Linked = true;
+ roundOne.Width = 9;
((TrianglePart)project.AddPart(PartKind.Triangle)).Type = TriangleType.RightIsosceles;
project.AddPart(PartKind.Fiber);
var reflector = (BraggReflectorPart)project.AddPart(PartKind.BraggReflector);
@@ -2064,8 +2097,8 @@ internal static class Program
reflector.Index2 = 2.2;
project.AddPart(PartKind.GrinLens);
OpticalPart copy = project.Duplicate(reflector);
- Check(copy is BraggReflectorPart { Name: "Bragg reflector 1 copy", Angle: 45, Index2: 2.2 } && project.Parts.IndexOf(copy) == 7 && project.Parts.Count == 9, "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 == 8, "Remove and Move work on the parts list");
+ 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");
string xml;
using (var stream = new MemoryStream())
{
@@ -2076,17 +2109,17 @@ internal static class Program
"the file holds one element per kind, attributes only where they differ from the defaults");
Check(xml.Contains("<Outline Name=\"Outline 1\" X=\"100\" Y=\"60\" Mirror=\"true\">\r\n\t\t<Point X=\"3\" Y=\"-4\" />\r\n\t</Outline>".Replace("\r\n", Environment.NewLine)) || xml.Contains("<Outline Name=\"Outline 1\" X=\"100\" Y=\"60\" Mirror=\"true\">\n\t\t<Point X=\"3\" Y=\"-4\" />\n\t</Outline>"),
"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("<Triangle Name=\"Triangle 1\" X=\"100\" Y=\"60\" Type=\"RightIsosceles\" AngleA=\"45\" AngleB=\"45\" />"),
- "the polygon, rectangle and triangle elements, sparse");
+ 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.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 == 8 && back.Parts.Select(p => p.Kind).SequenceEqual([PartKind.BraggReflector, PartKind.Lens, PartKind.Outline, PartKind.Polygon, PartKind.Rectangle, PartKind.Triangle, PartKind.Fiber, PartKind.GrinLens]), "the eight kinds load back in order");
- Check(back.Parts[6] 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 TrianglePart { Type: TriangleType.RightIsosceles, AngleB: 45 },
+ 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[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");
var watched = new ProjectWatcher(back);
var changes = new List<ProjectChange>();