[cairo] New query functions: cairo_current_path, cairo_current_path_flat

Carl Worth cworth at east.isi.edu
Thu Feb 26 18:34:02 PST 2004


On Feb 18, Bill Spitzak wrote:
 > Because of alignment, the id may take the same space as a double. If this is 
 > a problem, perhaps 2 arrays can be returned, one with id's and the other with 
 > x/y pairs. Or 3 can be returned, with id's, x, and y in different
 > arrays.

As you can see, there are a lot of different data structure options
here. There's not one that is obviously right, and none are especially
easy to work with. The struggle to come up with a good structure is
what led me to postpone implementing this for so long. And no matter
what, the user is probably going to want her own structure anyway.

As an anecdote, inside cairo, we've got a memory-efficient data
structure for storing the path. It uses parallel (chunky) arrays, (one
for operators and one for coordinate pairs). The operators consume
anywhere from 0 to 3 pairs each.

This structure is such a pain to navigate that long ago I (or Keith
probably) wrote a single interpreter that is called from several
places with a callback interface.

It was only recently that I noticed that PostScript has a similar
callback interface and I realized that exporting this neatly avoids
the data structure specification problem entirely.

For now, I'm worried more about making the API clean and easy than I
am about performance. If there are real performance problems that
require making the API uglier, we can deal with that when the time is
right. In the meantime, my feeling is that even with the awkwardness
of the callback interface, it's easier to use correctly than any data
structure I've been able to imagine.

-Carl




More information about the cairo mailing list