Re: GnomeCanvasLine

Gustavo Joćo Alves Marques Carneiro <> writes:
>   Because of a school project I'm working on (a 3D modeler using
> GnomeCanvas), I need to make sure that the routine that checks if a point
> belongs to an item. I'm using exclusively GnomeCanvasLine. 
>   gnome_canvas_get_item_at  calls the function
> gnome_canvas_item_invoke_point, which calls the item's point virtual
> function.  This function calculates the distance between the point and
> each of the item's edges, using formulas like 			
> 	dist = sqrt (dx * dx + dy * dy) - width / 2.0;
>   This is very slow; my teacher says we should use something like
> 	dist = dx; if the line's inclination is < 1.0, or
> 	dist = dy; otherwise.

dx or dy won't be the shortest distance to the line, as far as I can
tell. That's why sqrt is used there. Of course, the point() method
should probably simply be a contains() method and I think Federico had
such a plan once; in that case, you can just check whether dx and dy
are both 0. However right now the definition of point() is that it
returns the shortest distance to the item. So your teacher's solution
does not compute the correct value.
>   gnome_canvas_item_invoke_point is also invoked as the pointer moves
> across the canvas, to synthesize enter/leave notify events to canvas
> items. This is also very slow. Amazingly, I don't notice it being slow. I
> must be reading the code wrong. 

The sqrt() call certainly isn't very slow. It might be slightly slower
than some other solution, but we are talking about extremely small
amount of time, on the order of microseconds. There's no way you'll be
able to see this slowness. Thus there's no reason to spend time fixing


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]