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


1.5
date     92.08.20.11.08.59;  author thoth;  state Exp;
branches ;
next     1.4;

1.4
date     92.08.14.15.46.00;  author thoth;  state Exp;
branches ;
next     1.3;

1.3
date     92.07.26.16.28.03;  author thoth;  state Exp;
branches ;
next     1.2;

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

1.1
date     92.07.16.11.55.32;  author thoth;  state Exp;
branches ;
next     ;


desc
@implementation of the Boxy IntPointSet object
@


1.5
log
@BaseIPS now requires the dimension upon construction
@
text
@// Emacs: -*- C++ -*-
static char rcsid[] = "$Id: BoxyIPS.cc,v 1.4 92/08/14 15:46:00 thoth Exp $";

// 
// $Log:	BoxyIPS.cc,v $
// Revision 1.4  92/08/14  15:46:00  thoth
// Added an index(IntPoint) function to the IntPointSet
// 
// Revision 1.3  92/07/26  16:28:03  thoth
// Added some comments so people might be able to understand the code.
// 
// Revision 1.2  92/07/21  11:17:54  thoth
// used IntPoints for the bounds
// 
// Revision 1.1  92/07/16  11:55:32  thoth
// Initial revision
// 
// 

#include "ia.h"
#include "BoxyIPS.h"
#pragma implementation

#include "IntPointSet.h"

// construct a BoxyIPS given two corners of the hyperrectangle
BoxyIPS::BoxyIPS(const IntPoint& p1, const IntPoint& p2)
: BaseIPS(p1.dimensions())
{
    // we should throw a different error when there is a mismatch.
    if (p1.dimensions()==0 || p1.dimensions() != p2.dimensions())
	throw(IA::POINT_UNINITIALIZED, __FILE__, __LINE__);

    // dimen can not be zero.  The two points must have equal dimension

    // this just gets them to have the right size
    start = end = p1;

    // start is pointwise <= end
    for (unsigned idx =0; idx<this->dimen; idx++) {
	if (p1[idx]<p2[idx]) {
	    this->start[idx] = p1[idx];
	    this->end[idx] = p2[idx];
	} else {
	    this->end[idx] = p1[idx];
	    this->start[idx] = p2[idx];
	}
    }
}

BoxyIPS& BoxyIPS::operator=(const BoxyIPS& bps)
{
    this->dimen = bps.dimen;
    this->start = bps.start;
    this->end = bps.end;

    return *this;
}

// The following code uses the member initialization syntax.  It's
// faster than allowing the no-argument constructor for members and
// then using assignment.
BoxyIPS::BoxyIPS(const BoxyIPS& bps)
: BaseIPS(bps.dimen),
  start(bps.start),
  end(bps.end)
{
}

int BoxyIPS::equal(BaseIPS * psb) const
{
    return psb->type() == BOXY &&
	*this == *(BoxyIPS*)psb;
}

int BoxyIPS::hash_self(int modulus) const
{
    unsigned	sigma = 0;
    for (unsigned i=0; i<this->dimen; i++) {
	sigma += this->start[i];
	sigma += this->end[i];
    }
    return sigma % modulus;
}

int BoxyIPS::operator==(const BoxyIPS& bps) const
{
    if (this->dimen != bps.dimen)
	return 0;

    return this->start == bps.start && this->end == bps.end;
}

int BoxyIPS::contains(IntPoint ip) const
{
    return this->start <= ip && ip <= this->end;
}

unsigned BoxyIPS::index(const IntPoint &ip) const
{
    if (!this->contains(ip)) {
	if (IntPointSet::throw_on_index_uncontained)
	    throw(IA::INVALID_OPERATION, __FILE__,__LINE__);
	return IntPointSet::index_of_uncontained;
    }

    unsigned offset=0;
    for (unsigned i=0; i<this->dimen; i++) {
	offset *= this->end[i] - this->start[i] +1;
	offset += ip[i] - this->start[i];
    }
    return offset;
}

unsigned BoxyIPS::card() const
{
    unsigned	size=1;

    for (unsigned idx=0; idx < this->dimen; idx++) {
	size *= this->end[idx] - this->start[idx] +1;
    }
    return size;
}

void BoxyIPS::output(ostream &o, unsigned indent) const
{
  for (unsigned i=0; i<indent; i++)
    o << ' ';
  o << start << ".." << end << '\n';
}
@


1.4
log
@Added an index(IntPoint) function to the IntPointSet
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: BoxyIPS.cc,v 1.3 92/07/26 16:28:03 thoth Exp Locker: thoth $";
d6 3
d28 1
a35 2
    this->dimen = p1.dimensions();

d64 1
a64 1
: dimen(bps.dimen),
d123 7
@


1.3
log
@Added some comments so people might be able to understand the code.
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: BoxyIPS.cc,v 1.2 92/07/21 11:17:54 thoth Exp Locker: thoth $";
d6 3
d21 2
d95 16
@


1.2
log
@used IntPoints for the bounds
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: BoxyIPS.cc,v 1.1 92/07/16 11:55:32 thoth Exp Locker: thoth $";
d6 3
d53 3
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char rcsid[] = "$Id$";
d5 3
a7 1
// $Log$
d9 1
d26 2
a27 3
    // start and end are never NULL
    this->start = new int[this->dimen];
    this->end = new int[this->dimen];
d43 3
a45 7
    if (this->dimen != bps.dimen) {
	delete[] this->start;
	delete[] this->end;
	this->dimen = bps.dimen;
	this->start = new int[this->dimen];
	this->end = new int[this->dimen];
    }
a46 5
    for (unsigned i=0; i < this->dimen; i++) {
	this->start[i] = bps.start[i];
	this->end[i] = bps.end[i];
    }

d51 3
a54 7
    this->dimen = bps.dimen;
    this->start = new int[this->dimen];
    this->end = new int[this->dimen];
    for (unsigned i=0; i < this->dimen; i++) {
	this->start[i] = bps.start[i];
	this->end[i] = bps.end[i];
    }
d65 2
a66 4
    int	sigma;
    unsigned i;
    sigma = 0;
    for (i=0; i<this->dimen; i++) {
d78 1
a78 6
    for (unsigned idx=0; idx<this->dimen; idx++)
	if (this->start[idx] != bps.start[idx] ||
	    this->end[idx] != bps.end[idx])
	    return 0;

    return 1;
d83 1
a83 5
    for (unsigned idx=0; idx < this->dimen; idx++) {
	if (ip[idx]<start[idx] || ip[idx] > end[idx] )
	    return 0;
    }
    return 1;
@
