aboutsummaryrefslogtreecommitdiff
path: root/Carpet
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2010-08-25 10:13:09 -0400
committerBarry Wardell <barry.wardell@gmail.com>2011-12-14 18:21:18 +0000
commiteac0f67696b808ae567f14a6ba7c229762d29426 (patch)
tree0f5d06a7f7de4de3519389db6c5e176e27a08f4f /Carpet
parente1b6234d1858c30404d5a2553d829730c50fef99 (diff)
CarpetLib: Generalise "expand" function
Allow expanding bboxes by fractions of the stride.
Diffstat (limited to 'Carpet')
-rw-r--r--Carpet/CarpetLib/src/bbox.cc16
-rw-r--r--Carpet/CarpetLib/src/bbox.hh15
2 files changed, 31 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/bbox.cc b/Carpet/CarpetLib/src/bbox.cc
index e0b72f1a6..c5a429d5e 100644
--- a/Carpet/CarpetLib/src/bbox.cc
+++ b/Carpet/CarpetLib/src/bbox.cc
@@ -174,6 +174,22 @@ bbox<T,D> bbox<T,D>::expand (const vect<T,D>& lo, const vect<T,D>& hi) const {
return bbox(lb,ub,str);
}
+// Expand the bbox a little by multiples of a fraction of the stride
+template<typename T, int D>
+bbox<T,D> bbox<T,D>::expand (const vect<T,D>& lo, const vect<T,D>& hi,
+ const vect<T,D>& denom) const
+{
+ // Allow expansion only into directions where the extent is not negative
+ // ASSERT_BBOX (all(lower()<=upper() or (lo==T(0) and hi==T(0))));
+ ASSERT_BBOX (all(shape()>=vect<T,D>(0) or (lo==T(0) and hi==T(0))));
+ ASSERT_BBOX (all(denom>vect<T,D>(0)));
+ const vect<T,D> str = stride();
+ ASSERT_BBOX (all (str%denom==vect<T,D>(0)));
+ const vect<T,D> lb = lower() - lo * str / denom;
+ const vect<T,D> ub = upper() + hi * str / denom;
+ return bbox(lb,ub,str);
+}
+
// Find the smallest b-compatible box around *this
template<typename T, int D>
bbox<T,D> bbox<T,D>::expanded_for (const bbox& b) const {
diff --git a/Carpet/CarpetLib/src/bbox.hh b/Carpet/CarpetLib/src/bbox.hh
index d2dac83cc..c3c346058 100644
--- a/Carpet/CarpetLib/src/bbox.hh
+++ b/Carpet/CarpetLib/src/bbox.hh
@@ -153,6 +153,21 @@ public:
bbox expand (const vect<vect<T,D>,2>& lohi) const
{ return expand (lohi[0], lohi[1]); }
+ /** Shift the bbox by multiples of the stride. */
+ bbox shift (const vect<T,D>& v) const
+ { return expand (-v, v); }
+
+ /** Expand (enlarge) the bbox by multiples of a fraction of the
+ stride. */
+ bbox expand (const vect<T,D>& lo, const vect<T,D>& hi,
+ const vect<T,D>& denom) const;
+ bbox expand (const vect<vect<T,D>,2>& lohi, const vect<T,D>& denom) const
+ { return expand (lohi[0], lohi[1], denom); }
+
+ /** Shift the bbox by multiples of a fraction of the stride. */
+ bbox shift (const vect<T,D>& v, const vect<T,D>& denom) const
+ { return expand (-v, v, denom); }
+
/** Find the smallest b-compatible box around this bbox.
("compatible" means having the same stride.) */
bbox expanded_for (const bbox& b) const;