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


2.0
date     92.07.29.03.20.03;  author fischer;  state Exp;
branches ;
next     1.1;

1.1
date     92.07.01.03.54.19;  author fischer;  state Exp;
branches ;
next     ;


desc
@Nicely formatted output of relational tests, exhaustively over
a small range of INTEGER Points, and randomly over a small range
of REAL Points.
@


2.0
log
@Fixed up for new version with IntPoint/FloatPoint.
Doesn't compare between Floats and Ints.
@
text
@// Emacs: -*- C++ -*-

#include <FloatPoint.h>
#include <ACG.h>

#define TBL_SIZE 100

int main(int argc, char**argv)
{
    void	print_relational_table(char*, IntPoint[], int);
    void	print_relational_table(char*, FloatPoint[], int);
    void	make_points(FloatPoint[], int, ACG&);              // random integer valued
    void	sort_points(FloatPoint[], int);

    ACG		generator;    
    FloatPoint  floats[TBL_SIZE];
    IntPoint    ints[TBL_SIZE];

    int		number_int_points = 0;
    int		number_real_points = 15;

    for (int i = -1; i <= 1; i++)
	for (int j = -1; j <= 1; j++)
	    ints[number_int_points++] = IntPoint(i, j);

    print_relational_table("IntPoints relational tests", ints, number_int_points);

    cout << "\f";
    make_points(floats, number_real_points, generator);
    sort_points(floats, number_real_points);
    print_relational_table("FloatPoints relational tests", floats, number_real_points);
}

void
make_points(FloatPoint point_array[], int number_points, ACG& generator)
{
    FloatPoint	make_random_point(int, int, int, ACG&); // dimension, bottom, top, type

    for (int i = 0; i < ( 2 * number_points / 3); i++) 
	point_array[i] = make_random_point(2, -1, +1, generator);
    for (i = ( 2 * number_points / 3); i < number_points;  i++) 
	point_array[i] = make_random_point(1, -1, +1, generator);
}	


void
print_relational_table(char* label, FloatPoint point_array[], int number_points)
{
//  Run all relational ops on an array of points, printing a table

    char first_page = 1;
    
    cout << label << "\n" << "<    <=   ==   >=   >    !=\tArguments\n";
    for (int i = 0; i < number_points; i++) {
        for (int j = 0; j < number_points; j++) {

	    if (((i * number_points + j) % 60) == 0) {
		if (first_page)
		    first_page = 0;
		else
		    cout << "\f" << label << "(continued)\n" << "<    <=   ==   >=   >    !=\tArguments\n";
	    }
	    cout << (int) (point_array[i] <  point_array[j]) << "    ";
	    cout << (int) (point_array[i] <= point_array[j]) << "    ";
	    cout << (int) (point_array[i] == point_array[j]) << "    ";
	    cout << (int) (point_array[i] >= point_array[j]) << "    ";
	    cout << (int) (point_array[i] >  point_array[j]) << "    ";
	    cout << (int) (point_array[i] != point_array[j]) << "\t";
	    cout << point_array[i] << "\t" << point_array[j] << "\n";
	}
    }
}

void
print_relational_table(char* label, IntPoint point_array[], int number_points)
{
//  Run all relational ops on an array of points, printing a table

    char first_page = 1;
    
    cout << label << "\n" << "<    <=   ==   >=   >    !=\tArguments\n";
    for (int i = 0; i < number_points; i++) {
        for (int j = 0; j < number_points; j++) {

	    if (((i * number_points + j) % 60) == 0) {
		if (first_page)
		    first_page = 0;
		else
		    cout << "\f" << label << "(continued)\n" << "<    <=   ==   >=   >    !=\tArguments\n";
	    }
	    cout << (int) (point_array[i] <  point_array[j]) << "    ";
	    cout << (int) (point_array[i] <= point_array[j]) << "    ";
	    cout << (int) (point_array[i] == point_array[j]) << "    ";
	    cout << (int) (point_array[i] >= point_array[j]) << "    ";
	    cout << (int) (point_array[i] >  point_array[j]) << "    ";
	    cout << (int) (point_array[i] != point_array[j]) << "\t";
	    cout << point_array[i] << "\t" << point_array[j] << "\n";
	}
    }
}


FloatPoint
make_random_point(int dimensions, int bottom, int top, ACG& gen)
{
    int   range;

    if (top < bottom) {
	int temp = top;
	top = bottom;
	bottom = temp;
    }
    range = top - bottom;

    switch (dimensions) {
    case 0:
	return FloatPoint();
    case 1:
	return FloatPoint(bottom +  gen.asFloat() * range);
    case 2:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    case 3:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    case 4:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    case 5:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    default:
	return FloatPoint(0.0, 0.0, 0.0, 0.0, 0.0);    // should not happen
    }
}

void
sort_points(FloatPoint points[], int size)
{
    // Very stupid bubble sorter. Please fix (where *is* my copy of Sedgwick?).

    char my_less_than(const FloatPoint&, const FloatPoint&);

    FloatPoint temp;
    for (int i = 0; i < size; i++) {
	for (int j = i; j < size; j++) {
	    if (my_less_than(points[i], points[j])) {
		temp = points[i];
		points[i] = points[j];
		points[j] = temp;
	    }
	}
    }
}


char
my_less_than (const FloatPoint& p0, const FloatPoint& p1)
{
    char bool = Pointcmp(p0, p1);
    if (bool == -1)
	return (char) 1;
    else if (bool == 0) 				// may be equal iff zero extended
	return (p0.dimensions() < p1.dimensions());	// so check
    else
	return (char) 0;
}
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
#include <Point.h>
d10 4
a13 4
    void	print_relational_table(char*, Point[], int);
    void	make_INTEGER_points(Point[], int, ACG&);             // random integer valued
    void	make_REAL_points(Point[], int, ACG&);                // random integer valued
    void	sort_points(Point[], int);
d16 2
a17 3
    Point       points_list[TBL_SIZE];
    int		number_real_points;
    int		number_integer_points;
d19 2
d22 3
a24 1
    //////// INTEGER POINTS ////////
d26 1
a26 1
    number_integer_points = 0;
a27 16
    for (Coord c0 = -1; c0 <= 1; c0++) 
	for (Coord c1 = -1; c1 <= 1; c1++)
	    points_list[number_integer_points++] = (c0, c1);

    //  I want to generate these on the end of points_list so
    //  I can check the lexicographic sorting routine built on Pointcmp.
    
    for (c0 = -1; c0 <= 1; c0++) 
	points_list[number_integer_points++] = (c0);
    
    sort_points(points_list, number_integer_points);

    print_relational_table("INTEGER Points relational tests", points_list, number_integer_points);

    //////// REAL POINTS ////////

d29 3
a31 4
    number_real_points = 15;
    make_REAL_points(points_list, number_real_points, generator);
    sort_points(points_list, number_real_points);
    print_relational_table("REAL Points relational tests", points_list, number_real_points);
d35 1
a35 1
make_REAL_points(Point point_array[], int number_points, ACG& generator)
d37 1
a37 1
    Point	make_random_point(int, int, int, NumericType, ACG&); // dimension, bottom, top, type
d40 1
a40 1
	point_array[i] = make_random_point(2, -1, +1, REAL, generator);
d42 1
a42 1
	point_array[i] = make_random_point(1, -1, +1, REAL, generator);
d45 1
d47 1
a47 1
make_INTEGER_points(Point point_array[], int number_points, ACG& generator)
d49 1
a49 1
    Point	make_random_point(int, int, int, NumericType, ACG&); // dimension, bottom, top, type
d51 5
a55 3
    for (int i = 0; i < number_points; i++) 
	point_array[i] = make_random_point(2, -2, +2, INTEGER, generator);
}	
d57 17
d75 1
a75 1
print_relational_table(char* label, Point point_array[], int number_points)
d103 2
a104 2
Point
make_random_point(int dimensions, int bottom, int top, NumericType type, ACG& gen)
a105 3
    // There is a fencepost error in the range of random points for integers.
    
    Coord coordinate;
d115 25
a139 59
    if (type == REAL)
      switch (dimensions) {
      case 0:
          return Point();
      case 1:
          coordinate = (bottom +  gen.asFloat() * range);
          return Point(coordinate);
      case 2:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      case 3:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      case 4:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      case 5:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      default:
          return Point(0.0, 0.0, 0.0, 0.0, 0.0);    // shouldn't happen
      }
    else if (type == INTEGER)
      switch (dimensions) {
      case 0:
          return Point();
      case 1:
          coordinate = (bottom + int(gen.asFloat() * range));
          return Point(coordinate);
      case 2:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      case 3:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      case 4:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      case 5:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      default:
          return Point(0, 0, 0, 0, 0);    // shouldn't happen
      }
    else {
      cout << "random_point: NumericType " << type << " is not one of REAL, INTEGER\n";
      exit(1);
a140 1
    return Point(-1, -1, -1, -1, -1);    // can\'t happen, but make compiler shut up.
d144 1
a144 1
sort_points(Point points[], int size)
d148 1
a148 1
    char my_less_than(const Point&, const Point&);
d150 1
a150 1
    Point temp;
d162 1
d164 1
a164 1
my_less_than (const Point& p0, const Point& p1)
@
