[Cairo] cairo-0.1.12: New functions cairo_in_stroke and cairo_in_fill
cworth at east.isi.edu
Fri Nov 7 12:35:14 PST 2003
I've just committed an implementation of cairo_in_stroke and
cairo_in_fill as of cairo-0.1.12.
Both functions accept a coordinate in user space and return an integer
indicating whether that coordinate is inside the region that would be
painted by the corresponding stroke or fill operation. The functions
do not consider the results of any clip that might be in effect, nor
do they modify the current path.
I've updated cairo-demo/X11/cairo-spline to demonstrate the use of
these functions. Clicking and dragging on the stroked spline will drag
it around, while clicking and dragging on the filled circle around any
control point will adjust that point.
Thanks again to Thomas Hunger whose initial implementation of these
functions gave me the impetus to implement them. (My version differs
from his in the addition of user space->device space conversion and
the use of fixed-point arithmetic.)
Brief ad hoc testing suggests the functions are accurate, but do let
me know if you find any problems.
I haven't noticed any performance problems. The functions will never
be slower than the corresponding drawing operations.
But if performance becomes an issue, there are still a couple of
things to do:
1) Users can reduce the accuracy of the tests.
By default the functions test containment to within an accuracy of
0.1 device pixels. This may be excessive, (eg. for testing a
pointer device with single pixel precision). Calling
"cairo_set_tolerance (cr, 1.0)" will reduce the accuracy to a
single pixel and potentially improve the performance.
If you do do this don't forget to restore the tolerance
value. Otherwise subsequent stroke/fill operations will not look as
nice as they should.
2) Another option that may be useful in some scenarios is to have
cairo_in_stroke/fill cache the trapezoid data for possible future
use by cairo_stroke/fill.
No need to optimize yet, but there are some possibilities we can look
at if future profiling suggests the need.
More information about the cairo