[cairo] Transform+Repeat patch for libpixman
Carl Worth
cworth at cworth.org
Wed Oct 13 12:02:50 PDT 2004
On Tue, 12 Oct 2004 11:48:28 -0400, Owen Taylor wrote:
> Just to set the record straight - this version didn't come from me,
> I just cut-and-pasted from elsewhere in the code assuming that it
> was done right.
>
> http://bugzilla.gnome.org/show_bug.cgi?id=3D148893
Thanks. That's just the thing I was hoping to see, and the thread does
result in the same result Keith came up with.
On Tue, 12 Oct 2004 12:03:08 -0700, Bill Spitzak wrote:
> On Tuesday 12 October 2004 11:37 am, Keith Packard wrote:
> > It would, however be nice to get the right answer in all cases. ═I think
> > that's as simple as:
> >
> > ((b) - (-a - 1) % b) - 1
>
> Just tried that and it works. And like you said both sides of the modulus are
> always positive (or 0 for the left side) and thus it avoids all unknown parts
> of how % works on different machines.
OK. Sounds like we're all satisfied with this. I'm putting the following
into the code. (I assume the special case for b==1 is to make fast the
common single-pixel repeat for solid-color fills.)
/* C89 has implementation-defined behavior for % with negative operands.
C99 has well-defined behavior which is that / with integers rounds toward zero
and a%b is defined so that (a/b)*b + a%b == a.
The C99 version gives negative remainders rather than the modulus
in [0 .. b-1] that we want. This macro avoids using % with negative
operands to avoid both problems.
a and b are integers. b > 0.
*/
#define MOD(a, b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-(a) - 1) % (b) - 1)
-Carl
More information about the cairo
mailing list