From eac0f67696b808ae567f14a6ba7c229762d29426 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Wed, 25 Aug 2010 10:13:09 -0400 Subject: CarpetLib: Generalise "expand" function Allow expanding bboxes by fractions of the stride. --- Carpet/CarpetLib/src/bbox.cc | 16 ++++++++++++++++ Carpet/CarpetLib/src/bbox.hh | 15 +++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'Carpet') 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 bbox::expand (const vect& lo, const vect& hi) const { return bbox(lb,ub,str); } +// Expand the bbox a little by multiples of a fraction of the stride +template +bbox bbox::expand (const vect& lo, const vect& hi, + const vect& 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(0) or (lo==T(0) and hi==T(0)))); + ASSERT_BBOX (all(denom>vect(0))); + const vect str = stride(); + ASSERT_BBOX (all (str%denom==vect(0))); + const vect lb = lower() - lo * str / denom; + const vect ub = upper() + hi * str / denom; + return bbox(lb,ub,str); +} + // Find the smallest b-compatible box around *this template bbox bbox::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,2>& lohi) const { return expand (lohi[0], lohi[1]); } + /** Shift the bbox by multiples of the stride. */ + bbox shift (const vect& v) const + { return expand (-v, v); } + + /** Expand (enlarge) the bbox by multiples of a fraction of the + stride. */ + bbox expand (const vect& lo, const vect& hi, + const vect& denom) const; + bbox expand (const vect,2>& lohi, const vect& denom) const + { return expand (lohi[0], lohi[1], denom); } + + /** Shift the bbox by multiples of a fraction of the stride. */ + bbox shift (const vect& v, const vect& 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; -- cgit v1.2.3