- register int bx; /* multiplicative x factor */
- register int x; /* x position drawing to */
- register int yk; /* the square-root term */
- register int y; /* y position drawing to */
- double k1; /* k? are constants depending on parameters */
- int k2, oldy1, oldy2; /* oldy? are last y points drawn to */
-
-
- if (hd < ELLIPSEDX) {
- if (output) HGtline(hpos, vpos, hpos + hd, vpos);
- hmot(hd);
- return;
- }
-
- bx = 4 * (hpos + hd);
- x = hpos;
- k1 = vd / (2.0 * hd);
- k2 = hd * hd - (2 * hpos + hd) * (2 * hpos + hd);
- oldy1 = vpos;
- oldy2 = vpos;
-
- hmot (hd); /* end position is the right-hand side of the ellipse */
-
- if (output) {
- while ((hd -= ELLIPSEDX) > 0) {
- yk=(int)(k1*sqrt((double)(k2+(bx-=(4*ELLIPSEDX))*(x+=ELLIPSEDX))));
-
- HGtline (x-ELLIPSEDX, oldy1, x, y = vpos + yk); /* top half */
- oldy1 = y;
- HGtline (x-ELLIPSEDX, oldy2, x, y = vpos - yk); /* bottom */
- oldy2 = y;
+ double xs, ys, xepsilon, yepsilon;
+ register int thick;
+ register int basex;
+ register int basey;
+ register int x;
+ register int y;
+
+
+ basex = hpos + (hd >> 1); /* bases == coordinates of center */
+ hmot(hd); /* horizontal motion (hpos should */
+ basey = vpos; /* NOT be used after this) */
+ /* hd and vd are radii, not diameters */
+ if ((hd = hd >> 1) < 1) hd++; /* neither diameter can be zero. */
+ if ((vd = vd >> 1) < 1) vd++; /* hd changed!! no hmot after this */
+ ys = (double) vd; /* start at top of the ellipse */
+ xs = 0.0; /* (y = 1/2 diameter, x = 0) */
+
+ if ((thick = vd) > hd) thick = hd;
+ xepsilon = (double) thick / (double) (vd * vd);
+ yepsilon = (double) thick / (double) (hd * hd);
+
+ /* Calculate trajectory of the ellipse for 1/4 */
+ /* the circumference (while ys is non-negative) */
+ /* and mirror to get the other three quadrants. */
+
+ thick = linethickness / 2;
+ if (thick) { /* more than one pixel thick */
+ RoundEnd(basex, ((int)(ys + 0.5)) + basey, thick, 0);
+ RoundEnd(basex, basey - ((int)(ys + 0.5)), thick, 0);
+ while (ys >= 0) {
+ xs += xepsilon * ys; /* generate circumference */
+ ys -= yepsilon * xs;
+ x = (int)(xs + 0.5);
+ y = (int)(ys + 0.5);
+ RoundEnd(x + basex, y + basey, thick, 0);
+ RoundEnd(x + basex, basey - y, thick, 0);
+ RoundEnd(basex - x, y + basey, thick, 0);
+ RoundEnd(basex - x, basey - y, thick, 0);