From 8d7841048b079ce2a582ff17c90e82e0081e5f42 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Sun, 17 Jan 2010 19:00:47 +0100 Subject: [PATCH] Round caps coverage extimate explanation Comment on how the round caps coverage has been computed, explaining the complete procedure. The comments doesn't contain intermediate (verbose and ugly) results, but when executed in a symbolic math program (sage, for example) computes the expected results. Reviewed-by: M. Joonas Pihlaja --- src/cairo-stroke-style.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cairo-stroke-style.c b/src/cairo-stroke-style.c index 6ef85f4ba..28dc5ffb7 100644 --- a/src/cairo-stroke-style.c +++ b/src/cairo-stroke-style.c @@ -145,6 +145,22 @@ _cairo_stroke_style_dash_period (const cairo_stroke_style_t *style) /* * Coefficient of the linear approximation (minimizing square difference) * of the surface covered by round caps + * + * This can be computed in the following way: + * the area inside the circle with radius w/2 and the region -d/2 <= x <= d/2 is: + * f(w,d) = 2 * integrate (sqrt (w*w/4 - x*x), x, -d/2, d/2) + * The square difference to a generic linear approximation (c*d) in the range (0,w) would be: + * integrate ((f(w,d) - c*d)^2, d, 0, w) + * To minimize this difference it is sufficient to find a solution of the differential with + * respect to c: + * solve ( diff (integrate ((f(w,d) - c*d)^2, d, 0, w), c), c) + * Which leads to c = 9/32*pi*w + * Since we're not interested in the true area, but just in a coverage extimate, + * we always divide the real area by the line width (w). + * The same computation for square caps would be + * f(w,d) = 2 * integrate(w/2, x, -d/2, d/2) + * c = 1*w + * but in this case it would not be an approximation, since f is already linear in d. */ #define ROUND_MINSQ_APPROXIMATION (9*M_PI/32)