head	1.25;
access;
symbols
	bobbase:1.25
	bob:1.25.1
	r2_1:1.23
	r2_0:1.22
	r1_1_beta:1.16
	r1_1_alpha:1.15
	r1_0:1.15
	r0_11:1.15
	r0_10:1.13
	r0_9:1.13
	Eglin_alpha_1:1.11;
locks
	thoth:1.25; strict;
comment	@// @;


1.25
date	94.11.10.18.49.44;	author ljr;	state Exp;
branches
	1.25.1.1;
next	1.24;

1.24
date	94.10.17.19.09.42;	author fjsoria;	state Exp;
branches;
next	1.23;

1.23
date	94.09.13.21.02.51;	author fjsoria;	state Exp;
branches;
next	1.22;

1.22
date	94.08.25.19.28.53;	author fjsoria;	state Exp;
branches;
next	1.21;

1.21
date	94.08.25.18.07.25;	author fjsoria;	state Exp;
branches;
next	1.20;

1.20
date	94.08.25.03.24.11;	author gmt;	state Exp;
branches;
next	1.19;

1.19
date	94.08.22.14.39.02;	author thoth;	state Exp;
branches;
next	1.18;

1.18
date	94.08.18.17.51.28;	author fjsoria;	state Exp;
branches;
next	1.17;

1.17
date	94.08.16.21.03.13;	author fjsoria;	state Exp;
branches;
next	1.16;

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

1.15
date	94.03.14.18.44.44;	author jnw;	state Exp;
branches;
next	1.14;

1.14
date	94.03.14.18.33.16;	author jnw;	state Exp;
branches;
next	1.13;

1.13
date	93.11.16.13.27.10;	author thoth;	state Exp;
branches;
next	1.12;

1.12
date	93.09.15.12.25.58;	author thoth;	state Exp;
branches;
next	1.11;

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

1.10
date	93.05.26.16.59.57;	author rjj;	state Exp;
branches;
next	1.9;

1.9
date	93.04.06.22.28.17;	author rjj;	state Exp;
branches;
next	1.8;

1.8
date	93.04.05.23.18.00;	author rjj;	state Exp;
branches;
next	1.7;

1.7
date	92.12.11.01.10.35;	author rjj;	state Exp;
branches;
next	1.6;

1.6
date	92.09.02.14.51.27;	author rjj;	state Exp;
branches;
next	1.5;

1.5
date	92.09.01.21.08.17;	author rjj;	state Exp;
branches;
next	1.4;

1.4
date	92.09.01.20.46.24;	author rjj;	state Exp;
branches;
next	1.3;

1.3
date	92.08.27.12.11.55;	author jnw;	state Exp;
branches;
next	1.2;

1.2
date	92.08.23.13.33.19;	author thoth;	state Exp;
branches;
next	1.1;

1.1
date	92.08.20.22.24.54;	author rjj;	state Exp;
branches;
next	;

1.25.1.1
date	94.11.30.16.16.38;	author thoth;	state Exp;
branches;
next	1.25.1.2;

1.25.1.2
date	94.12.08.14.31.41;	author thoth;	state Exp;
branches;
next	;


desc
@Initial creation from Point.cc.m4
@


1.25
log
@Added IA_NO_RCS_STATIC_DATA guard.
@
text
@// Emacs: -*- C++ -*-

#ifndef IA_NO_RCS_STATIC_DATA
static char rcsid[] = "$Id: Point_c.m4,v 1.24 1994/10/17 19:09:42 fjsoria Exp ljr $";
#endif

/*
        Copyright 1993, Center for Computer Vision and Visualization,
        University of Florida.  All rights reserved.

// $Log: Point_c.m4,v $
// Revision 1.24  1994/10/17  19:09:42  fjsoria
// *** empty log message ***
//
// Revision 1.23  1994/09/13  21:02:51  fjsoria
// correction to derange for no_loop_unrolling
//
// Revision 1.22  1994/08/25  19:28:53  fjsoria
// abs is not defined in c-front redefined abs, fixed bug in derange
//
// Revision 1.21  1994/08/25  18:07:25  fjsoria
// removed abs for scalars since it is supported by UNIX, DOS, and Mac
// platforms
//
// Revision 1.20  1994/08/25  03:24:11  gmt
// Added Mac specific pragma (template_access) to tell the compiler that the
// generated files are actually template instances via template instantiation.
//
// Revision 1.19  1994/08/22  14:39:02  thoth
// fixed conflict with system's abs.
//
// Revision 1.18  1994/08/18  17:51:28  fjsoria
// corrected DoublePoint.h .c to DblPoint.h .c for DOS compat.
//
// Revision 1.17  1994/08/16  21:03:13  fjsoria
// added derange and enorm as non-member functions, keeping member versions
// added inorm, mnorm, abs, fabs as non-member functions
//
// Revision 1.16  1994/07/25  16:42:26  thoth
// FloatPoint is now either Point<double> or DoublePoint.
//
// Revision 1.15  1994/03/14  18:44:44  jnw
// Modified sum and product
//
// Revision 1.14  1994/03/14  18:33:16  jnw
// Added point reduce functions 'sum' and 'product'
//
// Revision 1.13  1993/11/16  13:27:10  thoth
// Pointcmp is now pointcmp
//
// Revision 1.12  1993/09/15  12:25:58  thoth
// Point is now a template with specializations only.
//
// Revision 1.11  93/05/28  15:43:31  thoth
// fix comment errors.
// 
// Revision 1.10  1993/05/26  16:59:57  rjj
// Added copyright notice
//
// Revision 1.9  93/04/06  22:28:17  rjj
// Changed name of file from "Point.C.m4" to "Point.c.m4"
// Fixed lattice bugs with != by defining functions to invoke ==
// Changed "const {int|double}" to "{int|double}"
// Fixed a leftover FloatPoint name ref in trunc()
// Changed bitwise unsigned parameters to int
// 
//Revision 1.8  93/04/05  23:18:00  rjj
//Many changes to support changes necessary to mutate to the
//  interface defined by newpoint.  Please see the list for
//  Point.h.m4 revison 2.10
//  Error in operator ~ () corrected
//  Lattice operator != is probably still wrong, need to check !
//  m4 defines *_*_RELATION changed to LATTICE_*_*
//  Postfix ++ and -- code added
//  file rearanged to suit my tastes, your milage my vary ;-)
//
//Revision 1.7  92/12/11  01:10:35  rjj
//Modified to support the IA_ prefix naming convention.
//Also put #ifdef IA_PRII around the #pragma stmt
//
//Revision 1.6  92/09/02  14:51:27  rjj
//Corrected code in FloatPoint( IntPoint ) to allocated array of type TYPE
//Changed enorm() cast from (float) to (double)
//
//Revision 1.5  92/09/01  21:08:17  rjj
//Changed max(POINT_TYPE,POINT_TYPE) to be supremum(POINT_TYPE,POINT_TYPE)
//Changed min(POINT_TYPE,POINT_TYPE) to be infimum(POINT_TYPE,POINT_TYPE)
//
//Revision 1.4  92/09/01  20:46:24  rjj
//Added support to ensure float op IntPoint and IntPoint op float yield FloatPoint.
//
//Revision 1.3  92/08/27  12:11:55  jnw
//Added C style comments around Log Messages to fixx gcc-cpp bug
//
//Revision 1.2  92/08/23  13:33:19  thoth
//Cfrontified
//didn't hint to inline for loop stuff any more (braindead compiler).
//hack-around for switch statements that CFront's flow analysis
//can't fully understand.
//throw changed to ia_throw.
//removed duplicate default values for formal parameters (ARM spec).
//
// Revision 1.1  92/08/20  22:24:54  rjj
// Initial revision
// 
// 
// 

*/

#include <math.h>

#ifdef IA_PRII
ifdef(`INTPOINT', `#pragma implementation "IntPoint.h"')
ifdef(`DOUBLEPOINT', `#pragma implementation "DblPoint.h"')
#endif
ifdef(`INTPOINT', `#include "IntPoint.h"')
ifdef(`DOUBLEPOINT', `#include "DblPoint.h"')

#ifdef __SC__
#pragma template_access public
#endif

////////////////////////////////////////////////////////////
// C O N S T R U C T O R S
////////////////////////////////////////////////////////////

POINT_TYPE extend_to_point (TYPE initial_value, unsigned length) {
    POINT_TYPE pt;

    pt.coordinates = new TYPE[pt.dimen = length];

#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 0; i < length; i++)
	pt.coordinates[i] = initial_value;
#else
    switch (pt.dim()) {
    case 5: pt.coordinates[4] = initial_value;
    case 4: pt.coordinates[3] = initial_value;
    case 3: pt.coordinates[2] = initial_value;
    case 2: pt.coordinates[1] = initial_value;
    case 1: pt.coordinates[0] = initial_value;
    case 0: break;
    default:
	    {
		for (unsigned i = 0; i < length; i++)
		    pt.coordinates[i] = initial_value;
	    }
    }
#endif    
    return pt;
}


POINT_TYPE::POINT (const POINT_TYPE &ip)
{

// new TYPE[0] creates a pointer to one TYPE; we never use it.
// This is to keep from having to do "if (dim() == 0) ..." everywhere.
// The destructor will delete it, though.
    
    this->coordinates = new TYPE[this->dimen = ip.dim()];

#ifdef NO_LOOP_UNROLLING    
    for (unsigned i=0; i<this->dim(); i++)
	this->coordinates[i] = ip.coordinates[i];
#else
    switch (this->dim()) {
    case 5: this->coordinates[4] = ip.coordinates[4];
    case 4: this->coordinates[3] = ip.coordinates[3];
    case 3: this->coordinates[2] = ip.coordinates[2];
    case 2: this->coordinates[1] = ip.coordinates[1];
    case 1: this->coordinates[0] = ip.coordinates[0];
    case 0: break;
    default:
	    {
		for (unsigned i=0; i<this->dim(); i++)
		    this->coordinates[i] = ip.coordinates[i];
	    }
    }
#endif
}


POINT_TYPE::POINT (TYPE *vec, unsigned length, int giveaway)
{
    this->dimen = length;
    if (giveaway) {
	this->coordinates = vec;
	return;
    }
    
    this->coordinates = new TYPE[this->dim()];
    
#ifdef NO_LOOP_UNROLLING    
    for (unsigned length=0; length<this->dim(); length++)
	this->coordinates[length] = vec[length];
#else	
    switch (this->dim()) {
    case 5: this->coordinates[4] = vec[4];
    case 4: this->coordinates[3] = vec[3];
    case 3: this->coordinates[2] = vec[2];
    case 2: this->coordinates[1] = vec[1];
    case 1: this->coordinates[0] = vec[0];
    case 0: break;
    default:
	    {
		for (unsigned length=0; length<this->dim(); length++)
		    this->coordinates[length] = vec[length];
	    }
    }
#endif
}

ifdef(`DOUBLEPOINT',`
//  DoublePoint includes IntPoint.h so we can have a constructor
//  from IntPoint to DoublePoint: this gives us all DoublePoint/IntPoint
//  operations for free.

POINT_TYPE::POINT (const IPOINT &ipt) {

    this->coordinates = new TYPE[this->dimen = ipt.dim()];

#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 0; i < ipt.dim(); i++)
	coordinates[i] = ipt[i];
#else
    switch (ipt.dim()) {
    case 5: coordinates[4] = ipt[4];
    case 4: coordinates[3] = ipt[3];
    case 3: coordinates[2] = ipt[2];
    case 2: coordinates[1] = ipt[1];
    case 1: coordinates[0] = ipt[0];
    case 0: break;     
    default:
	{
	    for (unsigned i = 0; i < ipt.dim(); i++)
		coordinates[i] = ipt[i];
	}
    }
#endif
}
')


// POINT_TYPE = concat (POINT_TYPE, POINT_TYPE)
//
// Given a combination of Points and numbers, create a new Point that is
// the concatenation of the arguments.  Lets the user construct larger
// points than the usual 5 arg constructor.

// TO DO -- These could be modified to not check for zero-length
// points (since we now know that "new foo[0]" returns a deletable
// pointer to one foo that we will never access), and also we could
// do some loop unrolling here as well.

POINT_TYPE concat(const POINT_TYPE& lhs, const POINT_TYPE& rhs)
{
    POINT_TYPE result_point;
    
    if (lhs.dim() == 0) {
	if (rhs.dim() == 0)
	    return result_point;
	else 
	    return rhs;
    } else if (rhs.dim() == 0)
	return lhs;

    unsigned int total_dimen = lhs.dim() + rhs.dim();

    result_point.coordinates = new TYPE[result_point.dimen = total_dimen];
    
    for (unsigned int i = 0; i < lhs.dim(); i++) 
	result_point.coordinates[i] = lhs.coordinates[i];

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

    return result_point;
}


POINT_TYPE concat(const POINT_TYPE& lhs, TYPE rhs)
{
    POINT_TYPE result_point;

    if (lhs.dim() == 0) 
	return POINT_TYPE (rhs);
    
    unsigned int total_dimen = lhs.dim() + 1;

    result_point.coordinates = new TYPE[total_dimen];
    result_point.dimen = total_dimen;
    
    for (unsigned int i = 0; i < lhs.dim(); i++) 
	result_point.coordinates[i] = lhs.coordinates[i];
    
    result_point.coordinates[i] = rhs;
    
    return result_point;
}


POINT_TYPE concat(TYPE lhs, const POINT_TYPE& rhs)
{
    POINT_TYPE result_point;
    
    if (rhs.dim() == 0)
	return POINT_TYPE (lhs);

    unsigned int total_dimen = rhs.dim() + 1;

    result_point.coordinates = new TYPE[total_dimen];
    result_point.dimen = total_dimen;

    result_point.coordinates[0] = lhs;

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

    return result_point;
}

//  cdr(POINT_TYPE, skip=1):
//
//  Given a point of dimension n, return a point made of the n-skip last
//  coordinates (or if skip is negative, the n+skip first coordinates),
//  where skip defaults to 1.


POINT_TYPE cdr(const POINT_TYPE& pt, int skip) {

    unsigned  abs_skip;

    abs_skip = (skip < 0) ? -skip : skip;
    
    if (pt.dim() < abs_skip) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return POINT_TYPE ();
    } else if (pt.dim() == skip)
	return POINT_TYPE ();

    if (skip < 0)
	return POINT_TYPE (pt.coordinates, pt.dim()+skip);
    else
	return POINT_TYPE (pt.coordinates+skip, pt.dim()-skip);
}


////////////////////////////////////////////////////////////
// M I S C    O P E R A T I O N S
////////////////////////////////////////////////////////////

POINT_TYPE &POINT_TYPE::operator = (const POINT_TYPE &point) {
    // return directly when self-assignment
    //  (not sure the if is worth it in general)

    if (this == &point)
	return *this;

    // We need to deallocate/reallocate if differing dimens.
    
    if (point.dim() != this->dim()) {
        delete[] this->coordinates;
        this->coordinates = new TYPE[this->dimen = point.dim()];
    }

#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 0; i < this->dim(); i++)
	this->coordinates[i] = point.coordinates[i];
#else
    switch (this->dim()) {
    case 5: this->coordinates[4] = point.coordinates[4];
    case 4: this->coordinates[3] = point.coordinates[3];
    case 3: this->coordinates[2] = point.coordinates[2];
    case 2: this->coordinates[1] = point.coordinates[1];
    case 1: this->coordinates[0] = point.coordinates[0];
    case 0: break;
    default:
	    {
		for (unsigned i = 0; i < this->dim(); i++)
		    this->coordinates[i] = point.coordinates[i];
	    }
    }
#endif
    return *this;
}


FRIEND_SELECT_BINARY(inf, <)
FRIEND_SELECT_BINARY(sup, >)

FRIEND_SELECT_UNARY(min, <)
FRIEND_SELECT_UNARY(max, >)


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


////////////////////////////////////////////////////////////
// I N D E X I N G    O P E R A T I O N S
////////////////////////////////////////////////////////////
// Index derangement: "POINT_TYPE (point_index, point_index..)"
//
// Construct new points from old points, possibly with different
// dimensions and indices rearanged.
// For instance, let  a=Point(10, 20, 30).
// Then b=a.derange(2,0) is equivalent to b=Point(30,10).



POINT_TYPE derange (const POINT_TYPE &pt, unsigned i0)
{
      
    if (i0 >= pt.dim()) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return POINT_TYPE ();
    }
    
    TYPE *p = new TYPE [1];

    p[0] = pt(i0);
    return POINT_TYPE ( p, 1, 1);
}


POINT_TYPE derange (const POINT_TYPE &pt, unsigned i0, unsigned i1) 
{
    

    if (i0 >= pt.dim() || i1 >= pt.dim()) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return POINT_TYPE ();
    }

    TYPE *p = new TYPE [2];
    
    p[0] = pt(i0);
    p[1] = pt(i1);
    return POINT_TYPE ( p, 2, 1);
}


POINT_TYPE derange (const POINT_TYPE &pt, unsigned i0, unsigned i1,unsigned i2)
{
    

    if (i0 >= pt.dim() || i1 >= pt.dim() || i2 >= pt.dim()) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return POINT_TYPE ();
    }

    TYPE *p = new TYPE [3];
    p[0] = pt(i0);
    p[1] = pt(i1);
    p[2] = pt(i2);
    return POINT_TYPE ( p, 3, 1);
}




POINT_TYPE derange (const POINT_TYPE &pt, unsigned i0, unsigned i1, unsigned i2, unsigned i3)
{
    
    if (i0 >= pt.dim() || i1 >= pt.dim() || i2 >= pt.dim() || i3 >= pt.dim()) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return POINT_TYPE ();
    }

    TYPE *p = new TYPE [4];
    p[0]= pt(i0);
    p[1] = pt(i1);
    p[2] = pt(i2);
    p[3] = pt(i3);
    return POINT_TYPE ( p, 4, 1);
}


POINT_TYPE derange (const POINT_TYPE &pt, unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4)
{
    
    if (i0 >= pt.dim() || i1 >= pt.dim() || i2 >= pt.dim() ||
	i3 >= pt.dim() || i4 >= pt.dim()) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return POINT_TYPE ();
    }

    TYPE *p = new TYPE [5];
    p[0] = pt(i0);
    p[1] = pt(i1);
    p[2] = pt(i2);
    p[3] = pt(i3);
    p[4] = pt(i4);
    return POINT_TYPE ( p, 5, 1);
}



    
POINT_TYPE derange (const POINT_TYPE &pt, unsigned *vec, const unsigned vecLen)
{
    // We need to deallocate/reallocate if differing dimens.
    unsigned i;
    for (i=0; i<vecLen; i++) {
	if (vec[i] >= pt.dim()) {
	    ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__ );
	    return POINT_TYPE ();  // An empty point
	}
    }

    TYPE *p = new TYPE [vecLen];

#ifdef NO_LOOP_UNROLLING
    for (i = 0; i < vecLen; i++)
	p[i] = pt(vec[i]);
#else
    switch (vecLen) {
    case 5: p[4] = pt(vec[4]);
    case 4: p[3] = pt(vec[3]);
    case 3: p[2] = pt(vec[2]);
    case 2: p[1] = pt(vec[1]);
    case 1: p[0] = pt(vec[0]);
    case 0: break;
    default:
	    {
		for (i = 0; i < vecLen; i++)
		    p[i] = pt(vec[i]);
	    }
    }
#endif
    return POINT_TYPE ( p, vecLen, 1);
}



  inline static TYPE IA_abs ( TYPE t)
{
  t = (t < 0) ? -t : t;
  return t;
}





// abs will work on double and int points, is a friend of point

POINT_TYPE abs (const POINT_TYPE &p)
{
    
  if (p.dim() == 0) {
    ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
    return POINT_TYPE (); //if invalid return a point of 0 dim
  }

  TYPE *result = new TYPE[p.dim()];
  
#ifdef NO_LOOP_UNROLLING
  for (unsigned i = 0; i < p.dim(); i++)	
    result[i] = IA_abs(p(i));
#else
  switch (p.dim()) {
  case 5: result[4] =IA_abs(p(4));  
  case 4: result[3] =IA_abs(p(3));  
  case 3: result[2] =IA_abs(p(2));  
  case 2: result[1] =IA_abs(p(1));
  case 1: result[0] =IA_abs(p(0));  
  case 0: break;
  default:
    {
      for (unsigned i = 0; i < p.dim(); i++)
	result[i] = IA_abs(p(i));
    }
  
  }
#endif 
  return POINT_TYPE (result, p.dim(), 1);
}


// fabs to follow stdlib.h will only work on double

ifdef(`DOUBLEPOINT',`
IA_Point<double> fabs (const IA_Point<double> &p)
{
  
  if (p.dim() == 0) {
    ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
    return IA_Point<double> ();
  }

  double *result = new double[p.dim()];
  
#ifdef NO_LOOP_UNROLLING
  for (unsigned i = 0; i < p.dim(); i++)	
    result[i] = fabs(p(i));
#else
  switch (p.dim()) {
  case 5: result[4] = fabs(p(4));  
  case 4: result[3] = fabs(p(3));  
  case 3: result[2] = fabs(p(2));  
  case 2: result[1] = fabs(p(1));
  case 1: result[0] = fabs(p(0));  
  case 0: break;
  default:
    {
      for (unsigned i = 0; i < p.dim();  i++)
	result[i] = fabs(p(i));
    }
  
  }
#endif
  return IA_Point<double> ( result, p.dim(), 1);
}')



// inorm and enorm uses abs() for both points of double and ints
// enorm: Euclidean distance from origin.

double enorm (const POINT_TYPE &p)
{
    double result_number = 0;

    if (p.dim() == 0)
      {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_number;
      }

#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 0; i < p.dim(); i++)
      result_number = result_number +
	(double) (p(i) * p(i));
#else
    switch (p.dim()) {
    case 5: result_number += (double) (p(4) * p(4));
    case 4: result_number += (double) (p(3) * p(3));
    case 3: result_number += (double) (p(2) * p(2));
    case 2: result_number += (double) (p(1) * p(1));
    case 1: result_number += (double) (p(0) * p(0));
    case 0: break;
    default:
      {
	for (unsigned i = 0; i < p.dim(); i++)
	  result_number += (double) (p(i) * p(i));
      }
    }
#endif
    return sqrt(result_number);
}


// inorm: infinity norm , checkerboard distance

TYPE inorm(const POINT_TYPE &p)
{
  TYPE result = 0;
  
  if (p.dim() == 0) {
       ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
       return result;
   }
  result =  max(abs(p));
  return result;
}

// mnorm: manhattan distance

TYPE mnorm(const POINT_TYPE &p)
{
  TYPE result = 0;
  
  if (p.dim() == 0) {
       ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
       return result;
    }
  result = sum(abs(p));
  return result;
}



////////////////////////////////////////////////////////////
// A R I T H M E T I C   O P E R A T I O N S
////////////////////////////////////////////////////////////

COMPOUND_ARITH_ASSIGN_POINT(+)
COMPOUND_ARITH_ASSIGN_POINT(-)
COMPOUND_ARITH_ASSIGN_POINT(*)
COMPOUND_ARITH_ASSIGN_POINT(/)


COMPOUND_ARITH_ASSIGN_NUMBER(+)
COMPOUND_ARITH_ASSIGN_NUMBER(-)
COMPOUND_ARITH_ASSIGN_NUMBER(*)
COMPOUND_ARITH_ASSIGN_NUMBER(/)
    

ARITH_POINT_POINT(+)
ARITH_POINT_POINT(-)
ARITH_POINT_POINT(*)
ARITH_POINT_POINT(/)
    
ARITH_NUMBER_POINT(+)
ARITH_NUMBER_POINT(-)
ARITH_NUMBER_POINT(*)
ARITH_NUMBER_POINT(/)
    
ARITH_POINT_NUMBER(+)
ARITH_POINT_NUMBER(-)
ARITH_POINT_NUMBER(*)
ARITH_POINT_NUMBER(/)
    
ifdef(`DOUBLEPOINT', `ARITH_DOUBLE_INTPOINT(+)')
ifdef(`DOUBLEPOINT', `ARITH_DOUBLE_INTPOINT(-)')
ifdef(`DOUBLEPOINT', `ARITH_DOUBLE_INTPOINT(*)')
ifdef(`DOUBLEPOINT', `ARITH_DOUBLE_INTPOINT(/)')

ifdef(`DOUBLEPOINT', `ARITH_INTPOINT_DOUBLE(+)')
ifdef(`DOUBLEPOINT', `ARITH_INTPOINT_DOUBLE(-)')
ifdef(`DOUBLEPOINT', `ARITH_INTPOINT_DOUBLE(*)')
ifdef(`DOUBLEPOINT', `ARITH_INTPOINT_DOUBLE(/)')


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

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

    result_point.coordinates = new TYPE[result_point.dimen = this->dim()];

#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 0; i < result_point.dim(); i++)
	result_point.coordinates[i] =  -this->coordinates[i];
#else
    switch (result_point.dim()) {
    case 5: result_point.coordinates[4] = -this->coordinates[4];
    case 4: result_point.coordinates[3] = -this->coordinates[3];
    case 3: result_point.coordinates[2] = -this->coordinates[2];
    case 2: result_point.coordinates[1] = -this->coordinates[1];
    case 1: result_point.coordinates[0] = -this->coordinates[0];
    case 0: break;
    default:
	    {
		for (unsigned i = 0; i < result_point.dim(); i++)
		    result_point.coordinates[i] =  - this->coordinates[i];
	    }
    }
#endif
    return result_point;
}


// Prefix ++
POINT_TYPE& POINT_TYPE::operator ++ () {
    if (this->dim() == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this += 1;
    return  *this;
}


// Prefix --
POINT_TYPE& POINT_TYPE::operator -- () {
    if (this->dim() == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this -= 1;
    return  *this;
}


// Postfix ++
POINT_TYPE  POINT_TYPE::operator ++ (int) {
    if (this->dim() == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    POINT_TYPE  result = *this;
    *this += 1;
    return  result;
}


// Postfix --
POINT_TYPE  POINT_TYPE::operator -- (int) {
    if (this->dim() == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    POINT_TYPE  result = *this;
    *this -= 1;
    return  result;
}


// Point reduce operations

TYPE sum(const POINT_TYPE &p)
{
    TYPE result;
    
    if (p.dim() == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result;
    }
    
    result = p[0];
    
#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 1; i < p.dim(); i++)
	result += p[i];
#else
    switch (p.dim()) {
    case 5: result += p[4];
    case 4: result += p[3];
    case 3: result += p[2];
    case 2: result += p[1];
    case 1: break;
    default:
	{
	    for (unsigned i = 1; i < p.dim(); i++)
		result += p[i];
	}
    }
#endif
    return result;
}

TYPE product(const POINT_TYPE &p)
{
    TYPE result;
    
    if (p.dim() == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result;
    }
    
    result = p[0];
    
#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 1; i < p.dim(); i++)
	result *= p[i];
#else
    switch (p.dim()) {
    case 5: result *= p[4];
    case 4: result *= p[3];
    case 3: result *= p[2];
    case 2: result *= p[1];
    case 1: break;
    default:
	{
	    for (unsigned i = 1; i < p.dim(); i++)
		result *= p[i];
	}
    }
#endif
    return result;
}



ifdef(`DOUBLEPOINT', `
// Math rounding functions as friends.
//  
// All of the following routines perform some rounding function.  Except
// for irint, nint and trunc, the routines always return double points.
// irint, nint, and trunc alway pass back int points.  See rint (3)
// for details.')

ifdef(`DOUBLEPOINT', `ROUNDING_DOUBLE_TO_DOUBLE(aint)')
ifdef(`DOUBLEPOINT', `ROUNDING_DOUBLE_TO_DOUBLE(anint)')
ifdef(`DOUBLEPOINT', `ROUNDING_DOUBLE_TO_DOUBLE(ceil)')
ifdef(`DOUBLEPOINT', `ROUNDING_DOUBLE_TO_DOUBLE(floor)')
ifdef(`DOUBLEPOINT', `ROUNDING_DOUBLE_TO_DOUBLE(rint)')

ifdef(`DOUBLEPOINT', `ROUNDING_DOUBLE_TO_INT(irint)')
ifdef(`DOUBLEPOINT', `ROUNDING_DOUBLE_TO_INT(nint)')

ifdef(`DOUBLEPOINT', `
IPOINT trunc(const POINT_TYPE& p) 
{ 
    int	*iptr;
    iptr = new int[p.dim()];	    
    unsigned i;
    
#ifdef NO_LOOP_UNROLLING
    for (i = 0; i < p.dim(); i++) 
	iptr[i] = int(p.coordinates[i]);    
#else
    switch (p.dim()) {
    case 5: iptr[4] = int(p.coordinates[4]);
    case 4: iptr[3] = int(p.coordinates[3]);
    case 3: iptr[2] = int(p.coordinates[2]);
    case 2: iptr[1] = int(p.coordinates[1]);
    case 1: iptr[0] = int(p.coordinates[0]);
    case 0: break;
    default:
	    {
		for (i = 0; i < p.dim(); i++) 
		    iptr[i] = int(p.coordinates[i]);
	    }
    }
#endif    
    return IPOINT (iptr, p.dim(), 1);
}')


////////////////////////////////////////////////////////////
// L A T T I C E   O P E R A T I O N S
////////////////////////////////////////////////////////////

// Relational operators

// POINT_TYPE < POINT_TYPE    

LATTICE_POINT_POINT(<)
LATTICE_POINT_POINT(<=)
LATTICE_POINT_POINT(>)
LATTICE_POINT_POINT(>=)
LATTICE_POINT_POINT(==)

int POINT_TYPE::operator != (const POINT_TYPE& rhs) const
{
    return ! (*this == rhs);
}


// POINT_TYPE < TYPE

LATTICE_POINT_NUMBER(<)
LATTICE_POINT_NUMBER(<=)
LATTICE_POINT_NUMBER(>)
LATTICE_POINT_NUMBER(>=)
LATTICE_POINT_NUMBER(==)

int  POINT_TYPE::operator != (TYPE rhs) const
{
    return ! (*this == rhs);
}

// TYPE < POINT_TYPE 

LATTICE_NUMBER_POINT(<)
LATTICE_NUMBER_POINT(<=)
LATTICE_NUMBER_POINT(>)
LATTICE_NUMBER_POINT(>=)
LATTICE_NUMBER_POINT(==)

int operator != (TYPE lhs, const POINT_TYPE& rhs)  
{
    return !(rhs == lhs);
}


ifdef(`INTPOINT', `
// Intpoint op double
LATTICE_INTPOINT_DOUBLE(<)
LATTICE_INTPOINT_DOUBLE(<=)
LATTICE_INTPOINT_DOUBLE(>)
LATTICE_INTPOINT_DOUBLE(>=)
LATTICE_INTPOINT_DOUBLE(==)

int POINT_TYPE::operator !=  (double rhs) const
{
    return ! (*this == rhs);
}


// double < INTPOINT
LATTICE_DOUBLE_INTPOINT(<)
LATTICE_DOUBLE_INTPOINT(<=)
LATTICE_DOUBLE_INTPOINT(>)
LATTICE_DOUBLE_INTPOINT(>=)
LATTICE_DOUBLE_INTPOINT(==)

int operator != (double lhs, const POINT_TYPE& rhs)  
{
    return ! (rhs == lhs);
}
')

//  Point comparison: pointcmp(POINT_TYPE, POINT_TYPE)
//
// A sort of lexicographic comparison of Points, except that
// points are zero extended for comparison, e.g., <1 0> is equal
// to <1>;  <> is equal <0 0 0>, etc. Returns 0 for equality, -1
// if the first is less than the second, 1 if the first is greater
// than the second,

int pointcmp(const POINT_TYPE &lhs, const POINT_TYPE &rhs)
{
    if (lhs.dim() > rhs.dim()) {
	for (unsigned i=0; i < rhs.dim(); i++) {
	    if (lhs[i] < rhs[i])
		return -1;
	    else if (lhs[i] > rhs[i])
		return 1;
	}
	for ( ; i<lhs.dim(); i++) {
	    if (lhs[i] < 0)
		return -1;
	    else if (lhs[i] > 0)
		return 1;
	}
    } else {
	for (unsigned i=0; i < lhs.dim(); i++) {
	    if (lhs[i] < rhs[i])
		return -1;
	    else if (lhs[i] > rhs[i])
		return 1;
	}
	for ( ; i < rhs.dim(); 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.dim() == rhs.dim())
    // 		return 0;
    //     else if (lhs.dim() > rhs.dim())
    // 		return 1;
    //     else
    // 		return -1;

}


////////////////////////////////////////////////////////////
// B I T W I S E   O P E R A T I O N S
////////////////////////////////////////////////////////////

ifdef(`INTPOINT', `
POINT_TYPE POINT_TYPE::operator ~ () const
{
    POINT_TYPE result_point;
    
    if (this->dim() == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }

    result_point.coordinates = new int[result_point.dimen = this->dim()];

#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 0; i < result_point.dim(); i++)
	result_point.coordinates[i] =  ~(this->coordinates[i]);
#else
    switch (result_point.dim()) {
    case 5: result_point.coordinates[4] = ~(this->coordinates[4]);
    case 4: result_point.coordinates[3] = ~(this->coordinates[3]);
    case 3: result_point.coordinates[2] = ~(this->coordinates[2]);
    case 2: result_point.coordinates[1] = ~(this->coordinates[1]);
    case 1: result_point.coordinates[0] = ~(this->coordinates[0]);
    case 0: break;
    default:
	    {
		for (unsigned i = 0; i < result_point.dim(); i++)
		    result_point.coordinates[i] = ~(this->coordinates[i]);
	    }
    }
#endif    
    return result_point;
}')


ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(%)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(<<)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(>>)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(&)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(^)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(|)')

ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(%)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(<<)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(>>)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(&)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(^)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(|)')

ifdef(`INTPOINT', `BITWISE_POINT_POINT(%)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(<<)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(>>)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(&)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(^)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(|)')

ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(%)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(<<)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(>>)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(&)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(^)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(|)')

ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(%)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(<<)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(>>)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(&)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(^)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(|)')

@


1.25.1.1
log
@Added cross product and dot product.
@
text
@d4 1
a4 1
static char rcsid[] = "$Id: Point_c.m4,v 1.25 1994/11/10 18:49:44 ljr Exp thoth $";
a11 3
// Revision 1.25  1994/11/10  18:49:44  ljr
// Added IA_NO_RCS_STATIC_DATA guard.
//
a119 2
#include "point_errors.h"

a1132 25
POINT_TYPE cross(const POINT_TYPE &a, const POINT_TYPE &b)
{
    if (a.dim()!=3 || b.dim()!=3) {
	ia_throw(Point_CrossProductRequireDimension3_Exception(__FILE__,__LINE__));
	return POINT_TYPE `()';
    }

    return POINT_TYPE `'(a[1]*b[2]-a[2]*b[1],
			 a[2]*b[0]-a[0]*b[2],
			 a[0]*b[1]-a[1]*b[0]);
}

TYPE dot(const POINT_TYPE &a, const POINT_TYPE &b)
{
    if (a.dim() != b.dim()) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);  
	return TYPE `'();  
    }

    TYPE	rval=0;
    for (int i=0; i<a.dim(); i++) {
	rval += a[i]*b[i];
    }
    return rval;
}
@


1.25.1.2
log
@All throws are now of class objects.
@
text
@d4 1
a4 1
static char rcsid[] = "$Id: Point_c.m4,v 1.25.1.1 1994/11/30 16:16:38 thoth Exp thoth $";
a11 3
// Revision 1.25.1.1  1994/11/30  16:16:38  thoth
// Added cross product and dot product.
//
d343 1
a343 1
	ia_throw(Point_BadIndex_Exception(__FILE__, __LINE__));
d433 1
a433 1
	ia_throw(Point_BadIndex_Exception(__FILE__, __LINE__));
d449 1
a449 1
	ia_throw(Point_BadIndex_Exception(__FILE__, __LINE__));
d466 1
a466 1
	ia_throw(Point_BadIndex_Exception(__FILE__, __LINE__));
d484 1
a484 1
	ia_throw(Point_BadIndex_Exception(__FILE__, __LINE__));
d502 1
a502 1
	ia_throw(Point_BadIndex_Exception(__FILE__, __LINE__));
d524 1
a524 1
	    ia_throw(Point_BadIndex_Exception(__FILE__, __LINE__));
d570 1
a570 1
    ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d606 1
a606 1
    ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d645 1
a645 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d679 1
a679 1
       ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d693 1
a693 1
       ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d749 1
a749 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d780 1
a780 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d791 1
a791 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d802 1
a802 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d814 1
a814 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d830 1
a830 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d861 1
a861 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d1075 1
a1075 1
	ia_throw(Point_Uninitialized_Exception(__FILE__, __LINE__));;
d1153 1
a1153 1
	ia_throw(Point_DimensionMismatch_Exception(__FILE__, __LINE__));  
@


1.24
log
@*** empty log message ***
@
text
@d3 3
a5 1
static char rcsid[] = "$Id: Point_c.m4,v 1.23 1994/09/13 21:02:51 fjsoria Exp fjsoria $";
d12 3
@


1.23
log
@correction to derange for no_loop_unrolling
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point_c.m4,v 1.22 1994/08/25 19:28:53 fjsoria Exp fjsoria $";
d10 3
a106 2
ifdef(`INTPOINT', `#include "IntPoint.h"')
ifdef(`DOUBLEPOINT', `#include "DblPoint.h"')
d109 2
a110 1
#pragma implementation
d112 2
@


1.22
log
@abs is not defined in c-front redefined abs, fixed bug in derange
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point_c.m4,v 1.21 1994/08/25 18:07:25 fjsoria Exp fjsoria $";
d10 3
d507 2
a508 2
    
    for (unsigned i=0; i<vecLen; i++) {
d518 1
a518 1
    for (unsigned i = 0; i < vecLen; i++)
d530 1
a530 1
		for (unsigned i = 0; i < vecLen; i++)
d897 2
a898 1

d900 1
a900 1
    for (unsigned i = 0; i < p.dim(); i++) 
d912 1
a912 1
		for (unsigned i = 0; i < p.dim(); i++) 
@


1.21
log
@removed abs for scalars since it is supported by UNIX, DOS, and Mac
platforms
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point_c.m4,v 1.20 1994/08/25 03:24:11 gmt Exp fjsoria $";
d10 4
d420 1
a420 1
    TYPE *p = new TYPE [pt.dim()];
d423 1
a423 1
    return POINT_TYPE ( p, pt.dim(), 1);
d436 1
a436 1
    TYPE *p = new TYPE [pt.dim()];
d440 1
a440 1
    return POINT_TYPE ( p, pt.dim(), 1);
d453 1
a453 1
    TYPE *p = new TYPE [pt.dim()];
d457 1
a457 1
    return POINT_TYPE ( p, pt.dim(), 1);
d471 1
a471 1
    TYPE *p = new TYPE [pt.dim()];
d476 1
a476 1
    return POINT_TYPE ( p, pt.dim(), 1);
d489 1
a489 1
    TYPE *p = new TYPE [pt.dim()];
d495 1
a495 1
    return POINT_TYPE ( p, pt.dim(), 1);
d515 1
a515 1
    for (unsigned i = 0; i < pt.dim(); i++)
d518 1
a518 1
    switch (pt.dim()) {
d527 1
a527 1
		for (unsigned i = 0; i < pt.dim(); i++)
d532 9
a540 1
    return POINT_TYPE ( p, pt.dim(), 1);
d546 1
d561 1
a561 1
    result[i] = abs(p(i));
d564 5
a568 5
  case 5: result[4] = abs(p(4));  
  case 4: result[3] = abs(p(3));  
  case 3: result[2] = abs(p(2));  
  case 2: result[1] = abs(p(1));
  case 1: result[0] = abs(p(0));  
d573 1
a573 1
	result[i] = abs(p(i));
@


1.20
log
@Added Mac specific pragma (template_access) to tell the compiler that the
generated files are actually template instances via template instantiation.
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point_c.m4,v 1.19 1994/08/22 14:39:02 thoth Exp gmt $";
d10 4
a533 10
// abs uses TYPE and Static so it will not overlap users name space
// abs uses TYPE and Static so it will not overlap users name space

inline static TYPE IA_abs ( TYPE t)
{
  t = (t < 0) ? -t : t;
  return t;
}


d548 1
a548 1
    result[i] = IA_abs(p(i));
d551 5
a555 5
  case 5: result[4] = IA_abs(p(4));  
  case 4: result[3] = IA_abs(p(3));  
  case 3: result[2] = IA_abs(p(2));  
  case 2: result[1] = IA_abs(p(1));
  case 1: result[0] = IA_abs(p(0));  
d560 1
a560 1
	result[i] = IA_abs(p(i));
@


1.19
log
@fixed conflict with system's abs.
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point_c.m4,v 1.18 1994/08/18 17:51:28 fjsoria Exp thoth $";
d10 3
d98 4
@


1.18
log
@corrected DoublePoint.h .c to DblPoint.h .c for DOS compat.
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.17 1994/08/16 21:03:13 fjsoria Exp fjsoria $";
d9 4
a12 1
// $Log: Point.c.m4,v $
d526 1
a526 9
#ifndef __BCPLUSPLUS__
ifdef(`INTPOINT', `#define IA_NEED_INT_ABS')
#endif
     
ifdef(`DOUBLEPOINT', `#define IA_NEED_DOUBLE_ABS')
ifdef(`INTPOINT', `#ifdef IA_NEED_INT_ABS')
ifdef(`DOUBLEPOINT', `#ifdef IA_NEED_DOUBLE_ABS')

inline static TYPE abs ( TYPE t)
a530 1
#endif
d547 1
a547 1
    result[i] = abs(p(i));
d550 5
a554 5
  case 5: result[4] = abs(p(4));  
  case 4: result[3] = abs(p(3));  
  case 3: result[2] = abs(p(2));  
  case 2: result[1] = abs(p(1));
  case 1: result[0] = abs(p(0));  
d559 1
a559 1
	result[i] = abs(p(i));
@


1.17
log
@added derange and enorm as non-member functions, keeping member versions
added inorm, mnorm, abs, fabs as non-member functions
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.16 1994/07/25 16:42:26 thoth Exp fjsoria $";
d10 4
d88 1
a88 1
ifdef(`DOUBLEPOINT', `#include "DoublePoint.h"')
d523 1
d525 2
@


1.16
log
@FloatPoint is now either Point<double> or DoublePoint.
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.15 1994/03/14 18:44:44 jnw Exp thoth $";
d10 3
d389 2
a390 1
POINT_TYPE POINT_TYPE::derange (unsigned i0) const
d392 2
a393 3
    POINT_TYPE p(0);
    
    if (i0 >= this->dim()) {
d397 5
a401 2
    p.coordinates[0] = this->coordinates[i0];
    return p;
d405 1
a405 1
POINT_TYPE POINT_TYPE::derange (unsigned i0, unsigned i1) const
d407 1
a407 1
    POINT_TYPE p((TYPE)0, (TYPE)0);
d409 1
a409 1
    if (i0 >= this->dim() || i1 >= this->dim()) {
d413 6
a418 3
    p.coordinates[0] = this->coordinates[i0];
    p.coordinates[1] = this->coordinates[i1];
    return p;
d422 1
a422 1
POINT_TYPE POINT_TYPE::derange (unsigned i0, unsigned i1, unsigned i2) const
d424 1
a424 1
    POINT_TYPE p((TYPE)0, (TYPE)0, (TYPE)0);
d426 1
a426 1
    if (i0 >= this->dim() || i1 >= this->dim() || i2 >= this->dim()) {
d430 6
a435 5
    
    p.coordinates[0] = this->coordinates[i0];
    p.coordinates[1] = this->coordinates[i1];
    p.coordinates[2] = this->coordinates[i2];
    return p;
d438 4
a441 1
POINT_TYPE POINT_TYPE::derange (unsigned i0, unsigned i1, unsigned i2, unsigned i3) const
d443 2
a444 3
    POINT_TYPE p(0,0,0,0);

    if (i0 >= this->dim() || i1 >= this->dim() || i2 >= this->dim() || i3 >= this->dim()) {
d449 6
a454 5
    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;
d457 2
a458 1
POINT_TYPE POINT_TYPE::derange (unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4) const
d460 3
a462 4
    POINT_TYPE p(0,0,0,0,0);

    if (i0 >= this->dim() || i1 >= this->dim() || i2 >= this->dim() ||
	i3 >= this->dim() || i4 >= this->dim()) {
d467 7
a473 6
    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;
d475 3
d479 1
a479 1
POINT_TYPE POINT_TYPE::derange (unsigned *vec, const unsigned vecLen) const
d484 1
a484 1
	if (vec[i] >= this->dim()) {
d490 1
a490 2
    POINT_TYPE  point;  // Our new point
    point.coordinates = new TYPE[point.dimen = vecLen];
d493 2
a494 2
    for (unsigned i = 0; i < this->dim(); i++)
	this->coordinates[i] = point.coordinates[vec[i]];
d496 6
a501 6
    switch (this->dim()) {
    case 5: this->coordinates[4] = point.coordinates[vec[4]];
    case 4: this->coordinates[3] = point.coordinates[vec[3]];
    case 3: this->coordinates[2] = point.coordinates[vec[2]];
    case 2: this->coordinates[1] = point.coordinates[vec[1]];
    case 1: this->coordinates[0] = point.coordinates[vec[0]];
d505 2
a506 2
		for (unsigned i = 0; i < this->dim(); i++)
		    this->coordinates[i] = point.coordinates[vec[i]];
d510 142
a651 1
    return point;
d654 1
d656 11
a789 13

// enorm: Euclidean distance from origin.

double POINT_TYPE::enorm () const
{
    double result_number = 0;
    
    for (unsigned i = 0; i < this->dim(); i++)
	result_number = result_number +
	    (double) (this->coordinates[i] * this->coordinates[i]);
    
    return sqrt(result_number);
}
@


1.15
log
@Modified sum and product
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.14 1994/03/14 18:33:16 jnw Exp jnw $";
d10 3
d81 1
a81 1
ifdef(`FLOATPOINT', `#include "FloatPoint.h"')
d178 3
a180 3
ifdef(`FLOATPOINT',`
//  FloatPoint includes IntPoint.h so we can have a constructor
//  from IntPoint to FloatPoint: this gives us all FloatPoint/IntPoint
d532 9
a540 9
ifdef(`FLOATPOINT', `ARITH_FLOAT_INTPOINT(+)')
ifdef(`FLOATPOINT', `ARITH_FLOAT_INTPOINT(-)')
ifdef(`FLOATPOINT', `ARITH_FLOAT_INTPOINT(*)')
ifdef(`FLOATPOINT', `ARITH_FLOAT_INTPOINT(/)')

ifdef(`FLOATPOINT', `ARITH_INTPOINT_FLOAT(+)')
ifdef(`FLOATPOINT', `ARITH_INTPOINT_FLOAT(-)')
ifdef(`FLOATPOINT', `ARITH_INTPOINT_FLOAT(*)')
ifdef(`FLOATPOINT', `ARITH_INTPOINT_FLOAT(/)')
d701 1
a701 1
ifdef(`FLOATPOINT', `
d705 1
a705 1
// for irint, nint and trunc, the routines always return float points.
d709 5
a713 5
ifdef(`FLOATPOINT', `ROUNDING_FLOAT_TO_FLOAT(aint)')
ifdef(`FLOATPOINT', `ROUNDING_FLOAT_TO_FLOAT(anint)')
ifdef(`FLOATPOINT', `ROUNDING_FLOAT_TO_FLOAT(ceil)')
ifdef(`FLOATPOINT', `ROUNDING_FLOAT_TO_FLOAT(floor)')
ifdef(`FLOATPOINT', `ROUNDING_FLOAT_TO_FLOAT(rint)')
d715 2
a716 2
ifdef(`FLOATPOINT', `ROUNDING_FLOAT_TO_INT(irint)')
ifdef(`FLOATPOINT', `ROUNDING_FLOAT_TO_INT(nint)')
d718 1
a718 1
ifdef(`FLOATPOINT', `
d794 6
a799 6
// Intpoint op float
LATTICE_INTPOINT_FLOAT(<)
LATTICE_INTPOINT_FLOAT(<=)
LATTICE_INTPOINT_FLOAT(>)
LATTICE_INTPOINT_FLOAT(>=)
LATTICE_INTPOINT_FLOAT(==)
d807 6
a812 6
// float < INTPOINT
LATTICE_FLOAT_INTPOINT(<)
LATTICE_FLOAT_INTPOINT(<=)
LATTICE_FLOAT_INTPOINT(>)
LATTICE_FLOAT_INTPOINT(>=)
LATTICE_FLOAT_INTPOINT(==)
@


1.14
log
@Added point reduce functions 'sum' and 'product'
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.13 1993/11/16 13:27:10 thoth Exp jnw $";
d10 3
d634 1
a634 1
POINT_TYPE sum(const POINT_TYPE &p)
d636 1
a636 1
    POINT_TYPE result;
d665 1
a665 1
POINT_TYPE product(const POINT_TYPE &p)
d667 1
a667 1
    POINT_TYPE result;
@


1.13
log
@Pointcmp is now pointcmp
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.12 1993/09/15 12:25:58 thoth Exp thoth $";
d10 3
d625 36
d662 29
a690 1
    return sqrt(result_number);
d692 1
@


1.12
log
@Point is now a template with specializations only.
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.11 93/05/28 15:43:31 thoth Exp Locker: thoth $";
d9 4
a12 1
// $Log:	Point.c.m4,v $
d746 1
a746 1
//  Point comparison: Pointcmp(POINT_TYPE, POINT_TYPE)
d754 1
a754 1
int Pointcmp(const POINT_TYPE &lhs, const POINT_TYPE &rhs)
@


1.11
log
@fix comment errors.
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.10 1993/05/26 16:59:57 rjj Exp thoth $";
d9 4
a12 1
// $Log: Point.c.m4,v $
d106 1
a106 1
POINT_TYPE::POINT_TYPE (const POINT_TYPE &ip)
d136 1
a136 1
POINT_TYPE::POINT_TYPE (TYPE *vec, unsigned length, int giveaway)
d171 1
a171 1
POINT_TYPE::POINT_TYPE (const IA_IntPoint &ipt) {
d642 1
a642 1
IA_IntPoint trunc(const IA_FloatPoint& p) 
d665 1
a665 1
    return IA_IntPoint(iptr, p.dim(), 1);
d804 1
a804 1
IA_IntPoint IA_IntPoint::operator ~ () const
d806 1
a806 1
    IA_IntPoint result_point;
@


1.10
log
@Added copyright notice
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.c.m4,v 1.9 93/04/06 22:28:17 rjj Exp Locker: rjj $";
d9 4
a12 1
// $Log:	Point.c.m4,v $
a679 1
#// LATTICE_POINT_POINT(!=)  Wrong, consider <1,2>!=<2,2>
a693 1
#// LATTICE_POINT_NUMBER(!=)  Wrong
a706 1
#//LATTICE_NUMBER_POINT(!=)
a720 1
#//LATTICE_INTPOINT_FLOAT(!=)
a733 1
#//LATTICE_FLOAT_INTPOINT(!=)
@


1.9
log
@Changed name of file from "Point.C.m4" to "Point.c.m4"
Fixed lattice bugs with != by defining functions to invoke ==
Changed "const {int|double}" to "{int|double}"
Fixed a leftover FloatPoint name ref in trunc()
Changed bitwise unsigned parameters to int
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.8 93/04/05 23:18:00 rjj Exp Locker: rjj $";
d6 2
d9 8
a16 1
// $Log:	Point.C.m4,v $
@


1.8
log
@Many changes to support changes necessary to mutate to the
  interface defined by newpoint.  Please see the list for
  Point.h.m4 revison 2.10
  Error in operator ~ () corrected
  Lattice operator != is probably still wrong, need to check !
  m4 defines *_*_RELATION changed to LATTICE_*_*
  Postfix ++ and -- code added
  file rearanged to suit my tastes, your milage my vary ;-)
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.7 92/12/11 01:10:35 rjj Exp Locker: rjj $";
d8 10
d627 1
a627 1
IA_IntPoint trunc(const FloatPoint& p) 
a666 1
LATTICE_POINT_POINT(!=)
d668 7
a681 1
LATTICE_POINT_NUMBER(!=)
d683 6
a695 1
LATTICE_NUMBER_POINT(!=)
d697 7
a710 1
LATTICE_INTPOINT_FLOAT(!=)
d712 7
d725 6
a730 1
LATTICE_FLOAT_INTPOINT(!=)
@


1.7
log
@Modified to support the IA_ prefix naming convention.
Also put #ifdef IA_PRII around the #pragma stmt
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.6 92/09/02 14:51:27 rjj Exp Locker: rjj $";
d8 4
d50 3
a52 4
ifdef(`FLOATPOINT',`    
//  FloatPoint includes IntPoint.h so we can have a constructor
//  from IntPoint to FloatPoint: this gives us all FloatPoint/IntPoint
//  operations for free.
a53 28
    FloatPoint::FloatPoint(const IntPoint &ipt) {

//  new TYPE[0] will allocate a pointer to one TYPE; we ignore it
//  to keep from having to insert an "if (size == 0) ..." everywhere.

    this->coordinates = new TYPE[this->size = ipt.dimensions()];

#ifdef NO_LOOP_UNROLLING
   for (unsigned i = 0; i < this->size; i++)
	this->coordinates[i] = ipt[i];
#else
    switch (this->size) {
    case 5: this->coordinates[4] = ipt[4];
    case 4: this->coordinates[3] = ipt[3];
    case 3: this->coordinates[2] = ipt[2];
    case 2: this->coordinates[1] = ipt[1];
    case 1: this->coordinates[0] = ipt[0];
    case 0: break;     
    default:
	    {
		for (unsigned i = 0; i < this->size; i++)
		    this->coordinates[i] = ipt[i];
	    }
    }
#endif
}
')

d57 1
a57 1
    pt.coordinates = new TYPE[pt.size = length];
d63 1
a63 1
    switch (pt.size) {
d85 1
a85 1
// This is to keep from having to do "if (size == 0) ..." everywhere.
d88 1
a88 1
    this->coordinates = new TYPE[this->size = ip.size];
d91 1
a91 1
    for (unsigned i=0; i<this->size; i++)
d94 1
a94 1
    switch (this->size) {
d103 1
a103 1
		for (unsigned i=0; i<this->size; i++)
d110 1
d113 1
a113 1
    this->size=length;
d119 1
a119 1
    this->coordinates = new TYPE[this->size];
d122 1
a122 1
    for (unsigned length=0; length<this->size; length++)
d125 1
a125 1
    switch (this->size) {
d134 1
a134 1
		for (unsigned length=0; length<this->size; length++)
d141 4
d146 1
a146 3
POINT_TYPE &POINT_TYPE::operator = (const POINT_TYPE &point)
{
    // return directly when self-assignment (not sure the if is worth it in general)
d148 1
a148 2
    if (this == &point)
	return *this;
a149 7
    // We need to deallocate/reallocate if differing sizes.
    
    if (point.size != this->size) {
        delete[] this->coordinates;
        this->coordinates = new TYPE[this->size = point.size];
    }

d151 2
a152 2
    for (unsigned i = 0; i < this->size; i++)
	this->coordinates[i] = point.coordinates[i];
d154 7
a160 7
    switch (this->size) {
    case 5: this->coordinates[4] = point.coordinates[4];
    case 4: this->coordinates[3] = point.coordinates[3];
    case 3: this->coordinates[2] = point.coordinates[2];
    case 2: this->coordinates[1] = point.coordinates[1];
    case 1: this->coordinates[0] = point.coordinates[0];
    case 0: break;
d162 4
a165 4
	    {
		for (unsigned i = 0; i < this->size; i++)
		    this->coordinates[i] = point.coordinates[i];
	    }
a167 1
    return *this;
d169 1
d171 13
a183 1
ostream &operator << (ostream &stream, const POINT_TYPE& point)
d185 21
a205 10
    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;
a207 4
COMPOUND_ARITH_ASSIGN_POINT(+)
COMPOUND_ARITH_ASSIGN_POINT(-)
COMPOUND_ARITH_ASSIGN_POINT(*)
COMPOUND_ARITH_ASSIGN_POINT(/)
d209 3
d213 2
a214 4
COMPOUND_ARITH_ASSIGN_NUMBER(+)
COMPOUND_ARITH_ASSIGN_NUMBER(-)
COMPOUND_ARITH_ASSIGN_NUMBER(*)
COMPOUND_ARITH_ASSIGN_NUMBER(/)
d216 1
d218 2
a219 4
ARITH_POINT_POINT(+)
ARITH_POINT_POINT(-)
ARITH_POINT_POINT(*)
ARITH_POINT_POINT(/)
d221 2
a222 4
ARITH_NUMBER_POINT(+)
ARITH_NUMBER_POINT(-)
ARITH_NUMBER_POINT(*)
ARITH_NUMBER_POINT(/)
d224 1
a224 4
ARITH_POINT_NUMBER(+)
ARITH_POINT_NUMBER(-)
ARITH_POINT_NUMBER(*)
ARITH_POINT_NUMBER(/)
d226 1
a226 17
ifdef(`FLOATPOINT', `ARITH_NUMBER_INTPOINT(+)')
ifdef(`FLOATPOINT', `ARITH_NUMBER_INTPOINT(-)')
ifdef(`FLOATPOINT', `ARITH_NUMBER_INTPOINT(*)')
ifdef(`FLOATPOINT', `ARITH_NUMBER_INTPOINT(/)')

ifdef(`FLOATPOINT', `ARITH_INTPOINT_NUMBER(+)')
ifdef(`FLOATPOINT', `ARITH_INTPOINT_NUMBER(-)')
ifdef(`FLOATPOINT', `ARITH_INTPOINT_NUMBER(*)')
ifdef(`FLOATPOINT', `ARITH_INTPOINT_NUMBER(/)')

const POINT_TYPE& POINT_TYPE::operator ++ () {
    if (this->size == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this += 1;
    return  *this;
a228 8
const POINT_TYPE& POINT_TYPE::operator -- () {
    if (this->size == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return *this;
    }
    *this -= 1;
    return  *this;
}
d230 1
a230 2

POINT_TYPE POINT_TYPE::operator - () const
d233 3
d237 1
a237 4
    if (this->size == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
	return result_point;
    }
d239 2
a240 1
    result_point.coordinates = new TYPE[result_point.size = this->size];
d242 5
a246 18
#ifdef NO_LOOP_UNROLLING
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] =  -this->coordinates[i];
#else
    switch (result_point.size) {
    case 5: result_point.coordinates[4] = -this->coordinates[4];
    case 4: result_point.coordinates[3] = -this->coordinates[3];
    case 3: result_point.coordinates[2] = -this->coordinates[2];
    case 2: result_point.coordinates[1] = -this->coordinates[1];
    case 1: result_point.coordinates[0] = -this->coordinates[0];
    case 0: break;
    default:
	    {
		for (unsigned i = 0; i < result_point.size; i++)
		    result_point.coordinates[i] =  - this->coordinates[i];
	    }
    }
#endif
d250 5
a254 6
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(%)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(<<)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(>>)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(&)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(^)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_POINT(|)')
a255 6
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(%)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(<<)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(>>)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(&)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(^)')
ifdef(`INTPOINT', `COMPOUND_BITWISE_ASSIGN_NUMBER(|)')
d257 1
a257 6
ifdef(`INTPOINT', `BITWISE_POINT_POINT(%)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(<<)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(>>)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(&)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(^)')
ifdef(`INTPOINT', `BITWISE_POINT_POINT(|)')
d259 3
a261 4
ifdef(`INTPOINT', `
IntPoint IntPoint::operator ~ () const
{
    IntPoint result_point;
d263 22
a284 2
    if (this->size == 0) {
	ia_throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);
d286 6
a293 2
    result_point.coordinates = new int[result_point.size = this->size];

d295 2
a296 2
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] =  ~(this->coordinates[i]);
d298 6
a303 6
    switch (result_point.size) {
    case 5: result_point.coordinates[4] = ~(this->coordinates[4]);
    case 4: result_point.coordinates[3] = ~(this->coordinates[3]);
    case 3: result_point.coordinates[2] = ~(this->coordinates[2]);
    case 2: result_point.coordinates[1] = ~(this->coordinates[1]);
    case 1: result_point.coordinates[0] = ~(this->coordinates[0]);
d307 2
a308 2
		for (unsigned i = 0; i < result_point.size; i++)
		    result_point.coordinates[i] =  - this->coordinates[i];
d311 3
a313 3
#endif    
    return result_point;
}')
d316 2
a317 6
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(%)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(<<)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(>>)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(&)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(^)')
ifdef(`INTPOINT', `BITWISE_NUMBER_POINT(|)')
d319 2
a320 6
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(%)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(<<)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(>>)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(&)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(^)')
ifdef(`INTPOINT', `BITWISE_POINT_NUMBER(|)')
a321 1
// Relational operators
d323 13
a335 1
// POINT_TYPE < POINT_TYPE    
a336 6
POINT_POINT_RELATION(<)
POINT_POINT_RELATION(<=)
POINT_POINT_RELATION(>)
POINT_POINT_RELATION(>=)
POINT_POINT_RELATION(==)
POINT_POINT_RELATION(!=)
d338 3
a340 37
// POINT_TYPE < int

POINT_INT_RELATION(<)
POINT_INT_RELATION(<=)
POINT_INT_RELATION(>)
POINT_INT_RELATION(>=)
POINT_INT_RELATION(==)
POINT_INT_RELATION(!=)

// int < POINT_TYPE 

INT_POINT_RELATION(<)
INT_POINT_RELATION(<=)
INT_POINT_RELATION(>)
INT_POINT_RELATION(>=)
INT_POINT_RELATION(==)
INT_POINT_RELATION(!=)

// POINT_TYPE < float
    
POINT_FLOAT_RELATION(<)
POINT_FLOAT_RELATION(<=)
POINT_FLOAT_RELATION(>)
POINT_FLOAT_RELATION(>=)
POINT_FLOAT_RELATION(==)
POINT_FLOAT_RELATION(!=)

// float < POINT_TYPE

FLOAT_POINT_RELATION(<)
FLOAT_POINT_RELATION(<=)
FLOAT_POINT_RELATION(>)
FLOAT_POINT_RELATION(>=)
FLOAT_POINT_RELATION(==)
FLOAT_POINT_RELATION(!=)


d343 4
a346 3
// Function call overloading on Point gives us a new Point with
// by-point_index selection.  For instance, let  a=Point(10, 20, 30).
// Then b=a(2,0) is equivalent to b=Point(30,10).
d349 1
a349 1
POINT_TYPE POINT_TYPE::operator () (unsigned i0) const
d353 1
a353 1
    if (i0 >= this->size) {
d361 2
a362 1
POINT_TYPE POINT_TYPE::operator () (unsigned i0, unsigned i1) const
d364 1
a364 1
    POINT_TYPE p((int)0,(int)0);
d366 1
a366 1
    if (i0 >= this->size || i1 >= this->size) {
d375 2
a376 1
POINT_TYPE POINT_TYPE::operator () (unsigned i0, unsigned i1, unsigned i2) const
d378 1
a378 1
    POINT_TYPE p((int)0,0,0);
d380 1
a380 1
    if (i0 >= this->size || i1 >= this->size || i2 >= this->size) {
d391 1
a391 1
POINT_TYPE POINT_TYPE::operator () (unsigned i0, unsigned i1, unsigned i2, unsigned i3) const
d395 1
a395 1
    if (i0 >= this->size || i1 >= this->size || i2 >= this->size || i3 >= this->size) {
d407 1
a407 1
POINT_TYPE POINT_TYPE::operator () (unsigned i0, unsigned i1, unsigned i2, unsigned i3, unsigned i4) const
d411 2
a412 2
    if (i0 >= this->size || i1 >= this->size || i2 >= this->size ||
	i3 >= this->size || i4 >= this->size) {
d425 1
a425 4

// enorm: Euclidean distance from origin.

double POINT_TYPE::enorm () const
d427 1
a427 1
    double result_number = 0;
d429 6
a434 3
    for (unsigned i = 0; i < this->size; i++)
	result_number = result_number +
	    (double) (this->coordinates[i] * this->coordinates[i]);
d436 22
a457 1
    return sqrt(result_number);
a460 5
// POINT_TYPE = concat (POINT_TYPE, POINT_TYPE)
//
// Given a combination of Points and numbers, create a new Point that is
// the concatenation of the arguments.  Lets the user construct larger
// points than the usual 5 arg constructor.
a461 4
// TO DO -- These could be modified to not check for zero-length
// points (since we now know that "new foo[0]" returns a deletable
// pointer to one foo that we will never access), and also we could
// do some loop unrolling here as well.
a462 11
POINT_TYPE concat(const POINT_TYPE& lhs, const POINT_TYPE& rhs)
{
    POINT_TYPE result_point;
    
    if (lhs.size == 0) {
	if (rhs.size == 0)
	    return result_point;
	else 
	    return rhs;
    } else if (rhs.size == 0)
	return lhs;
d464 3
a466 1
    unsigned int total_size = lhs.size + rhs.size;
d468 10
a477 1
    result_point.coordinates = new TYPE[result_point.size = total_size];
a478 2
    for (unsigned int i = 0; i < lhs.size; i++) 
	result_point.coordinates[i] = lhs.coordinates[i];
d480 19
a498 2
    for (unsigned int j = 0; j < rhs.size; j++) 
	result_point.coordinates[i+j] = rhs.coordinates[j];
d500 4
a503 2
    return result_point;
}
a504 1
// POINT_TYPE = concat(POINT_TYPE, TYPE)
d506 1
a506 1
POINT_TYPE concat(const POINT_TYPE& lhs, TYPE rhs)
d510 4
a513 4
    if (lhs.size == 0) 
	return POINT_TYPE (rhs);
    
    unsigned int total_size = lhs.size + 1;
d515 20
a534 8
    result_point.coordinates = new TYPE[total_size];
    result_point.size = total_size;
    
    for (unsigned int i = 0; i < lhs.size; i++) 
	result_point.coordinates[i] = lhs.coordinates[i];
    
    result_point.coordinates[i] = rhs;
    
a537 1
// POINT_TYPE = concat(TYPE, POINT_TYPE)
d539 9
a547 6
POINT_TYPE concat(TYPE lhs, const POINT_TYPE& rhs)
{
    POINT_TYPE result_point;
    
    if (rhs.size == 0)
	return POINT_TYPE (lhs);
a548 1
    unsigned int total_size = rhs.size + 1;
d550 9
a558 2
    result_point.coordinates = new TYPE[total_size];
    result_point.size = total_size;
a559 1
    result_point.coordinates[0] = lhs;
d561 9
a569 4
    for (unsigned int i = 0; i < rhs.size; i++) 
	result_point.coordinates[i+1] = rhs.coordinates[i];

    return result_point;
a571 5
//  cdr(POINT_TYPE, skip=1):
//
//  Given a point of dimension n, return a point made of the n-skip last
//  coordinates (or if skip is negative, the n+skip first coordinates),
//  where skip defaults to 1.
d573 10
a583 1
POINT_TYPE cdr(const POINT_TYPE& pt, int skip) {
d585 1
a585 1
    unsigned  abs_skip;
d587 3
a589 1
    abs_skip = (skip < 0) ? -skip : skip;
d591 3
a593 5
    if (pt.size < abs_skip) {
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	return POINT_TYPE ();
    } else if (pt.size == skip)
	return POINT_TYPE ();
d595 1
a595 4
    if (skip < 0)
	return POINT_TYPE (pt.coordinates, pt.size+skip);
    else
	return POINT_TYPE (pt.coordinates+skip, pt.size-skip);
a597 2
FRIEND_SELECT_BINARY(infimum, <)
FRIEND_SELECT_UNARY(min, <)
a598 3
FRIEND_SELECT_BINARY(supremum, >)
FRIEND_SELECT_UNARY(max, >)

d617 1
a617 1
IntPoint trunc(const FloatPoint& p) 
d620 1
a620 1
    iptr = new int[p.size];	    
d623 1
a623 1
    for (unsigned i = 0; i < p.size; i++) 
d626 1
a626 1
    switch (p.size) {
d635 1
a635 1
		for (unsigned i = 0; i < p.size; i++) 
d640 1
a640 1
    return IntPoint(iptr, p.size, 1);
d644 51
d705 2
a706 2
    if (lhs.dimensions() > rhs.dimensions()) {
	for (unsigned i=0; i < rhs.dimensions(); i++) {
d712 1
a712 1
	for ( ; i<lhs.dimensions(); i++) {
d719 1
a719 1
	for (unsigned i=0; i < lhs.dimensions(); i++) {
d725 1
a725 1
	for ( ; i < rhs.dimensions(); i++) {
d741 1
a741 1
    //     if (lhs.dimensions() == rhs.dimensions())
d743 1
a743 1
    //     else if (lhs.dimensions() > rhs.dimensions())
d749 75
@


1.6
log
@Corrected code in FloatPoint( IntPoint ) to allocated array of type TYPE
Changed enorm() cast from (float) to (double)
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.5 92/09/01 21:08:17 rjj Exp Locker: rjj $";
d8 4
d42 1
d44 1
@


1.5
log
@Changed max(POINT_TYPE,POINT_TYPE) to be supremum(POINT_TYPE,POINT_TYPE)
Changed min(POINT_TYPE,POINT_TYPE) to be infimum(POINT_TYPE,POINT_TYPE)
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.4 92/09/01 20:46:24 rjj Exp Locker: rjj $";
d8 4
d47 1
a47 1
//  new float[0] will allocate a pointer to one float; we ignore it
d50 1
a50 1
    this->coordinates = new float[this->size = ipt.dimensions()];
d504 1
a504 1
	    (float) (this->coordinates[i] * this->coordinates[i]);
@


1.4
log
@Added support to ensure float op IntPoint and IntPoint op float yield FloatPoint.
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.3 92/08/27 12:11:55 jnw Exp Locker: rjj $";
d8 3
d611 1
a611 1
FRIEND_SELECT_BINARY(min, <)
d614 1
a614 1
FRIEND_SELECT_BINARY(max, >)
@


1.3
log
@Added C style comments around Log Messages to fixx gcc-cpp bug
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.2 92/08/23 13:33:19 thoth Exp Locker: jnw $";
d8 3
d229 10
@


1.2
log
@Cfrontified
didn't hint to inline for loop stuff any more (braindead compiler).
hack-around for switch statements that CFront's flow analysis
can't fully understand.
throw changed to ia_throw.
removed duplicate default values for formal parameters (ARM spec).
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 1.1 92/08/20 22:24:54 rjj Exp Locker: thoth $";
d5 2
d8 8
d21 2
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
static char rcsid[] = "$Id: Point.C.m4,v 2.7 92/08/20 21:59:10 rjj Exp $";
d6 2
d10 1
d16 1
d18 33
d68 4
a71 2
	for (unsigned i = 0; i < length; i++)
	    pt.coordinates[i] = initial_value;
d99 4
a102 2
	for (unsigned i=0; i<this->size; i++)
	    this->coordinates[i] = ip.coordinates[i];
d107 1
a107 1
POINT_TYPE::POINT_TYPE (TYPE *vec, unsigned length, int giveaway=0)
d129 4
a132 2
	for (unsigned length=0; length<this->size; length++)
		this->coordinates[length] = vec[length];
d164 4
a167 2
	for (unsigned i = 0; i < this->size; i++)
	    this->coordinates[i] = point.coordinates[i];
d256 4
a259 2
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] =  - this->coordinates[i];
d310 4
a313 2
    for (unsigned i = 0; i < result_point.size; i++)
	result_point.coordinates[i] =  - this->coordinates[i];
d403 1
a403 1
    POINT_TYPE p(0,0);
d416 1
a416 1
    POINT_TYPE p(0,0,0);
d565 1
a565 1
POINT_TYPE cdr(const POINT_TYPE& pt, int skip = 1) {
d624 4
a627 2
	for (unsigned i = 0; i < p.size; i++) 
	    iptr[i] = int(p.coordinates[i]);
@
