home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/draw.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* draw.h: header for draw.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define draw_h 1
-
- #include "all.h"
- #include "newext.h"
-
- static int *above;
- static int *below;
-
- /* EOF */
- /* cat > src+obj/draw/draw_done.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* draw_done: done drawing */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "draw.h" */
-
- void
- draw_done ()
- {
- free (above);
- free (below);
- }
- /* EOF */
- /* cat > src+obj/draw/draw_hline.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* draw_hline: Draw a line (may be just part of it */
- /* will show) and set the hiding boundaries */
- /* accordingly. The two end points are */
- /* given in (x1,y1) and (x2,y2). */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "draw.h" */
-
- void
- draw_hline (x1, y1, x2, y2)
- int x1, y1, x2, y2;
- {
- int xpos, ypos, xi, yi, xj, yj;
- int i, xx, yy, tmp;
- bool abv, blw;
- double dy, real_yi;
- void intersect ();
-
- if (x1 == x2)
- { /* the vertical line is vertical */
- if (y1 == y2)
- return;
- if (y1 < y2)
- {
- tmp = y1;
- y1 = y2;
- y2 = tmp;
- }
- if (y1 > above[x1])
- {
- plot_line (x1, y1, x1, MAX (y2, above[x1]));
- above[x1] = y1;
- }
- if (y2 < below[x2])
- {
- plot_line (x1, MIN (y1, below[x1]), x1, y2);
- below[x1] = y2;
- }
- return;
- }
-
- if (x2 < x1)
- {
- tmp = x1;
- x1 = x2;
- x2 = tmp;
- tmp = y1;
- y1 = y2;
- y2 = tmp;
- }
- dy = (double) (y2 - y1) / (double) (x2 - x1);
- xi = x1;
- yi = y1;
- abv = blw = FALSE;
- if (yi >= above[xi])
- {
- xpos = xi;
- ypos = yi;
- abv = TRUE;
- }
- if (yi <= below[xi])
- {
- xpos = xi;
- ypos = yi;
- blw = TRUE;
- }
- real_yi = (double) yi;
-
- do
- {
- if (abv)
- {
- /* If hitting the boundary while approaching
- from above draw the line up to there. */
- if (yi < above[xi])
- {
- intersect (above, xj, yj, xi, yi, &xx, &yy);
- plot_line (xpos, ypos, xx, yy);
- abv = FALSE;
- }
- else
- above[xi] = yi;
- }
- if (blw)
- {
- if (yi > below[xi])
- {
- intersect (below, xj, yj, xi, yi, &xx, &yy);
- plot_line (xpos, ypos, xx, yy);
- blw = FALSE;
- }
- else
- below[xi] = yi;
- }
- if (!abv && !blw)
- {
- if (yi >= above[xi])
- {
- intersect (above, xj, yj, xi, yi, &xpos, &ypos);
- above[xi] = yi;
- abv = TRUE;
- }
- if (yi <= below[xi])
- {
- intersect (below, xj, yj, xi, yi, &xpos, &ypos);
- below[xi] = yi;
- blw = TRUE;
- }
- }
- xj = xi++;
- yj = yi;
- real_yi += dy;
- yi = ROUND (real_yi);
- } while (xi < x2);
-
- if (abv || blw)
- {
- plot_line (xpos, ypos, x2, y2);
- }
- }
- /* EOF */
- /* cat > src+obj/draw/draw_init.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* draw_init: initialize drawing */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "draw.h" */
-
- draw_init ()
- {
- int i;
-
- if ((above = (int *) malloc ((PRECISION + 1) * sizeof (int))) == NULL)
- {
- msg_write ("Error: Not enough memory to create scan line depth upper bound.");
- return (-1); /* some nonzero value to indicate an error */
- }
- if ((below = (int *) malloc ((PRECISION + 1) * sizeof (int))) == NULL)
- {
- msg_write ("Error: Not enough memory to create scan line depth lower bound.");
- free (above);
- return (-1); /* some nonzero value to indicate an error */
- }
-
- /* set up hiden line boundaries */
- for (i = 0; i <= PRECISION; i++)
- {
- above[i] = -LARGE;
- below[i] = LARGE;
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/draw/intersect.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* intersect: Calculate the intersection of two lines */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "draw.h" */
-
- void
- intersect (bound, xj, yj, xi, yi, retx, rety)
- int bound[], xj, yj, xi, yi, *retx, *rety;
- {
- double a1, b1, a2, b2, x0, y0;
-
- if (yi == bound[xi] && yj == bound[xj])
- {
- *retx = xi;
- *rety = yi;
- return;
- }
- a1 = (double) (yi - yj);
- b1 = (double) (yj - a1 * xj);
- a2 = (double) (bound[xi] - bound[xj]);
- b2 = (double) (bound[xj] - a2 * xj);
- x0 = (b2 - b1) / (a1 - a2);
- y0 = a1 * x0 + b1;
- *retx = ROUND (x0);
- *rety = ROUND (y0);
- return;
- }
- /* EOF */
-