[cairo] Hit detect surface?

mental at rydia.net mental at rydia.net
Wed Mar 1 11:03:43 PST 2006

Quoting Carl Worth <cworth at cworth.org>:

> And as we're talking about picking, there are other techniques
> that should at least be mentioned. Cairo can determine whether a
> given point is within a path as stroked or filled with
> cairo_in_stroke and cairo_in_fill.

> In one sense, cairo_in_stroke/fill is the fundamental operation
> needed. It's just not very cheap, (each call does all the
> tessellation of cairo_stroke/fill, but not any rasterization or
> compositing).

Hmm, it's not necessary to do a full tesselation to implement those
functions -- for fills and strokes with round caps+joins, it's as
simple as flattening the path and then:

 - for fills: test the winding count on a horizontal ray shot from
the test point

 - for strokes: test whether the test point is within stroke_width
of any line segments

Accomodating other cap/join types would complicate the stroke test a
little, but not much.

However, to be really useful for user interface picking, you'd want
a tolerance radius, too.  I suppose that could be approximated by
testing against an appropriately-sized square rather than a point.


More information about the cairo mailing list