[cairo] Bug in cairo_in_stroke()

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Thu Mar 26 23:18:40 PDT 2009


Soeren Sandmann wrote:
> Since it worked so well last time (thanks Bertram!), here is a similar
> bug in cairo_in_stroke(). The attached program produces this image:
> 
>         http://imgur.com/AQYPK.png
> 
> As before, the red parts are where cairo_in_stroke() returns TRUE, the
> blue parts where it returns FALSE. 

Fixed by commit fe10cd64.

> This one was introduced here:
> 
>     commit e217c4da7bc5c4817e0d829ff61dd2bd5b3145a6
>     Author: Chris Wilson <chris at chris-wilson.co.uk>
>     Date:   Mon Jan 19 15:28:05 2009 +0000
> 
>         [in-stroke] Check point against extents before computing path.

That patch looks correct.

The fault was actually in the extents calculation. _cairo_spline_bound
had a wrong sign:

diff --git a/src/cairo-spline.c b/src/cairo-spline.c
index 948516e..45eedbd 100644
--- a/src/cairo-spline.c
+++ b/src/cairo-spline.c
@@ -289,7 +289,7 @@ _cairo_spline_bound (cairo_spline_add_point_func_t add_point_func,
                 *   0 < (-b±√delta)/a < 1 \
                 */ \
                if (_2ab >= 0) \
-                   feasible = delta > b2 && delta < a*a + b2 - _2ab; \
+                   feasible = delta > b2 && delta < a*a + b2 + _2ab; \
                else if (-b / a >= 1) \
                    feasible = delta < b2 && delta > a*a + b2 + _2ab; \
                else \

I'll write more about the math here later.

Bertram


More information about the cairo mailing list