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

Kalle Vahlman kalle.vahlman at gmail.com
Sat Sep 23 09:59:00 PDT 2006


2006/9/23, Mike Emmel <mike.emmel at gmail.com>:
> 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.

Oh, I really did mean only the non-relative versions of the functions,
sorry for not being exact. For relative operations setting the error
is IMO warranted.

> 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.

It's clearly documented though. If you see code that does not
explicitly set the starting point you'll look the definition for such
case in documentation instead of just assuming it means "from 0,0",
right?

-- 
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