aboutsummaryrefslogtreecommitdiff
path: root/contrib/groff/src/preproc/grn/hgraph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/groff/src/preproc/grn/hgraph.cpp')
-rw-r--r--contrib/groff/src/preproc/grn/hgraph.cpp144
1 files changed, 69 insertions, 75 deletions
diff --git a/contrib/groff/src/preproc/grn/hgraph.cpp b/contrib/groff/src/preproc/grn/hgraph.cpp
index d124c6c0b266..01208951f28f 100644
--- a/contrib/groff/src/preproc/grn/hgraph.cpp
+++ b/contrib/groff/src/preproc/grn/hgraph.cpp
@@ -8,19 +8,13 @@
#include "gprint.h"
-#ifdef NEED_DECLARATION_HYPOT
-extern "C" {
- double hypot(double, double);
-}
-#endif /* NEED_DECLARATION_HYPOT */
-
#define MAXVECT 40
#define MAXPOINTS 200
#define LINELENGTH 1
#define PointsPerInterval 64
#define pi 3.14159265358979324
#define twopi (2.0 * pi)
-#define len(a, b) hypot((double)(b.x-a.x), (double)(b.y-a.y))
+#define len(a, b) groff_hypot((double)(b.x-a.x), (double)(b.y-a.y))
extern int dotshifter; /* for the length of dotted curves */
@@ -43,7 +37,7 @@ extern int ytop;
extern int ybottom;
extern int xleft;
extern int xright;
-extern enum {
+extern enum E {
OUTLINE, FILL, BOTH
} polyfill;
@@ -62,17 +56,17 @@ void tmove(POINT * ptr);
void cr();
void drawwig(POINT * ptr, int type);
void HGtline(int x1, int y1);
-void dx(double x);
-void dy(double y);
+void deltax(double x);
+void deltay(double y);
void HGArc(register int cx, register int cy, int px, int py, int angle);
void picurve(register int *x, register int *y, int npts);
void HGCurve(int *x, int *y, int numpoints);
-void Paramaterize(int x[], int y[], float h[], int n);
-void PeriodicSpline(float h[], int z[],
- float dz[], float d2z[], float d3z[],
+void Paramaterize(int x[], int y[], double h[], int n);
+void PeriodicSpline(double h[], int z[],
+ double dz[], double d2z[], double d3z[],
int npoints);
-void NaturalEndSpline(float h[], int z[],
- float dz[], float d2z[], float d3z[],
+void NaturalEndSpline(double h[], int z[],
+ double dz[], double d2z[], double d3z[],
int npoints);
@@ -166,8 +160,8 @@ HGPrintElt(ELT *element,
* stipple fonts).
* If polyfill=BOTH, just use the \D'p ...' command.
*/
- float firstx = p1->x;
- float firsty = p1->y;
+ double firstx = p1->x;
+ double firsty = p1->y;
length = 0; /* keep track of line length so */
/* single lines don't get long */
@@ -223,8 +217,8 @@ HGPrintElt(ELT *element,
while (!Nullpoint((PTNextPoint(p1)))) {
p1 = PTNextPoint(p1);
- dx((double) p1->x);
- dy((double) p1->y);
+ deltax((double) p1->x);
+ deltay((double) p1->y);
if (length++ > LINELENGTH) {
length = 0;
printf("\\\n");
@@ -233,8 +227,8 @@ HGPrintElt(ELT *element,
/* close polygon if not done so by user */
if ((firstx != p1->x) || (firsty != p1->y)) {
- dx((double) firstx);
- dy((double) firsty);
+ deltax((double) firstx);
+ deltay((double) firsty);
}
putchar('\'');
cr();
@@ -412,7 +406,7 @@ HGSetBrush(int mode)
/*----------------------------------------------------------------------------*
- | Routine: dx (x_destination)
+ | Routine: deltax (x_destination)
|
| Results: Scales and outputs a number for delta x (with a leading
| space) given `lastx' and x_destination.
@@ -421,7 +415,7 @@ HGSetBrush(int mode)
*----------------------------------------------------------------------------*/
void
-dx(double x)
+deltax(double x)
{
register int ix = (int) (x * troffscale);
@@ -431,7 +425,7 @@ dx(double x)
/*----------------------------------------------------------------------------*
- | Routine: dy (y_destination)
+ | Routine: deltay (y_destination)
|
| Results: Scales and outputs a number for delta y (with a leading
| space) given `lastyline' and y_destination.
@@ -441,7 +435,7 @@ dx(double x)
*----------------------------------------------------------------------------*/
void
-dy(double y)
+deltay(double y)
{
register int iy = (int) (y * troffscale);
@@ -600,7 +594,7 @@ HGArc(register int cx,
length = 0;
- resolution = (1.0 + hypot(xs, ys) / res) * PointsPerInterval;
+ 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);
@@ -671,13 +665,13 @@ picurve(register int *x,
for (; npts--; x++, y++) { /* traverse the line segments */
xp = x[0] - x[1];
yp = y[0] - y[1];
- nseg = (int) hypot((double) xp, (double) yp);
+ 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) hypot((double) xp, (double) yp)) /
+ nseg = (int) ((double) (nseg + (int) groff_hypot((double) xp, (double) yp)) /
res * PointsPerInterval);
for (i = 1; i < nseg; i++) {
@@ -713,9 +707,9 @@ HGCurve(int *x,
int *y,
int numpoints)
{
- float h[MAXPOINTS], dx[MAXPOINTS], dy[MAXPOINTS];
- float d2x[MAXPOINTS], d2y[MAXPOINTS], d3x[MAXPOINTS], d3y[MAXPOINTS];
- float t, t2, t3;
+ double h[MAXPOINTS], dx[MAXPOINTS], dy[MAXPOINTS];
+ double d2x[MAXPOINTS], d2y[MAXPOINTS], d3x[MAXPOINTS], d3y[MAXPOINTS];
+ double t, t2, t3;
register int j;
register int k;
register int nx;
@@ -751,7 +745,7 @@ HGCurve(int *x,
if ((x[j] == x[j + 1]) && (y[j] == y[j + 1]))
continue;
for (k = 0; k <= PointsPerInterval; ++k) {
- t = (float) k *h[j] / (float) PointsPerInterval;
+ t = (double) k *h[j] / (double) PointsPerInterval;
t2 = t * t;
t3 = t * t * t;
nx = x[j] + (int) (t * dx[j] + t2 * d2x[j] / 2 + t3 * d3x[j] / 6);
@@ -779,14 +773,14 @@ HGCurve(int *x,
void
Paramaterize(int x[],
int y[],
- float h[],
+ double h[],
int n)
{
register int dx;
register int dy;
register int i;
register int j;
- float u[MAXPOINTS];
+ double u[MAXPOINTS];
for (i = 1; i <= n; ++i) {
u[i] = 0;
@@ -795,7 +789,7 @@ Paramaterize(int x[],
dy = y[j + 1] - y[j];
/* Here was overflowing, so I changed it. */
/* u[i] += sqrt ((double) (dx * dx + dy * dy)); */
- u[i] += hypot((double) dx, (double) dy);
+ u[i] += groff_hypot((double) dx, (double) dy);
}
}
for (i = 1; i < n; ++i)
@@ -814,16 +808,16 @@ Paramaterize(int x[],
*----------------------------------------------------------------------------*/
void
-PeriodicSpline(float h[], /* paramaterization */
+PeriodicSpline(double h[], /* paramaterization */
int z[], /* point list */
- float dz[], /* to return the 1st derivative */
- float d2z[], /* 2nd derivative */
- float d3z[], /* 3rd derivative */
+ double dz[], /* to return the 1st derivative */
+ double d2z[], /* 2nd derivative */
+ double d3z[], /* 3rd derivative */
int npoints) /* number of valid points */
{
- float d[MAXPOINTS];
- float deltaz[MAXPOINTS], a[MAXPOINTS], b[MAXPOINTS];
- float c[MAXPOINTS], r[MAXPOINTS], s[MAXPOINTS];
+ double d[MAXPOINTS];
+ double deltaz[MAXPOINTS], a[MAXPOINTS], b[MAXPOINTS];
+ double c[MAXPOINTS], r[MAXPOINTS], s[MAXPOINTS];
int i;
/* step 1 */
@@ -886,15 +880,15 @@ PeriodicSpline(float h[], /* paramaterization */
*----------------------------------------------------------------------------*/
void
-NaturalEndSpline(float h[], /* parameterization */
+NaturalEndSpline(double h[], /* parameterization */
int z[], /* Point list */
- float dz[], /* to return the 1st derivative */
- float d2z[], /* 2nd derivative */
- float d3z[], /* 3rd derivative */
+ double dz[], /* to return the 1st derivative */
+ double d2z[], /* 2nd derivative */
+ double d3z[], /* 3rd derivative */
int npoints) /* number of valid points */
{
- float d[MAXPOINTS];
- float deltaz[MAXPOINTS], a[MAXPOINTS], b[MAXPOINTS];
+ double d[MAXPOINTS];
+ double deltaz[MAXPOINTS], a[MAXPOINTS], b[MAXPOINTS];
int i;
/* step 1 */
@@ -970,11 +964,11 @@ change(register int x,
*----------------------------------------------------------------------------*/
void
-HGtline(int x1,
- int y1)
+HGtline(int x_1,
+ int y_1)
{
- register int x0 = lastx;
- register int y0 = lasty;
+ register int x_0 = lastx;
+ register int y_0 = lasty;
register int dx;
register int dy;
register int oldcoord;
@@ -986,7 +980,7 @@ HGtline(int x1,
register int dotcounter;
if (linmod == SOLID) {
- line(x1, y1);
+ line(x_1, y_1);
return;
}
@@ -995,11 +989,11 @@ HGtline(int x1,
xinc = 1;
yinc = 1;
- if ((dx = x1 - x0) < 0) {
+ if ((dx = x_1 - x_0) < 0) {
xinc = -xinc;
dx = -dx;
}
- if ((dy = y1 - y0) < 0) {
+ if ((dy = y_1 - y_0) < 0) {
yinc = -yinc;
dy = -dy;
}
@@ -1007,48 +1001,48 @@ HGtline(int x1,
res2 = 0;
visible = 0;
if (dx >= dy) {
- oldcoord = y0;
- while (x0 != x1) {
- if ((x0 & dotcounter) && !visible) {
- change(x0, y0, 0);
+ oldcoord = y_0;
+ while (x_0 != x_1) {
+ if ((x_0 & dotcounter) && !visible) {
+ change(x_0, y_0, 0);
visible = 1;
- } else if (visible && !(x0 & dotcounter)) {
- change(x0 - xinc, oldcoord, 1);
+ } else if (visible && !(x_0 & dotcounter)) {
+ change(x_0 - xinc, oldcoord, 1);
visible = 0;
}
if (res1 > res2) {
- oldcoord = y0;
+ oldcoord = y_0;
res2 += dx - res1;
res1 = 0;
- y0 += yinc;
+ y_0 += yinc;
}
res1 += dy;
- x0 += xinc;
+ x_0 += xinc;
}
} else {
- oldcoord = x0;
- while (y0 != y1) {
- if ((y0 & dotcounter) && !visible) {
- change(x0, y0, 0);
+ oldcoord = x_0;
+ while (y_0 != y_1) {
+ if ((y_0 & dotcounter) && !visible) {
+ change(x_0, y_0, 0);
visible = 1;
- } else if (visible && !(y0 & dotcounter)) {
- change(oldcoord, y0 - yinc, 1);
+ } else if (visible && !(y_0 & dotcounter)) {
+ change(oldcoord, y_0 - yinc, 1);
visible = 0;
}
if (res1 > res2) {
- oldcoord = x0;
+ oldcoord = x_0;
res2 += dy - res1;
res1 = 0;
- x0 += xinc;
+ x_0 += xinc;
}
res1 += dx;
- y0 += yinc;
+ y_0 += yinc;
}
}
if (visible)
- change(x1, y1, 1);
+ change(x_1, y_1, 1);
else
- change(x1, y1, 0);
+ change(x_1, y_1, 0);
}
/* EOF */