// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.hh,v 1.13 2003/09/19 16:06:41 schnetter Exp $ #ifndef BBOX_HH #define BBOX_HH #include #include "defs.hh" #include "vect.hh" using namespace std; // Forward declaration template class bbox; // Input/Output template istream& operator>> (istream& is, bbox& b); template ostream& operator<< (ostream& os, const bbox& b); // Bounding box class template class bbox { // Fields vect _lower, _upper, _stride; // bounds are inclusive public: // Constructors bbox (); bbox (const bbox& b); bbox& operator= (const bbox& b); bbox (const vect& lower, const vect& upper, const vect& stride); // Accessors // (Don't return references; *this might be a temporary) vect lower () const { return _lower; } vect upper () const { return _upper; } vect stride () const { return _stride; } vect shape () const { return _upper - _lower + _stride; } bool empty() const { return any(lower()>upper()); } T size () const; // Queries bool contains (const vect& x) const; // Operators bool operator== (const bbox& b) const; bool operator!= (const bbox& b) const; bool operator< (const bbox& b) const; bool operator> (const bbox& b) const; bool operator<= (const bbox& b) const; bool operator>= (const bbox& b) const; // Intersection bbox operator& (const bbox& b) const; // Containment bool is_contained_in (const bbox& b) const; // Alignment check bool is_aligned_with (const bbox& b) const; // Expand the bbox a little by multiples of the stride bbox expand (const vect& lo, const vect& hi) const; // Find the smallest b-compatible box around *this bbox expanded_for (const bbox& b) const; // Find the largest b-compatible box inside *this bbox contracted_for (const bbox& b) const; // Smallest bbox containing both boxes bbox expanded_containing (const bbox& b) const; // Iterators class iterator { protected: const bbox& box; vect pos; public: iterator (const bbox& box, const vect& pos); const vect& operator* () const { return pos; } bool operator!= (const iterator& i) const; iterator& operator++ (); }; iterator begin () const; iterator end () const; class iteratorT { protected: const bbox& box; vect pos; public: iteratorT (const bbox& box, const vect& pos); const vect& operator* () const { return pos; } bool operator!= (const iteratorT& i) const; iteratorT& operator++ (); }; iteratorT beginT () const; iteratorT endT () const; // Input/Output void input (istream& is); void output (ostream& os) const; }; // Input template inline istream& operator>> (istream& is, bbox& b) { b.input(is); return is; } // Output template inline ostream& operator<< (ostream& os, const bbox& b) { b.output(os); return os; } #endif // BBOX_HH