From a989c94165585c16724f02dc638c887e75a88cdc Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Wed, 25 Aug 2010 10:15:16 -0400 Subject: CarpetLib: Generalise "expand" function. Implement "shift" function. Allow expanding bboxset by multiples of a fraction of the stride. Allow shifting bboxsets. --- Carpet/CarpetLib/src/bboxset.cc | 25 ++++++++++++++++++++++++- Carpet/CarpetLib/src/bboxset.hh | 17 ++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'Carpet') diff --git a/Carpet/CarpetLib/src/bboxset.cc b/Carpet/CarpetLib/src/bboxset.cc index 7ffd61699..a830c0b73 100644 --- a/Carpet/CarpetLib/src/bboxset.cc +++ b/Carpet/CarpetLib/src/bboxset.cc @@ -464,7 +464,9 @@ bboxset bboxset::pseudo_inverse (const int n) const { } template -bboxset bboxset::expand (const vect& lo, const vect& hi) const { +bboxset bboxset::expand (const vect& lo, const vect& hi) + const +{ // We don't know (yet?) how to shrink a set assert (all (lo>=0 and hi>=0)); bboxset res; @@ -474,6 +476,27 @@ bboxset bboxset::expand (const vect& lo, const vect& hi) con return res; } +template +bboxset bboxset::expand (const vect& lo, const vect& hi, + const vect& denom) const +{ + assert (all(denom > vect(0))); + bboxset res; + if (all (lo == -hi)) { + // Special case for shifting, since this is faster + for (const_iterator bi=begin(); bi!=end(); ++bi) { + res += (*bi).expand(lo,hi,denom); + } + } else { + // We don't know (yet?) how to shrink a set + assert (all ((lo>=0 and hi>=0) or (lo == hi))); + for (const_iterator bi=begin(); bi!=end(); ++bi) { + res |= (*bi).expand(lo,hi,denom); + } + } + return res; +} + template bboxset bboxset::expanded_for (const box& b) const { bboxset res; diff --git a/Carpet/CarpetLib/src/bboxset.hh b/Carpet/CarpetLib/src/bboxset.hh index 5624ef4b1..23b2dc18c 100644 --- a/Carpet/CarpetLib/src/bboxset.hh +++ b/Carpet/CarpetLib/src/bboxset.hh @@ -142,11 +142,26 @@ public: /** Find the pseudo-inverse. */ bboxset pseudo_inverse (const int n) const; - /** Expand (enlarge) the bbox by multiples of the stride. */ + /** Expand (enlarge) the bboxset by multiples of the stride. */ bboxset expand (const vect& lo, const vect& hi) const; bboxset expand (const vect,2>& lohi) const { return expand (lohi[0], lohi[1]); } + /** Shift the bboxset by multiples of the stride. */ + bboxset shift (const vect& v) const + { return expand (-v, v); } + + /** Expand (enlarge) the bboxset by multiples of a fraction of the + stride. */ + bboxset expand (const vect& lo, const vect& hi, + const vect& denom) const; + bboxset expand (const vect,2>& lohi, const vect& denom) const + { return expand (lohi[0], lohi[1], denom); } + + /** Shift the bboxset by multiples of a fraction of the stride. */ + bboxset 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.) */ bboxset expanded_for (const box& b) const; -- cgit v1.2.3