]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Enlarge BoundingBox 7914/head
authorLuca Heltai <luca.heltai@sissa.it>
Thu, 11 Apr 2019 13:52:36 +0000 (15:52 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Fri, 12 Apr 2019 08:09:37 +0000 (10:09 +0200)
doc/news/changes/minor/20190411LucaHeltai-b [new file with mode: 0644]
include/deal.II/base/bounding_box.h
tests/base/bounding_box_5.cc [new file with mode: 0644]
tests/base/bounding_box_5.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20190411LucaHeltai-b b/doc/news/changes/minor/20190411LucaHeltai-b
new file mode 100644 (file)
index 0000000..70e5583
--- /dev/null
@@ -0,0 +1,3 @@
+New: Added BoundingBox::extend() that allows extending and shrinking of BoundingBox objects. 
+<br>
+(Luca Heltai, 2019/04/11)
index d4c594c55a63f6f2666eb5bfe1a139f9aa4c56d1..97acdb873d786ea516b3fd0dff424b99b5030ae8 100644 (file)
@@ -140,6 +140,16 @@ public:
   bool
   point_inside(const Point<spacedim, Number> &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<spacedim, Number>::BoundingBox(
   this->boundary_points = boundary_points;
 }
 
+template <int spacedim, typename Number>
+inline void
+BoundingBox<spacedim, Number>::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 <int spacedim, typename Number>
 template <class Archive>
diff --git a/tests/base/bounding_box_5.cc b/tests/base/bounding_box_5.cc
new file mode 100644 (file)
index 0000000..8f97903
--- /dev/null
@@ -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 <deal.II/base/bounding_box.h>
+
+#include <iostream>
+#include <vector>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+
+template <int dim>
+void
+test()
+{
+  Point<dim> p0, p1;
+  for (unsigned int d = 0; d < dim; ++d)
+    p1[d] = 1;
+
+  BoundingBox<dim> 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 (file)
index 0000000..837b1d9
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.