[cairo] adding a new curve type to cairo
William Swanson
swansontec at gmail.com
Thu Jul 13 02:49:29 PDT 2006
On 7/12/06, Paul Davis <paul at linuxaudiosystems.com> wrote:
> then please feel free to cook up the converter code overnight, and i'll
> merge it into our code and try to write up a cairo tester for the
> result. did i say thanks yet? :))
Bill Spitzak's earlier email already contains the solution. In code,
it would look something like this:
for (i = 0; i < point_count - 1; i++)
double f0 = /*Calculate f'(i) according to the paper */;
double f1 = /*Calculate f'(i+1) according to the paper */;
if (i == 0)
cairo_move_to(x[i], y[i]);
cairo_curve_to(
(2*x[i] + x[i+1]) / 3, y[i] + f0 * (x[i+1]-x[i]) / 3,
(x[i] + 2*x[i+1]) / 3, y[i+1] - f1 * (x[i+1]-x[i]) / 3,
x[i+1], y[i+1]
);
}
Here, function f'() is the same as formula 7a in the paper. At the
endpoints, it becomes either formula 7b or 7c. You already calculate
these functions on lines 124 - 162, so this part should be pretty much
copy-paste.
Also, the math seems simple enough to run directly in the rendering
loop as shown above. There is no need to pre-calculate and store
Bezier control points when you can get them on-the-fly with only a few
simple operations.
-s_tec
More information about the cairo
mailing list