head     1.1;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @@;


1.1
date     92.07.30.16.36.59;  author jnw;  state Exp;
branches ;
next     ;


desc
@Initial revision
@



1.1
log
@Initial revision
@
text
@// Emacs: -*- C++ -*-
static char rcsid[] = "$Id$";

#include "IntPoint.h"
#include "IntPointSet.h"
#include "IPSIter.h"

#include <iostream.h>

void test_intersection(IntPointSet a, IntPointSet b, IntPointSet ab)
{
    IntPoint	p, p2;

    {
	IPSIter	iter(ab);

	while (iter(p)) {
	    cout << p;
	    if (!a.contains(p) || !b.contains(p)) {
		cout << "##extra##";
	    }
	    cout << '\t';
	}
	cout << '\n';
    }

    {
	IPSIter	iter(a), iter2(b);

	while (iter(p)) {
	    iter2.reset();
	    while (iter2(p2)){
		if (p == p2) {
		    cout << p;
		    if (! (ab.contains(p))) {
			cout << "##missing##";
		    }	
		    cout << '\t';
		}
	    }
	}
	cout << '\n';
    }

    cout << '\n';
}

void printIntSet(IntPointSet ips)
{
    char	image[80][40];
    int	x,y;
    
    for (x=0; x<40; x++)
	for (y=0; y<40; y++)
	    image[x][y] = ' ';
    
    IPSIter	iter(ips);
    IntPoint	p;
    while (iter(p)) {
	image[p[0]+20][p[1]+10] = '#';
    }

    for (x=40; x<80; x++)
	for (y=0; y<40; y++)
	    image[x][y] = ips.contains(IntPoint(x-60,y-10)) ? '*' : '.';
    
    for (y=0; y<40; y++) {
	for (x=0; x<75; x++)
	    cout << image[x][y];
	cout << '\n';
    }
    
}

main()
{
    const int	x0=-5, x1=-3, x2=0, x3=3, x4=5, x5=10, x6= 15;
    const int	y0=-5, y1=-3, y2=0, y3=3, y4=5, y5=10;

    IntPointSet ps0,ps1,ps2;

    malloc_debug(2);

    ps0 = IntPointSet(IntPoint(x0), IntPoint(x3));
    ps1 = IntPointSet(IntPoint(x1), IntPoint(x4));
    ps2 = ps0 & ps1;
    test_intersection(ps0, ps1, ps0&ps1);

    ps0 = IntPointSet(IntPoint(x0), IntPoint(x2)) |
	IntPointSet(IntPoint(x4), IntPoint(x6));
    ps1 = IntPointSet(IntPoint(x1), IntPoint(x4));
    ps2 = ps0 & ps1;
    test_intersection(ps0, ps1, ps0&ps1);


    ps0 = IntPointSet(IntPoint(x0,y2),IntPoint(x4,y4)) |
	IntPointSet(IntPoint(x2,y0),IntPoint(x4,y4));
    printIntSet(ps0);

    ps1 = IntPointSet(IntPoint(x1,y1),IntPoint(x3,y5)) |
	IntPointSet(IntPoint(x1,y1),IntPoint(x5,y3));
    printIntSet(ps1);

    printIntSet(ps0&ps1);
    test_intersection(ps0, ps1, ps0&ps1);

}






@
