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 l

⟦c6e9a9275⟧ TextFile

    Length: 1284 (0x504)
    Types: TextFile
    Names: »lines.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/X/Roids/lines.c« 

TextFile

/* lines.c -- paint a bunch of lines with minimal requests. */

/* %%% Too lazy to compress these; maybe I'll do it later. */


#include "roids.h"

void BeginLines() {}

void AddLine(fromx, fromy, tox, toy, gc)
int fromx, fromy, tox, toy;
GC gc;
{
    XDrawLine(dpy, gamewindow, gc, fromx, fromy, tox, toy);
}

void EndLines() {}


#define BETWEEN(x, a, b) ((a <= b && x >= a && x <= b) ||	\
			  (a > b && x <= a && x >= b))

Boolean CheckIntersects(ax, ay, bx, by, cx, cy, dx, dy)
int ax, ay, bx, by, cx, cy, dx, dy;
{
    float m1, m2, b1, b2, x, y;
    if (bx == ax) {
	if (dx == cx) return FALSE; /* Parallel; hacking, assume they miss. */
	m2 = ((float) (dy - cy)) / ((float) (dx - cx));
	b2 = cy - cx*m2;
	x = ax;
	y = m2 * x + b2;
	return (BETWEEN(y, ay, by) && BETWEEN(x, cx, dx) &&
		BETWEEN(y, cy, dy));
    }
    if (dx == cx) {
	return CheckIntersects(cx, cy, dx, dy, ax, ay, bx, by);
    }
    m1 = ((float) (by - ay)) / ((float) (bx - ax));
    m2 = ((float) (dy - cy)) / ((float) (dx - cx));
    b1 = ay - ax*m1;
    b2 = cy - cx*m2;
    if (m1 == m2) {		/* Parallel lines */
	return FALSE;		/* Hack. */
    }
    x = (b2 - b1) / (m1 - m2);
    y = m1 * x + b1;
    return (BETWEEN(x, ax, bx) && BETWEEN(y, ay, by) &&
	    BETWEEN(x, cx, dx) && BETWEEN(y, cy, dy));
}