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


1.3
date     92.06.25.19.11.14;  author fischer;  state Exp;
branches ;
next     1.2;

1.2
date     92.06.23.07.27.25;  author fischer;  state Exp;
branches ;
next     1.1;

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


desc
@trash.
@


1.3
log
@*** empty log message ***
@
text
@// Emacs: -*- C++ -*-

#include <Point.h>
#include <ACG.h>

#define TBL_SIZE 40
#define MAX_RANDOM_DIMENSIONS 3

// MAX_RANDOM_DIMENSIONS is the max sized point we\'ll  let the make_random_point\(\) routine make.

int main(int argc, char**argv)
{
    void	sort_points(Point[], int);
    void	print_relational_table(Point[], int);
    void	make_points1(Point[], int);                          //
    void	make_points2(Point[], int);                          //
    void	make_points3(Point[], int, ACG&);                    // random integer valued
    void	make_points4(Point[], int);                          // mix of zero valued, 
    Point	make_random_point(int, int, int, NumericType, ACG&); // dimension, bottom, top, type
    Point	make_random_point(int, int, NumericType, ACG&);      // bottom, top, type
    Point	make_random_point(int, int, ACG&);                   // bottom, top
    Point       points_list[TBL_SIZE];
    ACG		generator(69, 96);    
    int		i;

//  make_points3(points_list, TBL_SIZE, generator);

    make_points1(points_list, TBL_SIZE);

    for (i = 0; i < TBL_SIZE; i++) {
	cout << points_list[i] << "\n";
    }

    cout << "Sorting...";
    
    sort_points(points_list, TBL_SIZE);
    
    cout << "done.\n";

    for (i = 0; i < TBL_SIZE; i++) {
	cout << points_list[i] << "\n";
    }


//    print_relational_table(points_list, TBL_SIZE);
}

void
make_points1(Point point_array[], int number_points)
{
    // make an exhaustive list \(array\)  of points with coordinates from set \{-1, 0, 1\}
    // for 0, 1, 2, and 3 dimensions, or.. 3 + 3*3 + 3*3*3 + 1 = 40 empty.
    Coord i, j, k;
    
    int number_generated = 0;
    for (i = -1; i <= 1; i++) 
	if (number_generated < number_points)
	    point_array[number_generated++] = Point(i);

    for (i = -1; i <= 1; i++) 
	for (j = -1; j <= 1; j++) 
	if (number_generated < number_points)
	    point_array[number_generated++] = Point(i,j);

    for (i = -1; i <= 1; i++) 
	for (j = -1; j <= 1; j++) 
	    for (k = -1; k <= 1; k++) 
	if (number_generated < number_points)
	    point_array[number_generated++] = Point(i,j,k);

    if (number_generated < number_points)
	point_array[number_generated++] = Point();

}	

void
make_points2(Point point_array[], int number_points)
{
    // make an exhaustive list \(array\)  of points with coordinates from set \{-1, 0, 1\}
    // for 0, 1 and 2 dimensions, or.. 3 + 3*3  + 1 empty = 13

    Coord i, j;
    
    int number_generated = 0;
    for (i = -1; i <= 1; i++) 
	if (number_generated < number_points)
	    point_array[number_generated++] = Point(i);
    
    for (i = -1; i <= 1; i++) 
	for (j = -1; j <= 1; j++) 
	    if (number_generated < number_points)
		point_array[number_generated++] = Point(i,j);
    
    if (number_generated < number_points)
	point_array[number_generated++] = Point();

}	

void
make_points3(Point point_array[], int number_points, ACG& generator)
{
    Point   make_random_point(int, int, NumericType, ACG&);      // bottom, top, type

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

void
make_points4(Point point_array[], int number_points)
{
    // make a list \(array\)  of zero points with coordinates of various dimensions.

    int number_generated = 0;
    Point z(0);
    
    for (;;)  {
	if (number_generated < number_points) 
	    point_array[number_generated++] = z;
	if (number_generated < number_points) 
	    point_array[number_generated++] = Point(0,0);
	if (number_generated < number_points) 
	    point_array[number_generated++] = Point(0,0,0);
	if (number_generated >= number_points)
	    break;
    }
}	

void
print_relational_table(Point point_array[], int number_points)
{
//  Run all relational ops on an array of points, printing a table
    
    cout << "1st arg \t2nd arg\t\t< \t<= \t== \t>= \t> \t!=\n";
    for (int i = 0; i < number_points; i++) {
	for (int j = i; j < number_points; j++) {

	    cout << point_array[i] << "\t\t" << point_array[j] << "\t\t";
	    cout << (int) (point_array[i] <  point_array[j]) << "\t";
	    cout << (int) (point_array[i] <= point_array[j]) << "\t";
	    cout << (int) (point_array[i] == point_array[j]) << "\t";
	    cout << (int) (point_array[i] >= point_array[j]) << "\t";
	    cout << (int) (point_array[i] >  point_array[j]) << "\t";
	    cout << (int) (point_array[i] != point_array[j]) << "\t\n";

	    cout << point_array[j] << "\t\t" << point_array[i] << "\t\t";
	    cout << (int) (point_array[j] <  point_array[i]) << "\t";
	    cout << (int) (point_array[j] <= point_array[i]) << "\t";
	    cout << (int) (point_array[j] == point_array[i]) << "\t";
	    cout << (int) (point_array[j] >= point_array[i]) << "\t";
	    cout << (int) (point_array[j] >  point_array[i]) << "\t";
	    cout << (int) (point_array[j] != point_array[i]) << "\t\n";

	}
    }
}

Point
make_random_point(int dimensions, int bottom, int top, NumericType type, ACG& gen)
{
    Coord coordinate;
    int   range;

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

    dimensions = (gen.asLong() % MAX_RANDOM_DIMENSIONS);

    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);
    }
    return Point(-1, -1, -1, -1, -1);    // can\'t happen, but make compiler shut up.
}

Point
make_random_point(int bottom, int top, ACG& gen)
{
    int   range;
    Coord coordinate;
    NumericType type;
    int dimensions;

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

    range = top - bottom + 1;    

    if ((gen.asLong() % 2) == 0)
	type = REAL;
    else
	type = INTEGER;

    dimensions = (gen.asLong() % MAX_RANDOM_DIMENSIONS);

    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);
    }
    return Point(-1, -1, -1, -1, -1);    // can\'t happen, but make compiler shut up.
}

Point
make_random_point(int bottom, int top, NumericType type, ACG& gen)
{
    int   range;    
    Coord coordinate;
    int dimensions;
    
    if (top < bottom) {
	int temp = top;
	top = bottom;
	bottom = temp;
    }    
    range = top - bottom + 1;    

    dimensions = (gen.asLong() % MAX_RANDOM_DIMENSIONS);

    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);
    }
    return Point(-1, -1, -1, -1, -1);    // can\'t happen, but make compiler shut up.
}



void
sort_points(Point points[], int size)
{
    // very stupid bubble sorter. please fix.
    
    Point temp;
    for (int i = 0; i < size; i++) {
	for (int j = i; j < size; j++) {
	    if (Pointcmp(points[i], points[j]) < 1) {
		temp = points[i];
		points[i] = points[j];
		points[j] = temp;
	    }
	}
    }
}
@


1.2
log
@created random point generator. right now, it
just does 3-coord points, int or float.
@
text
@a4 1
#include <Uniform.h>
d6 5
d13 12
a24 3
    void	pr(Point);
    void	prl(char*, Point);
    void	prb(char);
d26 1
a26 2
    ACG		generator;
    Uniform	distribution(0.0, 1.0, &generator);
d28 1
a28 2
    Point	random_point(ACG&);	               // uniformly distributed from -1000 to 1000
    Point	another_random_point(int, Random&);
d30 2
a31 2
    for (int i = 0; i < 100; i++) {
	cout << random_point(generator) << '\n';
d34 12
d48 2
a49 2
Point
random_point(ACG& gen)
d51 8
a58 3
    int   top = 2000;
    int   mid = top/2;
    char  floatp;
d60 4
a63 1
    floatp = gen.asFloat() > 0.5;
d65 5
a69 6
    if (floatp)
	return Point(mid - gen.asFloat() * top, mid - gen.asFloat() * top, mid - gen.asFloat() * top);
    else
	return Point(mid - int(gen.asFloat() * top), mid - int(gen.asFloat() * top), mid - int(gen.asFloat() * top));
	
}
d71 2
d74 4
a77 2
Point
another_random_point(int dimensions, Random& dist)
d79 2
a80 2
    int   top = 100;
    int   mid = top/2;
d82 14
a95 2
    return Point(mid - dist() * top, mid - dist() * top, mid - dist() * top);
}
d97 1
d99 4
d104 4
d109 1
a109 1
pr (Point point)
d111 1
a111 2
    cout << point.type() << point << "\n";
}
d113 15
d129 1
a129 1
prb (char boolean)
d131 122
a252 2
    if (boolean == 0)
	cout << "False";
d254 65
a318 1
	cout << "True";
d321 2
a322 2
void
prl (char* label, Point point)
d324 74
a397 1
    cout << label << point.type() << point << "\n";
d401 17
@


1.1
log
@Initial revision
@
text
@d4 2
a6 1

d13 2
a14 11
    Coord c;
    Point p(0,1,2);
//     PointSub ps;
// 
//     cout << "ps=c[i]\n"; 
//    
//     ps = p[0];       // this is PointSub =,  returns a Coord.
// 
//     cout << "c=ps()\n";
//    
//     c = ps();      // 
d16 2
d19 4
a22 1
    
d24 29
a66 2
	    
    
d68 1
d73 1
@
