Category : C Source Code
Archive   : ADVGRAPH.ZIP
Filename : COM_FILL.C

 
Output of file : COM_FILL.C contained in archive : ADVGRAPH.ZIP

/* COM_FILL.C creates a complex fill for non-regular
* boundaries. The procedure is tolerant of inclusions and
* incursions as long as boundaries are continuous (they
* connect) and do not intersect or touch each other.
* Lengths of arrays must be predicted carefully.
*/

#define TRUE -1
#define FALSE 0
#define ON TRUE
#define OFF FALSE
#define X 0
#define Y 1


com_fill(line_array, coord_array, length, style, color, orxor)
int line_array[][4], coord_array[][2];
unsigned length, style;
int color, orxor;
{
unsigned pointer, element = 0, sorted = FALSE, new_start = 1;

for (pointer = 0; pointer < length; ++pointer)
line_int(line_array[pointer], coord_array, &element);

while(!sorted) /* sort on y */
{
sorted = TRUE;
for (pointer = 1; pointer < element; ++pointer)
if (coord_array[pointer-1][Y]
> coord_array[pointer][Y])
{
swap(&coord_array[pointer-1][Y],
&coord_array[pointer][Y]);
swap(&coord_array[pointer-1][X],
&coord_array[pointer][X]);
sorted = FALSE;
}
}

sorted = FALSE;
while(!sorted) /* sort on x within y */
{
sorted = TRUE;
for (pointer = new_start; pointer < element; ++pointer)
if (coord_array[pointer-1][Y]
== coord_array[pointer][Y])
if (coord_array[pointer-1][X]
> coord_array[pointer][X])
{
swap(&coord_array[pointer-1][Y],
&coord_array[pointer][Y]);
swap(&coord_array[pointer-1][X],
&coord_array[pointer][X]);
sorted = FALSE;
}
else {
if (sorted == TRUE) new_start = pointer;
sorted = FALSE;
break;
}
}

for (pointer = 0; pointer < element; pointer += 2)
linef(coord_array[pointer][X],
coord_array[pointer][Y],
coord_array[pointer+1][X],
coord_array[pointer+1][Y],
color, style, orxor, ON);
}



line_int(line_array, coord_array, element)
int line_array[4], coord_array[][2], *element;
{
int ix, iy, i, inc, x, y, dx, dy, plot, plotx, ploty;

dx = line_array[2] - line_array[0];
dy = line_array[3] - line_array[1];
ix = abs(dx);
iy = abs(dy);
inc = max(ix, iy);

plotx = line_array[0];
ploty = line_array[1];
x = y = 0;

/* first pixel on line is not plotted */
/* last pixel on line is not plotted */
/* thus endpoints are not included */

for (i = 0; i < inc; ++i)
{
x += ix;
y += iy;
plot = FALSE;

if (x > inc)
{
plot = TRUE;
x -= inc;
plotx += sign(dx);
}

if (y > inc)
{
plot = TRUE;
y -= inc;
ploty += sign(dy);
}

if (plot)
{
coord_array[*element][X] = plotx;
coord_array[*element++][Y] = ploty;
}
}
}





  3 Responses to “Category : C Source Code
Archive   : ADVGRAPH.ZIP
Filename : COM_FILL.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/