gEDA-dev: [PATCH] PCB/gtk: Draw rotated arcs correctly
Peter Clifton
pcjc2 at cam.ac.uk
Tue Apr 17 06:24:46 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;
angle = ( start_angle + 180 ) % 360;
I've not checked, but I think % has higher precedence than +.
> 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?
I'm not sure, but indeed, negative numbers don't play nicely with %. The
advantage of using %, is that it catches overflow involving multiple
rotations.
The code I introduced in the libgd printing routine for libgeda is:
/* Ensure each angle is within 0-359. Negative angles make libgd blow
up. */
start_angle = ( start_angle < 0 ) ? 360 - ( (-start_angle) % 360 ) :
start_angle % 360;
end_angle = ( end_angle < 0 ) ? 360 - ( (-end_angle ) % 360 ) :
end_angle % 360;
libgd doesn't have the same semantics for angles as X11, so you might
need to adjust this as necessary. (And pre-add the extra +180 degrees.)
There are branches hidden in there of course, but I'm not sure how much
difference it makes in real terms. (Certainly arc's aren't the most
common primitive on a schematic, but might be more so in a layout.)
Regards,
Peter C
More information about the geda-dev
mailing list