DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T s

⟦fd27b9b58⟧ TextFile

    Length: 3319 (0xcf7)
    Types: TextFile
    Names: »sun_ellipse.c«

Derivation

└─⟦52210d11f⟧ Bits:30007239 EUUGD2: TeX 3 1992-12
    └─⟦af5ba6c8e⟧ »unix3.0/DVIWARE.tar.Z« 
        └─⟦ca79c7339⟧ 
            └─⟦this⟧ »DVIware/crt-viewers/sunview/dvisun/sun_ellipse.c« 

TextFile

/* Fast circle/ellipse generator for SUNs */

#include <sunwindow/window_hs.h>

extern char *malloc();

extern int draw_mode, pen_size;
extern struct pixrect *display;

static struct precomputed {
    int xradius, yradius;	/* Size of object (circle/ellipse) */
    int pen_size;		/* Size of pen used for this ellipse */
    struct pixrect *pr;		/* Data for display */
    struct precomputed *next;	/* Link to next in list */
} ellipses;


#define	panic(msg)	Fatal(msg)


/* Create a new precomputed object */
static struct precomputed *new_precomputed()
{
    struct precomputed *result;

    result = (struct precomputed *) malloc(sizeof(struct precomputed));
    if (!result) panic("Out of memory");
    return(result);
}

static int cirpx[]={999, 996, 984, 965, 938, 905, 864, 819, 768,
        713, 655, 594, 531, 470, 407, 346, 288, 233, 182, 137,
        96, 63, 36, 17, 5, 1, 5, 17, 36, 63,
        96, 137, 182, 233, 288, 346, 407, 470, 531, 594, 655,
        713, 768, 819, 864, 905, 938, 965, 984, 994, 999};
static float cirpy[]={530, 563, 624, 684, 741, 794, 842, 885, 922, 952,
        976, 991, 999, 999, 991, 976, 952, 922, 885, 842, 794, 741,
        684, 624, 563, 500, 438, 377, 317, 260, 207, 159, 116,
        79, 49, 25, 10, 1, 1, 10, 25, 49, 79,
        116, 159, 207, 260, 317, 377, 438, 470};
 
/* Draw a line of the correct thickness between the indicated points */
static void line_btw(pr, x0, y0, x1, y1)
struct pixrect *pr;
int x0, y0, x1, y1;
{
    register int i;

    for (i=0; i<pen_size; i++) {
	pr_vector(pr, x0, y0, x1, y1, PIX_SRC, 1);
	if (abs(y1-y0) > abs(x1-x0)) {
	    ++x0;
	    ++x1;
	}
	else {
	    ++y0;
	    ++y1;
	}
    }
}


/* Make an ellipse and return its pixrect */
static struct pixrect *make_ellipse(xrad, yrad)
int xrad, yrad;
{
    struct pixrect *pr;
    register int i, lastx, lasty, curx, cury;
    int zerox, zeroy, istep, imax;

    pr = mem_create(xrad*2+1, yrad*2+1, 1);
    if (!pr) panic("Out of memory");
    imax = sizeof(cirpx) / sizeof(cirpx[0]) - 1;
    zerox = lastx = (cirpx[0]*xrad + 250) / 500;
    zeroy = lasty = (cirpy[0]*yrad + 250) / 500;
    if (xrad < 76 && yrad < 76) istep = 2;
    else istep = 1;
    for (i=1; i<imax; i += istep) {
	curx = (cirpx[i]*xrad + 250) / 500;
	cury = (cirpy[i]*yrad + 250) / 500;
	line_btw(pr, lastx, lasty, curx, cury);
	lastx = curx;
	lasty = cury;
    }
    line_btw(pr, lastx, lasty, zerox, zeroy);
    return(pr);
}


/* Draw a circle at the current location.  Arguments are in pixels. */
void sun_draw_ellipse(x, y, xrad, yrad)
int x, y, xrad, yrad;
{
    register struct precomputed *p, *prev;
    register struct pixrect *pr;

    prev = &ellipses;
    for (p = prev->next; p && p->xradius < xrad; p = p->next) prev = p;
    while (p && p->xradius == xrad && p->yradius < yrad) {
	prev = p;
	p = p->next;
    }
    while (p && p->xradius == xrad && p->yradius == yrad &&
      p->pen_size < pen_size) {
	prev = p;
	p = p->next;
    }
    if (!p || p->xradius != xrad || p->yradius != yrad ||
      p->pen_size != pen_size) {
	p = new_precomputed();
	p->pr = make_ellipse(xrad, yrad);
	p->xradius = xrad;
	p->yradius = yrad;
	p->pen_size = pen_size;
	p->next = prev->next;
	prev->next = p;
    }
    pr = p->pr;
    pr_rop(display, x-xrad, y-yrad, pr->pr_width, pr->pr_height,
	draw_mode, pr, 0, 0);
}