[cairo] Zero matrix transformation
Behdad Esfahbod
behdad at behdad.org
Fri Mar 21 02:09:01 PDT 2008
On Thu, 2008-03-20 at 04:05 -0400, Daniel Kraft wrote:
> I'd tend to say all this should be allowed to stay consistent with
> "allow zero matrices, simply draw nothing/shade with average colour",
> but well, this is probably not my decision ;)
You are pretty close. Forget about the implementation details and think
about the API. Whatever makes sense, should be possible. Pretty much
the only thing that should cause an error is
cairo_transform_device_to_user() when the matrix is degenerate. And
that should return a cairo_status_t.
> I can think of two possible solutions:
>
> 1) Simply make the matrix all zero,
Note that 0,0,0,0 is not the only degenerate matrix. Rank-1 matrices
are particularly hard to deal with.
> and add special handling to
> inversion routines to allow this one and define the inverse as, say,
> / Inf 0 \
> \ 0 Inf /.
> I'm not sure if this is 100% consistent with, say, rotating the
> matrix
> by 90/180 degrees and expecting that the inverse mapping produces
> Infinity with the "correct" signs and such. But this is probably not
> something very needed, anyway.
Nah, we don't want to invent workarounds. We need to add an internal
cairo_transform_t type that keeps a matrix, it's invert, and various
properties about the matrix (is_identity, is_integer_transform,
is_invertible, ...). If the matrix is degenerate, there wouldn't be an
invert, and any place you *need* the invert, an error will be generated.
> 2) Store to each matrix in addition to the six components a scalar
> factor; this would allow the structure of the matrix to be kept when
> scaling it down to zero (and possibly to simply set the factor to
> something else later to restore it) and would be easier to keep
> consistent. On the other hand this would mean a lot of extra
> multiplications every time something is transformed. Would this be a
> performance problem?
Keeping a separate matrix shape may be necessary, yes. For example to
do really correct EXTEND_PAD on image surfaces. But that's getting
really hard really quick.
> BTW, should a matrix like (0, 0, 0, 0, 1, 1) be allowed, that is,
> mapping every point to (1, 1)? (But this can only be done by
> cairo_set_matrix as scaling would bring the offset down to zero, too,
> I suppose).
Yes, of course. The idea is: any matrix is allowed to be set. Only err
when a matrix does not let you do mathematically correct computation
when you need to.
--
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