[cairo] cairo_matrix_transform_point, only X or Y

Gustavo J. A. M. Carneiro gjc at inescporto.pt
Tue Aug 8 18:00:55 PDT 2006


On Ter, 2006-08-08 at 17:25 -0700, Bill Spitzak wrote:
> If Cairo is doing rotations, the output x depends on both the x and y.

  True.  But if you know for sure there is no rotation involved, then
either X or Y is insignificant.

  There are two items that may be considered waste of cpu time:

	1- To return a transformed X, Y is used in the computations, even
though no rotation is involved;

	2- You may only want only the return value for X, however Y is computed
at the same time.

  In case of 1, if the math processing engine of the CPU is smart it can
notice that some elements of the matrix are zero and skip the
multiplication, so this might not constitute a performance penalty.  I'm
not sure; I guess it depends on the CPU implementation.

  In case of 2, it's a no brainer: if you only want X, why bother
computing Y?..

  If we consider 1 and 2, we need an API like "x2 = transformed_x(x1)".
If we neglect 1 and consider only 2, the API would be "x2 =
transformed_x(x1,y1)" as you suggest below.

> 
> I have found it very useful to have a transformed_x(x,y) call that 
> actually returns the value. This makes it much easier to write code 
> because you don't need to define temporary variables to pass as 
> references, ie "foo(transformed_x(x,y),transformed_y(x,y))" rather than 
> "double tx,ty; transform(x,y,&tx,&ty); foo(tx,ty)". However Cairo 
> functions always returns an error status (right?) so such an api would 
> not fit in.

  Well, I don't think transformations _can_ produce error conditions, so
we could return the value like you say.

> 
> Gustavo J. A. M. Carneiro wrote:
> >   I found myself in a postion where I'd like to convert some code to
> > transform coordinate systems over to use the cairo matrices APIs.  I
> > would like to use cairo_matrix_transform_point; however, in many places
> > I only need to convert either X or Y, not both, and it seems wasteful to
> > transform a dummy coordinate to throw it away.
> > 
> >   My question requires some knowledge of CPU performance in this case
> > and I seek advice:
> > 
> > 	1- Should I prepare a patch to add cairo_matrix_transform_x and
> > cairo_matrix_transform_y?
> > 
> > 	2- Or is it pointless to optimise here?
> > 
> >   Any thoughts?
> > 
> >   Regards,
> > 
-- 
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
The universe is always one step beyond logic



More information about the cairo mailing list