[cairo] set a reverse clip

Carl Worth cworth at cworth.org
Fri Sep 11 09:37:41 PDT 2009

Excerpts from zaheer ahmad's message of Wed Sep 09 23:18:17 -0700 2009:
> Thanks carl. i found the the solution in the mailing list using
> WINDING/EVEN_ODD with A and C (intersect of A and B), for that i had to
> compute the intersect rect C. with the two clips suggested, computing C
> would not be required.

Right. I'm always happy if cairo can save people some work.
> This and the documentation on the fill rule behavior ("The ray can be in any
> direction, as long as it doesn't pass through the end point of a segment or
> have a tricky intersection such as intersecting tangent to the path.")
> requires some graphics theory to understand it. I cant at this moment.

That particular sentence might be confusing yes, (but isn't actually
necessary to understand the winding rule).

Here's an example of what all this talk of "rays" is all about for
determining which portions are inside and outside.

First, let's take the two rectangles I suggested drawn in opposite
directions. Please forgive my crude ASCII art, but hopefully you can
understand the arrows used to indication the direction of each

          |           |
          |     A     v
          |           |
          ^     +--<--+-----+
          |     |     |     |
          |     v  B  |     |
          |     |     |     ^
          +--<--+-----+  C  |
                |           |

OK. So now imagine that the lines of the rectangles are fences in a
field. The fences divide the field into three different regions, A, B,
and C. Further imagine that you are standing in turn in each of these
three regions. Your job now is to implement the fill rule to determine
whether the region you are in is "inside" or "outside" the fences.

For the even-odd rule, all you have to do is to look out any direction
in a straight line and count the number of fences you see. For
example, standing in A you will either see 1 or 3 fences, in B you
will see 2 fences, and again in C you will see 1 or 3 fences. The
even-odd rule says that if you count an even number of fences you are
outside, while an even number puts you inside. So according to this
rule, A and C are inside, while B is outside (or subtracted out).

The winding rule is similar, but you have to actually pay attention to
the direction of the fences, (adding one to your count for any fences
going to the right, say, and subtracting one for any fences going to
the right). And with the winding rule, a non-zero count is inside,
while a zero count in outside. So, A and C with counts of 1 and -1 are
inside, while B with a count of 0 is outside.

Does that help explain things at all?

The sentence you quoted above about "tricky intersections" merely
means that if you're standing inside a fence looking in any particular
direction and seeing something confusing, (say, a junction of two
fences---do I count that once or twice?), then you can always just
choose an easier direction to look and you'll get the correct result.

And of course, all this talk about standing and "looking" doesn't
correspond with how the implementation actually works. It's simply a
way to try to define what the correct answer should be. It's supposed
to make it easier to understand, but sometimes it still ends up
sounding complicated.

Have fun!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20090911/2376a923/attachment.pgp 

More information about the cairo mailing list