gEDA-dev: [PATCH] PCB/gtk: Draw rotated arcs correctly
Peter Clifton
pcjc2 at cam.ac.uk
Tue Apr 17 06:29:38 EDT 2007
On Tue, 2007-04-17 at 11:00 +0100, Peter TB Brett wrote:
> On Tuesday 17 April 2007 10:38:20 Bernd Jendrissek wrote:
> >
> > diff -up ./src/hid/gtk/gtkhid-main.c.borig ./src/hid/gtk/gtkhid-main.c
> > --- ./src/hid/gtk/gtkhid-main.c.borig 2007-04-16 17:56:08.000000000 +0200
> > +++ ./src/hid/gtk/gtkhid-main.c 2007-04-17 11:23:09.000000000 +0200
> > @@ -649,6 +649,10 @@ ghid_draw_arc (hidGC gc, int cx, int cy,
> > start_angle =-start_angle + 180;;
> > delta_angle = -delta_angle;;
> > }
> > + /* Prevent overflow in X11. */
> > + if (start_angle + 180 >= 360) {
> > + start_angle -= 360;
> > + }
>
> How about something along these lines:
>
> angle = start_angle + 180 % 360;
>
> gdk_draw_arc (gport->drawable, gport->u_gc, 0,
> DRAW_X (cx) - vrx, DRAW_Y (cy) - vry,
> vrx * 2, vry * 2, angle * 64, delta_angle * 64);
>
> This avoids a branch, and requires fewer instructions. OTOH, can start_angle
> be negative?
Perhaps a better solution (thinking about it) is to make sure the angle
never over-flows in the first place. Can PCB's internal data-structures
accommodate any necessary range limitation?
You'd then perform the limit wrapping at each load / modification to the
data-structure rather than at draw time. This prevents any internal
overflows too, whilst keeping drawing faster.
At the very least, if there is internal range-limiting, (e.g. angle
won't go -ve, or won't go >360) the range limit wanted for drawing can
be applied more simply).
Peter C.
More information about the geda-dev
mailing list