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

Mike Emmel mike.emmel at gmail.com
Sat Sep 23 09:01:12 PDT 2006


On 9/23/06, Kalle Vahlman <kalle.vahlman at gmail.com> wrote:
> 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.
>
Thats not true line_to does a move to but other functions like
cairo_rel_curve_to error instead of say doing a move_to 0, 0
then drawing. Which would be consistent with the way line_to
works. Same with  cairo_rel_line_to.

I'm sorry but the line_to -> move_to thing is a hack and if you read
the code it does not show you whats really going on unless your
aware of the hack.


> 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
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
>


More information about the cairo mailing list