# Re: GnomeCanvasLine

• From: Gustavo Joćo Alves Marques Carneiro <ee96090 fe up pt>
• To: Havoc Pennington <hp redhat com>
• Cc: gnome-devel-list gnome org
• Subject: Re: GnomeCanvasLine
• Date: Wed, 3 May 2000 22:09:38 +0100 (WEST)

```On 3 May 2000, Havoc Pennington wrote:

>
>
> Gustavo Joćo Alves Marques Carneiro <ee96090@fe.up.pt> 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.

Yes. It's not correct, but it's a lot faster, IMHO.

>
> >   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
> it.

ok, nevermind. I'll just override the point method of GnomeCanvasLine.
Thanks anyway.

>
> Havoc
>
>
>
> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gnome-devel-list
>

--
Gustavo J.A.M. Carneiro
[reinolinux.fe.up.pt/~ee96090]

```