16 #ifndef WORLD_BUILDER_BOUNDING_BOX_H 17 #define WORLD_BUILDER_BOUNDING_BOX_H 96 template <
unsigned int spacedim>
122 template <
class Container>
168 const double tolerance = std::numeric_limits<double>::epsilon())
const;
181 extend(
const double amount);
225 const double tolerance = std::numeric_limits<double>::epsilon())
const;
241 -std::numeric_limits<double>::max(),
242 -std::numeric_limits<double>::max(),
246 +std::numeric_limits<double>::max(),
247 +std::numeric_limits<double>::max(),
257 -std::numeric_limits<double>::max(),
258 -std::numeric_limits<double>::max(),
259 -std::numeric_limits<double>::max(),
263 +std::numeric_limits<double>::max(),
264 +std::numeric_limits<double>::max(),
265 +std::numeric_limits<double>::max(),
273 template <
unsigned int spacedim>
278 boundary_points (boundary_points_)
281 for (
unsigned int i = 0; i < spacedim; ++i)
282 WBAssert(boundary_points.first[i] <= boundary_points.second[i],
283 "Bounding Box can't be created: the points' " 284 "order should be bottom left, top right!");
289 template <
unsigned int spacedim>
290 template <
class Container>
295 if (points.size() > 0)
297 auto &min = boundary_points.first;
298 auto &max = boundary_points.second;
299 std::fill(min.begin_raw(),
301 std::numeric_limits<double>::infinity());
302 std::fill(max.begin_raw(),
304 -std::numeric_limits<double>::infinity());
307 for (
unsigned int d = 0; d < spacedim; ++d)
309 min[d] = std::min(min[d], point[d]);
310 max[d] = std::max(max[d], point[d]);
317 template <
unsigned int spacedim>
320 return this->boundary_points;
325 template <
unsigned int spacedim>
328 return this->boundary_points;
333 template <
unsigned int spacedim>
343 template <
unsigned int spacedim>
353 template <
unsigned int spacedim>
357 for (
unsigned int d = 0; d < spacedim; ++d)
359 boundary_points.first[d] -= amount;
360 boundary_points.second[d] += amount;
361 WBAssert(boundary_points.first[d] <= boundary_points.second[d],
362 "Bounding Box can't be shrunk this much: the points' " 363 "order should remain bottom left, top right.");
368 template <
unsigned int spacedim>
372 const double tolerance)
const 375 "Cannot compare two points which represent different coordinate systems.");
377 "Cannot compare two points which represent different coordinate systems.");
392 return (point_inside_implementation(point, tolerance) ||
393 point_inside_implementation(other_point, tolerance));
396 return point_inside_implementation(point, tolerance);
400 template <
unsigned int spacedim>
404 const double tolerance)
const 407 "Cannot compare two points which represent different coordinate systems.");
409 "Cannot compare two points which represent different coordinate systems.");
411 for (
unsigned int i = 0; i < spacedim; ++i)
416 if ((p[i] < this->boundary_points.first[i] -
417 tolerance * std::abs(this->boundary_points.second[i] -
418 this->boundary_points.first[i])) ||
419 (p[i] > this->boundary_points.second[i] +
420 tolerance * std::abs(this->boundary_points.second[i] -
421 this->boundary_points.first[i])))
429 template <
unsigned int spacedim>
435 for (
unsigned int i = 0; i < spacedim; ++i)
437 this->boundary_points.first[i] =
438 std::min(this->boundary_points.first[i],
440 this->boundary_points.second[i] =
441 std::max(this->boundary_points.second[i],
448 template <
unsigned int spacedim>
453 for (
unsigned int i = 0; i < spacedim; ++i)
454 vol *= (this->boundary_points.second[i] - this->boundary_points.first[i]);
460 template <
unsigned int spacedim>
467 return boundary_points.first[direction];
472 template <
unsigned int spacedim>
479 return boundary_points.second[direction];
484 template <
unsigned int spacedim>
489 for (
unsigned int i = 0; i < spacedim; ++i)
490 point[i] = .5 * (boundary_points.first[i] + boundary_points.second[i]);
497 template <
unsigned int spacedim>
502 WBAssert(direction < spacedim,
"Invalid index");
504 return boundary_points.second[direction] - boundary_points.first[direction];
double lower_bound(const unsigned int direction) const
double side_length(const unsigned int direction) const
double upper_bound(const unsigned int direction) const
CoordinateSystem get_coordinate_system() const
std::pair< Point< spacedim >, Point< spacedim > > boundary_points
std::pair< Point< spacedim >, Point< spacedim > > & get_boundary_points()
void extend(const double amount)
#define WBAssert(condition, message)
Point< spacedim > center() const
bool operator!=(const BoundingBox< spacedim > &box) const
bool operator==(const BoundingBox< spacedim > &box) const
bool point_inside_implementation(const Point< spacedim > &p, const double tolerance=std::numeric_limits< double >::epsilon()) const
void merge_with(const BoundingBox< spacedim > &other_bbox)
bool point_inside(const Point< spacedim > &p, const double tolerance=std::numeric_limits< double >::epsilon()) const