Re: GnomeCanvasLine

On Thu, 4 May 2000, Federico Mena Quintero wrote:

> >    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. 
> A 3D modeller using the canvas?  Are you sure you don't want to use
> OpenGL instead?

  But OpenGL doesn't give you enter/leave events. All I want is a
wireframe model using GnomeCanvas to edit / select objects. Maybe I'll
make an OpenGL view to actually render the scene. This is meant to be only
an exercise, not 3D Studio :)

> >    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.
> That will not calculate the correct distance to the line.
  I know. But it's faster.
> >    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. If not, can I make a patch to GnomeCanvas?
> It is not slow.  The ::point() method is only invoked for items whose
> bounding box intersects the mouse position.  Moreover, you normally
> don't have a million overlapping items, so you'll only need to take a
> few square roots on each mouse motion.
> "Floating point is slow" is a fallacy.  It depends entirely on what
> you are doing.
> However, having a point-distance computation method for canvas items
> is overkill, and it is a leftover of the design of Tk's canvas.  I
> intend to replace ::point() with a simpler ::contains() that just
> returns a boolean value.  This makes hit testing easier and probably
> faster as well.
>   Federico

Gustavo J.A.M. Carneiro

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