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(
// 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;
<< 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