From: Niklas Fehn Date: Fri, 5 Jun 2020 17:57:53 +0000 (+0200) Subject: add docu and test, make implementation more readable X-Git-Tag: v9.3.0-rc1~1480^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5e07b2b892ce725406faeb357b72dbdb4a3f81c;p=dealii.git add docu and test, make implementation more readable --- diff --git a/include/deal.II/base/bounding_box.h b/include/deal.II/base/bounding_box.h index f97673e26e..8d4d7f2536 100644 --- a/include/deal.II/base/bounding_box.h +++ b/include/deal.II/base/bounding_box.h @@ -182,7 +182,10 @@ public: merge_with(const BoundingBox &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( diff --git a/source/base/bounding_box.cc b/source/base/bounding_box.cc index 72f097aa07..c071e52b32 100644 --- a/source/base/bounding_box.cc +++ b/source/base/bounding_box.cc @@ -27,10 +27,12 @@ BoundingBox::point_inside(const Point &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; diff --git a/tests/base/bounding_box_1.cc b/tests/base/bounding_box_1.cc index 56a0a43ccc..7c4f9486a3 100644 --- a/tests/base/bounding_box_1.cc +++ b/tests/base/bounding_box_1.cc @@ -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::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