[cairo] Re: On recovery from errors in cairo (was: cairo reset)

Kalle Vahlman kalle.vahlman at gmail.com
Sat Sep 23 04:12:20 PDT 2006

2006/9/22, Carl Worth <cworth at cworth.org>:
> I do understand that drawing something that's "wrong" in an obvious
> way might make it easier to debug than setting an error. But, we don't
> have an error in this case, we instead have the line_to implicitly
> convert to a move_to. The motivation for this is to allow for code
> which can loop over an array of points to set up a polygonal path:
>         for (i = 0; i < num_points; i++)
>             cairo_line_to (cr, points[i].x, points[i].y);
> rather than having to special-case the first point:
>         for (i = 0; i < num_points; i++)
>             if (i == 0)
>                 cairo_move_to (cr, points[i].x, points[i].y);
>             else
>                 cairo_line_to (cr, points[i].x, points[i].y);
> Of course, the special-casing approach still _works_ just fine. I just
> thought it would be kinder to allow the simpler approach above by
> defining reasonable behavior instead of an error state.

I can imagine not requiring an explicilty defined starting point (in
the application context) could be annoying if it is not consistent
throughout the API. A quick look indicates that it is, at least among
the cairo_*_to()-functions.

So I agree with this approach, but I'd still like to point out that
the alternative doesn't have to include an if statement that is only
baggage after the first iteration, nor to be so verbose:

    cairo_move_to (cr, points[0].x, points[0].y)
    for (i = 1; i< num_points; i++)
          cairo_line_to (cr, points[i].x, points[i].y);


Kalle Vahlman, zuh at iki.fi
Powered by http://movial.fi
Interesting stuff at http://syslog.movial.fi

More information about the cairo mailing list