From: Luca Heltai Date: Thu, 11 Apr 2019 13:52:36 +0000 (+0200) Subject: Enlarge BoundingBox X-Git-Tag: v9.1.0-rc1~198^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7914%2Fhead;p=dealii.git Enlarge BoundingBox --- diff --git a/doc/news/changes/minor/20190411LucaHeltai-b b/doc/news/changes/minor/20190411LucaHeltai-b new file mode 100644 index 0000000000..70e5583207 --- /dev/null +++ b/doc/news/changes/minor/20190411LucaHeltai-b @@ -0,0 +1,3 @@ +New: Added BoundingBox::extend() that allows extending and shrinking of BoundingBox objects. +
+(Luca Heltai, 2019/04/11) diff --git a/include/deal.II/base/bounding_box.h b/include/deal.II/base/bounding_box.h index d4c594c55a..97acdb873d 100644 --- a/include/deal.II/base/bounding_box.h +++ b/include/deal.II/base/bounding_box.h @@ -140,6 +140,16 @@ public: bool point_inside(const Point &p) const; + /** + * Increase (or decrease) the size of the bounding box by the given amount. + * + * If you call this method with a negative number, and one of the axes of the + * original bounding box is smaller than amount/2, the method will trigger + * an assertion. + */ + void + extend(const Number &amount); + /** * Compute the volume (i.e. the dim-dimensional measure) of the BoundingBox. */ @@ -176,6 +186,20 @@ inline BoundingBox::BoundingBox( this->boundary_points = boundary_points; } +template +inline void +BoundingBox::extend(const Number &amount) +{ + for (unsigned int d = 0; d < spacedim; ++d) + { + boundary_points.first[d] -= amount; + boundary_points.second[d] += amount; + Assert(boundary_points.first[d] <= boundary_points.second[d], + ExcMessage("Bounding Box can't be shrinked this much: the points' " + "order should remain bottom left, top right.")); + } +} + template template diff --git a/tests/base/bounding_box_5.cc b/tests/base/bounding_box_5.cc new file mode 100644 index 0000000000..8f9790337d --- /dev/null +++ b/tests/base/bounding_box_5.cc @@ -0,0 +1,60 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// test BoundingBox::extend + +#include + +#include +#include + +#include "../tests.h" + +using namespace dealii; + + +template +void +test() +{ + Point p0, p1; + for (unsigned int d = 0; d < dim; ++d) + p1[d] = 1; + + BoundingBox box({p0, p1}); + + box.extend(.5); + + deallog << "New points: " << box.get_boundary_points().first << ", " + << box.get_boundary_points().second << std::endl; + + + box.extend(-.8); + + deallog << "New points: " << box.get_boundary_points().first << ", " + << box.get_boundary_points().second << std::endl; +} + + + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/base/bounding_box_5.output b/tests/base/bounding_box_5.output new file mode 100644 index 0000000000..837b1d9bd9 --- /dev/null +++ b/tests/base/bounding_box_5.output @@ -0,0 +1,7 @@ + +DEAL::New points: -0.500000, 1.50000 +DEAL::New points: 0.300000, 0.700000 +DEAL::New points: -0.500000 -0.500000, 1.50000 1.50000 +DEAL::New points: 0.300000 0.300000, 0.700000 0.700000 +DEAL::New points: -0.500000 -0.500000 -0.500000, 1.50000 1.50000 1.50000 +DEAL::New points: 0.300000 0.300000 0.300000, 0.700000 0.700000 0.700000