[cairo] multiple paths

Behdad Esfahbod behdad at behdad.org
Mon Nov 5 10:31:34 PST 2007


On Mon, 2007-11-05 at 08:56 -0500, control H wrote:
> Hi,

Hi,

> I have a list of measured values and want to plot them. For every x_i
> from the list I do cairo_line_to(i,x_i) and when I've processed the
> whole list I stroke. Simple.
> 
> However, every x_i also has its own variance. And I want to plot a
> variance band around the line connecting the x_i's. For the code to be
> as efficient as possible I thought it's best when I iterate through
> the list of x_i's only once.

Normally, you should go ahead and write the code the easiest way
possible.  Then if it's slow, profile it and find a bottleneck and
optimize that.  This kind of assumption you are making most probably
falls in the premature-optimization zone.

> I was thinking of a solution like this: make 3 cairo paths. For every
> x_i, line_to in path1, line_to(i,x_i - variance_x_i) in path2 and
> line_to (i,x_i + variance_x_i) in path three. At the end, stroke
> path1, reverse path3, concat path3 to path2 and close path2, stroke
> path2.

I'd say build path1, path2, and path3, then just stroke them, and fixup
anything on the sides if you need.  Avoid the reversing.

> Now for the questions:
> first: how to make these paths in cairo
> second: is this the way to do it? Or is it really clumsy? I feel I'm
> missing something.

It definitely is clumsy.  The only way to do that in cairo is to create
three cairo_t objects for your surface and use each for one of the
paths.  This is because cairo doesn't have separate path creation API
other than that in cairo_t.

> thanks for your input,
> CH

Have fun with cairo!

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759





More information about the cairo mailing list