diff options
Diffstat (limited to 'Carpet')
-rw-r--r-- | Carpet/CarpetLib/src/bbox.cc | 16 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/bbox.hh | 15 |
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; |