head     1.29;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @// @;


1.29
date     92.07.02.18.04.37;  author fischer;  state Exp;
branches ;
next     1.28;

1.28
date     92.07.01.18.09.25;  author fischer;  state Exp;
branches ;
next     1.27;

1.27
date     92.07.01.13.17.16;  author thoth;  state Exp;
branches ;
next     1.26;

1.26
date     92.06.30.07.56.28;  author fischer;  state Exp;
branches ;
next     1.25;

1.25
date     92.06.29.07.36.00;  author fischer;  state Exp;
branches ;
next     1.24;

1.24
date     92.06.28.05.23.50;  author fischer;  state Exp;
branches ;
next     1.23;

1.23
date     92.06.27.05.27.31;  author fischer;  state Exp;
branches ;
next     1.22;

1.22
date     92.06.27.04.57.46;  author fischer;  state Exp;
branches ;
next     1.21;

1.21
date     92.06.26.20.24.02;  author fischer;  state Exp;
branches ;
next     1.20;

1.20
date     92.06.25.19.11.33;  author fischer;  state Exp;
branches ;
next     1.19;

1.19
date     92.06.24.12.19.17;  author fischer;  state Exp;
branches ;
next     1.18;

1.18
date     92.06.24.10.03.25;  author thoth;  state Exp;
branches ;
next     1.17;

1.17
date     92.06.24.09.55.00;  author fischer;  state Exp;
branches ;
next     1.16;

1.16
date     92.06.22.13.59.25;  author thoth;  state Exp;
branches ;
next     1.15;

1.15
date     92.06.22.07.43.05;  author fischer;  state Exp;
branches ;
next     1.14;

1.14
date     92.06.21.17.00.17;  author thoth;  state Exp;
branches ;
next     1.13;

1.13
date     92.06.21.05.57.59;  author fischer;  state Exp;
branches ;
next     1.12;

1.12
date     92.06.15.14.10.21;  author fischer;  state Exp;
branches ;
next     1.11;

1.11
date     92.06.15.12.04.28;  author thoth;  state Exp;
branches ;
next     1.10;

1.10
date     92.06.12.06.10.48;  author fischer;  state Exp;
branches ;
next     1.9;

1.9
date     92.06.10.18.03.39;  author fischer;  state Exp;
branches ;
next     1.8;

1.8
date     92.06.10.05.12.17;  author fischer;  state Exp;
branches ;
next     1.7;

1.7
date     92.06.08.22.54.04;  author thoth;  state Exp;
branches ;
next     1.6;

1.6
date     92.06.08.02.56.23;  author fischer;  state Exp;
branches ;
next     1.5;

1.5
date     92.06.05.03.15.31;  author fischer;  state Exp;
branches ;
next     1.4;

1.4
date     92.06.03.10.49.21;  author fischer;  state Exp;
branches ;
next     1.3;

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

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

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


desc
@Fairly complete version of Point, based on simple vector
model,  where the vector components are always Coord.
@


1.29
log
@Fixed bassackwards Point operator --
@
text
@// Emacs: -*- C++ -*-
static char rscid[] = "$Id: Point.cc,v 1.28 92/07/01 18:09:25 fischer Exp Locker: fischer $";
// 
// $Log:	Point.cc,v $
// Revision 1.28  92/07/01  18:09:25  fischer
// Fixed irint problem, moved code for ``,'' operator to concat friend.
// 
// Revision 1.27  92/07/01  13:17:16  thoth
// made friend versions of ceil family of functions work.
// eliminated warnings for Coord%Coord like functions.
// 
// Revision 1.26  92/06/30  07:56:28  fischer
// Frobnicating rounding functions as friends and user functions,
// nothing really changed.
// 
// Revision 1.25  92/06/29  07:36:00  fischer
// changes max_coordinates to max_dimensions, made output << use
// Point.coordinates[i] instead of Point[i] to work around bugs
// from SubPoint int() and float() -- compiler bugs.
// added rounding functions -- see rint (3m) -- as methods. Adding
// as user functions caused hostility from SubPoints.
// 
// Revision 1.24  92/06/28  05:23:50  fischer
// Added const static unsigned int Point::max_coordinates = 5;
// Sprinkled in const declarations. Added Point concatenation
// operator ``,'', gave it fairly thorough testing.
// 
// Revision 1.23  92/06/27  05:27:31  fischer
// Corrected some erroneous comments about relational operators on constants.
// 
// Revision 1.22  92/06/27  04:57:46  fischer
// changed relationals to extend Coord over entire dimension of Points
// in test.
// 
// Revision 1.21  92/06/26  20:24:02  fischer
// Removed previous additions to Pointcmp. Added bitwise operators
// using the corresponding bitwise compound assignment operators.
// Added checking for uninitialized points and coordinates.
// 
// Revision 1.20  92/06/25  19:11:33  fischer
// Made Pointcmp check size of Points if they are equal, as last check.
// 
// Revision 1.19  92/06/24  12:19:17  fischer
// Fixed bug in printing of points of dimension 1 as <>.
// Owe Joe a beer.
// 
// Revision 1.18  92/06/24  10:03:25  thoth
// fixed xerox bug in Pointcmp
// 
// Revision 1.17  92/06/24  09:55:00  fischer
// Made relational ops work pointwise.
// Found problem with Point(x): if int x, mistaken
// gcc complaint about bad cast (gcc 2.2.2); if Coord x,
// zero length point is retured.  Various workarounds didn't.
// 
// Revision 1.16  92/06/22  13:59:25  thoth
// updated to follow new include conventions.
// 
// Revision 1.15  92/06/22  07:43:05  fischer
// Added logical coumpound functions, reordered functions
// to match Point.h.
// 
// Revision 1.14  92/06/21  17:00:17  thoth
// soothed some warnings (unsigned comparison with signed)
// adjusted for throw's potential non-volatility.
// wrote a Pointcmp lexical comparison routine, it is still untested.
// 
// Revision 1.13  92/06/21  05:57:59  fischer
// Changed enum literals for throw function
// to uppercase.
// 
// Revision 1.12  92/06/15  14:10:21  fischer
// Renamed NumericType enum to capitilized literals.
// 
// Revision 1.11  92/06/15  12:04:28  thoth
// fixed problem with Point::operator=
// 
// Revision 1.10  92/06/12  06:10:48  fischer
// Check for Coord[0] special cases in binary operators.
// Nested promote() calls.
// 
// Revision 1.9  92/06/10  18:03:39  fischer
// Fixed compound assignments so they return Point& instead of 
// const Point&,  started doing check for zero-sized points in
// arithmetic binary operations,  and return the already
// constructed zero-dimensioned temporary.
// 
// 
// Revision 1.8  92/06/10  05:12:17  fischer
// Made all Point/Point and Point/Coord relational operators
// use lexicographical (partial) ordering.  Added index derangement
// as operator () on points.  
// 
// Revision 1.7  92/06/08  22:54:04  thoth
// made enorm work.
// 
// Revision 1.6  92/06/08  02:56:23  fischer
// euclidean_distance renamed to enorm.  Checked ++, gcc 2.0
// seems to make it preincrement always. tweaked relational
// ops to use enorm in comparison if size of two points differ.
// 
// Revision 1.5  92/06/05  03:15:31  fischer
// Modified relational ops to compare points via lexicographical
// functions.   Point <> Const or vice versa still uses euclidean
// distance (or rather, broken euclidean distance - no sqrt).
// 
// Revision 1.4  92/06/03  10:49:21  fischer
// Renamed to Point,  we'll use this for a while.
// 
// Revision 1.3  92/06/02  01:48:50  fischer
// Removed deprecated Point--Point binary ops such as *, /, %.
// Made assignment operations return const references.
// Got rid of the local emacs variables at EOF in favor of mode line.
// Do checks to get rid of possibly two representations of Points,
// one where coordinates was a NULL pointer, the other where size
// was zero, but zero length array was allocated (I thought this was
// illegal, anyway, and ``couldn't happen'').
// 
// Revision 1.2  92/05/27  16:53:40  fischer
// Built vector-based version on top of Coord.
//

// If we include math AFTER Point.h, then the nint family of functions
// will get hosed.  This is a bug in the compiler and I have submitted
// a bug report.

#include <math.h>
#include "Point.h"

Point::Point(const Point& point)
{
    this->size = point.size;
    if (this->size == 0) 
	this->coordinates = NULL;
    else {
	this->coordinates = new Coord[size];
	for (unsigned i = 0; i < this->size; i++)
	    this->coordinates[i] = point.coordinates[i];
    }
}

Point& Point::operator = (const  Point &point)
{
    if (this == &point)	 // Is the extra test worth it, normally?
	return *this;

    // If point.size is zero (empty point) set *this to an
    // empty point and return.
    
    if (point.size == 0) {
	delete[] this->coordinates;   // OK even if coordinates already NULL
	this->coordinates = NULL;
	this->size = 0;
	return *this;
    }

    // We need to deallocate/reallocate if differing sizes.
    
    if (point.size != this->size) {
        delete[] this->coordinates;
        this->coordinates = new Coord[point.size];
        this->size = point.size;
    }
    
    for (unsigned i = 0; i < this->size; i++)
        this->coordinates[i] = point.coordinates[i];

    return *this;
}

Point::Point(Coord c0)
{
    coordinates = new Coord[size = 1];
    coordinates[0] =  c0;
}

Point::Point(Coord c0, Coord c1)
{
    NumericType coerced_type = IA::result_type(c0.type(), c1.type());
    
    coordinates = new Coord[size = 2];
    coordinates[0] = c0.promote(coerced_type);
    coordinates[1] = c1.promote(coerced_type);
}

Point::Point(Coord c0, Coord c1, Coord c2)
{
    NumericType coerced_type;

    coerced_type = IA::result_type(IA::result_type(c0.type(), c1.type()),
				   c2.type());

    coordinates = new Coord[size = 3];
    coordinates[0] = c0.promote(coerced_type);
    coordinates[1] = c1.promote(coerced_type);
    coordinates[2] = c2.promote(coerced_type);
}

Point::Point(Coord c0, Coord c1, Coord c2, Coord c3)
{
    NumericType coerced_type;

    coerced_type = IA::result_type(IA::result_type(c0.type(), c1.type()),
				   IA::result_type(c2.type(), c3.type()));

    coordinates = new Coord[size = 4];
    coordinates[0] = c0.promote(coerced_type);
    coordinates[1] = c1.promote(coerced_type);
    coordinates[2] = c2.promote(coerced_type);
    coordinates[3] = c3.promote(coerced_type);
}


Point::Point(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4)
{
    NumericType coerced_type;

    coerced_type = IA::result_type(IA::result_type(IA::result_type(c0.type(), c1.type()),
						   IA::result_type(c2.type(), c3.type())),
				   c4.type());

    coordinates = new Coord[size = 5];
    coordinates[0] = c0.promote(coerced_type);
    coordinates[1] = c1.promote(coerced_type);
    coordinates[2] = c2.promote(coerced_type);
    coordinates[3] = c3.promote(coerced_type);
    coordinates[4] = c4.promote(coerced_type);
}


//////////////////////// Plus
//
// Point = Point + Point

Point Point::operator + (const Point& right) const
{
    Point result_point;

    if (this->size != right.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return result_point;
    }

    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];
    
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] + right.coordinates[i];

    return result_point;
}

// Point = Point + Coord

Point operator + (const Point& left, const Coord& right)
{
    Point result_point;

    if (left.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = left.size;
    result_point.coordinates = new Coord[left.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left.coordinates[i] + right;
    return result_point;
}


// Point = Coord + Point

Point operator + (const Coord& left, const Point& right)
{
    Point result_point;

    if (right.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = right.size;
    result_point.coordinates = new Coord[right.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left + right.coordinates[i];
    return result_point;
}

//////////////////////// Minus
//
// Point = Point - Point

Point Point::operator - (const Point& right) const
{
    Point result_point;

    if (this->size != right.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return result_point;
    }

    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }
    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];
    
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] - right.coordinates[i];
    return result_point;
}

// Point = Point - Coord

Point operator - (const Point& left, const Coord& right)
{
    Point result_point;

    if (left.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = left.size;
    result_point.coordinates = new Coord[left.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left.coordinates[i] - right;
    return result_point;
}

// Point = Coord - Point

Point operator - (const Coord& left, const Point& right)
{
    Point result_point;

    if (right.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = right.size;
    result_point.coordinates = new Coord[right.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left - right.coordinates[i];
    return result_point;
}

// Point = -Point

Point Point::operator - () const
{
    Point result_point;

    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] =  - this->coordinates[i];
    return result_point;
}

//////////////////////// Multiply
//
// Point = Point * Point

Point Point::operator * (const Point& right) const
{
    Point result_point;

    if (this->size != right.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return result_point;
    }

    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];
    
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] * right.coordinates[i];
    return result_point;
}

// Point = Point * Coord

Point operator * (const Point& left, const Coord& right)
{
    Point result_point;

    if (left.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = left.size;
    result_point.coordinates = new Coord[left.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left.coordinates[i] * right;
    return result_point;
}

// Point = Coord * Point

Point operator * (const Coord& left, const Point& right)
{
    Point result_point;

    if (right.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = right.size;
    result_point.coordinates = new Coord[right.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left * right.coordinates[i];
    return result_point;
}


//////////////////////// Divide
//
// Point = Point / Point

Point Point::operator / (const Point& right) const
{
    Point result_point;

    if (this->size != right.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return result_point;
    }

    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];
    
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] / right.coordinates[i];
    return result_point;
}

// Point = Point / Coord

Point operator / (const Point& left, const Coord& right)
{
    Point result_point;

    if (left.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = left.size;
    result_point.coordinates = new Coord[left.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left.coordinates[i] / right;
    return result_point;
}

// Point = Coord / Point

Point operator / (const Coord& left, const Point& right)
{
    Point result_point;

    if (right.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = right.size;
    result_point.coordinates = new Coord[right.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  left / right.coordinates[i];
    return result_point;
}


//////////////////////// Modulus
//
// Point = Point % Point

Point Point::operator % (const Point& right) const
{
    Point result_point;

    if (this->size != right.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return result_point;
    }

    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];
    
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  int(this->coordinates[i]) % int(right.coordinates[i]);
    return result_point;
}

// Point = Point % Coord

Point operator % (const Point& left, const Coord& right)
{
    Point result_point;

    if (left.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = left.size;
    result_point.coordinates = new Coord[left.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  int(left.coordinates[i]) % int(right);
    return result_point;
}

// Point = Coord % Point

Point operator % (const Coord& left, const Point& right)
{
    Point result_point;

    if (right.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }

    result_point.size = right.size;
    result_point.coordinates = new Coord[right.size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  int(left) % int(right.coordinates[i]);
    return result_point;
}


//////////////////////// Compound assignments.
//
// Underlying operator will catch errors. 
//
// 1. All of these operators #= have the potential of being much faster
// than the equivalent foo = foo # bar,  and so should be re-written.
// 2. Then the regular # operators can be modified to use the #= forms.

const Point& Point::operator += (const Point& rhs)	
{ *this = *this + rhs; 	return  *this; }

const Point& Point::operator += (const Coord& rhs)	
{ *this = *this + rhs; 	return  *this; }

const Point& Point::operator -= (const Point& rhs)	
{ *this = *this - rhs; 	return  *this; }

const Point& Point::operator -= (const Coord& rhs)	
{ *this = *this - rhs; 	return  *this; }

const Point& Point::operator *= (const Point& rhs)	
{ *this = *this * rhs; 	return  *this; }

const Point& Point::operator *= (const Coord& rhs)	
{ *this = *this * rhs; 	return  *this; }

const Point& Point::operator /= (const Point& rhs)	
{ *this = *this / rhs; 	return  *this; }

const Point& Point::operator /= (const Coord& rhs)	
{ *this = *this / rhs; 	return  *this; }

const Point& Point::operator %= (const Point& rhs)	
{ *this = *this % rhs; 	return  *this; }

const Point& Point::operator %= (const Coord& rhs)	
{ *this = *this % rhs; 	return  *this; }

const Point& Point::operator ++ () {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this += 1;
    return  *this;
}

const Point& Point::operator -- () {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this -= 1;
    return  *this;
}

// The following bitwise operators use the fact that for the underlying Coords
// the int() operator is  defined only for the integer Coords. Bitwise operators
// are not defined directly on Coords.  All of these will result in runtime errors
// if erroneously applied to non-integer Coords.

const Point& Point::operator <<= (const Point& rhs) {
    if (this->size != rhs.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) << int(rhs.coordinates[i]);
    return *this;
}

const Point& Point::operator <<= (unsigned int rhs) {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) << int(rhs);
    return *this;
}
	
const Point& Point::operator >>= (const Point& rhs) {
    if (this->size != rhs.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) >> int(rhs.coordinates[i]);
    return *this;
}

const Point& Point::operator >>= (unsigned int rhs) {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) >> rhs;
    return *this;
}

const Point& Point::operator &= (const Point& rhs) {
    if (this->size != rhs.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) & int(rhs.coordinates[i]);
    return *this;
}

const Point& Point::operator &= (unsigned int rhs) {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) & rhs;
    return *this;
}
	
const Point& Point::operator ^= (const Point& rhs) {
    if (this->size != rhs.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) ^ int(rhs.coordinates[i]);
    return *this;
}

const Point& Point::operator ^= (unsigned int rhs) {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) ^ rhs;
    return *this;
}

const Point& Point::operator |= (const Point& rhs) {
    if (this->size != rhs.size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) | int(rhs.coordinates[i]);
    return *this;
}

const Point& Point::operator |= (unsigned int rhs) {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    for (unsigned i = 0; i < this->size; i++) 
	this->coordinates[i] = int(this->coordinates[i]) | rhs;
    return *this;
}

/////////////// Bitwise operators
//
//  These are built upon the bitwise compound assignment versions
//  except of course for ~.  

Point operator << (const Point& point, unsigned int shift)
{
    Point result_point = point;    return result_point <<= shift;
}

Point operator >> (const Point& point, unsigned int shift)
{
    Point result_point = point;    return result_point <<= shift;
}

Point Point::operator & (const Point& rhs) const
{
    Point result_point = *this;          return result_point &= rhs;
}

Point operator & (const Point& lhs, const Coord& rhs)
{
    Point result_point = lhs;           return result_point &= rhs;
}

Point operator & (const Coord& lhs, const Point& rhs)
{
    Point result_point = Point(lhs);    return result_point &= rhs;
}

Point Point::operator ^ (const Point& rhs) const
{
    Point result_point = *this;         return result_point ^= rhs;
}

Point operator ^ (const Point& lhs, const Coord& rhs)
{
    Point result_point = lhs;           return result_point ^= rhs;
}

Point operator ^ (const Coord& lhs, const Point& rhs)
{
    Point result_point = Point(lhs);    return result_point ^= rhs;
}


Point Point::operator | (const Point& rhs) const
{
    Point result_point = *this;         return result_point |= rhs;
}

Point operator | (const Point& lhs, const Coord& rhs)
{
    Point result_point = lhs;           return result_point |= rhs;
}

Point operator | (const Coord& lhs, const Point& rhs)
{
    Point result_point = Point(lhs);    return result_point |= rhs;
}

Point Point::operator ~ () const
{
    Point result_point;
    
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }

// Why do we have to use int(this->coordinates[i]) !?
// as long as we do, this is superfluous.
//    
//     if (this->type() != INTEGER) {
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return *this;
//     }

    result_point.size = this->size;
    result_point.coordinates = new Coord[result_point.size];

    for (unsigned int i=0; i < this->size; i++) {
	result_point.coordinates[i] = ~int(this->coordinates[i]);
    }
	    
    return result_point;
}
    

//////////////////////// Relational operators.
//
// All Point/Point and Point/Coord comparisons must involve initialized
// data, or an exception is thrown. Coords have thier values extended to
// the dimensions of the Point.  Point/Point comparisions require Points
// to be of the same dimensionality.


// Point > Point,   Const > Point,   Point > Const

char Point::operator > (const Point& rhs) const
{
    if (this->size == 0 || rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (this->size != rhs.size)
	return (char) 0;
    
    for (unsigned i = 0; i < this->size ; i++) 
	if (! (this->coordinates[i] > rhs.coordinates[i]))
	    return char(0);
    
    return char(1);
}

char operator > (const Coord& lhs, const Point& rhs)
{
    if (lhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    if (rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    for (unsigned int i = 0; i < rhs.dimensions(); i++)
	if (! (lhs > rhs.coordinates[i]))
	    return (char) 0;

    return (char) 1;
}

char operator > (const Point& lhs, const Coord& rhs)
{
    if (lhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (rhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    for (unsigned int i = 0; i < lhs.dimensions(); i++)
	if (! (lhs.coordinates[i] > rhs))
	    return (char) 0;

    return (char) 1;
}

// Point < Point,   Const < Point,   Point < Const

char Point::operator < (const Point& rhs) const
{
    if (this->size == 0 || rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (this->size != rhs.size)
	return (char) 0;

    for (unsigned i = 0; i < this->size ; i++) 
	if (! (this->coordinates[i] < rhs.coordinates[i]))
	    return char(0);

    return char(1);
}

char operator < (const Coord& lhs, const Point& rhs)
{
    if (lhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    if (rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    for (unsigned int i = 0; i < rhs.dimensions(); i++)
	if (! (lhs < rhs.coordinates[i]))
	    return (char) 0;

    return (char) 1;
}

char operator < (const Point& lhs, const Coord& rhs)
{
    if (lhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (rhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    for (unsigned int i = 0; i < lhs.dimensions(); i++)
	if (! (lhs.coordinates[i] < rhs))
	    return (char) 0;

    return (char) 1;    
}

// Point == Point,  Coord == Point,  Point == Coord

char Point::operator == (const Point& rhs) const
{
    if (this->size == 0 || rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (this->size != rhs.size)
	return (char) 0;

    for (unsigned i = 0; i < this->size; i++) 
	if (! (this->coordinates[i] == rhs.coordinates[i]))
	    return (char) 0;
    
    return (char) 1;
}

char operator == (const Coord& lhs, const Point& rhs)
{
    if (lhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    if (rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    for (unsigned int i = 0; i < rhs.dimensions(); i++)
	if (! (lhs == rhs.coordinates[i]))
	    return (char) 0;

    return (char) 1;
}

char operator == (const Point& lhs, const Coord& rhs)
{
    if (lhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (rhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }    
    for (unsigned int i = 0; i < lhs.dimensions(); i++)
	if (! (lhs.coordinates[i] == rhs))
	    return (char) 0;

    return (char) 1;
}

// Point <= Point,   Const <= Point,   Point <= Const

char Point::operator <= (const Point& rhs) const
{
    if (this->size == 0 || rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (this->size != rhs.size)
	return (char) 0;

    for (unsigned i = 0; i < this->size ; i++) 
	if  (! (this->coordinates[i] <= rhs.coordinates[i]))
	    return char(0);

    return char(1);
}

char operator <= (const Coord& lhs, const Point& rhs)
{
    if (lhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    if (rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    for (unsigned int i = 0; i < rhs.dimensions(); i++)
	if (! (lhs <= rhs.coordinates[i]))
	    return (char) 0;

    return (char) 1;
}

char operator <= (const Point& lhs, const Coord& rhs)
{
    if (lhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (rhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }

    for (unsigned int i = 0; i < lhs.dimensions(); i++)
	if (! (lhs.coordinates[i] <= rhs))
	    return (char) 0;

    return (char) 1;
}


// Point >= Point,   Const >= Point,   Point >= Const

char Point::operator >= (const Point& rhs) const
{
    if (this->size == 0 || rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (this->size != rhs.size)
	return (char) 0;

    for (unsigned i = 0; i < this->size ; i++) 
	if  (! (this->coordinates[i] >= rhs.coordinates[i]))
	    return char(0);

    return char(1);
}

char operator >= (const Coord& lhs, const Point& rhs)
{
    if (lhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    if (rhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    for (unsigned int i = 0; i < rhs.dimensions(); i++)
	if (! (lhs >= rhs.coordinates[i]))
	    return (char) 0;

    return (char) 1;
}

char operator >= (const Point& lhs, const Coord& rhs)
{
    if (lhs.size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }	
    if (rhs.type() == NONE) {
	throw(IA::COORD_UNINITIALIZED, __FILE__, __LINE__);
	return (char) 0;
    }
    for (unsigned int i = 0; i < lhs.dimensions(); i++)
	if (! (lhs.coordinates[i] >= rhs))
	    return (char) 0;

    return (char) 1;

}

// Point != Point,  Coord != Point,  Point != Coord

char Point::operator != (const Point& rhs) const
{
    return ! (*this == rhs);
}

char operator != (const Coord& lhs, const Point& rhs)
{
    return ! (lhs == rhs);
}

char operator != (const Point& lhs, const Coord& rhs)
{
    return ! (lhs == rhs);
}


//////////////////////// Distance measures Point.enorm()
//
// enorm: Euclidean distance from origin.

double Point::enorm () const
{
    double result_number = 0;
    
    for (unsigned i = 0; i < this->size; i++)
	result_number = result_number +
	    (float) (this->coordinates[i] * this->coordinates[i]);

    return sqrt(result_number);
}


//////////////////////// Index derangement, "Point(index, index..)"
//
// Function call overloading on Point gives us a new Point with
// by-index selection.  For instance, let  a=Point(10, 20, 30).
// Then b=a(2,0) is equivalent to b=Point(30,10).


// The one index version is provided for completeness,
// though it hardly makes sense.

Point Point::operator () (unsigned i0) const
{
    Point p(0);
    
    if (i0 >= this->size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
    }
    p.coordinates[0] = this->coordinates[i0];
    return p;
}

Point Point::operator () (unsigned i0, unsigned i1) const
{
    Point p(0,0);

    if (i0 >= this->size || i1 >= this->size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
    }
    p.coordinates[0] = this->coordinates[i0];
    p.coordinates[1] = this->coordinates[i1];
    return p;
}

Point Point::operator () (unsigned i0, unsigned i1, unsigned i2) const
{
    Point p(0,0,0);

    if (i0 >= this->size || i1 >= this->size || i2 >= this->size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
    }
    
    p.coordinates[0] = this->coordinates[i0];
    p.coordinates[1] = this->coordinates[i1];
    p.coordinates[2] = this->coordinates[i2];
    return p;
}

Point Point::operator () (unsigned i0, unsigned i1, unsigned i2, unsigned i3) const
{
    Point p(0,0,0,0);

    if (i0 >= this->size || i1 >= this->size || i2 >= this->size || i3 >= this->size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
    }

    p.coordinates[0] = this->coordinates[i0];
    p.coordinates[1] = this->coordinates[i1];
    p.coordinates[2] = this->coordinates[i2];
    p.coordinates[3] = this->coordinates[i3];
    return p;
}

Point Point::operator () (unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4) const
{
    Point p(0,0,0,0,0);

    if (i0 >= this->size || i1 >= this->size || i2 >= this->size ||
	i3 >= this->size || i4 >= this->size) {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
    }

    p.coordinates[0] = this->coordinates[i0];
    p.coordinates[1] = this->coordinates[i1];
    p.coordinates[2] = this->coordinates[i2];
    p.coordinates[3] = this->coordinates[i3];
    p.coordinates[4] = this->coordinates[i4];
    return p;
}
    
////////////////////////  Point concatenation concat(Point,Point)
//
// Given a combination of Points and Coords, create a new Point that is
// the concatenation of the arguments.  Throws when the result Point
// would have greater dimension than Point::max_dimensions, currently 5.


// Point = concat (Point, Point)

Point concat(const Point& lhs, const Point& rhs)
{
    Point result_point;
    
    if (lhs.type() == NONE) {
	if (rhs.type() == NONE)
	    return result_point;
	else 
	    return rhs;
    } else if (rhs.type() == NONE)
	return lhs;

    unsigned int total_size = lhs.size + rhs.size;

    if  (total_size > Point::max_dimensions) {
	throw(IA::POINT_TOO_LARGE, __FILE__, __LINE__);
	return result_point;
    }	    

    NumericType result_type = IA::result_type(lhs.type(), rhs.type());

    if (total_size > 0) {
	result_point.size = total_size;
	result_point.coordinates = new Coord[total_size];
    }
    
    for (unsigned int i = 0; i < lhs.size; i++) 
	result_point.coordinates[i] = (lhs.coordinates[i]).promote(result_type);

    for (unsigned int j = 0; j < rhs.size; j++) 
	result_point.coordinates[i+j] = (rhs.coordinates[j]).promote(result_type);

    return result_point;
}

// Point = concat(Point, Coord)

Point concat(const Point& lhs, const Coord& rhs)
{
    Point result_point;

    if (lhs.type() == NONE) {
	if (rhs.type() == NONE)
	    return result_point;
	else 
	    return Point(rhs);
    } else if (rhs.type() == NONE)
	return lhs;

    NumericType result_type = IA::result_type(lhs.type(), rhs.type());

    unsigned int total_size = lhs.size + 1;

    if  (total_size > Point::max_dimensions) {
	throw(IA::POINT_TOO_LARGE, __FILE__, __LINE__);
	return result_point;
    }

    result_point.coordinates = new Coord[total_size];
    result_point.size = total_size;

    for (unsigned int i = 0; i < lhs.size; i++) 
	result_point.coordinates[i] = (lhs.coordinates[i]).promote(result_type);

    result_point.coordinates[i] = rhs.promote(result_type);

    return result_point;
}

// Point = concat(Coord, Point)

Point concat(const Coord& lhs, const Point& rhs)
{
    Point result_point;

    if (lhs.type() == NONE) {
	if (rhs.type() == NONE)
	    return result_point;
	else 
	    return rhs;
    } else if (rhs.type() == NONE)
	return Point(lhs);

    NumericType result_type = IA::result_type(lhs.type(), rhs.type());

    unsigned int total_size = rhs.size + 1;

    if  (total_size > Point::max_dimensions) {
	throw(IA::POINT_TOO_LARGE, __FILE__, __LINE__);
	return result_point;
    }

    result_point.coordinates = new Coord[total_size];
    result_point.size = total_size;

    result_point.coordinates[0] = lhs.promote(result_type);

    for (unsigned int i = 0; i < rhs.size; i++) 
	result_point.coordinates[i+1] = (rhs.coordinates[i]).promote(result_type);

    return result_point;
}


////////////////////////  I/O operations.
//
// TO DO: input.

ostream &operator << (ostream &stream, Point& point)
{
    int last_index = point.size - 1;
    stream << "<";
    for  ( int i = 0; i < last_index; ++i ) {
	stream << point.coordinates[i] << " ";
    }
    if ( point.size > 0 ) {
	stream << point.coordinates[last_index];
    };
    stream << ">";
    return stream;
}



//////////////// type conversion functions
//

Point Point::toREAL () const
{
    Point result = *this;

    switch (this->type()) {
    case INTEGER:
	for (unsigned i = 0; i < this->dimensions(); i++)
	    result.coordinates[i] = float(result.coordinates[i]);
	break;
    case REAL:
	break;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	break;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
    }
    return result;
}

Point Point::toINTEGER () const
{
    Point result;

    switch (this->type()) {
    case INTEGER:
	return *this;
    case REAL:
	result.coordinates = new Coord [result.size = this->size];
	for (unsigned i = 0; i < result.size; i++)
	    result.coordinates[i] = int(float(this->coordinates[i]));
	return result;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}

////////////////////////  Point comparison
//
// A sort of lexicographic comparison of Points, except that
// points are zero extended for comparison, e.g., <0> is equal
// to <0 0>, <>, <0 0 0>, etc
//

char Pointcmp(const Point &lhs, const Point &rhs)
{
    if (lhs.dimensions() > rhs.dimensions()) {
	for (unsigned i=0; i < rhs.dimensions(); i++) {
	    if (lhs[i] < rhs[i])
		return -1;
	    else if (lhs[i] > rhs[i])
		return 1;
	}
	for ( ; i<lhs.dimensions(); i++) {
	    if (lhs[i] < 0)
		return -1;
	    else if (lhs[i] > 0)
		return 1;
	}
    } else {
	for (unsigned i=0; i < lhs.dimensions(); i++) {
	    if (lhs[i] < rhs[i])
		return -1;
	    else if (lhs[i] > rhs[i])
		return 1;
	}
	for ( ; i < rhs.dimensions(); i++) {
	    if (0 < rhs[i])
		return  -1;
	    else if (0 > rhs[i])
		return  1;
	}
    }
    return 0;

    // If this were to be used for a lexicographic sorter, then we would
    // need the following additional code:
    //
    // At this point the zero-extended Coordinates do not differ in value,
    // so check for number of dimensions; shorter Points are considered
    // less than longer Points.
    // 
    //     if (lhs.dimensions() == rhs.dimensions())
    // 		return 0;
    //     else if (lhs.dimensions() > rhs.dimensions())
    // 		return 1;
    //     else
    // 		return -1;

}

//////////////// math rounding functions as friends.
//  
// All of the following routines perform some rounding function.  Except
// for irint, nint and trunc, the routines always return REAL points.
// irint, nint, and trunc alway pass back INTEGER points.  See rint (3)
// for details.

#define IA_FLOAT2FLOAT(func)						\
Point func (Point p)							\
{									\
    Point	rval;							\
    switch (p.type()) {							\
    case INTEGER:							\
	return p.toREAL();						\
    case REAL:								\
    rval = p;								\
	for (unsigned i = 0; i < p.dimensions(); i++) 			\
	    rval.coordinates[i] = func((float)rval.coordinates[i]);	\
	return rval;							\
    case NONE:								\
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);		\
	return p;							\
    default:								\
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);			\
	return p;							\
    }									\
}

// I think that the macros are much better.  We are making the commonality
// of all these function explicit.

IA_FLOAT2FLOAT(aint)
IA_FLOAT2FLOAT(anint)
IA_FLOAT2FLOAT(ceil)
IA_FLOAT2FLOAT(floor)
IA_FLOAT2FLOAT(rint)

#undef IA_FLOAT2FLOAT

#define IA_FLOAT2INT(func)						\
Point func (Point p)							\
{									\
    Point	rval;							\
    switch (p.type()) {							\
    case INTEGER:							\
	return p;							\
    case REAL:								\
	rval = p;							\
	for (unsigned i = 0; i < p.dimensions(); i++) 			\
	    rval.coordinates[i] = func((float)rval.coordinates[i]);	\
	return rval;							\
    case NONE:								\
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);		\
	return p;							\
    default:								\
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);			\
	return p;							\
    }									\
}
IA_FLOAT2INT(irint)
IA_FLOAT2INT(nint)

#undef IA_FLOAT2INT

Point trunc (Point p)
{
    return p.toINTEGER();
}


@


1.28
log
@Fixed irint problem, moved code for ``,'' operator to concat friend.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.27 92/07/01 13:17:16 thoth Exp Locker: fischer $";
d5 3
d641 1
a641 1
    *this -= -1;
@


1.27
log
@made friend versions of ceil family of functions work.
eliminated warnings for Coord%Coord like functions.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.26 92/06/30 07:56:28 fischer Exp Locker: thoth $";
d5 4
d120 1
a120 1
// if we include math AFTER Point.h, then the nint family of functions
d123 1
d1245 1
a1245 1
////////////////////////  Point concatenation "Point,Point"
d1252 1
a1252 1
// Point = Point, Point
d1254 1
a1254 1
Point Point::operator , (const Point& rhs) const
d1258 1
a1258 1
    if (this->type() == NONE) {
d1264 1
a1264 1
	return *this;
d1266 1
a1266 1
    unsigned int total_size = this->size + rhs.size;
d1273 1
a1273 1
    NumericType result_type = IA::result_type(this->type(), rhs.type());
d1280 2
a1281 2
    for (unsigned int i = 0; i < this->size; i++) 
	result_point.coordinates[i] = (this->coordinates[i]).promote(result_type);
d1289 1
a1289 1
// Point = Point , Coord
d1291 1
a1291 1
Point operator , (const Point& lhs, const Coord& rhs)
d1323 1
a1323 1
// Point = Coord , Point
d1325 1
a1325 1
Point operator , (const Coord& lhs, const Point& rhs)
a1356 1
// Point = Coord, Coord
a1357 32
Point operator , (const Coord& lhs, const Coord& rhs)
{

    if (lhs.type() == NONE) {
	if (rhs.type() == NONE)
	    return Point();
	else
	    return Point(rhs);
	}
    else {
	if (rhs.type() == NONE)
	    return Point(lhs);
	else {
	    NumericType result_type = IA::result_type(lhs.type(), rhs.type());
	    return Point(lhs.promote(result_type),
			 rhs.promote(result_type));
	}
    }
}

//  gcc 2.2.2  won't let us do Point p = (2, 1): "bad argument 0 for function `Point::operator
//  = (const class Point&)' (type was int )": it effectively ignores it, using the default
//  rules (i.e., 2 evaluted as 2, then 1 evaluated as 1 and returned for the assignment)
//  giving us the same (incorrect) error as Point p = 1;
//
// Point = int, int
// 
// Point operator , (const int lhs, const int rhs)
// {
//     return Point(Coord(lhs), Coord(rhs));
// }

d1476 1
a1476 2
#if 1
//////////////// math rounding functions as friends (or not)
d1483 10
a1492 10
#define IA_FLOAT2FLOAT(func)	\
Point func (Point p)		\
{				\
    Point	rval;		\
    switch (p.type()) {		\
    case INTEGER:		\
	return p.toREAL();	\
    case REAL:			\
	rval = p;		\
	for (unsigned i = 0; i < p.dimensions(); i++) 	\
d1494 8
a1501 8
	return rval;		\
    case NONE:			\
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);	\
	return p;		\
    default:			\
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);	\
	return p;		\
    }				\
d1506 1
a1511 1
IA_FLOAT2FLOAT(irint)
d1515 19
a1533 22
Point nint (Point p)
{
    Point rval;
    
    switch (p.type()) {
    case INTEGER:
	return p;
    case REAL:
	rval = p;
	for (unsigned i = 0; i < p.dimensions(); i++) {
	    rval.coordinates[i] =
		nint((float)p.coordinates[i]);
	}
	Coord(1);
	return rval;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return p;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return p;
    }
d1535 2
d1538 1
a1544 171
#else

//////////////// Rob: these work OK, but defining these as friends
//////////////// or as just plain old functions in above form always 
//////////////// gives me this error:
//////////////// bad argument 0 for function `SubPoint::operator = (class Coord)' (type was class Point)


//////////////// math rounding functions as member functions
//  
// All of the following routines perform some rounding function.  Except
// for irint, nint and trunc, the routines always return REAL points.
// irint, nint, and trunc alway pass back INTEGER points.  See rint (3)
// for details.
// 
// 
Point Point::aint () const
{
    Point p;
    
    switch (this->type()) {
    case INTEGER:
	return this->toREAL();
    case REAL:
	p = *this;
	for (unsigned i = 0; i < this->size; i++) 
	    p.coordinates[i] = ::aint(this->coordinates[i]);
	return p;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}

Point Point::anint () const
{
    Point p;

    switch (this->type()) {
    case INTEGER:
	return this->toREAL();
    case REAL:
	p = *this;
	for (unsigned i = 0; i < this->size; i++)
	    p.coordinates[i] = ::anint(this->coordinates[i]);
	return p;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}

Point Point::ceil () const
{
    Point p;

    switch (this->type()) {
    case INTEGER:
	return this->toREAL();
    case REAL:
	p = *this;
	for (unsigned i = 0; i < this->size; i++)
	    p.coordinates[i] = ::ceil(this->coordinates[i]);
	return p;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}

Point Point::floor () const
{
    Point p;

    switch (this->type()) {
    case INTEGER:
	return this->toREAL();
    case REAL:
	p = *this;
	for (unsigned i = 0; i < this->size; i++)
	    p.coordinates[i] = ::floor(this->coordinates[i]);
	return p;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}

Point Point::rint () const
{
    Point p;
    
    switch (this->type()) {
    case INTEGER:
	return this->toREAL();
    case REAL:
	p = *this;
	for (unsigned i = 0; i < this->size; i++)
	    p.coordinates[i] = ::rint(this->coordinates[i]);
	return p;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}


Point Point::irint () const
{
    Point p;
    
    switch (this->type()) {
    case INTEGER:
	return *this;
    case REAL:
	p = this->toINTEGER();
	for (unsigned i = 0; i < this->size; i++)
	    p.coordinates[i] = ::irint(this->coordinates[i]);
	return p;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}

Point Point::nint () const
{
    Point p;
    
    switch (this->type()) {
    case INTEGER:
	return *this;
    case REAL:
	p = this->toINTEGER();
	for (unsigned i = 0; i < this->size; i++)
	    p.coordinates[i] = ::nint(this->coordinates[i]);
	return p;
    case NONE:
	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
	return *this;
    default:
	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
	return *this;
    }
}


Point Point::trunc () const
{
    return this->toINTEGER();
}

#endif
@


1.26
log
@Frobnicating rounding functions as friends and user functions,
nothing really changed.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.25 92/06/29 07:36:00 fischer Exp Locker: fischer $";
d5 4
d115 5
a120 1
#include <math.h>
d536 1
a536 1
	    =  this->coordinates[i] % right.coordinates[i];
d556 1
a556 1
	    =  left.coordinates[i] % right;
d576 1
a576 1
	    =  left % right.coordinates[i];
d1432 1
a1432 1
        
d1504 1
a1510 139
// 
// Point aint (Point p)
// {
//     switch (p.type()) {
//     case INTEGER:
// 	return p.toREAL();
//     case REAL:
// 	for (unsigned i = 0; i < p.dimensions(); i++) 
// 	    p[i] = aint(p[i]);
// 	return p;
//     case NONE:
// 	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
// 	return p;
//     default:
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return p;
//     }
// }
// 
// Point anint (Point p)
// {
//     switch (p.type()) {
//     case INTEGER:
// 	return p.toREAL();
//     case REAL:
// 	for (unsigned i = 0; i < p.dimensions(); i++)
// 	    p[i] = anint(p[i]);
// 	return p;
//     case NONE:
// 	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
// 	return p;
//     default:
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return p;
//     }
// }
// 
// Point ceil (Point p)
// {
//     switch (p.type()) {
//     case INTEGER:
// 	return p.toREAL();
//     case REAL:
// 	for (unsigned i = 0; i < p.dimensions(); i++)
// 	    p[i] = ceil(p[i]);
// 	return p;
//     case NONE:
// 	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
// 	return p;
//     default:
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return p;
//     }
// }
// 
// Point floor (Point p)
// {
//     switch (p.type()) {
//     case INTEGER:
// 	return p.toREAL();
//     case REAL:
// 	for (unsigned i = 0; i < p.dimensions(); i++)
// 	    p[i] = floor(p[i]);
// 	return p;
//     case NONE:
// 	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
// 	return p;
//     default:
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return p;
//     }
// }
// 
// Point rint (Point p)
// {
//     switch (p.type()) {
//     case INTEGER:
// 	return p.toREAL();
//     case REAL:
// 	for (unsigned i = 0; i < p.dimensions(); i++)
// 	    p[i] = rint(p[i]);
// 	return p;
//     case NONE:
// 	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
// 	return p;
//     default:
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return p;
//     }
// }
// 
// 
// Point irint (Point p)
// {
//     Point q;
//     
//     switch (p.type()) {
//     case INTEGER:
// 	return p;
//     case REAL:
// 	q = p.toINTEGER();
// 	for (unsigned i = 0; i < p.dimensions(); i++)
// 	    q[i] = irint(p[i]);
// 	return q;
//     case NONE:
// 	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
// 	return p;
//     default:
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return p;
//     }
// }
// 
// Point nint (Point p)
// {
//     Point q;
//     
//     switch (p.type()) {
//     case INTEGER:
// 	return p;
//     case REAL:
// 	q = p.toINTEGER();
// 	for (unsigned i = 0; i < p.dimensions(); i++)
// 	    q[i] = nint(p[i]);
// 	return q;
//     case NONE:
// 	throw(IA::TYPE_UNSPECIFIED, __FILE__, __LINE__);
// 	return p;
//     default:
// 	throw(IA::TYPE_MISMATCH, __FILE__, __LINE__);
// 	return p;
//     }
// }
// 
// 
// Point trunc (Point p)
// {
//     return p.toINTEGER();
// }
d1512 20
d1533 43
d1744 1
a1744 1

@


1.25
log
@changes max_coordinates to max_dimensions, made output << use
Point.coordinates[i] instead of Point[i] to work around bugs
from SubPoint int() and float() -- compiler bugs.
added rounding functions -- see rint (3m) -- as methods. Adding
as user functions caused hostility from SubPoints.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.24 92/06/28 05:23:50 fischer Exp Locker: fischer $";
d5 7
d1366 12
d1496 1
a1496 1
//////////////// math rounding functions
d1502 2
a1503 2

// Point aint (const Point& p)
d1505 1
a1505 1
//     switch (q.type()) {
d1507 1
a1507 1
// 	return q.toREAL();
d1509 3
a1511 3
// 	for (unsigned i = 0; i < q.dimensions(); i++) 
// 	    q[i] = ::aint(p[i]);
// 	return q;
d1514 1
a1514 1
// 	return q;
d1517 1
a1517 1
// 	return q;
d1528 1
a1528 1
// 	    p[i] = ::anint(p[i]);
d1546 1
a1546 1
// 	    p[i] = ::ceil(p[i]);
d1564 1
a1564 1
// 	    p[i] = ::floor(p[i]);
d1582 1
a1582 1
// 	    p[i] = ::rint(p[i]);
d1604 1
a1604 1
// 	    q[i] = ::irint(p[i]);
d1625 1
a1625 1
// 	    q[i] = ::nint(p[i]);
d1641 14
d1656 1
a1656 1

@


1.24
log
@Added const static unsigned int Point::max_coordinates = 5;
Sprinkled in const declarations. Added Point concatenation
operator ``,'', gave it fairly thorough testing.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.23 92/06/27 05:27:31 fischer Exp Locker: fischer $";
d5 5
a103 1

d256 1
d1229 1
a1229 1
// would have greater dimension than Point::max_coordinates, currently 5.
d1248 1
a1248 1
    if  (total_size > Point::max_coordinates) {
d1287 1
a1287 1
    if  (total_size > Point::max_coordinates) {
d1321 1
a1321 1
    if  (total_size > Point::max_coordinates) {
d1368 1
a1368 1
	stream << point[i] << " ";
d1371 1
a1371 1
	stream << point[last_index];
d1379 44
d1476 304
@


1.23
log
@Corrected some erroneous comments about relational operators on constants.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.22 92/06/27 04:57:46 fischer Exp Locker: fischer $";
d5 3
d69 1
a69 1
// as operator() on points.  
d115 1
a115 1
Point& Point::operator= (const  Point &point)
d208 1
a208 1
Point Point::operator+ (const Point& right) const
d234 1
a234 1
Point operator+ (const Point& left, const Coord& right)
d254 1
a254 1
Point operator+ (const Coord& left, const Point& right)
d276 1
a276 1
Point Point::operator- (const Point& right) const
d300 1
a300 1
Point operator- (const Point& left, const Coord& right)
d320 1
a320 1
Point operator- (const Coord& left, const Point& right)
d340 1
a340 1
Point Point::operator- () const
d361 1
a361 1
Point Point::operator* (const Point& right) const
d386 1
a386 1
Point operator* (const Point& left, const Coord& right)
d406 1
a406 1
Point operator* (const Coord& left, const Point& right)
d429 1
a429 1
Point Point::operator/ (const Point& right) const
d454 1
a454 1
Point operator/ (const Point& left, const Coord& right)
d474 1
a474 1
Point operator/ (const Coord& left, const Point& right)
d497 1
a497 1
Point Point::operator% (const Point& right) const
d522 1
a522 1
Point operator% (const Point& left, const Coord& right)
d542 1
a542 1
Point operator% (const Coord& left, const Point& right)
d569 2
a570 1
Point& Point::operator+= (const Point& rhs)	{ *this = *this + rhs; 	return  *this; }
d572 2
a573 1
Point& Point::operator+= (const Coord& rhs)	{ *this = *this + rhs; 	return  *this; }
d575 2
a576 1
Point& Point::operator-= (const Point& rhs)	{ *this = *this - rhs; 	return  *this; }
d578 2
a579 1
Point& Point::operator-= (const Coord& rhs)	{ *this = *this - rhs; 	return  *this; }
d581 2
a582 1
Point& Point::operator*= (const Point& rhs)	{ *this = *this * rhs; 	return  *this; }
d584 2
a585 1
Point& Point::operator*= (const Coord& rhs)	{ *this = *this * rhs; 	return  *this; }
d587 2
a588 1
Point& Point::operator/= (const Point& rhs)	{ *this = *this / rhs; 	return  *this; }
d590 2
a591 1
Point& Point::operator/= (const Coord& rhs)	{ *this = *this / rhs; 	return  *this; }
d593 2
a594 1
Point& Point::operator%= (const Point& rhs)	{ *this = *this % rhs; 	return  *this; }
d596 2
a597 1
Point& Point::operator%= (const Coord& rhs)	{ *this = *this % rhs; 	return  *this; }
d599 8
a606 3
// The following functions use the fact that underlying Coords *may* have
// an integer interpretation, but no int() function is defined for
// the non-integer case. 
d608 15
a622 1
Point& Point::operator<<= (const Point& rhs) {
d636 1
a636 1
Point& Point::operator<<= (unsigned int rhs) {
d642 1
a642 1
	this->coordinates[i] = int(this->coordinates[i]) << rhs;
d646 1
a646 1
Point& Point::operator>>= (const Point& rhs) {
d660 1
a660 1
Point& Point::operator>>= (unsigned int rhs) {
d670 1
a670 1
Point& Point::operator&= (const Point& rhs) {
d684 1
a684 1
Point& Point::operator&= (unsigned int rhs) {
d694 1
a694 1
Point& Point::operator^= (const Point& rhs) {
d708 1
a708 1
Point& Point::operator^= (unsigned int rhs) {
d718 1
a718 1
Point& Point::operator|= (const Point& rhs) {
d732 1
a732 1
Point& Point::operator|= (unsigned int rhs) {
d742 1
a742 1
/////////////// bitwise operators
d747 1
a747 1
Point operator<< (const Point& point, unsigned int shift)
d752 1
a752 1
Point operator>> (const Point& point, unsigned int shift)
d757 1
a757 1
Point Point::operator& (const Point& rhs)
d762 1
a762 1
Point operator& (const Point& lhs, const Coord& rhs)
d767 1
a767 1
Point operator& (const Coord& lhs, const Point& rhs)
d772 1
a772 1
Point Point::operator^ (const Point& rhs)
d777 1
a777 1
Point operator^ (const Point& lhs, const Coord& rhs)
d782 1
a782 1
Point operator^ (const Coord& lhs, const Point& rhs)
d788 1
a788 1
Point Point::operator| (const Point& rhs)
d793 1
a793 1
Point operator| (const Point& lhs, const Coord& rhs)
d798 1
a798 1
Point operator| (const Coord& lhs, const Point& rhs)
d803 1
a803 1
Point Point::operator~ ()
d831 6
a836 8
const Point& Point::operator++ () {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this += 1;
    return  *this;
}
a837 8
const Point& Point::operator-- () {
    if (this->size == 0) {
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this -= -1;
    return  *this;
}
a838 7
//////////////////////// Relational operators.
//  
//  All Point/Point and Point/Coord comparisons must involve initialized
//  data, or an exception is thrown. Coords  have thier values extend to 
//  the dimensions of the Point.  Point/Point comparisions require Points to
//  be of the same dimensionality.

d841 1
a841 1
char Point::operator> (const Point& rhs)
d857 1
a857 1
char operator> (const Coord& lhs, const Point& rhs)
d874 1
a874 1
char operator> (const Point& lhs, const Coord& rhs)
d893 1
a893 1
char Point::operator< (const Point& rhs)
d909 1
a909 1
char operator< (const Coord& lhs, const Point& rhs)
d926 1
a926 1
char operator< (const Point& lhs, const Coord& rhs)
d945 1
a945 1
char Point::operator== (const Point& rhs)
d961 1
a961 1
char operator== (const Coord& lhs, const Point& rhs)
d978 1
a978 1
char operator== (const Point& lhs, const Coord& rhs)
d997 1
a997 1
char Point::operator<= (const Point& rhs)
d1013 1
a1013 1
char operator<= (const Coord& lhs, const Point& rhs)
d1030 1
a1030 1
char operator<= (const Point& lhs, const Coord& rhs)
d1051 1
a1051 1
char Point::operator>= (const Point& rhs)
d1067 1
a1067 1
char operator>= (const Coord& lhs, const Point& rhs)
d1084 1
a1084 1
char operator>= (const Point& lhs, const Coord& rhs)
d1104 1
a1104 1
char Point::operator!= (const Point& rhs)
d1109 1
a1109 1
char operator!= (const Coord& lhs, const Point& rhs)
d1114 1
a1114 1
char operator!= (const Point& lhs, const Coord& rhs)
d1120 1
a1120 1
//////////////////////// Distance measures.
d1124 1
a1124 1
double Point::enorm ()const
d1136 1
a1136 1
//////////////////////// Index derangement, "()"
d1143 2
a1144 3
// The one index version is provided for completeness, as it only make sense
// in a general subroutine where some precondition of the program guarentees that the
// index will always be 0 whenever a 1-dimensional point is used.
d1146 1
a1146 1
Point Point::operator() (unsigned i0)
d1158 1
a1158 1
Point Point::operator() (unsigned i0, unsigned i1)
d1171 1
a1171 1
Point Point::operator() (unsigned i0, unsigned i1, unsigned i2)
d1186 1
a1186 1
Point Point::operator() (unsigned i0, unsigned i1, unsigned i2, unsigned i3)
d1202 1
a1202 1
Point Point::operator() (unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4)
d1220 1
a1220 1
////////////////////////  Point concatenation ","
d1222 3
d1227 1
d1229 125
d1358 1
a1358 1
ostream &operator<<(ostream &stream, Point& point)
d1416 1
a1416 1
    // so we check for number of dimensions; shorter Points are considered
@


1.22
log
@changed relationals to extend Coord over entire dimension of Points
in test.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.21 92/06/26 20:24:02 fischer Exp Locker: fischer $";
d5 4
d820 3
a822 3
//  data, or an exception is thrown. Coords are treated as one-dimensional
//  Points (not zero extended).  Point/Point comparisions require Points to
//   be of the same dimensionality.
@


1.21
log
@Removed previous additions to Pointcmp. Added bitwise operators
using the corresponding bitwise compound assignment operators.
Added checking for uninitialized points and coordinates.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.20 92/06/25 19:11:33 fischer Exp Locker: fischer $";
d5 5
d620 1
a620 1
	this->coordinates[i] = int(this->coordinates[i]) >> rhs.coordinates[i];
d775 4
d783 1
d832 2
a833 1
	if  (this->coordinates[i] <= rhs.coordinates[i]) return char(0);
d848 3
a850 2
    if (rhs.dimensions() != 1)
	return (char) 0;
d852 1
a852 1
    return lhs > rhs.coordinates[1];
d865 3
a867 2
    if (lhs.dimensions() != 1)
	return (char) 0;
d869 1
a869 1
    return lhs.coordinates[1] > rhs;
d884 2
a885 1
	if  (this->coordinates[i] >= rhs.coordinates[i]) return char(0);
d900 3
a902 2
    if (rhs.dimensions() != 1)
	return (char) 0;
d904 1
a904 1
    return lhs < rhs.coordinates[1];
d917 3
a919 2
    if (lhs.dimensions() != 1)
	return (char) 0;
d921 1
a921 1
    return lhs.coordinates[1] < rhs;
d936 2
a937 1
	if (this->coordinates[i] != rhs.coordinates[i]) return (char) 0;
d952 3
a954 2
    if (rhs.dimensions() != 1)
	return (char) 0;
d956 1
a956 1
    return lhs == rhs.coordinates[1];
d969 3
a971 2
    if (lhs.dimensions() != 1)
	return (char) 0;
d973 1
a973 1
    return lhs.coordinates[1] == rhs;
d988 2
a989 1
	if  (this->coordinates[i] > rhs.coordinates[i]) return char(0);
d1004 3
a1006 2
    if (rhs.dimensions() != 1)
	return (char) 0;
d1008 1
a1008 1
    return lhs <= rhs.coordinates[1];
a1020 2
    if (lhs.dimensions() != 1)
	return (char) 0;
d1022 5
a1026 1
    return lhs.coordinates[1] <= rhs;
d1042 2
a1043 1
	if  (this->coordinates[i] < rhs.coordinates[i]) return char(0);
d1058 3
a1060 2
    if (rhs.dimensions() != 1)
	return (char) 0;
d1062 1
a1062 1
    return lhs >= rhs.coordinates[1];
d1075 3
a1077 2
    if (lhs.dimensions() != 1)
	return (char) 0;
d1079 2
a1080 1
    return lhs.coordinates[1] >= rhs;
a1082 2


d1110 2
a1111 1
	result_number = result_number + (float) (this->coordinates[i] * this->coordinates[i]);
@


1.20
log
@Made Pointcmp check size of Points if they are equal, as last check.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.19 92/06/24 12:19:17 fischer Exp Locker: fischer $";
d5 3
d202 1
a202 1
	return Point();
d205 2
a206 1
    if (this->size == 0)
d208 10
a217 9
    else {
	result_point.size = this->size;
	result_point.coordinates = new Coord[this->size];
	
	for (unsigned i = 0; i < result_point.size; i++)
	    result_point.coordinates[i] 
		=  this->coordinates[i] + right.coordinates[i];
	return result_point;
    }    
d227 2
a228 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d247 2
a248 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d270 1
a270 1
	return Point();
d273 2
a274 1
    if (this->size == 0)
a275 8
    else {
	result_point.size = this->size;
	result_point.coordinates = new Coord[this->size];
	
	for (unsigned i = 0; i < result_point.size; i++)
	    result_point.coordinates[i] 
		=  this->coordinates[i] - right.coordinates[i];
	return result_point;
d277 7
d293 2
a294 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d313 2
a314 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d332 5
d355 1
a355 1
	return Point();
d358 2
a359 1
    if (this->size == 0)
a360 8
    else {
	result_point.size = this->size;
	result_point.coordinates = new Coord[this->size];
	
	for (unsigned i = 0; i < result_point.size; i++)
	    result_point.coordinates[i] 
		=  this->coordinates[i] * right.coordinates[i];
	return result_point;
d362 8
d379 2
a380 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d399 2
a400 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d423 1
a423 1
	return Point();
d426 2
a427 1
    if (this->size == 0)
a428 8
    else {
	result_point.size = this->size;
	result_point.coordinates = new Coord[this->size];
	
	for (unsigned i = 0; i < result_point.size; i++)
	    result_point.coordinates[i] 
		=  this->coordinates[i] / right.coordinates[i];
	return result_point;
d430 8
d447 2
a448 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d467 2
a468 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d491 1
a491 1
	return Point();
d494 2
a495 1
    if (this->size == 0)
a496 8
    else {
	result_point.size = this->size;
	result_point.coordinates = new Coord[this->size];
	
	for (unsigned i = 0; i < result_point.size; i++)
	    result_point.coordinates[i] 
		=  this->coordinates[i] % right.coordinates[i];
	return result_point;
d498 8
d515 2
a516 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d535 2
a536 2
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
d586 4
d591 1
a591 1
	this->coordinates[i] = this->coordinates[i] << rhs.coordinates[i];
d596 4
d601 1
a601 1
	this->coordinates[i] = this->coordinates[i] << rhs;
d610 4
d615 1
a615 1
	this->coordinates[i] = this->coordinates[i] >> rhs.coordinates[i];
d620 4
d625 1
a625 1
	this->coordinates[i] = this->coordinates[i] >> rhs;
d634 4
d639 1
a639 1
	this->coordinates[i] = this->coordinates[i] & rhs.coordinates[i];
d644 4
d649 1
a649 1
	this->coordinates[i] = this->coordinates[i] & rhs;
d658 4
d663 1
a663 1
	this->coordinates[i] = this->coordinates[i] ^ rhs.coordinates[i];
d668 4
d673 1
a673 1
	this->coordinates[i] = this->coordinates[i] ^ rhs;
d682 4
d687 1
a687 1
	this->coordinates[i] = this->coordinates[i] | rhs.coordinates[i];
d692 4
d697 1
a697 1
	this->coordinates[i] = this->coordinates[i] | rhs;
d701 4
a704 1
const Point& Point::operator++ () { *this += 1;  return  *this; }
d706 4
a709 1
const Point& Point::operator-- () { *this -= -1; return  *this; }
d711 4
d716 4
d721 4
d726 4
d731 4
d736 4
d741 62
d804 5
a808 3
// 
// 
// 
d814 4
d820 1
a820 1

d823 1
a823 1

d829 8
a836 3
    if (lhs.type() == NONE)
	return (rhs.size == 0);
    
d845 8
a852 3
    if (rhs.type() == NONE)
	return (lhs.size == 0);
    
d863 4
d878 8
a885 3
    if (lhs.type() == NONE)
	return (rhs.size == 0);
    
d894 8
a901 3
    if (rhs.type() == NONE)
	return (lhs.size == 0);
    
d912 4
d927 8
a934 3
    if (lhs.type() == NONE)
	return (rhs.size == 0);
    
d943 8
a950 3
    if (rhs.type() == NONE)
	return (lhs.size == 0);
    
d961 4
d976 8
a983 3
    if (lhs.type() == NONE)
	return (rhs.size == 0);
    
d992 8
a999 3
    if (rhs.type() == NONE)
	return (lhs.size == 0);
    
d1011 4
d1026 8
a1033 3
    if (lhs.type() == NONE)
	return (rhs.size == 0);
    
d1042 8
a1049 3
    if (rhs.type() == NONE)
	return (lhs.size == 0);
    
d1091 1
a1091 1
//////////////////////// Index derangement.
d1098 16
a1121 1

d1176 2
d1179 2
d1200 2
a1201 1
////////////////////////  lexical comparison of Points
d1203 3
d1237 1
a1237 3
    // the zero-extended Coordinates do not differ in value,
    // check for number of dimensions; shorter Points are less
    // than longer Points.
d1239 14
a1252 6
    if (lhs.dimensions() == rhs.dimensions())
	return 0;
    else if (lhs.dimensions() > rhs.dimensions())
	return 1;
    else
	return -1;
@


1.19
log
@Fixed bug in printing of points of dimension 1 as <>.
Owe Joe a beer.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.18 92/06/24 10:03:25 thoth Exp Locker: fischer $";
d5 4
d971 2
a972 2
	for (unsigned i=0; i<rhs.dimensions(); i++) {
	    if (lhs[i]<rhs[i])
d974 1
a974 1
	    else if (lhs[i]>rhs[i])
d978 1
a978 1
	    if (lhs[i]<0)
d980 1
a980 1
	    else if (lhs[i]>0)
d984 2
a985 2
	for (unsigned i=0; i<lhs.dimensions(); i++) {
	    if (lhs[i]<rhs[i])
d987 1
a987 1
	    else if (lhs[i]>rhs[i])
d990 5
a994 5
	for ( ; i<rhs.dimensions(); i++) {
	    if (rhs[i]<0)
		return 1;
	    else if (rhs[i]>0)
		return -1;
d997 10
a1006 2
    // the points do not differ
    return 0;
@


1.18
log
@fixed xerox bug in Pointcmp
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.17 92/06/24 09:55:00 fischer Exp Locker: thoth $";
d5 3
d945 1
a945 1
ostream &operator<<(ostream &stream, Point point)
d952 1
a952 1
    if ( last_index > 0 ) {
@


1.17
log
@Made relational ops work pointwise.
Found problem with Point(x): if int x, mistaken
gcc complaint about bad cast (gcc 2.2.2); if Coord x,
zero length point is retured.  Various workarounds didn't.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.16 92/06/22 13:59:25 thoth Exp Locker: fischer $";
d5 6
d985 2
a987 2
	    else if (rhs[i]>0)
		return 1;
@


1.16
log
@updated to follow new include conventions.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.15 92/06/22 07:43:05 fischer Exp Locker: thoth $";
d5 3
d94 1
a94 1

d118 1
a118 2
    size = 1;
    coordinates = new Coord[1];
d125 2
a126 3

    size = 2;
    coordinates = new Coord[2];
d137 2
a138 2
    size = 3;
    coordinates = new Coord[3];
d150 2
a151 2
    size = 4;
    coordinates = new Coord[4];
d166 2
a167 2
    size = 5;
    coordinates = new Coord[5];
d175 1
a175 1

d241 1
a241 1

d321 1
a321 1

d388 1
a388 1

d455 1
a455 1

d522 1
a522 1

d551 4
d565 1
a565 1
Point& Point::operator<<= (const Coord& rhs) {
d581 1
a581 1
Point& Point::operator>>= (const Coord& rhs) {
d597 1
a597 1
Point& Point::operator&= (const Coord& rhs) {
d613 1
a613 1
Point& Point::operator^= (const Coord& rhs) {
d629 1
a629 1
Point& Point::operator|= (const Coord& rhs) {
d635 1
a635 1
const Point& Point::operator++ ()		{ *this = *this + 1; return  *this; }
d637 1
a637 1
const Point& Point::operator-- ()		{ *this = *this - 1; return  *this; }
a638 4

//////////////////////// Distance measures.
//
// enorm: Euclidean distance from origin.
a639 6
double Point::enorm ()const
{
    double result_number = 0;
    
    for (unsigned i = 0; i < this->size; i++)
	result_number = result_number + (float) (this->coordinates[i] * this->coordinates[i]);
a640 2
    return sqrt(result_number);
}
d642 3
a644 1

d654 2
a655 1
    unsigned int max;
d657 2
a658 4
    if (this->size > rhs.size)
	max = this->size;
    else
	max = rhs.size;
d660 1
a660 4
    for (unsigned i = 0; i < max; i++) 
	if  (this->coordinates[i] > rhs.coordinates[i]) return char(1);

    return char(0);
d665 7
a671 1
    return (lhs > rhs.coordinates[0]);
d676 7
a682 1
    return (lhs.coordinates[0] > rhs);
d689 2
a690 1
    unsigned int max;
d692 2
a693 4
    if (this->size > rhs.size)
	max = this->size;
    else
	max = rhs.size;
d695 1
a695 4
    for (unsigned i = 0; i < max; i++) 
	if  (this->coordinates[i] < rhs.coordinates[i]) return char(1);

    return char(0);
d700 7
a706 1
    return (lhs < rhs.coordinates[0]);
d711 7
a717 1
    return (lhs.coordinates[0] < rhs);
d735 7
a741 1
    return (rhs.size == 1 && lhs == rhs.coordinates[0]);
d746 7
a752 1
    return (lhs.size == 1 && lhs.coordinates[0] == rhs);
a754 3
// All the following comparisons are made using the above.  These
// perhaps should be re-written to be more efficient.

d759 7
a765 1
    return (*this < rhs || *this == rhs);
d770 7
a776 1
    return (lhs <= rhs.coordinates[0]);
d781 7
a787 1
    return (lhs.coordinates[0] <= rhs);
d795 7
a801 1
    return (*this > rhs || *this == rhs);
d806 7
a812 1
    return (lhs >= rhs.coordinates[0]);
d817 7
a823 1
    return (lhs.coordinates[0] >= rhs);
d827 1
d846 15
a860 1

d868 1
a868 1
Point Point::operator() (unsigned a)
a869 13
    Point p(0);

    if (a >= this->size)  {
	throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return Point();
    }

    p.coordinates[0] = this->coordinates[a];
    return p;
}

Point Point::operator() (unsigned a, unsigned b)
{
d872 1
a872 1
    if (a >= this->size || b >= this->size) {
d877 2
a878 2
    p.coordinates[0] = this->coordinates[a];
    p.coordinates[1] = this->coordinates[b];
d882 1
a882 1
Point Point::operator() (unsigned a, unsigned b, unsigned c)
d886 1
a886 1
    if (a >= this->size || b >= this->size || c >= this->size) {
d891 3
a893 3
    p.coordinates[0] = this->coordinates[a];
    p.coordinates[1] = this->coordinates[b];
    p.coordinates[2] = this->coordinates[c];
d897 1
a897 1
Point Point::operator() (unsigned a, unsigned b, unsigned c, unsigned d)
d901 1
a901 1
    if (a >= this->size || b >= this->size || c >= this->size || d >= this->size) {
d906 4
a909 4
    p.coordinates[0] = this->coordinates[a];
    p.coordinates[1] = this->coordinates[b];
    p.coordinates[2] = this->coordinates[c];
    p.coordinates[3] = this->coordinates[d];
d913 1
a913 1
Point Point::operator() (unsigned a, unsigned b, unsigned c, unsigned d, unsigned e)
d917 2
a918 1
    if (a >= this->size || b >= this->size || c >= this->size || d >= this->size || e >= this->size) {
d923 5
a927 5
    p.coordinates[0] = this->coordinates[a];
    p.coordinates[1] = this->coordinates[b];
    p.coordinates[2] = this->coordinates[c];
    p.coordinates[3] = this->coordinates[d];
    p.coordinates[4] = this->coordinates[e];
d931 1
a931 1

@


1.15
log
@Added logical coumpound functions, reordered functions
to match Point.h.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.14 92/06/21 17:00:17 thoth Exp Locker: fischer $";
d5 4
d69 1
a69 1
#include <Point.h>
@


1.14
log
@soothed some warnings (unsigned comparison with signed)
adjusted for throw's potential non-volatility.
wrote a Pointcmp lexical comparison routine, it is still untested.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.13 92/06/21 05:57:59 fischer Exp Locker: thoth $";
d5 5
d11 1
a11 1
// Changed enum literals for throw function and NumberTypes
d237 1
a237 1
//////////////////////// Multiply
d239 1
a239 1
// Point = Point * Point
d241 1
a241 1
Point Point::operator* (const Point& right) const
d258 1
a258 1
		=  this->coordinates[i] * right.coordinates[i];
d263 1
a263 1
// Point = Point * Coord
d265 1
a265 1
Point operator* (const Point& left, const Coord& right)
d279 1
a279 1
	    =  left.coordinates[i] * right;
d283 1
a283 1
// Point = Coord * Point
d285 1
a285 1
Point operator* (const Coord& left, const Point& right)
d299 1
a299 1
	    =  left * right.coordinates[i];
d303 13
d317 1
a317 1
//////////////////////// Divide
d319 1
a319 1
// Point = Point / Point
d321 1
a321 1
Point Point::operator/ (const Point& right) const
d338 1
a338 1
		=  this->coordinates[i] / right.coordinates[i];
d343 1
a343 1
// Point = Point / Coord
d345 1
a345 1
Point operator/ (const Point& left, const Coord& right)
d359 1
a359 1
	    =  left.coordinates[i] / right;
d363 1
a363 1
// Point = Coord / Point
d365 1
a365 1
Point operator/ (const Coord& left, const Point& right)
d379 1
a379 1
	    =  left / right.coordinates[i];
d384 1
a384 1
//////////////////////// Modulus
d386 1
a386 1
// Point = Point % Point
d388 1
a388 1
Point Point::operator% (const Point& right) const
d405 1
a405 1
		=  this->coordinates[i] % right.coordinates[i];
d410 1
a410 1
// Point = Point % Coord
d412 1
a412 1
Point operator% (const Point& left, const Coord& right)
d426 1
a426 1
	    =  left.coordinates[i] % right;
d430 1
a430 1
// Point = Coord % Point
d432 1
a432 1
Point operator% (const Coord& left, const Point& right)
d446 1
a446 1
	    =  left % right.coordinates[i];
d451 1
a451 1
//////////////////////// Minus
d453 1
a453 1
// Point = Point - Point
d455 1
a455 1
Point Point::operator- (const Point& right) const
d472 1
a472 1
		=  this->coordinates[i] - right.coordinates[i];
d477 1
a477 1
// Point = Point - Coord
d479 1
a479 1
Point operator- (const Point& left, const Coord& right)
d493 1
a493 1
	    =  left.coordinates[i] - right;
d497 1
a497 1
// Point = Coord - Point
d499 1
a499 1
Point operator- (const Coord& left, const Point& right)
d513 1
a513 1
	    =  left - right.coordinates[i];
a516 13
// Point = -Point

Point Point::operator- () const
{
    Point result_point;

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] =  - this->coordinates[i];
    return result_point;
}
d521 2
a522 1
// All of these operators #= have the potential of being much faster
d524 1
d546 9
a554 1
const Point& Point::operator++ ()			{ *this = *this + 1; return  *this; }
d556 15
a570 1
const Point& Point::operator-- ()			{ *this = *this - 1; return  *this; }
d572 58
d647 3
a649 6
//
// Use lexicographical order to compare two Points, or a Point and a
// Coord.  Point/Point comparisions are made as member functions since
// we never have a non-Point coerced to a point.  The Point/Coord
// operators are non-member friends,  however,  so regular numbers can
// be used and coerced in the place of the Coord.
@


1.13
log
@Changed enum literals for throw function and NumberTypes
to uppercase.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.12 92/06/15 14:10:21 fischer Exp Locker: fischer $";
d5 4
d70 1
a70 1
	for (int i = 0; i < this->size; i++)
d98 1
a98 1
    for (int i = 0; i < this->size; i++)
d174 1
a174 1
    if (this->size != right.size)
d176 2
d185 1
a185 1
	for (int i = 0; i < result_point.size; i++)
d198 1
a198 1
    if (left.size == 0)
d200 2
d206 1
a206 1
    for (int i = 0; i < result_point.size; i++)
d218 1
a218 1
    if (right.size == 0)
d220 2
d226 1
a226 1
    for (int i = 0; i < result_point.size; i++)
d240 1
a240 1
    if (this->size != right.size)
d242 2
d251 1
a251 1
	for (int i = 0; i < result_point.size; i++)
d264 1
a264 1
    if (left.size == 0)
d266 2
d272 1
a272 1
    for (int i = 0; i < result_point.size; i++)
d284 1
a284 1
    if (right.size == 0)
d286 2
d292 1
a292 1
    for (int i = 0; i < result_point.size; i++)
d307 1
a307 1
    if (this->size != right.size)
d309 2
d318 1
a318 1
	for (int i = 0; i < result_point.size; i++)
d331 1
a331 1
    if (left.size == 0)
d333 2
d339 1
a339 1
    for (int i = 0; i < result_point.size; i++)
d351 1
a351 1
    if (right.size == 0)
d353 2
d359 1
a359 1
    for (int i = 0; i < result_point.size; i++)
d374 1
a374 1
    if (this->size != right.size)
d376 2
d385 1
a385 1
	for (int i = 0; i < result_point.size; i++)
d398 1
a398 1
    if (left.size == 0)
d400 2
d406 1
a406 1
    for (int i = 0; i < result_point.size; i++)
d418 1
a418 1
    if (right.size == 0)
d420 2
d426 1
a426 1
    for (int i = 0; i < result_point.size; i++)
d441 1
a441 1
    if (this->size != right.size)
d443 2
d452 1
a452 1
	for (int i = 0; i < result_point.size; i++)
d465 1
a465 1
    if (left.size == 0)
d467 2
d473 1
a473 1
    for (int i = 0; i < result_point.size; i++)
d485 1
a485 1
    if (right.size == 0)
d487 2
d493 1
a493 1
    for (int i = 0; i < result_point.size; i++)
d508 1
a508 1
    for (int i = 0; i < result_point.size; i++)
d552 1
a552 1
    for (int i = 0; i < this->size; i++)
d571 1
a571 1
    int max;
d578 1
a578 1
    for (int i = 0; i < max; i++) 
d598 1
a598 1
    int max;
d605 1
a605 1
    for (int i = 0; i < max; i++) 
d628 1
a628 1
    for (int i = 0; i < this->size; i++) 
d713 1
a713 1
    if (a >= this->size) 
d715 2
d726 1
a726 1
    if (a >= this->size || b >= this->size)
d728 2
d740 1
a740 1
    if (a >= this->size || b >= this->size || c >= this->size)
d742 2
d755 1
a755 1
    if (a >= this->size || b >= this->size || c >= this->size || d >= this->size)
d757 2
d771 1
a771 1
    if (a >= this->size || b >= this->size || c >= this->size || d >= this->size || e >= this->size)
d773 2
d801 38
@


1.12
log
@Renamed NumericType enum to capitilized literals.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.11 92/06/15 12:04:28 thoth Exp Locker: fischer $";
d5 3
d171 1
a171 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d193 1
a193 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d211 1
a211 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d231 1
a231 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d253 1
a253 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d271 1
a271 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d292 1
a292 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d314 1
a314 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d332 1
a332 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
a351 3
    if ((this->type() != INTEGER) || (right.type() != INTEGER))
	throw(IA::TypeMismatch, __FILE__, __LINE__);

d353 1
a353 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
a373 3
    if ((left.type() != INTEGER) || (right.type() != INTEGER))
	throw(IA::TypeMismatch, __FILE__, __LINE__);

d375 1
a375 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
a391 3
    if ((left.type() != INTEGER) || (right.type() != INTEGER))
	throw(IA::TypeMismatch, __FILE__, __LINE__);

d393 1
a393 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d414 1
a414 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d436 1
a436 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d454 1
a454 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
d680 2
a681 2
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
    p.size = 1;
d691 1
a691 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
a692 1
    p.size = 2;
d703 1
a703 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
a704 1
    p.size = 3;
d716 1
a716 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
a717 1
    p.size = 4;
d730 1
a730 1
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
a731 1
    p.size = 5;
@


1.11
log
@fixed problem with Point::operator=
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.10 92/06/12 06:10:48 fischer Exp Locker: thoth $";
d5 3
d349 1
a349 1
    if ((this->type() != Integer) || (right.type() != Integer))
d374 1
a374 1
    if ((left.type() != Integer) || (right.type() != Integer))
d395 1
a395 1
    if ((left.type() != Integer) || (right.type() != Integer))
@


1.10
log
@Check for Coord[0] special cases in binary operators.
Nested promote() calls.
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.9 92/06/10 18:03:39 fischer Exp Locker: fischer $";
d5 4
d75 1
@


1.9
log
@Fixed compound assignments so they return Point& instead of 
const Point&,  started doing check for zero-sized points in
arithmetic binary operations,  and return the already
constructed zero-dimensioned temporary.

@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.8 92/06/10 05:12:17 fischer Exp Locker: fischer $";
d5 7
a48 3
// THE NEXT TWO HAVE PROBLEMS.   Modify everything to guarentee that size==0 <->
// coordinates==NULL 

d52 7
a58 3
    this->coordinates = new Coord[size];
    for (int i = 0; i < this->size; i++)
        this->coordinates[i] = point.coordinates[i];
d63 1
a63 1
    if ( this == &point )	 // Is the extra test worth it, normally?
d65 13
a77 2
	   
    if ( point.size != this->size) {
d82 1
d108 1
a108 2
    NumericType coerced_type = IA::result_type(c0.type(), c1.type());
    coerced_type = IA::result_type(coerced_type, c2.type());
d110 2
d121 1
a121 3
    NumericType coerced_type = IA::result_type(c0.type(), c1.type());
    coerced_type = IA::result_type(coerced_type, c2.type());
    coerced_type = IA::result_type(coerced_type, c3.type());
d123 2
d136 1
a136 4
    NumericType coerced_type = IA::result_type(c0.type(), c1.type());
    coerced_type = IA::result_type(coerced_type, c2.type());
    coerced_type = IA::result_type(coerced_type, c3.type());
    coerced_type = IA::result_type(coerced_type, c4.type());
d138 3
d222 11
a232 7
    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] * right.coordinates[i];
    return result_point;
d283 11
a293 7
    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] / right.coordinates[i];
    return result_point;
d347 11
a357 7
    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] % right.coordinates[i];
    return result_point;
d414 11
a424 7
    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] - right.coordinates[i];
    return result_point;
d480 2
a502 2
// Gcc 2.0 does not use the postincrement function provided.

a504 2
const Point& Point::operator++ (int dummy)		{ *this = *this + 1; return  *this; }

d535 1
a535 1
    int max(int, int);
d537 6
a542 1
    for (int i = 0; i < max(this->size, rhs.size); i++) 
d562 1
a562 1
    int max(int, int);
d564 6
a569 1
    for (int i = 0; i < max(this->size, rhs.size); i++) 
a758 14
}


////////////////////////  Helper functions.
//
// max, intwise.


int max(int lhs, int rhs)
{
    if ( lhs >= rhs )
	return lhs;
    else
	return rhs;
@


1.8
log
@Made all Point/Point and Point/Coord relational operators
use lexicographical (partial) ordering.  Added index derangement
as operator() on points.  
@
text
@d2 1
a2 1
static char rscid[] = "$Id: Point.cc,v 1.7 92/06/08 22:54:04 thoth Exp Locker: fischer $";
d5 5
d141 11
a151 7
    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] + right.coordinates[i];
    return result_point;
d444 1
a444 1
const Point& Point::operator+= (const Point& rhs)	{ *this = *this + rhs; 	return  *this; }
d446 1
a446 1
const Point& Point::operator+= (const Coord& rhs)	{ *this = *this + rhs; 	return  *this; }
d448 1
a448 1
const Point& Point::operator-= (const Point& rhs)	{ *this = *this - rhs; 	return  *this; }
d450 1
a450 1
const Point& Point::operator-= (const Coord& rhs)	{ *this = *this - rhs; 	return  *this; }
d452 1
a452 1
const Point& Point::operator*= (const Point& rhs)	{ *this = *this * rhs; 	return  *this; }
d454 1
a454 1
const Point& Point::operator*= (const Coord& rhs)	{ *this = *this * rhs; 	return  *this; }
d456 1
a456 1
const Point& Point::operator/= (const Point& rhs)	{ *this = *this / rhs; 	return  *this; }
d458 1
a458 1
const Point& Point::operator/= (const Coord& rhs)	{ *this = *this / rhs; 	return  *this; }
d460 1
a460 1
const Point& Point::operator%= (const Point& rhs)	{ *this = *this % rhs; 	return  *this; }
d462 1
a462 1
const Point& Point::operator%= (const Coord& rhs)	{ *this = *this % rhs; 	return  *this; }
@


1.7
log
@made enorm work.
@
text
@d2 1
a2 3

static char rscid[] = "$Id: Point.cc,v 1.6 92/06/08 02:56:23 fischer Exp Locker: thoth $";

d5 3
a31 1
// 
a32 1
//
d37 2
a38 2
// WARNING: my math library support was broken (gcc 2.0 on math.ufl.edu), so
// sqrt in Point.enorm() below was commented out.  Please fix! 
a39 2
// THIS IS STILL JUNK.   Modify to guarentee that size==0 <-> coordinates==NULL

a47 2
// THIS IS STILL JUNK.   Modify to guarentee that size==0 <-> coordinates==NULL

d124 3
a126 4
// Some of the element-wise arithmetic operations.
// I should be using function templates here!

// Plus
d180 3
a182 2

// Multiply
d237 3
a239 1
// Divide
d294 3
a296 1
// Modulus
d360 3
a362 1
// Minus
d430 4
d435 1
a435 1
// Destructive compound assignments.  Underlying operator will catch errors. 
d437 32
a468 1
const Point& Point::operator+= (const Point& rhs) 
d470 6
a475 2
    *this = *this + rhs;
    return  *this;
d478 12
a489 1
const Point& Point::operator+= (const Coord& rhs) 
d491 6
a496 2
    *this = *this + rhs;
    return  *this;
d499 1
a499 1
const Point& Point::operator-= (const Point& rhs) 
d501 1
a501 2
    *this = *this - rhs;
    return  *this;
d504 1
a504 1
const Point& Point::operator-= (const Coord& rhs) 
d506 1
a506 2
    *this = *this - rhs;
    return  *this;
d509 3
a511 1
const Point& Point::operator*= (const Point& rhs) 
d513 6
a518 2
    *this = *this * rhs;
    return  *this;
d521 1
a521 1
const Point& Point::operator*= (const Coord& rhs) 
d523 1
a523 2
    *this = *this * rhs;
    return  *this;
d526 1
a526 1
const Point& Point::operator/= (const Point& rhs) 
d528 1
a528 2
    *this = *this / rhs;
    return  *this;
d531 3
a533 1
const Point& Point::operator/= (const Coord& rhs) 
d535 7
a541 2
    *this = *this / rhs;
    return  *this;
d544 1
a544 1
const Point& Point::operator%= (const Point& rhs) 
d546 1
a546 2
    *this = *this % rhs;
    return  *this;
d549 1
a549 1
const Point& Point::operator%= (const Coord& rhs) 
d551 1
a551 2
    *this = *this % rhs;
    return  *this;
d554 2
a555 3
// Do we need post- and pre-increment/decrement  functions here?
// 
// TO DO:  check how this works for post/pre.
d557 3
a559 1
const Point& Point::operator++ ()
d561 1
a561 2
    *this = *this + 1;
    return  *this;
d564 1
a564 1
const Point& Point::operator++ (int dummy)
d566 1
a566 2
    *this = *this + 1;
    return  *this;
d569 1
a569 1
const Point& Point::operator-- ()
d571 1
a571 2
    *this = *this - 1;
    return  *this;
a573 1
// Euclidean distance function, for comparisions.
d575 1
a575 7
double Point::enorm ()const
{
    double result_number = 0;
    
    for (int i = 0; i < this->size; i++)
	result_number = result_number 
	    + (float) (this->coordinates[i] * this->coordinates[i]);
d577 1
a577 9
#if 1
    return sqrt(result_number);
#else
    return result_number;
#endif
}


char operator>= (const Point& lhs, const Point& rhs)
d579 1
a579 8
    if (lhs.dimensions() != rhs.dimensions())
	return (lhs.enorm() >= rhs.enorm());

    for (int i = 0; i < rhs.size; i++) 
	if  (lhs[i] < rhs[i])
	    return char(0);
    
    return char(1);
d584 1
a584 1
    return (lhs >= rhs.enorm());
d589 1
a589 1
    return (lhs.enorm() >= rhs);
d592 4
a595 1
char operator<= (const Point& lhs, const Point& rhs)
d597 1
a597 8
    if (lhs.dimensions() != rhs.dimensions())
	return (lhs.enorm() <= rhs.enorm());
    
    for (int i = 0; i < rhs.size; i++) 
	if  (lhs[i] > rhs[i])
	    return char(0);
    
    return char(1);
d600 1
a600 1
char operator<= (const Coord& lhs, const Point& rhs)
d602 1
a602 1
    return (lhs <= rhs.enorm());
d605 1
a605 1
char operator<= (const Point& lhs, const Coord& rhs)
d607 1
a607 1
    return (lhs.enorm() <= rhs);
d610 10
a619 1
char operator> (const Point& lhs, const Point& rhs)
d621 7
a627 8
    if (lhs.dimensions() != rhs.dimensions())
	return (lhs.enorm() > rhs.enorm());
    
    for (int i = 0; i < rhs.size; i++) 
	if  (lhs[i] <= rhs[i])
	    return char(0);
    
    return char(1);
d630 1
a630 1
char operator> (const Coord& lhs, const Point& rhs)
d632 9
a640 1
    return (lhs > rhs.enorm());
d643 1
a643 1
char operator> (const Point& lhs, const Coord& rhs)
d645 1
a645 2
    return (lhs.enorm() > rhs);
}
d647 2
a648 4
char operator< (const Point& lhs, const Point& rhs)
{
    if (lhs.dimensions() != rhs.dimensions())
	return (lhs.enorm() < rhs.enorm());
d650 5
a654 5
    for (int i = 0; i < rhs.size; i++) 
	if  (lhs[i] >= rhs[i])
	    return char(0);
    
    return char(1);
d657 1
a657 1
char operator< (const Coord& lhs, const Point& rhs)
d659 1
a659 2
    return (lhs < rhs.enorm());
}
d661 9
a669 3
char operator< (const Point& lhs, const Coord& rhs)
{
    return (lhs.enorm() < rhs);
d672 1
a672 3
// These are a bit different,  checking structural  equality.

char operator== (const Point& lhs, const Point& rhs)
d674 1
a674 2
    if (lhs.size != rhs.size)
	return (lhs.enorm() == rhs.enorm());
d676 2
a677 5
    for (int i = 0; i < lhs.size; i++) 
	if (lhs[i] != rhs[i]) return (char) 0;
    
    return (char) 1;
}
d679 7
a685 3
char operator!= (const Point& lhs, const Point& rhs)
{
    return ! (lhs == rhs);
d687 5
d707 13
@


1.6
log
@euclidean_distance renamed to enorm.  Checked ++, gcc 2.0
seems to make it preincrement always. tweaked relational
ops to use enorm in comparison if size of two points differ.
@
text
@d3 1
a3 1
static char rscid[] = "$Id: Point.cc,v 1.5 92/06/05 03:15:31 fischer Exp Locker: fischer $";
d7 5
d523 4
a526 2
    
    // return sqrt(result_number);
d528 1
@


1.5
log
@Modified relational ops to compare points via lexicographical
functions.   Point <> Const or vice versa still uses euclidean
distance (or rather, broken euclidean distance - no sqrt).
@
text
@d1 1
a1 1
// This may look like C code, emacs, but it is really -*- C++ -*-
d3 1
a3 1
static char rscid[] = "$Id: Point.cc,v 1.4 92/06/03 10:49:21 fischer Exp Locker: fischer $";
d7 5
d34 1
a34 3
// sqrt in Point.euclidean_distance() below was commented out.  Please fix! 
// Note that since sqrt is a monotonic increasing mapping, this works fine
// for the comparison uses I put it to.
d36 1
a36 1
// THIS IS JUNK.   Modify to guarentee that size==0 <-> coordinates==NULL
d41 1
a41 6

    if ( point.size == 0 )
	this->coordinates = NULL;
    else
	this->coordinates = new Coord[size];

d43 1
a43 1
	this->coordinates[i] = point.coordinates[i];
d46 1
a46 1
// THIS IS JUNK.   Modify to guarentee that size==0 <-> coordinates==NULL
d50 1
a50 6
    if ( point.size == 0 ) {
	this->size = 0;
	if ( this->coordinates != NULL ) {     // != 0 is better stylistically?
	    delete[] this->coordinates;           
	    this->coordinates = NULL;          // Is this necessary?
	}
d52 1
a52 2
    }
	
d54 3
a56 5
	if ( this->coordinates != NULL )     
	    delete[] this->coordinates;           
	
	this->coordinates = new Coord[point.size];
	this->size = point.size;
d59 1
a59 1
	this->coordinates[i] = point.coordinates[i];
d497 6
d511 1
a511 1
double Point::euclidean_distance ()const
d519 1
a519 1
    //    return sqrt(result_number);
a525 3
    //    if (lhs.dimensions() != rhs.dimensions())
    //	      throw(IA::PointIndexMismatch, __FILE__, __LINE__);
    
d527 2
a528 2
	return char(0);
    
d538 1
a538 1
    return (lhs >= rhs.euclidean_distance());
d543 1
a543 1
    return (lhs.euclidean_distance() >= rhs);
d549 1
a549 1
	return char(0);
d560 1
a560 1
    return (lhs <= rhs.euclidean_distance());
d565 1
a565 1
    return (lhs.euclidean_distance() <= rhs);
d571 1
a571 1
	return char(0);
d582 1
a582 1
    return (lhs > rhs.euclidean_distance());
d587 1
a587 1
    return (lhs.euclidean_distance() > rhs);
d593 1
a593 1
	return char(0);
d604 1
a604 1
    return (lhs < rhs.euclidean_distance());
d609 1
a609 1
    return (lhs.euclidean_distance() < rhs);
d617 1
a617 1
	return (char) 0;
@


1.4
log
@Renamed to Point,  we'll use this for a while.
@
text
@d1 4
a4 1
static char rscid[] = "$Id: Point.cc,v 1.3 92/06/02 01:48:50 fischer Exp Locker: fischer $";
d7 3
d33 2
d48 2
d195 3
a197 15
// Point Point::operator* (const Point& right) const
// {
//     Point result_point;
// 
//     if (this->size != right.size)
// 	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
// 
//     result_point.size = this->size;
//     result_point.coordinates = new Coord[this->size];
// 
//     for (int i = 0; i < result_point.size; i++)
// 	result_point.coordinates[i] 
// 	    =  this->coordinates[i] * right.coordinates[i];
//     return result_point;
// }
d199 12
d250 3
a252 15
// Point Point::operator/ (const Point& right) const
// {
//     Point result_point;
// 
//     if (this->size != right.size)
// 	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
// 
//     result_point.size = this->size;
//     result_point.coordinates = new Coord[this->size];
// 
//     for (int i = 0; i < result_point.size; i++)
// 	result_point.coordinates[i] 
// 	    =  this->coordinates[i] / right.coordinates[i];
//     return result_point;
// }
d254 12
d305 3
a307 18
// Point Point::operator% (const Point& right) const
// {
//     Point result_point;
// 
//     if ((this->type() != Integer) || (right.type() != Integer))
// 	throw(IA::TypeMismatch, __FILE__, __LINE__);
// 
//     if (this->size != right.size)
// 	throw(IA::PointIndexMismatch, __FILE__, __LINE__);
// 
//     result_point.size = this->size;
//     result_point.coordinates = new Coord[this->size];
// 
//     for (int i = 0; i < result_point.size; i++)
// 	result_point.coordinates[i] 
// 	    =  this->coordinates[i] % right.coordinates[i];
//     return result_point;
// }
d309 15
d461 5
a465 5
// const Point& Point::operator*= (const Point& rhs) 
// {
//     *this = *this * rhs;
//     return  *this;
// }
d473 5
a477 5
// const Point& Point::operator/= (const Point& rhs) 
// {
//     *this = *this / rhs;
//     return  *this;
// }
d485 5
a489 5
// const Point& Point::operator%= (const Point& rhs) 
// {
//     *this = *this % rhs;
//     return  *this;
// }
d499 1
a499 11
// const Point& Point::operator++ ()
// {
//     *this = *this + 1;
//     return  *this;
// }
// 
// const Point& Point::operator-- ()
// {
//     *this = *this - 1;
//     return  *this;
// }
d501 12
a527 2
// We could use a cheaper measure of distance here.

d530 11
a540 1
    return (lhs.euclidean_distance() >= rhs.euclidean_distance());
d555 8
a562 1
    return (lhs.euclidean_distance() <= rhs.euclidean_distance());
d577 8
a584 1
    return (lhs.euclidean_distance() > rhs.euclidean_distance());
d599 8
a606 1
    return (lhs.euclidean_distance() < rhs.euclidean_distance());
a635 8

// char operator! (const Point& point)
// {
//     for (int i = 0; i < point.size; i++) 
// 	if (point[i] != 0) return (char) 0;
//     
//     return (char) 1;
// }
@


1.3
log
@Removed deprecated Point--Point binary ops such as *, /, %.
Made assignment operations return const references.
Got rid of the local emacs variables at EOF in favor of mode line.
Do checks to get rid of possibly two representations of Points,
one where coordinates was a NULL pointer, the other where size
was zero, but zero length array was allocated (I thought this was
illegal, anyway, and ``couldn't happen'').
@
text
@d1 1
a1 1
static char rscid[] = "$Id: Poynt.cc,v 1.2 92/05/27 16:53:40 fischer Exp Locker: fischer $";
d3 10
a12 1
// $Log:	Poynt.cc,v $
d19 1
a19 1
#include <Poynt.h>
d23 1
a23 1
// sqrt in Poynt.euclidean_distance() below was commented out.  Please fix! 
d27 1
a27 1
Poynt::Poynt(const Poynt& point)
d40 1
a40 1
Poynt& Poynt::operator= (const  Poynt &point)
d64 1
a64 1
Poynt::Poynt(Coord c0)
d71 1
a71 1
Poynt::Poynt(Coord c0, Coord c1)
d81 1
a81 1
Poynt::Poynt(Coord c0, Coord c1, Coord c2)
d93 1
a93 1
Poynt::Poynt(Coord c0, Coord c1, Coord c2, Coord c3)
d108 1
a108 1
Poynt::Poynt(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4)
d128 1
a128 1
// Poynt = Poynt + Poynt
d130 1
a130 1
Poynt Poynt::operator+ (const Poynt& right) const
d132 1
a132 1
    Poynt result_point;
d146 1
a146 1
// Poynt = Poynt + Coord
d148 1
a148 1
Poynt operator+ (const Poynt& left, const Coord& right)
d150 1
a150 1
    Poynt result_point;
d164 1
a164 1
// Poynt = Coord + Poynt
d166 1
a166 1
Poynt operator+ (const Coord& left, const Poynt& right)
d168 1
a168 1
    Poynt result_point;
d183 1
a183 1
// Poynt = Poynt * Poynt
d185 1
a185 1
// Poynt Poynt::operator* (const Poynt& right) const
d187 1
a187 1
//     Poynt result_point;
d201 1
a201 1
// Poynt = Poynt * Coord
d203 1
a203 1
Poynt operator* (const Poynt& left, const Coord& right)
d205 1
a205 1
    Poynt result_point;
d219 1
a219 1
// Poynt = Coord * Poynt
d221 1
a221 1
Poynt operator* (const Coord& left, const Poynt& right)
d223 1
a223 1
    Poynt result_point;
d238 1
a238 1
// Poynt = Poynt / Poynt
d240 1
a240 1
// Poynt Poynt::operator/ (const Poynt& right) const
d242 1
a242 1
//     Poynt result_point;
d256 1
a256 1
// Poynt = Poynt / Coord
d258 1
a258 1
Poynt operator/ (const Poynt& left, const Coord& right)
d260 1
a260 1
    Poynt result_point;
d274 1
a274 1
// Poynt = Coord / Poynt
d276 1
a276 1
Poynt operator/ (const Coord& left, const Poynt& right)
d278 1
a278 1
    Poynt result_point;
d293 1
a293 1
// Poynt = Poynt % Poynt
d295 1
a295 1
// Poynt Poynt::operator% (const Poynt& right) const
d297 1
a297 1
//     Poynt result_point;
d314 1
a314 1
// Poynt = Poynt % Coord
d316 1
a316 1
Poynt operator% (const Poynt& left, const Coord& right)
d318 1
a318 1
    Poynt result_point;
d335 1
a335 1
// Poynt = Coord % Poynt
d337 1
a337 1
Poynt operator% (const Coord& left, const Poynt& right)
d339 1
a339 1
    Poynt result_point;
d357 1
a357 1
// Poynt = Poynt - Poynt
d359 1
a359 1
Poynt Poynt::operator- (const Poynt& right) const
d361 1
a361 1
    Poynt result_point;
d375 1
a375 1
// Poynt = Poynt - Coord
d377 1
a377 1
Poynt operator- (const Poynt& left, const Coord& right)
d379 1
a379 1
    Poynt result_point;
d393 1
a393 1
// Poynt = Coord - Poynt
d395 1
a395 1
Poynt operator- (const Coord& left, const Poynt& right)
d397 1
a397 1
    Poynt result_point;
d411 1
a411 1
// Poynt = -Poynt
d413 1
a413 1
Poynt Poynt::operator- () const
d415 1
a415 1
    Poynt result_point;
d427 1
a427 1
const Poynt& Poynt::operator+= (const Poynt& rhs) 
d433 1
a433 1
const Poynt& Poynt::operator+= (const Coord& rhs) 
d439 1
a439 1
const Poynt& Poynt::operator-= (const Poynt& rhs) 
d445 1
a445 1
const Poynt& Poynt::operator-= (const Coord& rhs) 
d451 1
a451 1
// const Poynt& Poynt::operator*= (const Poynt& rhs) 
d457 1
a457 1
const Poynt& Poynt::operator*= (const Coord& rhs) 
d463 1
a463 1
// const Poynt& Poynt::operator/= (const Poynt& rhs) 
d469 1
a469 1
const Poynt& Poynt::operator/= (const Coord& rhs) 
d475 1
a475 1
// const Poynt& Poynt::operator%= (const Poynt& rhs) 
d481 1
a481 1
const Poynt& Poynt::operator%= (const Coord& rhs) 
d489 1
a489 1
// const Poynt& Poynt::operator++ ()
d495 1
a495 1
// const Poynt& Poynt::operator-- ()
d503 1
a503 1
double Poynt::euclidean_distance ()const
d518 1
a518 1
char operator>= (const Poynt& lhs, const Poynt& rhs)
d523 1
a523 1
char operator>= (const Coord& lhs, const Poynt& rhs)
d528 1
a528 1
char operator>= (const Poynt& lhs, const Coord& rhs)
d533 1
a533 1
char operator<= (const Poynt& lhs, const Poynt& rhs)
d538 1
a538 1
char operator<= (const Coord& lhs, const Poynt& rhs)
d543 1
a543 1
char operator<= (const Poynt& lhs, const Coord& rhs)
d548 1
a548 1
char operator> (const Poynt& lhs, const Poynt& rhs)
d553 1
a553 1
char operator> (const Coord& lhs, const Poynt& rhs)
d558 1
a558 1
char operator> (const Poynt& lhs, const Coord& rhs)
d563 1
a563 1
char operator< (const Poynt& lhs, const Poynt& rhs)
d568 1
a568 1
char operator< (const Coord& lhs, const Poynt& rhs)
d573 1
a573 1
char operator< (const Poynt& lhs, const Coord& rhs)
d580 1
a580 1
char operator== (const Poynt& lhs, const Poynt& rhs)
d591 1
a591 1
char operator!= (const Poynt& lhs, const Poynt& rhs)
d596 1
a596 1
// char operator! (const Poynt& point)
d604 1
a604 1
ostream &operator<<(ostream &stream, Poynt point)
@


1.2
log
@Built vector-based version on top of Coord.
@
text
@d1 1
a1 1
static char rscid[] = "$Id$";
d3 4
a6 1
// $Log$
d21 6
a26 1
    this->coordinates = new Coord[size];
d33 9
d43 3
a45 1
	delete[] this->coordinates;
d59 1
a59 1
    this->set(0, c0);
d68 2
a69 2
    this->set(0, c0.promote(coerced_type));
    this->set(1, c1.promote(coerced_type));
d79 3
a81 3
    this->set(0, c0.promote(coerced_type));
    this->set(1, c1.promote(coerced_type));
    this->set(2, c2.promote(coerced_type));
d92 4
a95 4
    this->set(0, c0.promote(coerced_type));
    this->set(1, c1.promote(coerced_type));
    this->set(2, c2.promote(coerced_type));
    this->set(3, c3.promote(coerced_type));
d108 5
a112 5
    this->set(0, c0.promote(coerced_type));
    this->set(1, c1.promote(coerced_type));
    this->set(2, c2.promote(coerced_type));
    this->set(3, c3.promote(coerced_type));
    this->set(4, c4.promote(coerced_type));
d176 15
a190 3
Poynt Poynt::operator* (const Poynt& right) const
{
    Poynt result_point;
a191 12
    if (this->size != right.size)
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] * right.coordinates[i];
    return result_point;
}

d231 15
a245 3
Poynt Poynt::operator/ (const Poynt& right) const
{
    Poynt result_point;
a246 12
    if (this->size != right.size)
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] / right.coordinates[i];
    return result_point;
}

d286 18
a303 3
Poynt Poynt::operator% (const Poynt& right) const
{
    Poynt result_point;
a304 15
    if ((this->type() != Integer) || (right.type() != Integer))
	throw(IA::TypeMismatch, __FILE__, __LINE__);

    if (this->size != right.size)
	throw(IA::PointIndexMismatch, __FILE__, __LINE__);

    result_point.size = this->size;
    result_point.coordinates = new Coord[this->size];

    for (int i = 0; i < result_point.size; i++)
	result_point.coordinates[i] 
	    =  this->coordinates[i] % right.coordinates[i];
    return result_point;
}

d418 1
a418 1
Poynt& Poynt::operator += (const Poynt& rhs) 
d424 1
a424 1
Poynt& Poynt::operator += (const Coord& rhs) 
d430 1
a430 1
Poynt& Poynt::operator -= (const Poynt& rhs) 
d436 1
a436 1
Poynt& Poynt::operator -= (const Coord& rhs) 
d442 5
a446 5
Poynt& Poynt::operator *= (const Poynt& rhs) 
{
    *this = *this * rhs;
    return  *this;
}
d448 1
a448 1
Poynt& Poynt::operator *= (const Coord& rhs) 
d454 5
a458 5
Poynt& Poynt::operator /= (const Poynt& rhs) 
{
    *this = *this / rhs;
    return  *this;
}
d460 1
a460 1
Poynt& Poynt::operator /= (const Coord& rhs) 
d466 5
a470 5
Poynt& Poynt::operator %= (const Poynt& rhs) 
{
    *this = *this % rhs;
    return  *this;
}
d472 1
a472 1
Poynt& Poynt::operator %= (const Coord& rhs) 
d479 12
a491 12
Poynt& Poynt::operator ++ ()
{
    *this = *this + 1;
    return  *this;
}

Poynt& Poynt::operator -- ()
{
    *this = *this - 1;
    return  *this;
}

a493 1

d509 1
a509 1
char operator >= (const Poynt& lhs, const Poynt& rhs)
d514 1
a514 1
char operator >= (const Coord& lhs, const Poynt& rhs)
d519 1
a519 1
char operator >= (const Poynt& lhs, const Coord& rhs)
d524 1
a524 1
char operator <= (const Poynt& lhs, const Poynt& rhs)
d529 1
a529 1
char operator <= (const Coord& lhs, const Poynt& rhs)
d534 1
a534 1
char operator <= (const Poynt& lhs, const Coord& rhs)
d539 1
a539 1
char operator > (const Poynt& lhs, const Poynt& rhs)
d544 1
a544 1
char operator > (const Coord& lhs, const Poynt& rhs)
d549 1
a549 1
char operator > (const Poynt& lhs, const Coord& rhs)
d554 1
a554 1
char operator < (const Poynt& lhs, const Poynt& rhs)
d559 1
a559 1
char operator < (const Coord& lhs, const Poynt& rhs)
d564 1
a564 1
char operator < (const Poynt& lhs, const Coord& rhs)
d571 1
a571 1
char operator == (const Poynt& lhs, const Poynt& rhs)
d582 1
a582 1
char operator != (const Poynt& lhs, const Poynt& rhs)
d587 7
a593 7
char operator ! (const Poynt& point)
{
    for (int i = 0; i < point.size; i++) 
	if (point[i] != 0) return (char) 0;
    
    return (char) 1;
}
@


1.1
log
@Initial revision
@
text
@d1 6
@
