[cairo] Finding minimum distance to a stroke or fill

Bill Spitzak spitzak at d2.com
Wed Mar 1 15:23:25 PST 2006



Carl Worth wrote:

> Should we actually
> provide all four functions:
> 
> 	cairo_distance_squared_to_stroke
> 	cairo_distance_to_stroke
> 	cairo_distance_squared_to_fill
> 	cairo_distance_to_stroke
>
> Thoughts and suggestions?

This is a hard one.

It is really useful to return a negative value to indicate "inside", 
thus allowing "f()<=threshold" to detect hits, while 
"abs(f())<=threshold" to detect clicks on the edge. Also some 
intersection calculations will naturally produce such negative values.

But while "distance_to" may not suprise anybody by returning these 
negative numbers, they may not expect this from distance_squared.

But there is an obvious savings in not doing the sqrt, especially since 
many programs would immediatly square the result anyway.

My guess now is that only the squared functions should be provided, and 
they should return -d*d for inside values. But I'm really not sure...


More information about the cairo mailing list