# Pixel Building Forum

## Rasterization => Quadratic Pixel Building => Topic started by: PiotrGrochowski on September 19, 2020, 04:46:52 pm

Post by: PiotrGrochowski on September 19, 2020, 04:46:52 pm
The main way to turn quadratic outlines into pixel borders. This must be done twice horizontally and once vertically for correct rendering, for proper handling of half pixel corners later. This step is followed by Pixel Building inside the borders, done in one pass each for the top and bottom edges, and two passes each for left and right edges. The possibility of missing extrema is ignored.

First, we have to turn the Quadratic Bezier into a Quadratic Polynomial: for each dimension, given the points a, b, c, the quadratic function where f(0)=a and f(1)=c (curve goes from 0 to 1) is (a)x⁰+(2*(b-a))x¹+((c+a)-(2*b))x².

We have the quadratic polynomial, (q)x⁰+(w)x¹+(e)x². In both horizontal and vertical dimensions, where the curve goes from 0 to 1.

We apply this rule: For each half pixel position (let's say, j) along a dimension we place an edge. First we apply the Quadratic Formula to determine at what location on the curve the coordinate is located.
It is located at
double r = j-q; double t = w/(-2.0*e); double y; if(1.0/t == 0.0) y = r/w; else if(t<0.5) y = t+sqrt((t*t)+(r/e)); else y = t-sqrt((t*t)+(r/e)); return y;
With the location now known, it is possible to determine where the edge would be. On the other dimension, we simply do (q)x⁰+(w)x¹+(e)x² with the obtained location. It must then be rounded to nearest integer. For half-rounding note that because pixels on TOP of the outline are inside, half-edges on the top and right are rounded up, while half-edges on the bottom and left are rounded down.
The Quadratic Formula is absolutely necessary to rasterize quadratic outlines. It can be figured out with a lot of mathematical thinking, however it is very common to make mistakes in implementation of it.