[cairo] plots of contiguous rectangles

Tamas K Papp tpapp at Princeton.EDU
Thu Aug 9 02:21:22 PDT 2007


On Wed, Aug 08, 2007 at 09:57:14AM -0700, Carl Worth wrote:
> On Wed, 8 Aug 2007 18:50:16 +0200, Tamas K Papp wrote:
> >
> > How could I get rid of both?
> 
> Snapping to device-space integers is what I would recommend.
> 
> Something like:
> 
> 	void
> 	snap_point (cairo_t *cr, double *x, double *y)
> 	{
> 	    cairo_user_to_device (cr, x, y);
> 	    *x = round (*x);
> 	    *y = round (*y);
> 	    cairo_device_to_user (cr, x, y);
> 	}
> 
> 	snap_point (cr, &x1, &y1);
> 	snap_point (cr, &x2, &y2);
> 
> 	cairo_rectangle (cr, x1, y2, x2 - x1, y2 - y2);
> 
> >                              Snapping to integer grids is something I
> > want to avoid: I am drawing on vector and bitmap surfaces, and I would
> > have to keep tack of which is which.  But if there is not other
> > solution, I can try to manage that, I just need to know.
> 
> 
> Even if you didn't distinguish between vector and bitmap surfaces,
> (which I can understand your reluctance to do), the device-space grid
> for a vector surface such as PostScript or PDF will be 1 device-space
> unit == 1 point (1/72 inch). Would a maximum error of half of 1/144
> inch be a noticeable problem?

Thank you Carl,

Indeed it is not a problem, and your solution works fine.

Thanks,

Tamas







More information about the cairo mailing list