void picurve(register int *x, register int *y, int npts) { register int nseg; /* effective resolution for each curve */ register int xp; /* current point (and temporary) */ register int yp; int pxp, pyp; /* previous point (to make lines from) */ int i; /* inner curve segment traverser */ int length = 0; double w; /* position factor */ double t1, t2, t3; /* calculation temps */ if (x[1] == x[npts] && y[1] == y[npts]) { x[0] = x[npts - 1]; /* if the lines' ends meet, make */ y[0] = y[npts - 1]; /* sure the curve meets */ x[npts + 1] = x[2]; y[npts + 1] = y[2]; } else { /* otherwise, make the ends of the */ x[0] = x[1]; /* curve touch the ending points of */ y[0] = y[1]; /* the line segments */ x[npts + 1] = x[npts]; y[npts + 1] = y[npts]; } pxp = (x[0] + x[1]) / 2; /* make the last point pointers */ pyp = (y[0] + y[1]) / 2; /* point to the start of the 1st line */ tmove2(pxp, pyp); for (; npts--; x++, y++) { /* traverse the line segments */ xp = x[0] - x[1]; yp = y[0] - y[1]; nseg = (int) groff_hypot((double) xp, (double) yp); xp = x[1] - x[2]; yp = y[1] - y[2]; /* `nseg' is the number of line */ /* segments that will be drawn for */ /* each curve segment. */ nseg = (int) ((double) (nseg + (int) groff_hypot((double) xp, (double) yp)) / res * PointsPerInterval); for (i = 1; i < nseg; i++) { w = (double) i / (double) nseg; t1 = w * w; t3 = t1 + 1.0 - (w + w); t2 = 2.0 - (t3 + t1); xp = (((int) (t1 * x[2] + t2 * x[1] + t3 * x[0])) + 1) / 2; yp = (((int) (t1 * y[2] + t2 * y[1] + t3 * y[0])) + 1) / 2; HGtline(xp, yp); if (length++ > LINELENGTH) { length = 0; printf("\\\n"); } } } }
void Paramaterize(int x[], int y[], double h[], int n) { register int dx; register int dy; register int i; register int j; double u[MAXPOINTS]; for (i = 1; i <= n; ++i) { u[i] = 0; for (j = 1; j < i; j++) { dx = x[j + 1] - x[j]; dy = y[j + 1] - y[j]; /* Here was overflowing, so I changed it. */ /* u[i] += sqrt ((double) (dx * dx + dy * dy)); */ u[i] += groff_hypot((double) dx, (double) dy); } } for (i = 1; i < n; ++i) h[i] = u[i + 1] - u[i]; } /* end Paramaterize */
void HGArc(register int cx, register int cy, int px, int py, int angle) { double xs, ys, resolution, fullcircle; int m; register int mask; register int extent; register int nx; register int ny; register int length; register double epsilon; xs = px - cx; ys = py - cy; length = 0; resolution = (1.0 + groff_hypot(xs, ys) / res) * PointsPerInterval; /* mask = (1 << (int) log10(resolution + 1.0)) - 1; */ (void) frexp(resolution, &m); /* A bit more elegant than log10 */ for (mask = 1; mask < m; mask = mask << 1); mask -= 1; epsilon = 1.0 / resolution; fullcircle = (2.0 * pi) * resolution; if (angle == 0) extent = (int) fullcircle; else extent = (int) (angle * fullcircle / 360.0); HGtline(px, py); while (--extent >= 0) { xs += epsilon * ys; nx = cx + (int) (xs + 0.5); ys -= epsilon * xs; ny = cy + (int) (ys + 0.5); if (!(extent & mask)) { HGtline(nx, ny); /* put out a point on circle */ if (length++ > LINELENGTH) { length = 0; printf("\\\n"); } } } /* end for */ } /* end HGArc */
double hypot(const position &a) { return groff_hypot(a.x, a.y); }