]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add docu and test, make implementation more readable 10457/head
authorNiklas Fehn <fehn@lnm.mw.tum.de>
Fri, 5 Jun 2020 17:57:53 +0000 (19:57 +0200)
committerNiklas Fehn <fehn@lnm.mw.tum.de>
Fri, 5 Jun 2020 17:57:53 +0000 (19:57 +0200)
include/deal.II/base/bounding_box.h
source/base/bounding_box.cc
tests/base/bounding_box_1.cc

index f97673e26e71fbaeb5e6c02d393ecf4ff8932b5b..8d4d7f25361b40539ab1f3b03975373add5f2971 100644 (file)
@@ -182,7 +182,10 @@ public:
   merge_with(const BoundingBox<spacedim, Number> &other_bbox);
 
   /**
-   * Return true if the point is inside the Bounding Box, false otherwise.
+   * Return true if the point is inside the Bounding Box, false otherwise. The
+   * parameter @p tolerance is a factor by which the bounding box is enlarged
+   * relative to the dimensions of the bounding box in order to determine in a
+   * numerically robust way whether the point is inside.
    */
   bool
   point_inside(
index 72f097aa073110cd54ba0a364f268970f5ca6026..c071e52b32b485398ef99a2de6b57f4c79b1377a 100644 (file)
@@ -27,10 +27,12 @@ BoundingBox<spacedim, Number>::point_inside(const Point<spacedim, Number> &p,
       // Bottom left-top right convention: the point is outside if it's smaller
       // than the first or bigger than the second boundary point The bounding
       // box is defined as a closed set
-      if (tolerance * std::abs(this->boundary_points.first[i] + p[i]) <
-            this->boundary_points.first[i] - p[i] ||
-          tolerance * std::abs(this->boundary_points.second[i] + p[i]) <
-            p[i] - this->boundary_points.second[i])
+      if ((p[i] < this->boundary_points.first[i] -
+                    tolerance * std::abs(this->boundary_points.second[i] -
+                                         this->boundary_points.first[i])) ||
+          (p[i] > this->boundary_points.second[i] +
+                    tolerance * std::abs(this->boundary_points.second[i] -
+                                         this->boundary_points.first[i])))
         return false;
     }
   return true;
index 56a0a43ccc1472ff94ac1fe00b614c108b8e67e6..7c4f9486a36cc963fa0877201023001bac2eaa37 100644 (file)
@@ -116,6 +116,20 @@ test_unitary()
           << b.point_inside(p3) << " " << b.point_inside(p1 + p2) << " "
           << b.point_inside(p2 + p3) << " " << b.point_inside(p1 + p3) << " "
           << std::endl;
+
+  double eps = std::numeric_limits<double>::epsilon();
+  AssertThrow(b.point_inside(Point<3>(0.0, 0.0, 1.0 + 1.0 * eps), 10. * eps) ==
+                true,
+              ExcMessage("failed."));
+  AssertThrow(b.point_inside(Point<3>(0.0, 0.0, 1.0 + 10. * eps), 1.0 * eps) ==
+                false,
+              ExcMessage("failed."));
+  AssertThrow(b.point_inside(Point<3>(0.0 - 1.0 * eps, 0.0, 0.0), 10. * eps) ==
+                true,
+              ExcMessage("failed."));
+  AssertThrow(b.point_inside(Point<3>(0.0 - 10. * eps, 0.0, 0.0), 1.0 * eps) ==
+                false,
+              ExcMessage("failed."));
 }
 
 int

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.