Derivative

Nile, run on a different kind of number: the pipeline that draws a curve also says how the picture changes as the curve moves. Followed downhill, a circle finds a letter.

Led by the exact rasterizer (RasterizeExact: curves cut where they meet the grid)

Led by gezira's (RasterizeParallel: curves cut by gezira's DecomposeBeziers)

shape and letter agree shape where the letter is not letter the shape has not reached

Charge. The outline's signed height in each pixel, after ReduceBy: all the pipeline knows of the curve.
Its sum along each row (WindScan), as coverage (SpansOf): the picture.
Its derivative. How each pixel changes as the marked point moves right: the same pipeline, on dual numbers.

In the last three: less, or downward more, or upward. They show the shape on the left. Point at one of its control points to mark it; hold shift for its movement down.

How to use: type a letter, or pick one, and watch both circles look for it. start again sets the circle down somewhere else within a pixel; tick and again and the page keeps count of where each shape ends. Drag any control point away and let go: the shape goes back to looking. Letters with a hole or a second part (O, a, ?) are beyond one closed curve.

Rendering: about 120 lines of Nile and 190 of TypeScript; the looking (the error, its blur, the step) is the TypeScript. The page’s interface isn’t counted.

See the Nile pipeline

Nothing in this Nile was written to be differentiated. RasterizeExact is the rasterizer the other pages can draw with: it cuts each curve where it turns and where it meets the pixel grid, says the area each piece leaves in its pixel, sums those by pixel and runs the sum along each row. When this page loads, umgeni compiles the same source a second time, in your browser, as its own derivative: every number in every kernel becomes the number and how it changes as each of the shape's 32 control points moves across or down, 64 directions in all. The compiled code is then an ordinary pipeline whose tokens are 65 times as wide. The arithmetic of those wider numbers is written once, and the interpreter of Nile's meaning uses it too, which is how the compiled derivative is checked.

So each pixel of the shape's picture comes back with 64 slopes, and plain TypeScript does the looking: it compares the picture with the letter's, asks of each pixel on the outline which way would lessen the difference nearby, and moves the control points a little that way, nine hundred times. The view of the difference starts blurred and sharpens, because a pixel's coverage only changes where the outline is, and an outline cannot answer for what it is not touching.

The two shapes differ in one stage, the first: how a curve is cut into the pieces that become edge samples. gezira's DecomposeBeziers moves each cut onto the pixel grid when it is within a tenth of a pixel of it, so as a point moves the area it computes goes in small steps about the true one, and the slope it reports is the slope of the steps. The exact cutting is where the curve meets the grid, and its slope is the area's. Both shapes start from the same circle and take their steps by the same rule, and both are measured the same way, by the exact rasterizer's picture of where they ended.

What the truer slope buys is not always distance. It is that the shape ends in the same place. Set the circle down a fraction of a pixel away and the exact rasterizer's shape arrives where it did before, or close by; the other arrives somewhere else each time, sometimes nearly as far and sometimes well short, because every small step of its area sends it a slightly different way. Over eight random starts for each of S, C, G, 5, L and r while this page was written, the exact shape was ahead in all forty-eight. On S it ended at 97.3% every time and the other between 84 and 96; on L, its least steady, between 94.4 and 96.3 against 86.7 to 88.6.