aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/bbox.hh
diff options
context:
space:
mode:
authoreschnett <>2001-03-01 12:40:00 +0000
committereschnett <>2001-03-01 12:40:00 +0000
commitece47455bad491c45b3136362e9239f505de23b9 (patch)
tree0e121ebd44c2fbb7711943fcd8804e85626daca3 /Carpet/CarpetLib/src/bbox.hh
parent310f0ea48d18866b773136aed11200b6eda6378b (diff)
Initial revision
darcs-hash:20010301124010-f6438-fca5ed1e25f84efd816aa0d13fc23b58add7195d.gz
Diffstat (limited to 'Carpet/CarpetLib/src/bbox.hh')
-rw-r--r--Carpet/CarpetLib/src/bbox.hh142
1 files changed, 49 insertions, 93 deletions
diff --git a/Carpet/CarpetLib/src/bbox.hh b/Carpet/CarpetLib/src/bbox.hh
index e23d000ac..3529f944e 100644
--- a/Carpet/CarpetLib/src/bbox.hh
+++ b/Carpet/CarpetLib/src/bbox.hh
@@ -1,4 +1,22 @@
-// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.hh,v 1.15 2004/04/18 13:03:44 schnetter Exp $
+/***************************************************************************
+ bbox.hh - Bounding boxes
+ -------------------
+ begin : Sun Jun 11 2000
+ copyright : (C) 2000 by Erik Schnetter
+ email : schnetter@astro.psu.edu
+
+ $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.hh,v 1.1 2001/03/01 13:40:10 eschnett Exp $
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
#ifndef BBOX_HH
#define BBOX_HH
@@ -8,77 +26,52 @@
#include "defs.hh"
#include "vect.hh"
-using namespace std;
-
-// Forward declaration
+// Forward definition
template<class T, int D> class bbox;
-// Input/Output
-template<class T, int D>
-istream& operator>> (istream& is, bbox<T,D>& b);
-template<class T, int D>
+// Output
+template<class T,int D>
ostream& operator<< (ostream& os, const bbox<T,D>& b);
-/**
- * A bounding box, i.e. a rectangle with lower and upper bound and a
- * stride.
- */
+// Bounding box class
template<class T, int D>
class bbox {
// Fields
-
- /** Bounding box bounds and stride. The bounds are inclusive. */
- vect<T,D> _lower, _upper, _stride;
+ vect<T,D> _lower, _upper, _stride;// bounds are inclusive
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). */
+ const vect<T,D>& lower () const { return _lower; }
+ const vect<T,D>& upper () const { return _upper; }
+ const vect<T,D>& stride () const { return _stride; }
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
+ T size () const {
+ if (empty()) return 0;
+ return prod(shape());
+ }
- /** Find out whether the bbox contains the point x. */
- bool contains (const vect<T,D>& x) const;
+ T num_points () const {
+ if (empty()) return 0;
+ return prod((shape()+stride()-1)/stride());
+ }
// Operators
bool operator== (const bbox& b) const;
@@ -88,84 +81,47 @@ public:
bool operator<= (const bbox& b) const;
bool operator>= (const bbox& b) const;
- /** Calculate the intersection (the set of common points) with the
- bbox b. */
+ // Intersection
bbox operator& (const bbox& b) const;
- /** Find out whether this bbox is contained in the bbox b. */
- bool is_contained_in (const bbox& b) const;
+ // Containment
+ bool contained_in (const bbox& b) const;
- /** 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;
+ // Alignment check
+ bool aligned_with (const bbox& b) const;
- /** Expand (enlarge) the bbox by multiples of the stride. */
+ // Expand the bbox a little 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 bbox.
- ("compatible" means having the same stride.) */
+ // Find the smallest b-compatible box around *this
bbox expanded_for (const bbox& b) const;
- /** Find the largest b-compatible box inside this bbox. */
+ // Find the largest b-compatible box inside *this
bbox contracted_for (const bbox& b) const;
- /** 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. */
+ bbox box;
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 "after the last point" in a bbox,
- which means that it also points to the first point. */
iterator end () const;
- // Input/Output helpers
- void input (istream& is);
- void output (ostream& os) const;
+ // Output
+ friend ostream& operator<< <>(ostream& os, const bbox& b);
};
-// 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);
- return is;
-}
-
-
-
-// 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);
- return os;
-}
-
-
+#if defined(TMPL_IMPLICIT)
+# include "bbox.cc"
+#endif
#endif // BBOX_HH