Skip to main content

Module shape

Module shape 

Source
Expand description

Shapes in whole console pixels, by one integer rule every renderer follows (ADR-0085 §8): each gives its pixels as runs, and a renderer fills each run as a rectangle one console pixel high. So shuyi-app, the raster and the one-bit renderers draw the same pixels by construction.

The rules, in console pixels, integers only. A point names a pixel: (x, y) is that pixel’s centre.

  • A line one pixel wide (line_runs) is Bresenham’s, from from to to, both ends drawn: the all-octant form whose error term starts at dx + dy (dx = |x1 − x0|, dy = −|y1 − y0|). Along its major axis (x when |dx| ≥ |dy|) it takes one pixel a step; pixel k from from is round(k · minor / major) along the other, a half rounded towards to. That closed form gives the pixels of the walk, so a line far longer than the clip costs no more than the clip: only the steps inside it are taken.
  • A circle’s outline of radius r (circle_outline_runs) is 2r + 1 pixels across: the midpoint circle whose decision value starts at 1 − r, one octant walked (at most r steps), each step giving its eight mirrored pixels.

A run is (y, x0, x1): row y, pixels x0..x1, half-open, always inside the clip. Runs may overlap (a circle’s mirrored pixels where the octants meet); every renderer paints them opaque, so that doesn’t matter.

Functions§

circle_outline_runs
Calls f(y, x0, x1) for the runs of the outline of the circle of radius round center inside clip (the module’s rule): one pixel a run.
line_runs
Calls f(y, x0, x1) for the runs of the line one pixel wide from from to to, both ends drawn, inside clip (the module’s rule). Each row of the line is one run.