Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / new-s5r4 / graf / draw.c
1      /* Loglan82 Compiler&Interpreter\r
2      Copyright (C) 1981-1993 Institute of Informatics, University of Warsaw\r
3      Copyright (C)  1993, 1994 LITA, Pau\r
4      \r
5      This program is free software; you can redistribute it and/or modify\r
6      it under the terms of the GNU General Public License as published by\r
7      the Free Software Foundation; either version 2 of the License, or\r
8      (at your option) any later version.\r
9      \r
10      This program is distributed in the hope that it will be useful,\r
11      but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13      GNU General Public License for more details.\r
14      \r
15 =======================================================================\r
16 */\r
17 \r
18 #include "graf.h"
19
20
21 void pascal draw( _col, _row )
22    int *_col,*_row;
23 {
24    int X1 = inxpos(NULL);
25    int Y1 = inypos(NULL);
26    int X2 = *_col;
27    int Y2 = *_row;
28    int pos_slope;
29
30    int dX, dY,                                       /* vector components */
31        row, col,
32        final,                                  /* final row or col number */
33        G,                           /* used to test for new row or column */
34        inc1,             /* G increment when row or column doesn't change */
35        inc2;                /* G increment when row or column does change */
36
37    if( X2 < X1 )
38    {
39       X1 = *_col;
40       Y1 = *_row;
41       X2 = inxpos(NULL);
42       Y2 = inypos(NULL);
43    }
44
45    dX = X2 - X1;   dY = Y2 - Y1;                 /* find vector component */
46    pos_slope = (dX > 0);                            /* is slope positive? */
47    if (dY < 0) pos_slope = !pos_slope;
48    if (abs(dX) > abs(dY)) {                          /* shallow line case */
49       if (dX > 0) {              /* determine start point and last column */
50          col = X1; row = Y1; final = X2;
51       } else {
52          col = X1; row = Y2; final = X1;
53       }
54       inc1 = 2*abs(dY);             /* determine increments and initial G */
55       G = inc1 - abs(dX);
56       inc2 = 2 * (abs(dY) - abs(dX));
57       if (pos_slope)
58          while (col<=final) {     /* step thru cols. checking for new row */
59             point( &col, &row );
60             col++;
61             if (G >= 0) {                     /* it's time to change rows */
62                row++;  G+= inc2;      /* positive slope, so inc thru rows */
63             } else                                /* stay at the same row */
64                G += inc1;
65          } /* while */
66       else
67          while (col<=final) {        /* step thru cols, check for new row */
68             point( &col, &row );
69             col++;
70             if (G > 0) {                       /* time to change the rows */
71                row--;  G+= inc2;         /* negative slope, dec thru rows */
72             } else
73                G += inc1;                         /* stay at the same row */
74          } /* while */
75    } /* if |dX| > |dY| */  else {
76       if (dY > 0) {                 /* steep line case, angle > 45 degree */
77          col = X1; row = Y1; final = Y2; /* find start point and last row */
78       } else {
79          col = X2; row = Y2; final = Y1;
80       }
81       inc1 = 2 * abs(dX);           /* determine increments and initial G */
82       G = inc1 - abs(dY);
83       inc2 = 2 * (abs(dX) - abs(dY));
84       if (pos_slope)
85          while (row <= final) {  /* step thru rows - check for new column */
86             point( &col, &row );
87             row++;
88             if (G >= 0) {                  /* it's time to change columns */
89                col++;  G+= inc2;      /* pos. slope, increment thru cols. */
90             } else
91                G += inc1;                      /* stay at the same column */
92          } /* while */
93      else
94          while (row <= final) {/* step thru rows, checking for new column */
95             point( &col, &row );
96             row++;
97             if (G > 0) {                   /* it's time to change columns */
98                col--;  G+= inc2;  /* neg slope, so decrement thru columns */
99             } else
100                G += inc1;                      /* stay at the same column */
101          } /* while */
102    } /* if |dY| > |dX| */
103
104    move( _col, _row );
105 }
106
107
108 \r