27#ifndef EASY3D_CORE_GENERIC_BOX_H
28#define EASY3D_CORE_GENERIC_BOX_H
34#include <easy3d/core/vec.h>
46 template<
int DIM,
typename FT>
56 : min_(std::numeric_limits<FT>::
max())
57 , max_(-std::numeric_limits<FT>::
max()) {
79 for (
int i = 0; i < DIM; ++i) {
80 if (max_[i] >= min_[i] - std::numeric_limits<FT>::epsilon())
88 min_ =
Point(std::numeric_limits<FT>::max());
89 max_ =
Point(-std::numeric_limits<FT>::max());
104 assert(axis >= 0 && axis < DIM);
113 assert(axis >= 0 && axis < DIM);
121 inline FT
range(
unsigned int axis)
const {
122 assert(axis >= 0 && axis < DIM);
124 return max_[axis] - min_[axis];
131 FT max_value = max_[0] - min_[0];
132 for (
int i = 1; i < DIM; ++i)
133 max_value = std::max(max_value, max_[i] - min_[i]);
139 FT min_value = max_[0] - min_[0];
140 for (
int i = 1; i < DIM; ++i)
141 min_value = std::min(min_value, max_[i] - min_[i]);
147 unsigned int axis = 0;
148 FT max_value = max_[0] - min_[0];
149 for (
int i = 1; i < DIM; ++i) {
150 FT
range = max_[i] - min_[i];
151 if (
range > max_value) {
161 unsigned int axis = 0;
162 FT min_value = max_[0] - min_[0];
163 for (
int i = 1; i < DIM; ++i) {
164 FT
range = max_[i] - min_[i];
165 if (
range < min_value) {
176 return FT(0.5) * (min_ + max_);
188 for (
int i = 0; i < DIM; ++i) {
189 FT d = max_[i] - min_[i];
192 return std::sqrt(sqr_len);
206 return FT(2.0) * (ext[0] * ext[1] + ext[0] * ext[2] + ext[1] * ext[2]);
208 return ext[0] * ext[1];
210 std::cerr <<
"surface_area() is for 2D and 3D boxes" << std::endl;
218 for (
int i = 0; i < DIM; ++i) {
219 min_[i] = std::min(min_[i], p[i]);
220 max_[i] = std::max(max_[i], p[i]);
255 for (
int i = 0; i < DIM; ++i) {
256 if (p[i] <= min_[i] || p[i] >= max_[i])
269 for (
int i = 0; i < DIM; ++i) {
283 template<
int DIM,
typename FT>
292 template<
int DIM,
typename FT>
293 GenericBox<DIM, FT> box_union(GenericBox<DIM, FT>
const& a, GenericBox<DIM, FT>
const& b) {
294 return GenericBox<DIM, FT>(
comp_min(a.min_point(), b.min_point()),
comp_max(a.max_point(), b.max_point()));
297 template<
int DIM,
typename FT>
298 GenericBox<DIM, FT> box_intersection(GenericBox<DIM, FT>
const& a, GenericBox<DIM, FT>
const& b)
300 return GenericBox<DIM, FT>(
comp_max(a.min_point(), b.min_point()),
comp_min(a.max_point(), b.max_point()));
303 template<
int DIM,
typename FT>
304 GenericBox<DIM, FT> box_union(GenericBox<DIM, FT>
const& a, GenericBox<DIM, FT>
const& b) {
return a + b; }
306 template<
int DIM,
typename FT>
307 GenericBox<DIM, FT> box_intersection(GenericBox<DIM, FT>
const& a, GenericBox<DIM, FT>
const& b) {
309 return GenericBox<DIM, FT>(
comp_max(a.min_point(), b.min_point()),
comp_min(a.max_point(), b.max_point()));
311 return GenericBox<DIM, FT>();
GenericBox represents the bounding box of shapes.
Definition: box.h:47
bool contains(Point const &p) const
Definition: box.h:254
Point center() const
Definition: box.h:174
GenericBox()
Definition: box.h:55
FT max_coord(unsigned int axis) const
Definition: box.h:112
bool contains(thisclass const &b) const
Definition: box.h:263
const Point & min_point() const
Definition: box.h:93
FT range(unsigned int axis) const
Definition: box.h:121
Vector diagonal_vector() const
Definition: box.h:182
FT radius() const
Definition: box.h:198
Point & min_point()
Definition: box.h:95
FT min_coord(unsigned int axis) const
Definition: box.h:103
FT max_range() const
Definition: box.h:130
FT diagonal_length() const
Definition: box.h:185
FT min_range() const
Definition: box.h:138
thisclass & operator+=(const thisclass &b)
Definition: box.h:245
void grow(const thisclass &b)
Definition: box.h:229
unsigned int min_range_axis() const
Definition: box.h:160
const Point & max_point() const
Definition: box.h:98
bool is_valid() const
Definition: box.h:78
FT surface_area() const
Definition: box.h:203
GenericBox(const Point &c, FT r)
Definition: box.h:70
thisclass operator+(const thisclass &b) const
Definition: box.h:237
void clear()
Definition: box.h:87
unsigned int max_range_axis() const
Definition: box.h:146
GenericBox(const Point &pmin, const Point &pmax)
Definition: box.h:61
bool intersects(thisclass const &b) const
Definition: box.h:268
void grow(const Point &p)
Definition: box.h:216
Point & max_point()
Definition: box.h:100
thisclass & normalize()
Normalizes this vector.
Definition: vec.h:135
Definition: collider.cpp:182
FT max()
Function returning maximum representable value for a given type.
bool has_nan(const GenericBox< DIM, FT > &box)
Definition: box.h:284
Vec< N, T > comp_min(const Vec< N, T > &v1, const Vec< N, T > &v2)
Component-wise minimum vector.
Definition: vec.h:801
Vec< N, T > comp_max(const Vec< N, T > &v1, const Vec< N, T > &v2)
Component-wise maximum vector.
Definition: vec.h:810