From e8f652728c0d921055dc03dec17107476a67ab44 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Fri, 24 Mar 2023 21:26:41 +0100 Subject: [PATCH] Add new functions to BoundingBox --- include/deal.II/base/bounding_box.h | 44 +++++++++++++++++++++++++++++ tests/base/bounding_box_1.cc | 32 +++++++++++++++++++++ tests/base/bounding_box_1.output | 36 +++++++++++++++++++++++ tests/base/bounding_box_5.cc | 11 +++++++- tests/base/bounding_box_5.output | 6 ++++ 5 files changed, 128 insertions(+), 1 deletion(-) diff --git a/include/deal.II/base/bounding_box.h b/include/deal.II/base/bounding_box.h index 74643162c5..24d5a7befa 100644 --- a/include/deal.II/base/bounding_box.h +++ b/include/deal.II/base/bounding_box.h @@ -142,6 +142,22 @@ public: */ BoundingBox() = default; + /** + * Standard copy constructor operator. + */ + BoundingBox(const BoundingBox &box) = default; + + /** + * Standard copy assignment operator. + */ + BoundingBox & + operator=(const BoundingBox &t) = default; + + /** + * Standard constructor for an empty box around a point @p point. + */ + BoundingBox(const Point &point); + /** * Standard constructor for non-empty boxes: it uses a pair of points * which describe the box: one for the bottom and one for the top @@ -233,6 +249,13 @@ public: void extend(const Number amount); + /** + * The same as above with the difference that a new BoundingBox instance is + * created without changing the current object. + */ + BoundingBox + create_extended(const Number amount) const; + /** * Compute the volume (i.e. the dim-dimensional measure) of the BoundingBox. */ @@ -416,6 +439,14 @@ namespace internal #ifndef DOXYGEN +template +inline BoundingBox::BoundingBox( + const Point &p) + : BoundingBox({p, p}) +{} + + + template inline BoundingBox::BoundingBox( const std::pair, Point> @@ -512,6 +543,19 @@ BoundingBox::extend(const Number amount) } + +template +inline BoundingBox +BoundingBox::create_extended(const Number amount) const +{ + // create and modify copy + auto bb = *this; + bb.extend(amount); + + return bb; +} + + template template void diff --git a/tests/base/bounding_box_1.cc b/tests/base/bounding_box_1.cc index 8fb53c02cf..ae4fb3df9f 100644 --- a/tests/base/bounding_box_1.cc +++ b/tests/base/bounding_box_1.cc @@ -104,6 +104,38 @@ test_bounding_box() deallog << "Boxes should not be equal : " << (b2 != b) << std::endl; } deallog << std::endl; + + // Initalize box with point + { + Point p; + for (unsigned int i = 0; i < spacedim; ++i) + p[i] = i + 1; + + BoundingBox b(p); + deallog << "Boundary points: " << std::endl; + deallog << b.get_boundary_points().first << std::endl; + deallog << b.get_boundary_points().second << std::endl; + } + deallog << std::endl; + + // Initalize box with box + { + BoundingBox bb(b); + deallog << "Boundary points: " << std::endl; + deallog << bb.get_boundary_points().first << std::endl; + deallog << bb.get_boundary_points().second << std::endl; + } + deallog << std::endl; + + // Initalize box with box + { + BoundingBox bb; + bb = b; + deallog << "Boundary points: " << std::endl; + deallog << bb.get_boundary_points().first << std::endl; + deallog << bb.get_boundary_points().second << std::endl; + } + deallog << std::endl; } void diff --git a/tests/base/bounding_box_1.output b/tests/base/bounding_box_1.output index 0d37542091..cd3055366f 100644 --- a/tests/base/bounding_box_1.output +++ b/tests/base/bounding_box_1.output @@ -24,6 +24,18 @@ DEAL::10.0000 is inside: 0 DEAL::-12.5000 is inside: 0 DEAL::Boxes should not be equal : 1 DEAL:: +DEAL::Boundary points: +DEAL::1.00000 +DEAL::1.00000 +DEAL:: +DEAL::Boundary points: +DEAL::0.200000 +DEAL::0.800000 +DEAL:: +DEAL::Boundary points: +DEAL::0.200000 +DEAL::0.800000 +DEAL:: DEAL:: DEAL::Test for dimension 2 DEAL::Empty constructor: @@ -49,6 +61,18 @@ DEAL::10.0000 16.0000 is inside: 0 DEAL::-12.5000 -20.0000 is inside: 0 DEAL::Boxes should not be equal : 1 DEAL:: +DEAL::Boundary points: +DEAL::1.00000 2.00000 +DEAL::1.00000 2.00000 +DEAL:: +DEAL::Boundary points: +DEAL::0.200000 0.00000 +DEAL::0.800000 1.60000 +DEAL:: +DEAL::Boundary points: +DEAL::0.200000 0.00000 +DEAL::0.800000 1.60000 +DEAL:: DEAL:: DEAL::Test for dimension 3 DEAL::Empty constructor: @@ -74,6 +98,18 @@ DEAL::10.0000 16.0000 22.0000 is inside: 0 DEAL::-12.5000 -20.0000 -27.5000 is inside: 0 DEAL::Boxes should not be equal : 1 DEAL:: +DEAL::Boundary points: +DEAL::1.00000 2.00000 3.00000 +DEAL::1.00000 2.00000 3.00000 +DEAL:: +DEAL::Boundary points: +DEAL::0.200000 0.00000 -0.200000 +DEAL::0.800000 1.60000 2.40000 +DEAL:: +DEAL::Boundary points: +DEAL::0.200000 0.00000 -0.200000 +DEAL::0.800000 1.60000 2.40000 +DEAL:: DEAL:: DEAL::Test for dimension 3, unitary box DEAL::Boundary points: diff --git a/tests/base/bounding_box_5.cc b/tests/base/bounding_box_5.cc index a033ec3ae1..84f16b199d 100644 --- a/tests/base/bounding_box_5.cc +++ b/tests/base/bounding_box_5.cc @@ -13,7 +13,7 @@ // // --------------------------------------------------------------------- -// test BoundingBox::extend +// test BoundingBox::extend() and BoundingBox::create_extend() #include @@ -34,11 +34,20 @@ test() BoundingBox box({p0, p1}); + const auto box1 = box.create_extended(.5); + + deallog << "New points: " << box1.get_boundary_points().first << ", " + << box1.get_boundary_points().second << std::endl; + box.extend(.5); deallog << "New points: " << box.get_boundary_points().first << ", " << box.get_boundary_points().second << std::endl; + const auto box2 = box.create_extended(-.8); + + deallog << "New points: " << box2.get_boundary_points().first << ", " + << box2.get_boundary_points().second << std::endl; box.extend(-.8); diff --git a/tests/base/bounding_box_5.output b/tests/base/bounding_box_5.output index 837b1d9bd9..6035749676 100644 --- a/tests/base/bounding_box_5.output +++ b/tests/base/bounding_box_5.output @@ -1,7 +1,13 @@ DEAL::New points: -0.500000, 1.50000 +DEAL::New points: -0.500000, 1.50000 +DEAL::New points: 0.300000, 0.700000 DEAL::New points: 0.300000, 0.700000 DEAL::New points: -0.500000 -0.500000, 1.50000 1.50000 +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.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.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 +DEAL::New points: 0.300000 0.300000 0.300000, 0.700000 0.700000 0.700000 -- 2.39.5