/* See fltgraph.h */ /* Last edited on 2003-09-25 10:12:57 by stolfi */ #include "fltgraph.h" #include #include #include #include #include #include void fltgraph_plot ( FILE *psfile, Float f (Float x), Interval xd, Interval yd, int m ) { int xi; Float x0, y0, x1, y1; ROUND_NEAR; ps_comment(psfile, "Plot of actual graph"); x1 = xd.lo; y1 = f(x1); for (xi=0; xi= xd.lo) || (y1 >= xd.lo)) && ((y0 <= xd.hi) || (y1 <= xd.hi)) ) { ps_draw_segment(psfile, x0, y0, x1, y1); } } } void fltgraph_draw_axes ( FILE *psfile, Interval xd, Interval yd ) { if ((xd.lo < Zero) && (xd.hi > Zero)) { ps_draw_coord_line(psfile, 'x', 0.0); } if ((xd.lo < Zero) && (xd.hi > Zero)) { ps_draw_coord_line(psfile, 'y', 0.0); } } #define MAXLABLEN (300) void fltgraph_draw_ticks ( FILE *psfile, int axis, Float lo, Float hi, int n, double ticksz, char *labfmt, double labalign, Interval clip ) { int i; char buf[MAXLABLEN]; double eps = 0.1*(hi - lo)/((double)n); /* Origin-avoidance radius. */ for (i = 0; i <= n; i++) { double r = ((double)i)/((double)n); double c = (1-r)*lo + r*hi; if ((c > clip.lo) && (c <= clip.hi) && (fabs(c) > eps)) { if (labfmt != NULL) { snprintf(buf, MAXLABLEN, labfmt, c); } if (axis == 0) { ps_draw_tick(psfile, 'X', c, 0.0, ticksz, 0.5); if (labfmt != NULL) { ps_put_label(psfile, buf, c, 0.0, 0.5, labalign); } } else if (axis == 1) { ps_draw_tick(psfile, 'Y', 0.0, c, ticksz, 0.5); if (labfmt != NULL) { ps_put_label(psfile, buf, 0.0, c, labalign, 0.5); } } else { affirm(FALSE, "bad axis"); } } } fflush(psfile); }