home *** CD-ROM | disk | FTP | other *** search
- /* src/lline.c @finen */
-
- /*
- * file: lline.c
- *
- * sccs-id: @(#)lline.c 1.3 85/03/24
- *
- * description: this file contains a generalised line drawing routine.
- *
- *
- * author: simon kenyon.
- *
- * history: sck 1.1 85/03/01 created.
- * sck 1.2 85/03/08 tidied up for release.
- * sck 1.3 85/03/24 changed the include files around.
- */
-
- #include "layers.h"
-
- unsigned short penmap[] = {
- 0xffff
- };
- struct bitmap pen = {
- penmap, 1, {{
- 0, 0
- }, {
- 1, 1
- }
- }, 0, 0
- };
-
- /*
- * name: sign
- *
- * description: return the sign of the argument a.
- *
- * synopsis: int sign (a)
- * int a;
- *
- * globals: none.
- *
- * calls: nothing.
- *
- * called by: lline (lline.c)
- */
- int sign (a)
- int a;
- {
- if (a < 0)
- return (-1);
- else
- if (a > 0)
- return (1);
- else
- return (0);
- }
-
- /*
- * name: lline
- *
- * description: draw a line from p0 to p1 in a layer lp, using code f.
- * (this was snarfed from the 1st smalltalk-80 book. it
- * is nowhere as efficient as the restartable dda described
- * in rob's original paper, but i was having so much hassle
- * with the clipping in that, and i wanted to ship this...)
- *
- * synopsis: lline (lp, p0, p1, f)
- * struct layer *lp;
- * struct point *p0;
- * struct point *p1;
- * int f;
- *
- * globals: pen (r)
- *
- * calls: lblt (lblt.c)
- *
- * called by: this is a top level routine.
- */
- lline (lp, p0, p1, f)
- struct layer *lp;
- struct point *p0;
- struct point *p1;
- int f;
- {
- int dx;
- int dy;
- int px;
- int py;
- int p;
- struct point pt;
- int i;
-
- dx = sign ((p1 -> x) - (p0 -> x));
- dy = sign ((p1 -> y) - (p0 -> y));
- px = abs ((p1 -> y) - (p0 -> y));
- py = abs ((p1 -> x) - (p0 -> x));
- pt.x = (p0 -> x) + (lp -> ly_rect.origin.x);
- pt.y = (p0 -> y) + (lp -> ly_rect.origin.y);
- lblt (lp, &pen, &pen.rect, null, &pt, f);/* first point */
- if (py > px) { /* more horizontal */
- p = py / 2;
- for (i = 1; i < py; i++) {
- pt.x += dx;
- if ((p -= px) < 0) {
- pt.y += dy;
- p += py;
- }
- lblt (lp, &pen, &pen.rect, null, &pt, f);
- }
- }
- else { /* more horizontal */
- p = px / 2;
- for (i = 1; i <= px; i++) {
- pt.y += dy;
- if ((p -= py) < 0) {
- pt.x += dx;
- p += px;
- }
- lblt (lp, &pen, &pen.rect, null, &pt, f);
- }
- }
- }