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#
Quick JIT off in every build and no ReadyToRun: all of the app's code is compiled optimised at its first call
Alexander Graef38ccc39ea339
diff --git a/CLAUDE.md b/CLAUDE.mdindex 80354e1..db88887 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -26,11 +26,25 @@ harnesses run.targeted probe or screenshot for a local change, `library_check` (20 s) for a library change, a UI harness onlywhen its flow changed, **once**. Never loop a harness for a flake, never run the suite after an edit.- **Measure properly**: warm the JIT; never poll UI Automation while measuring (it loads the UI thread it- measures); the app's own log lines are the measurement. **A hot loop measured alone may be a tier-1 figure the app never- reaches** (2026-11-03: the part painter took 31 ms in a probe and 115–460 ms in the app, the same call; in a busy WPF process- the runtime kept its per-pixel methods at tier-0 — the probe pinned there with `DOTNET_TC_CallCounting=0` reproduced the- app's 212 ms): compare a probe against the app's log, and take a hot path out of tiering with- `[MethodImpl(MethodImplOptions.AggressiveOptimization)]` where the gap is that.+ measures); the app's own log lines are the measurement. **Quick JIT is off** (`TieredCompilationQuickJit` in+ `Directory.Build.props`, 2026-11-03, the user's choice, after the part painter took 31 ms in a probe and 115–460 ms in the+ app, the same call: the runtime's tiering counts calls only after 100 ms without a first call of any method, ours or the+ framework's, and interrupts its background compiler at every such call (`tieredcompilation.cpp`), so a window under+ interaction keeps this code at tier 0; at a start 1158 of its methods were, none promoted; seen with+ `DOTNET_JitDisasmSummary=1` and `DOTNET_JitStdOutFile=<file>`, which list every jitted method with its tier): every method+ of this code is compiled optimised at its first call, in the app, `library_check` and the harnesses alike, so a probe+ and the app run the same code; the framework's precompiled code keeps tiering up; dynamic PGO is off, it needs quick+ JIT. Every build starts 0.45 s later for it, the published ones too, since they are plain IL (see Publish). The+ `AggressiveOptimization` attributes the painter's path had carried since that morning are gone (the user's request,+ once provably a no-op: the runtime's `method.cpp` makes every method of a module without precompiled code ineligible+ for tiering when quick JIT is off, `library_check` compiled the painter's methods the same with and without them, and+ Example 16 opened in the published EXE painted in the same milliseconds). A hot path would need the attribute again+ only with ReadyToRun: its precompiled code must stay valid across servicing of the runtime, so it inlines nothing from+ outside its assembly and reaches every framework method and struct layout through an indirection, which made the+ per-pixel path 5–10× slower than a first-call JIT (`Math.Round`, `Math.Clamp`, a span conversion and even our own+ `SegmentDistance` as a call per pixel, the vertices a `ValueTuple` of unknown size); seen by printing the JIT's listing+ from crossgen2 (`--codegenopt:JitDisasm=<patterns> --codegenopt:JitStdOutFile=<file> --parallelism:1`) beside the+ runtime's (`DOTNET_JitDisasm`, `DOTNET_JitStdOutFile`).- **Harnesses are keyboard-only**: post `WM_KEYDOWN`/`WM_CHAR` to the window, read state through UIA properties,never UIA patterns, the mouse, `SendKeys` or `SetForegroundWindow` (each activates the window). Modifiers cannotbe posted, so every command a harness presses has an unmodified key. Everything a harness needs has an@@ -93,7 +107,16 @@ harnesses run.- `dotnet build WaveDudeNext.sln` → 0 warnings. Harnesses use `WaveDudeNext.WPF\bin\Debug\net10.0-windows\WaveDudeNext.WPF.exe`.- `dotnet run --project _tools/library_check -c Release` (`-- export`, `-- bench [w h]`, `-- bench-render [w h]`,`-- bench-export [w h]`); `powershell -ExecutionPolicy Bypass -File _tools/ui_check/<script>.ps1` (`-Trace`).-- Publish: `dotnet publish WaveDudeNext.WPF/WaveDudeNext.WPF.csproj -p:PublishProfile=SingleFile`. Version in+- Publish: `dotnet publish WaveDudeNext.WPF/WaveDudeNext.WPF.csproj -p:PublishProfile=SingleFile` (framework-dependent;+ `SingleFileBundled` carries the runtime). **No ReadyToRun** (2026-11-03, the user's choice after a day with it): it+ bought 0.55 s of start (1.90 s to the first idle of the window against 2.44 for the plain IL) and cost the painter's+ per-pixel path 5–10× until a tier-1 promotion a busy window postpones (see Measure properly), so the shipped EXE runs+ the code the probes measure: 7.3 MB, 2.44 s; the bundled one 146 MB. Should it return: for a self-contained single file+ the SDK defaults to one composite image of the runtime and the app (168 MB, 1.78 s, the one form of precompiled code+ that may inline the framework, untested on the painter), and its ReadyToRun step is incremental on+ `obj\...\win-x64\R2R`, which both profiles share: a publish after a composite one reused the composite's component stubs+ without their image, so the EXE died at start with a fail-fast before its first log line (both profiles;+ `DOTNET_ReadyToRun=0` let it start, which named the cause); that folder would need a clean before every publish. Version in`Directory.Build.props`; the commit hash lands in About. The license header is the `.editorconfig``file_header_template` (its warranty sentence ends in a full stop: Roslyn cuts the value at `;`). LICENSE.md isthe FSF's GPL-3.0 Markdown verbatim, nothing else (GitHub's detector rejects additions); the About dialog shows@@ -490,10 +513,12 @@ coalesced update repainted all four rectangles, one the whole canvas, "composedpoint and node lists) and paints on the thread pool, one composition in flight, the newest request after it, the UIthread taking only the finished pixels (20–24 ms a time, measured on a burst of ten nudges: three compositions of 395,212 and 128 ms on the worker); `LoadSceneImage` (a run or scratch request) joins an in-flight composition of the same-inputs rather than painting again. **The painter's per-pixel path is out of JIT tiering** (2026-11-03, the user's choice):-alone it took 31 ms for those four parts, in the app 115–460 ms, because the runtime left its methods at tier-0 code in-the busy process (pinned there, the probe took 212 ms); `AggressiveOptimization` on the shape methods a pixel reaches, the-painter's row lambdas and the glowing edges' makes a composition 26–35 ms a background and 10–17 ms a box in the app,+inputs rather than painting again. **The painter's per-pixel path is out of JIT tiering** (2026-11-03, the user's choice,+first by `AggressiveOptimization` on the shape methods a pixel reaches, the painter's row lambdas and the glowing edges',+since that evening by quick JIT off for all of this code, see Measure properly, the attributes gone): alone+it took 31 ms for those four parts, in the app 115–460 ms, because the runtime left its methods at+tier-0 code in the busy process (pinned there, the probe took 212 ms); optimised at first call,+a composition is 26–35 ms a background and 10–17 ms a box in the app,74 ms for the four during a burst of nudges (was 395–460), the pictures 17–32 ms on the UI thread. Each part logs itspaint time, and a composition logs the thread pool's state when it starts. **A pixel is sampled 16 times only where anedge is within reach** — the outline, the coating band's, or an inner edge the shape reports (`InnerEdgeDistance`: adiff --git a/Directory.Build.props b/Directory.Build.propsindex bf30106..1ac3b5f 100644--- a/Directory.Build.props+++ b/Directory.Build.props@@ -8,4 +8,18 @@<Description>A 2D wave simulator</Description></PropertyGroup>+ <!-- No quick JIT (2026-11-03, the user's choice): every method of this code, and of a package without precompiled+ code, is compiled optimised at its first call, so no tier-0 code exists in the app's own code. The runtime's+ tiering starts call counting only after 100 ms without a first call of any method, ours or the framework's, and+ interrupts its background compiler whenever that happens; a window under interaction keeps that delay alive, so+ the painter's per-pixel methods ran as tier-0 code at 115-460 ms a composition where a probe took 31 ms, and at a+ start 1158 methods of this code were tier-0 and none promoted. The framework's precompiled code keeps tiering up as+ Microsoft tuned it; dynamic PGO is off, since the runtime needs quick JIT for it. Here, so the app, library_check+ and every harness run alike. No ReadyToRun in the publish profiles either (the same day): its version-resilient+ code ran the painter's per-pixel path 5-10x slower than a first-call JIT, so the shipped build is compiled like+ the plain one, for about 0.45 s of start-up JIT. -->+ <PropertyGroup>+ <TieredCompilationQuickJit>false</TieredCompilationQuickJit>+ </PropertyGroup>+</Project>diff --git a/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFile.pubxml b/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFile.pubxmlindex ae80004..bd8dfe4 100644--- a/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFile.pubxml+++ b/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFile.pubxml@@ -3,6 +3,12 @@for the release by the project's NameReleaseFile target, the colour schemes and the examples embedded, no symbolfiles beside it. The .NET Desktop Runtime must be on the user's machine; without it the host shows Microsoft's"You must install .NET" dialog with the download link. SingleFileBundled.pubxml is the self-contained counterpart.+ No ReadyToRun (2026-11-03, the user's choice after a day with it): precompiled code must stay valid across servicing+ of the runtime, so it inlines nothing from outside its assembly and reaches every framework method and struct layout+ through an indirection, which made the painter's per-pixel path 5-10x slower than the code the runtime's JIT makes+ at a first call, until a tier-1 promotion a busy window postpones. With quick JIT off (Directory.Build.props) every+ method of this code is compiled optimised at its first call in every build, this one included, for about 0.45 s of+ start-up JIT. The details and the SDK trap a return would have to mind are in CLAUDE.md under Publish.dotnet publish WaveDudeNext.WPF/WaveDudeNext.WPF.csproj -p:PublishProfile=SingleFile --><Project><PropertyGroup>diff --git a/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFileBundled.pubxml b/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFileBundled.pubxmlindex 55a30e7..78c20d1 100644--- a/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFileBundled.pubxml+++ b/WaveDudeNext.WPF/Properties/PublishProfiles/SingleFileBundled.pubxml@@ -2,7 +2,13 @@<!-- Single-file, self-contained publish for 64-bit Windows: one EXE in bin\PublishBundled with the .NET runtime inside,so nothing has to be installed on the user's machine, named WaveDudeNext-<version>-bundled.exe for the release by theproject's NameReleaseFile target, no symbol files beside it. The counterpart of SingleFile.pubxml, which leaves the- runtime to the machine (2026-10-31, the user's request, to compare the two).+ runtime to the machine (2026-10-31, the user's request, to compare the two). No ReadyToRun, as in SingleFile.pubxml+ (2026-11-03). Should it ever return here: for a self-contained single file the SDK defaults to one composite image of+ the runtime and the app (22 MB more, the one form of precompiled code that may inline the framework, untested on the+ painter's path), and its ReadyToRun step is incremental on obj\...\R2R, which both profiles share: a publish after a+ composite one reused the composite's component stubs without their image, and the EXE died at start with a fail-fast+ (0xC0000602) before its first log line (2026-11-03, seen on both profiles). That folder would need a clean before+ every publish.dotnet publish WaveDudeNext.WPF/WaveDudeNext.WPF.csproj -p:PublishProfile=SingleFileBundled --><Project><PropertyGroup>diff --git a/WaveDudeNext/Parts/PartPainter.cs b/WaveDudeNext/Parts/PartPainter.csindex aceb9b7..dc1a849 100644--- a/WaveDudeNext/Parts/PartPainter.cs+++ b/WaveDudeNext/Parts/PartPainter.cs@@ -16,7 +16,6 @@// <https://www.gnu.org/licenses/>.using System.Diagnostics;-using System.Runtime.CompilerServices;using NLog;using WaveDudeNext.Model;using WaveDudeNext.Runs;@@ -131,7 +130,7 @@ public static class PartPainter{if (shape.IsMirror){- Parallel.For(y0, y1 + 1, [MethodImpl(MethodImplOptions.AggressiveOptimization)] (int y) =>+ Parallel.For(y0, y1 + 1, (int y) =>{int row = y * stride;for (int x = x0; x <= x1; x++)@@ -147,7 +146,7 @@ public static class PartPainterconst double step = 1.0 / Supersample;const double half = step / 2.0;int coating = shape.CoatingWidth;- Parallel.For(y0, y1 + 1, [MethodImpl(MethodImplOptions.AggressiveOptimization)] (int y) =>+ Parallel.For(y0, y1 + 1, (int y) =>{int row = y * stride;for (int x = x0; x <= x1; x++)@@ -213,7 +212,7 @@ public static class PartPainterfloat[] depths = new float[columns * (y1 - y0 + 1)];double deepest = 0.0;var gate = new Lock();- Parallel.For(y0, y1 + 1, () => 0.0, [MethodImpl(MethodImplOptions.AggressiveOptimization)] (int y, ParallelLoopState _, double local) =>+ Parallel.For(y0, y1 + 1, () => 0.0, (int y, ParallelLoopState _, double local) =>{int row = (y - y0) * columns;for (int x = x0; x <= x1; x++)@@ -233,7 +232,7 @@ public static class PartPainterdouble ramp = Math.Min(shape.AbsorptionRamp, deepest);int full = shape.Absorption;Logger.Debug("Absorption {Absorption} over a ramp of {Ramp:0.#} px (the part reaches {Deepest:0.#} px deep)", full, ramp, deepest);- Parallel.For(y0, y1 + 1, [MethodImpl(MethodImplOptions.AggressiveOptimization)] (int y) =>+ Parallel.For(y0, y1 + 1, (int y) =>{int row = (y - y0) * columns;for (int x = x0; x <= x1; x++)diff --git a/WaveDudeNext/Parts/PartShape.cs b/WaveDudeNext/Parts/PartShape.csindex f8c3f89..c9990ff 100644--- a/WaveDudeNext/Parts/PartShape.cs+++ b/WaveDudeNext/Parts/PartShape.cs@@ -15,7 +15,6 @@// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or// <https://www.gnu.org/licenses/>.-using System.Runtime.CompilerServices;using WaveDudeNext.Model;namespace WaveDudeNext.Parts;@@ -80,11 +79,9 @@ public abstract class PartShape/// The face nearest the point (x', y') of the part frame. Asked only inside the band of a part that leaves a face/// bare, so a shape without faces to tell apart answers <see cref="Face.Front"/>./// </summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected virtual Face FaceAt(double x, double y) => Face.Front;/// <summary>Whether the band at (x', y') is painted: the flag of the nearest face, without the search when every face is coated.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private bool Coated(double x, double y) =>_frontCoated && _backCoated && _sidesCoated || FaceAt(x, y) switch { Face.Front => _frontCoated, Face.Back => _backCoated, _ => _sidesCoated };@@ -96,7 +93,6 @@ public abstract class PartShape/// tenths of a percent of the best at two, where the linear ramp reflects three to four times as much./// </summary>/// <param name="t">Depth over thickness; clamped to 0..1.</param>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public static double GradedProfile(double t){t = Math.Clamp(t, 0.0, 1.0);@@ -147,7 +143,6 @@ public abstract class PartShape/// cubic close behind; the figures are under "Absorption" in OpticalParts.md./// </summary>/// <param name="t">Depth over ramp; clamped to 0..1.</param>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public static double AbsorptionProfile(double t){t = Math.Clamp(t, 0.0, 1.0);@@ -160,7 +155,6 @@ public abstract class PartShape/// <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>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public virtual double AbsorptionShareAt(double canvasX, double canvasY, double depth, double ramp) =>AbsorptionProfile(ramp > 0.0 ? depth / ramp : 1.0);@@ -180,11 +174,9 @@ public abstract class PartShape/// the outline nor an inner edge is within reach (2026-11-03: every pixel of a fibre had taken 16 samples, 400 ms for/// Example 23's wide fibre). A shape with inner edges that does not say returns 0, which keeps every inside pixel sampled./// </summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected virtual double InnerEdgeDistance(double x, double y) => HasInnerEdges ? 0.0 : double.PositiveInfinity;/// <summary>How far inside the outline the canvas point lies, in pixels (negative outside): the exact distance for straight and circular edges, so the painter can tell a pixel wholly inside or outside from one sample.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public double DepthAt(double canvasX, double canvasY){(double x, double y) = ToFrame(canvasX, canvasY);@@ -192,7 +184,6 @@ public abstract class PartShape}/// <summary><see cref="DepthAt"/> and the distance to the nearest inner edge (<see cref="InnerEdgeDistance"/>) of the canvas point, in one mapping into the part frame.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public (double Depth, double InnerEdge) DepthsAt(double canvasX, double canvasY){(double x, double y) = ToFrame(canvasX, canvasY);@@ -200,7 +191,6 @@ public abstract class PartShape}/// <summary>Maps a canvas point into the part frame: the inverse of the composite source's turn (x = dx cos + dy sin, y = dy cos - dx sin), the transpose.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private (double X, double Y) ToFrame(double canvasX, double canvasY){double ox = canvasX - _centreX;@@ -229,7 +219,6 @@ public abstract class PartShape}/// <summary>The index at a canvas point as <see cref="IndexAt(double, double, double)"/> gives it over a medium of index 1.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public double? IndexAt(double canvasX, double canvasY) => IndexAt(canvasX, canvasY, 1.0);/// <summary>@@ -241,7 +230,6 @@ public abstract class PartShape/// <param name="canvasX">Canvas x, continuous.</param>/// <param name="canvasY">Canvas y, continuous.</param>/// <param name="outside">The index the pixel had before the part, the medium a graded band rises from.</param>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public double? IndexAt(double canvasX, double canvasY, double outside){(double x, double y) = ToFrame(canvasX, canvasY);@@ -275,7 +263,6 @@ public abstract class PartShapeprotected static int GuardCoating(int coating) => Math.Clamp(coating, 0, OpticalPart.MaxCoating);/// <summary>Signed distance of (x, y) inside a simple polygon: the distance to the nearest edge, negative outside (even-odd rule).</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected static double PolygonDepth(ReadOnlySpan<(double X, double Y)> vertices, double x, double y){bool inside = false;@@ -298,7 +285,6 @@ public abstract class PartShape}/// <summary>Distance from (x, y) to the segment a–b.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected static double SegmentDistance(double ax, double ay, double bx, double by, double x, double y){double dx = bx - ax;@@ -341,20 +327,16 @@ public abstract class PartShapepublic override int Absorption { get; }public override int AbsorptionRamp { get; }protected override double Extent => _extent;- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double BodyIndex(double x, double y) => _index;/// <summary>How far a surface of radius <paramref name="radius"/> bows out beyond its vertex at the lens edge.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private double Sag(double radius) => LensPart.Sag(radius, _half);/// <summary>The least of: inside the first surface, inside the second, within the half-diameter.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double Depth(double x, double y) =>Math.Min(Math.Min(SurfaceDepth(x, y, _vertex1, _r1, -1), SurfaceDepth(x, y, _vertex2, _r2, +1)), _half - Math.Abs(y));/// <summary>The nearest of the three: the first surface is the front, the second the back, the rim the sides.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override Face FaceAt(double x, double y){double first = SurfaceDepth(x, y, _vertex1, _r1, -1);@@ -370,7 +352,6 @@ public abstract class PartShape/// radius and side have opposite signs. Distances are to the circle, so the coating band keeps its thickness/// along the normal./// </summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private static double SurfaceDepth(double x, double y, double vertex, double radius, int side){if (radius == 0.0)@@ -433,7 +414,6 @@ public abstract class PartShape}/// <summary>The face of the edge nearest the point.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override Face FaceAt(double x, double y){int nearest = 0;@@ -455,9 +435,7 @@ public abstract class PartShapepublic override int Absorption { get; }public override int AbsorptionRamp { get; }protected override double Extent => _extent;- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double Depth(double x, double y) => PolygonDepth(_vertices, x, y);- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double BodyIndex(double x, double y) => _index;}@@ -580,7 +558,6 @@ public abstract class PartShape/// outer radius − 2 × band to the peak, and falling the same way to nothing at the outer edge; the depth given by/// the painter is not used, so the band runs up to an end face and stops there instead of wrapping it./// </summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public override double AbsorptionShareAt(double canvasX, double canvasY, double depth, double ramp){if (_band <= 0.0)@@ -602,7 +579,6 @@ public abstract class PartShape/// The start face is the front, the end face the back, the tube the sides: with flat ends, whichever of the three/// the point is nearest to inside; with round ends, the caps before the start and beyond the end./// </summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override Face FaceAt(double x, double y){int last = _path.Length - 1;@@ -620,13 +596,10 @@ public abstract class PartShapepublic override bool HasInnerEdges { get; }/// <summary>The core boundary's distance, |r − core radius| by the distance from the path; none without a cladding.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double InnerEdgeDistance(double x, double y) => HasInnerEdges ? Math.Abs(PathDistance(x, y) - _coreRadius) : double.PositiveInfinity;protected override double Extent => _extent;- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double BodyIndex(double x, double y) => PathDistance(x, y) <= _coreRadius ? _coreIndex : _claddingIndex;- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double Depth(double x, double y){(int from, int to) = ChordsNear(x, y);@@ -675,7 +648,6 @@ public abstract class PartShape}/// <summary>Distance to the nearest chord of the path among those listed for the point's cell (exact within the tube, where the nearest chord is always listed).</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private double PathDistance(double x, double y){(int from, int to) = ChordsNear(x, y);@@ -689,7 +661,6 @@ public abstract class PartShape}/// <summary>The range in the chord lists for the cell of (x', y'): empty outside the grid.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private (int From, int To) ChordsNear(double x, double y){int column = (int)Math.Floor((x - _gridX) / CellSize);@@ -703,15 +674,12 @@ public abstract class PartShape}/// <summary>The cell holding (x', y'), clamped onto the grid.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private (int Column, int Row) CellOf(double x, double y) =>(Math.Clamp((int)Math.Floor((x - _gridX) / CellSize), 0, _columns - 1), Math.Clamp((int)Math.Floor((y - _gridY) / CellSize), 0, _rows - 1));- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private static double Square(double v) => v * v;/// <summary>The direction (x, y) as a unit vector, or null for a zero vector.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private static (double X, double Y)? Unit(double x, double y){double length = Math.Sqrt(x * x + y * y);@@ -744,17 +712,14 @@ public abstract class PartShapeprotected override double Extent => Math.Sqrt(_halfLength * _halfLength + _halfWidth * _halfWidth);/// <summary>The nearest layer boundary along x': a pair's edges at 0, its first thickness and the period.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double InnerEdgeDistance(double x, double y){double along = (x + _halfLength) % _period;return Math.Min(along, Math.Min(Math.Abs(along - _thickness1), _period - along));}- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double Depth(double x, double y) => Math.Min(_halfLength - Math.Abs(x), _halfWidth - Math.Abs(y));/// <summary>The first layer of a pair starts at -L/2 and the pairs repeat along +x'.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double BodyIndex(double x, double y){double along = (x + _halfLength) % _period;@@ -781,16 +746,13 @@ public abstract class PartShapepublic override bool IsMirror => false;protected override int Coating { get; }protected override double Extent => Math.Sqrt(_halfLength * _halfLength + _halfDiameter * _halfDiameter);- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double Depth(double x, double y) => Math.Min(_halfLength - Math.Abs(x), _halfDiameter - Math.Abs(y));/// <summary>The end faces across the axis are the front (−x') and the back, the long sides the sides.</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override Face FaceAt(double x, double y) =>_halfLength - Math.Abs(x) <= _halfDiameter - Math.Abs(y) ? (x < 0.0 ? Face.Front : Face.Back) : Face.Sides;/// <summary>n(y') = n_c − (n_c − n_e)·(y' / (D/2))².</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double BodyIndex(double x, double y){double t = y / _halfDiameter;@@ -828,13 +790,10 @@ public abstract class PartShapepublic 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);- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double Depth(double x, double y) => Math.Min(_halfThickness - Math.Abs(x), _outerHalfWidth - Math.Abs(y));- [MethodImpl(MethodImplOptions.AggressiveOptimization)]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>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public override double AbsorptionShareAt(double canvasX, double canvasY, double depth, double ramp){(double x, double y) = ToFrame(canvasX, canvasY);@@ -902,7 +861,6 @@ public abstract class PartShape/// 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>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]public override double AbsorptionShareAt(double canvasX, double canvasY, double depth, double ramp){(double x, double y) = ToFrame(canvasX, canvasY);@@ -918,7 +876,6 @@ public abstract class PartShape}/// <summary>The distance from the nearer arm's centre line, and whether that arm is B (below the axis).</summary>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]private (double Distance, bool ArmB) Nearest(double x, double y){(double offset, double slope) = _design.ArmOffsetAndSlope(x);@@ -926,11 +883,9 @@ public abstract class PartShapereturn (Math.Abs(Math.Abs(y) - offset) * cos, y > 0.0);}- [MethodImpl(MethodImplOptions.AggressiveOptimization)]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>- [MethodImpl(MethodImplOptions.AggressiveOptimization)]protected override double BodyIndex(double x, double y){(double distance, bool armB) = Nearest(x, y);diff --git a/WaveDudeNext/Rendering/GlowingEdges.cs b/WaveDudeNext/Rendering/GlowingEdges.csindex 8bd444b..b9b2eb5 100644--- a/WaveDudeNext/Rendering/GlowingEdges.cs+++ b/WaveDudeNext/Rendering/GlowingEdges.cs@@ -15,7 +15,6 @@// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or// <https://www.gnu.org/licenses/>.-using System.Runtime.CompilerServices;namespace WaveDudeNext.Rendering;@@ -56,7 +55,7 @@ public static class GlowingEdgesreturn result;}// rows are independent: a Full HD canvas took 60 ms on one core (2026-10-19)- Parallel.For(1, height - 1, [MethodImpl(MethodImplOptions.AggressiveOptimization)] (int y) =>+ Parallel.For(1, height - 1, (int y) =>{int rowUp = (y - 1) * strideBytes;int rowMid = y * strideBytes;