diff --git a/ChangeLog b/ChangeLog index 051bc54fc..156a19a68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2010-08-01 Robert Larice + * src/pkgIndex.tcl.in , + * src/tclspice.c , + * src/frontend/display.c , + * src/frontend/display.h , + * src/frontend/hpgl.c , + * src/frontend/postsc.c , + * src/frontend/plotting/grid.c , + * src/frontend/plotting/plot5.c , + * src/frontend/plotting/x11.c , + * src/frontend/wdisp/windisp.c , + * src/frontend/wdisp/winprint.c , + * src/include/ftedev.h : + bug fix, implementation of the X11 draw arc implementation. + parameter change for all Arc() functions. + from theta1, theta2 to theta,delta_theta + the previous interface was ambiguous. + fix the x11lineararcs implementation, which could loop forever. + but don't use it anyways, since the real X11 draw arc works properly now. + 2010-08-01 Holger Vogt * autogen.sh, spicelib/parser/inp2q.c: update for adms diff --git a/src/frontend/display.c b/src/frontend/display.c index 28e9843f1..a308996f9 100644 --- a/src/frontend/display.c +++ b/src/frontend/display.c @@ -209,10 +209,10 @@ void DrawLine(int x1, int y1, int x2, int y2) } -void Arc(int x0, int y0, int radius, double theta1, double theta2) +void Arc(int x0, int y0, int radius, double theta, double delta_theta) { - (*(dispdev->Arc))(x0, y0, radius, theta1, theta2); + (*(dispdev->Arc))(x0, y0, radius, theta, delta_theta); } diff --git a/src/frontend/display.h b/src/frontend/display.h index a1ab5e5a1..fc3e95e8f 100644 --- a/src/frontend/display.h +++ b/src/frontend/display.h @@ -18,7 +18,7 @@ int NewViewport(GRAPH *pgraph); void DevClose(void); void DevClear(void); void DrawLine(int x1, int y1, int x2, int y2); -void Arc(int x0, int y0, int radius, double theta1, double theta2); +void Arc(int x0, int y0, int radius, double theta, double delta_theta); void Text(char *text, int x, int y); void DefineColor(int colorid, double red, double green, double blue); void DefineLinestyle(int linestyleid, int mask); diff --git a/src/frontend/hpgl.c b/src/frontend/hpgl.c index 428490f3c..ced25448e 100644 --- a/src/frontend/hpgl.c +++ b/src/frontend/hpgl.c @@ -224,8 +224,9 @@ int x1, int y1, int x2, int y2) /* ARGSUSED */ int GL_Arc( int x0, int y0, int r, -double theta1, double theta2) +double theta, double delta_theta) { +/* double x1, y1; double angle1, angle2; @@ -236,7 +237,7 @@ double theta1, double theta2) angle2 = (double) (RAD_TO_DEG * theta2); x1 = (double) x0 + r * cos(theta1); y1 = (double) y0 + r * sin(theta1); -/* + fprintf(plotfile, "%lf %lf moveto ", x1+(double)xoff, y1+(double)yoff); fprintf(plotfile, "%d %d %d %lf %lf arc\n", x0+xoff, y0+yoff, r, angle1, angle2); diff --git a/src/frontend/plotting/grid.c b/src/frontend/plotting/grid.c index 881318cc7..c9bdb80c8 100644 --- a/src/frontend/plotting/grid.c +++ b/src/frontend/plotting/grid.c @@ -848,7 +848,7 @@ drawpolargrid(GRAPH *graph) Arc(graph->grid.xaxis.circular.center, graph->grid.yaxis.circular.center, graph->grid.xaxis.circular.radius, - (double) 0.0, (double) 0.0); + (double) 0.0, 2*M_PI); SetLinestyle(1); /* Now draw the circles. */ @@ -859,7 +859,7 @@ drawpolargrid(GRAPH *graph) { cliparc((double) graph->grid.xaxis.circular.center + relcx, (double) graph->grid.yaxis.circular.center + relcy, - (double) relrad, 0.0, 0.0, + (double) relrad, 0.0, 2*M_PI, graph->grid.xaxis.circular.center, graph->grid.yaxis.circular.center, graph->grid.xaxis.circular.radius, 0); @@ -1264,7 +1264,7 @@ drawsmithgrid(GRAPH *graph) SetLinestyle(0); - Arc(gr_xcenter, gr_ycenter, gr_radius, 0.0, 0.0); + Arc(gr_xcenter, gr_ycenter, gr_radius, 0.0, 2*M_PI); /* if ((xoff > - gr_radius) && (xoff < gr_radius)) { zheight = gr_radius * sin(acos((double) xoff / gr_radius)); @@ -1412,7 +1412,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx, return(-1); if (dist + rad < cliprad) { /* The arc is entirely in the boundary. */ - Arc((int)cx, (int)cy, (int)rad, start, end); + Arc((int)cx, (int)cy, (int)rad, start, end-start); return(flag?start:end); } else if ((dist - rad >= cliprad) || (rad - dist >= cliprad)) { /* The arc is outside of the boundary. */ @@ -1484,7 +1484,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx, start = d; d = tmp; } - Arc((int)cx, (int)cy, (int)rad, start, d); + Arc((int)cx, (int)cy, (int)rad, start, d-start); sclip = start; eclip = d; } @@ -1511,7 +1511,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx, } if (in) { - Arc((int)cx, (int)cy, (int)rad, l, d); + Arc((int)cx, (int)cy, (int)rad, l, d-l); sclip = l; eclip = d; } @@ -1521,7 +1521,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx, /* And from here to the end. */ if (in) { - Arc((int)cx, (int)cy, (int)rad, d, end); + Arc((int)cx, (int)cy, (int)rad, d, end-d); /* special case */ if (flag != 2) { sclip = d; diff --git a/src/frontend/plotting/plot5.c b/src/frontend/plotting/plot5.c index 856682f99..4fb7af149 100644 --- a/src/frontend/plotting/plot5.c +++ b/src/frontend/plotting/plot5.c @@ -116,7 +116,7 @@ Plt5_DrawLine(int x1, int y1, int x2, int y2) /* ARGSUSED */ /* until some code gets written */ int -Plt5_Arc(int x0, int y0, int radius, double theta1, double theta2) +Plt5_Arc(int x0, int y0, int radius, double theta, double delta_theta) { return 0; diff --git a/src/frontend/plotting/x11.c b/src/frontend/plotting/x11.c index 786e48239..accd8d729 100644 --- a/src/frontend/plotting/x11.c +++ b/src/frontend/plotting/x11.c @@ -93,7 +93,7 @@ static int numdispplanes; static void initlinestyles (void); static void initcolors (GRAPH *graph); static void X_ScreentoData (GRAPH *graph, int x, int y, double *fx, double *fy); -static void linear_arc(int x0, int y0, int radius, double theta1, double theta2); +static void linear_arc(int x0, int y0, int radius, double theta, double delta_theta); int errorhandler(Display *display, XErrorEvent *errorev) @@ -503,20 +503,19 @@ X11_DrawLine(int x1, int y1, int x2, int y2) int -X11_Arc(int x0, int y0, int radius, double theta1, double theta2) + +X11_Arc(int x0, int y0, int radius, double theta, double delta_theta) { int t1, t2; - if (!cp_getvar("x11lineararcs", CP_BOOL, NULL)) { - linear_arc(x0, y0, radius, theta1, theta2); + if (0 && !cp_getvar("x11lineararcs", CP_BOOL, NULL)) { + linear_arc(x0, y0, radius, theta, delta_theta); } if (DEVDEP(currentgraph).isopen) { - if (theta1 >= theta2) - theta2 = 2 * M_PI + theta2; - t1 = 64 * (180.0 / M_PI) * theta1; - t2 = 64 * (180.0 / M_PI) * theta2 - t1; + t1 = 64 * (180.0 / M_PI) * theta; + t2 = 64 * (180.0 / M_PI) * delta_theta; if (t2 == 0) return 0; XDrawArc(display, DEVDEP(currentgraph).window, DEVDEP(currentgraph).gc, @@ -1027,48 +1026,35 @@ out: } static void -linear_arc(int x0, int y0, int radius, double theta1, double theta2) +linear_arc(int x0, int y0, int radius, double theta, double delta_theta) /* x coordinate of center */ /* y coordinate of center */ /* radius of arc */ /* initial angle ( +x axis = 0 rad ) */ - /* final angle ( +x axis = 0 rad ) */ + /* delta angle /* * Notes: * Draws an arc of radius and center at (x0,y0) beginning at - * angle theta1 (in rad) and ending at theta2 + * angle theta (in rad) and ending at theta + delta_theta */ { int x1, y1, x2, y2; - int s = 60; - double dphi, phi; - - x2 = x0 + (int) (radius * cos(theta1)); - y2 = y0 + (int) (radius * sin(theta1)); + int i, s = 60; + double dphi; - while(theta1 >= theta2) - theta2 += 2 * M_PI; - dphi = (theta2 - theta1) / s; + x2 = x0 + (int) (radius * cos(theta)); + y2 = y0 + (int) (radius * sin(theta)); - if ((theta1 + dphi) == theta1) { - theta2 += 2 * M_PI; - dphi = (theta2 - theta1) / s; - } + dphi = delta_theta / s; - for(phi = theta1 + dphi; phi < theta2; phi += dphi) { + for(i=1; i<=s; i++) { x1 = x2; y1 = y2; - x2 = x0 + (int)(radius * cos(phi)); - y2 = y0 + (int)(radius * sin(phi)); + x2 = x0 + (int)(radius * cos(theta + i*dphi)); + y2 = y0 + (int)(radius * sin(theta + i*dphi)); X11_DrawLine(x1,y1,x2,y2); } - - x1 = x2; - y1 = y2; - x2 = x0 + (int)(radius * cos(theta2)); - y2 = y0 + (int)(radius * sin(theta2)); - X11_DrawLine(x1,y1,x2,y2); } #else diff --git a/src/frontend/postsc.c b/src/frontend/postsc.c index f4c3a4a7a..1419d5ad9 100644 --- a/src/frontend/postsc.c +++ b/src/frontend/postsc.c @@ -285,18 +285,16 @@ PS_DrawLine(int x1, int y1, int x2, int y2) } int -PS_Arc(int x0, int y0, int r, double theta1, double theta2) +PS_Arc(int x0, int y0, int r, double theta, double delta_theta) { double x1, y1; double angle1, angle2; PS_Stroke(); - while (theta1 >= theta2) - theta2 += 2 * M_PI; - angle1 = (double) (RAD_TO_DEG * theta1); - angle2 = (double) (RAD_TO_DEG * theta2); - x1 = (double) x0 + r * cos(theta1); - y1 = (double) y0 + r * sin(theta1); + angle1 = (double) (RAD_TO_DEG * theta); + angle2 = (double) (RAD_TO_DEG * (theta + delta_theta)); + x1 = (double) x0 + r * cos(theta); + y1 = (double) y0 + r * sin(theta); fprintf(plotfile, "%f %f moveto ", x1+(double)xoff, y1+(double)yoff); fprintf(plotfile, "%d %d %d %f %f arc\n", x0+xoff, y0+yoff, r, diff --git a/src/frontend/wdisp/windisp.c b/src/frontend/wdisp/windisp.c index ebc8ac108..9e7ecdc53 100644 --- a/src/frontend/wdisp/windisp.c +++ b/src/frontend/wdisp/windisp.c @@ -717,11 +717,11 @@ int WIN_DrawLine(int x1, int y1, int x2, int y2) } -int WIN_Arc(int x0, int y0, int radius, double theta1, double theta2) +int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta) /* * Notes: * Draws an arc of and center at (x0,y0) beginning at - * angle theta1 (in rad) and ending at theta2 + * angle theta (in rad) and ending at theta + delta_theta */ { tpWindowData wd; @@ -741,10 +741,9 @@ int WIN_Arc(int x0, int y0, int radius, double theta1, double theta2) if (!wd) return 0; direction = AD_COUNTERCLOCKWISE; - if (theta1 > theta2) { - temp = theta1; - theta1 = theta2; - theta2 = temp; + if (delta_theta < 0) { + theta = theta + delta_theta; + delta_theta = - delta_theta; direction = AD_CLOCKWISE; } SetArcDirection( wd->hDC, direction); @@ -759,15 +758,15 @@ int WIN_Arc(int x0, int y0, int radius, double theta1, double theta2) r = radius; dx0 = x0; dy0 = y0; - xs = (dx0 + (r * cos(theta1))); - ys = (dy0 + (r * sin(theta1))); - xe = (dx0 + (r * cos(theta2))); - ye = (dy0 + (r * sin(theta2))); + xs = (dx0 + (r * cos(theta))); + ys = (dy0 + (r * sin(theta))); + xe = (dx0 + (r * cos(theta + delta_theta))); + ye = (dy0 + (r * sin(theta + delta_theta))); /* plot */ NewPen = CreatePen( LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex] ); OldPen = SelectObject(wd->hDC, NewPen); - Arc( wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); + Arc( wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye);/*FIXME name clash*/ OldPen = SelectObject(wd->hDC, OldPen); DeleteObject( NewPen); diff --git a/src/frontend/wdisp/winprint.c b/src/frontend/wdisp/winprint.c index 8eee3cbb0..599e21087 100644 --- a/src/frontend/wdisp/winprint.c +++ b/src/frontend/wdisp/winprint.c @@ -339,11 +339,11 @@ int WPRINT_DrawLine(int x1, int y1, int x2, int y2) } -int WPRINT_Arc(int x0, int y0, int radius, double theta1, double theta2) +int WPRINT_Arc(int x0, int y0, int radius, double theta, double delta_theta) /* * Notes: * Draws an arc of and center at (x0,y0) beginning at - * angle theta1 (in rad) and ending at theta2 + * angle theta (in rad) and ending at theta + delta_theta */ { tpPrintData pd; @@ -368,10 +368,9 @@ int WPRINT_Arc(int x0, int y0, int radius, double theta1, double theta2) ColIndex = 1; direction = AD_COUNTERCLOCKWISE; - if (theta1 > theta2) { - temp = theta1; - theta1 = theta2; - theta2 = temp; + if (delta_theta < 0) { + theta = theta + delta_theta; + delta_theta = - delta_theta; direction = AD_CLOCKWISE; } SetArcDirection( PrinterDC, direction); @@ -386,15 +385,15 @@ int WPRINT_Arc(int x0, int y0, int radius, double theta1, double theta2) r = radius; dx0 = x0; dy0 = y0; - xs = (dx0 + (r * cos(theta1))); - ys = (dy0 + (r * sin(theta1))); - xe = (dx0 + (r * cos(theta2))); - ye = (dy0 + (r * sin(theta2))); + xs = (dx0 + (r * cos(theta))); + ys = (dy0 + (r * sin(theta))); + xe = (dx0 + (r * cos(theta + delta_theta))); + ye = (dy0 + (r * sin(theta + delta_theta))); /* Zeichnen */ NewPen = CreatePen( LineTable[pd->LineIndex], 0, ColorTable[ColIndex] ); OldPen = SelectObject(PrinterDC, NewPen); - Arc( PrinterDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); + Arc( PrinterDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye);/*FIXME name clash*/ OldPen = SelectObject(PrinterDC, OldPen); DeleteObject( NewPen); diff --git a/src/include/ftedev.h b/src/include/ftedev.h index b8cc4611a..7731d99ac 100644 --- a/src/include/ftedev.h +++ b/src/include/ftedev.h @@ -21,7 +21,7 @@ typedef int disp_fn_NewViewport_t (struct graph *); typedef int disp_fn_Close_t (void); typedef int disp_fn_Clear_t (void); typedef int disp_fn_DrawLine_t (int x1, int y1, int x2, int y2); -typedef int disp_fn_Arc_t (int x0, int y0, int radius, double theta1, double theta2); +typedef int disp_fn_Arc_t (int x0, int y0, int radius, double theta, double delta_theta); typedef int disp_fn_Text_t (char *text, int x, int y); typedef int disp_fn_DefineColor_t (int colorid, double red, double green, double blue); typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask); diff --git a/src/pkgIndex.tcl.in b/src/pkgIndex.tcl.in index 62ec633e6..f683ecea0 100755 --- a/src/pkgIndex.tcl.in +++ b/src/pkgIndex.tcl.in @@ -44,10 +44,10 @@ proc Loadspice { version dir } { puts "draw" .c create line [expr $x1 + 25] [expr 375 - $y1] [expr $x2 + 25] [expr 375 - $y2] } - proc spice_gr_Arc { x0 y0 radius theta1 theta2 } { + proc spice_gr_Arc { x0 y0 radius theta delta_theta } { .c create arc [expr $x0 - $radius + 25] [expr 375 - $y0 - $radius] \ [expr $x1 + $radius + 25 ] [expr 375 - $y1 + $radius] \ - -start $theta1 -extent $theta2 + -start $theta -extent [expr $theta + $delta_theta] } proc spice_gr_Text {text x y} { .c create text [expr $x + 25] [expr 375 - $y] -text $text diff --git a/src/tclspice.c b/src/tclspice.c index 229fd75e1..c26a75c98 100755 --- a/src/tclspice.c +++ b/src/tclspice.c @@ -1391,9 +1391,9 @@ int sp_Tk_DrawLine(int x1, int y1, int x2, int y2) { return 0; } -int sp_Tk_Arc(int x0, int y0, int radius, double theta1, double theta2) { +int sp_Tk_Arc(int x0, int y0, int radius, double theta, double delta_theta) { char buf[1024]; - sprintf(buf,"spice_gr_Arc %i %i %i %f %f", x0, y0, radius, theta1, theta2); + sprintf(buf,"spice_gr_Arc %i %i %i %f %f", x0, y0, radius, theta, delta_theta); if(Tcl_Eval(spice_interp,buf) != TCL_OK) { Tcl_ResetResult(spice_interp); return 1;