diff options
-rw-r--r-- | Carpet/CarpetLib/src/bbox.cc | 33 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/bbox.hh | 79 |
2 files changed, 55 insertions, 57 deletions
diff --git a/Carpet/CarpetLib/src/bbox.cc b/Carpet/CarpetLib/src/bbox.cc index e6123db5a..9cf82183c 100644 --- a/Carpet/CarpetLib/src/bbox.cc +++ b/Carpet/CarpetLib/src/bbox.cc @@ -1,4 +1,4 @@ -// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.cc,v 1.21 2004/02/27 15:40:40 schnetter Exp $ +// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.cc,v 1.22 2004/03/11 12:03:44 schnetter Exp $ #include <assert.h> @@ -210,37 +210,6 @@ typename bbox<T,D>::iterator bbox<T,D>::end () const { return iterator(*this, upper()); } -template<class T, int D> -bbox<T,D>::iteratorT::iteratorT (const bbox& box, const vect<T,D>& pos) - : box(box), pos(pos) { - if (box.empty()) this->pos=box.upper(); -} - -template<class T, int D> -bool bbox<T,D>::iteratorT::operator!= (const iteratorT& i) const { - return any(pos!=i.pos); -} - -template<class T, int D> -typename bbox<T,D>::iteratorT& bbox<T,D>::iteratorT::operator++ () { - for (int d=D-1; d>=0; --d) { - pos[d]+=box.stride()[d]; - if (pos[d]<=box.upper()[d]) break; - pos[d]=box.lower()[d]; - } - return *this; -} - -template<class T, int D> -typename bbox<T,D>::iteratorT bbox<T,D>::beginT () const { - return iteratorT(*this, lower()); -} - -template<class T, int D> -typename bbox<T,D>::iteratorT bbox<T,D>::endT () const { - return iteratorT(*this, upper()); -} - // Input diff --git a/Carpet/CarpetLib/src/bbox.hh b/Carpet/CarpetLib/src/bbox.hh index fc691b531..d22ad33b6 100644 --- a/Carpet/CarpetLib/src/bbox.hh +++ b/Carpet/CarpetLib/src/bbox.hh @@ -1,4 +1,4 @@ -// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.hh,v 1.13 2003/09/19 16:06:41 schnetter Exp $ +// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.hh,v 1.14 2004/03/11 12:03:44 schnetter Exp $ #ifndef BBOX_HH #define BBOX_HH @@ -23,36 +23,61 @@ ostream& operator<< (ostream& os, const bbox<T,D>& b); -// Bounding box class +/** + * A bounding box, i.e. a rectangle with lower and upper bound and a + * stride. + */ template<class T, int D> class bbox { // Fields - vect<T,D> _lower, _upper, _stride; // bounds are inclusive + + /** Bounding box bounds and stride. The bounds are inclusive. */ + vect<T,D> _lower, _upper, _stride; public: // Constructors + + /** Construct an empty bbox. */ bbox (); + + /** Copy constructor. */ bbox (const bbox& b); + + /** Assignment operator. */ bbox& operator= (const bbox& b); + + /** Create a bbox from bounds and stride. */ bbox (const vect<T,D>& lower, const vect<T,D>& upper, const vect<T,D>& stride); // Accessors // (Don't return references; *this might be a temporary) + + /** Get lower bound. */ vect<T,D> lower () const { return _lower; } + + /** Get upper bound. */ vect<T,D> upper () const { return _upper; } + + /** Get stride. */ vect<T,D> stride () const { return _stride; } + + /** Get the shape (or extent). */ vect<T,D> shape () const { return _upper - _lower + _stride; } + /** Determine whether the bbox is empty. */ bool empty() const { return any(lower()>upper()); } + /** Return the size, which is the product of the shape. */ T size () const; // Queries + + /** Find out whether the bbox contains the point x. */ bool contains (const vect<T,D>& x) const; // Operators @@ -63,57 +88,57 @@ public: bool operator<= (const bbox& b) const; bool operator>= (const bbox& b) const; - // Intersection + /** Calculate the intersection (the set of common points) with the + bbox b. */ bbox operator& (const bbox& b) const; - // Containment + /** Find out whether this bbox is contained in the bbox b. */ bool is_contained_in (const bbox& b) const; - // Alignment check + /** Find out whether this bbox is aligned with the bbox b. + ("aligned" means that both bboxes have the same stride and that + their boundaries are commesurate.) */ bool is_aligned_with (const bbox& b) const; - // Expand the bbox a little by multiples of the stride + /** Expand (enlarge) the bbox by multiples of the stride. */ bbox expand (const vect<T,D>& lo, const vect<T,D>& hi) const; - // Find the smallest b-compatible box around *this + /** Find the smallest b-compatible box around this bbox. + ("compatible" means having the same stride.) */ bbox expanded_for (const bbox& b) const; - // Find the largest b-compatible box inside *this + /** Find the largest b-compatible box inside this bbox. */ bbox contracted_for (const bbox& b) const; - // Smallest bbox containing both boxes + /** Find the smallest bbox containing both boxes. */ bbox expanded_containing (const bbox<T,D>& b) const; // Iterators + + /** An iterator over all points in a bbox. */ class iterator { protected: + /** The bbox over which we iterate. */ const bbox& box; + /** Current position. */ vect<T,D> pos; public: + /** Constructor. */ iterator (const bbox& box, const vect<T,D>& pos); + /** Accessor. */ const vect<T,D>& operator* () const { return pos; } + /** Check whether the position is the same. */ bool operator!= (const iterator& i) const; + /** Advance. */ iterator& operator++ (); }; + /** Create an iterator that points to the first point in a bbox. */ iterator begin () const; + /** Create an iterator that points to the last point in a bbox. */ iterator end () const; - class iteratorT { - protected: - const bbox& box; - vect<T,D> pos; - public: - iteratorT (const bbox& box, const vect<T,D>& pos); - const vect<T,D>& operator* () const { return pos; } - bool operator!= (const iteratorT& i) const; - iteratorT& operator++ (); - }; - - iteratorT beginT () const; - iteratorT endT () const; - - // Input/Output + // Input/Output helpers void input (istream& is); void output (ostream& os) const; }; @@ -121,6 +146,8 @@ public: // Input + +/** Read a formatted bbox from a stream. */ template<class T,int D> inline istream& operator>> (istream& is, bbox<T,D>& b) { b.input(is); @@ -130,6 +157,8 @@ inline istream& operator>> (istream& is, bbox<T,D>& b) { // Output + +/** Write a bbox formatted to a stream. */ template<class T,int D> inline ostream& operator<< (ostream& os, const bbox<T,D>& b) { b.output(os); |