Hi all,

Turns out that the previous patch I produced didn't work with arcs which
had a -ve swept angle - thanks Ales for discovering that.

I've re-done this one (and added some comments, as it isn't immediately
obvious why the code is as it is. We have libgd to thank there!

This _should_ work for any +/- start angle, and +/- sweep angle. Sweep
angles of magnitude greater than +/-360 may produce an odd effect
though, but that is really bogus data, and gschem probably won't allow
it to ever happen.

Ales - please give this patch a try! I had some time to think about how
it should be done more correctly, and this is what I came up with.

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)
diff --git a/libgeda/src/o_arc_basic.c b/libgeda/src/o_arc_basic.c
index 2403d3c..6d5f07a 100644
--- a/libgeda/src/o_arc_basic.c
+++ b/libgeda/src/o_arc_basic.c
@@ -1582,46 +1582,27 @@ o_arc_image_write(TOPLEVEL *w_current, O
     color = image_black;
   }
 
-  start_angle = o_current->arc->start_angle;
-  end_angle   = o_current->arc->end_angle;
-
-  if ( end_angle < 0) {
-
-    if (end_angle >= 180) {
-      start_angle = (start_angle - (end_angle)) % 360;
-    } else {
-      start_angle = (start_angle + (end_angle)) % 360;
-    }
-
-    end_angle = abs(end_angle);
-
-  }
-
-  end_angle = start_angle + end_angle;
-
-
-
-#if DEBUG
-  printf("%d %d -- %d %d -- %d %d\n", 
-         o_current->arc->screen_x, o_current->arc->screen_y,
-         o_current->arc->screen_width-o_current->arc->screen_x,
-         o_current->arc->screen_height-o_current->arc->screen_y,
-         start_angle, end_angle);
-#endif
-
-  if (start_angle < end_angle) {
-
-    start_angle = start_angle + 360;
-  }
-
-#if DEBUG
-  printf("%d %d -- %d %d -- %d %d\n", 
-         o_current->arc->screen_x, o_current->arc->screen_y,
-         o_current->arc->screen_width-o_current->arc->screen_x,
-         o_current->arc->screen_height-o_current->arc->screen_y,
-         start_angle, end_angle);
-#endif
-
+  // libgd angles are in opposite sense to gschem's internal angles
+  // Also, gschem's "end_angle" is actually the sweep of the arc, not absolute angle
+
+  // Intialise {start|end}_angle to the start of gschem's sweep
+  start_angle = -o_current->arc->start_angle;
+  end_angle   = -o_current->arc->start_angle;
+
+  // libgd always sweeps arcs clockwise so we either update
+  // the start_angle, or end_angle as appropriate
+  if ( o_current->arc->end_angle > 0 )
+    start_angle -= o_current->arc->end_angle;
+  else
+    end_angle -= o_current->arc->end_angle;
+
+  // 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 docs state that end angle should always be larger than start_angle
+  if (end_angle < start_angle)
+    end_angle += 360;
 
   width  = o_current->arc->screen_width;
   height = o_current->arc->screen_height;

_______________________________________________
geda-dev mailing list
[email protected]
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev

Reply via email to