46 #ifndef EIGEN_ALIGNEDBOX_H
47 #define EIGEN_ALIGNEDBOX_H
65 template <
typename _Scalar,
int _AmbientDim>
69 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
70 enum { AmbientDimAtCompileTime = _AmbientDim };
71 typedef _Scalar Scalar;
74 typedef typename ScalarTraits::Real RealScalar;
75 typedef typename ScalarTraits::NonInteger NonInteger;
102 {
if (EIGEN_CONST_CONDITIONAL(AmbientDimAtCompileTime!=
Dynamic))
setEmpty(); }
110 template<
typename OtherVectorType1,
typename OtherVectorType2>
111 EIGEN_DEVICE_FUNC
inline AlignedBox(
const OtherVectorType1& _min,
const OtherVectorType2& _max) : m_min(_min), m_max(_max) {}
114 template<
typename Derived>
121 EIGEN_DEVICE_FUNC
inline Index dim()
const {
return AmbientDimAtCompileTime==
Dynamic ? m_min.size() :
Index(AmbientDimAtCompileTime); }
131 EIGEN_DEVICE_FUNC
inline bool isEmpty()
const {
return (m_min.array() > m_max.array()).any(); }
153 {
return (m_min+m_max)/RealScalar(2); }
160 {
return m_max - m_min; }
163 EIGEN_DEVICE_FUNC
inline Scalar
volume()
const
164 {
return sizes().prod(); }
184 EIGEN_STATIC_ASSERT(_AmbientDim <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
191 if( mult & corner ) res[d] = m_max[d];
192 else res[d] = m_min[d];
205 if(!ScalarTraits::IsInteger)
207 r[d] = m_min[d] + (m_max[d]-m_min[d])
208 * internal::random<Scalar>(Scalar(0), Scalar(1));
211 r[d] = internal::random(m_min[d], m_max[d]);
217 template<
typename Derived>
220 typename internal::nested_eval<Derived,2>::type p_n(p.
derived());
221 return (m_min.array()<=p_n.array()).
all() && (p_n.array()<=m_max.array()).
all();
226 {
return (m_min.array()<=(b.
min)().array()).
all() && ((b.
max)().array()<=m_max.array()).
all(); }
231 {
return (m_min.array()<=(b.
max)().array()).
all() && ((b.
min)().array()<=m_max.array()).
all(); }
235 template<
typename Derived>
238 typename internal::nested_eval<Derived,2>::type p_n(p.
derived());
239 m_min = m_min.cwiseMin(p_n);
240 m_max = m_max.cwiseMax(p_n);
248 m_min = m_min.cwiseMin(b.m_min);
249 m_max = m_max.cwiseMax(b.m_max);
258 m_min = m_min.cwiseMax(b.m_min);
259 m_max = m_max.cwiseMin(b.m_max);
267 {
return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max)); }
273 {
return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max)); }
276 template<
typename Derived>
279 const typename internal::nested_eval<Derived,2>::type t(a_t.
derived());
286 template<
typename Derived>
298 template<
typename Derived>
311 template<
typename Derived>
325 template<
int Mode,
int Options>
338 template<
int Mode,
int Options>
342 EIGEN_STATIC_ASSERT(Mode ==
Affine || Mode ==
AffineCompact || Mode ==
Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS);
352 const VectorType rotated_center_2 = transform.
linear() * (this->m_max + this->m_min) +
355 this->m_max = (rotated_center_2 + rotated_extent_2) / Scalar(2);
356 this->m_min = (rotated_center_2 - rotated_extent_2) / Scalar(2);
363 template<
int Mode,
int Options>
376 template<
typename NewScalarType>
377 EIGEN_DEVICE_FUNC
inline typename internal::cast_return_type<
AlignedBox,
380 return typename internal::cast_return_type<
AlignedBox,
385 template<
typename OtherScalarType>
388 m_min = (other.
min)().template cast<Scalar>();
389 m_max = (other.
max)().template cast<Scalar>();
396 EIGEN_DEVICE_FUNC
bool isApprox(
const AlignedBox& other,
const RealScalar& prec = ScalarTraits::dummy_precision())
const
397 {
return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); }
401 VectorType m_min, m_max;
406 template<
typename Scalar,
int AmbientDim>
407 template<
typename Derived>
410 typename internal::nested_eval<Derived,2*AmbientDim>::type p(a_p.
derived());
413 for (
Index k=0; k<dim(); ++k)
415 if( m_min[k] > p[k] )
417 aux = m_min[k] - p[k];
420 else if( p[k] > m_max[k] )
422 aux = p[k] - m_max[k];
429 template<
typename Scalar,
int AmbientDim>
434 for (
Index k=0; k<dim(); ++k)
436 if( m_min[k] > b.m_max[k] )
438 aux = m_min[k] - b.m_max[k];
441 else if( b.m_min[k] > m_max[k] )
443 aux = b.m_min[k] - m_max[k];
466 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
468 typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix;
470 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
471 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \
472 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
473 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
474 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
475 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
477 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
int, i)
478 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
float, f)
479 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
double, d)
481 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
482 #undef EIGEN_MAKE_TYPEDEFS
486 #endif // EIGEN_ALIGNEDBOX_H
AlignedBox intersection(const AlignedBox &b) const
Definition: AlignedBox.h:266
AlignedBox & clamp(const AlignedBox &b)
Definition: AlignedBox.h:256
static const Eigen::internal::all_t all
Definition: IndexedViewHelper.h:171
NonInteger exteriorDistance(const AlignedBox &b) const
Definition: AlignedBox.h:319
Definition: AlignedBox.h:92
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
NonInteger exteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:312
internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
Definition: AlignedBox.h:378
Scalar squaredExteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:408
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient) center() const
Definition: AlignedBox.h:151
AlignedBox(Index _dim)
Definition: AlignedBox.h:105
Definition: Constants.h:457
VectorType sample() const
Definition: AlignedBox.h:200
bool intersects(const AlignedBox &b) const
Definition: AlignedBox.h:230
Derived & derived()
Definition: EigenBase.h:46
Definition: AlignedBox.h:83
void setEmpty()
Definition: AlignedBox.h:135
An axis aligned box.
Definition: AlignedBox.h:66
AlignedBox merged(const AlignedBox &b) const
Definition: AlignedBox.h:272
AlignedBox()
Definition: AlignedBox.h:101
Definition: AlignedBox.h:87
bool contains(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:218
Definition: AlignedBox.h:93
const VectorType &() max() const
Definition: AlignedBox.h:146
Represents a translation transformation.
Definition: Translation.h:30
bool isNull() const
Definition: AlignedBox.h:124
AlignedBox & extend(const AlignedBox &b)
Definition: AlignedBox.h:246
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
CornerType
Definition: AlignedBox.h:80
const VectorType &() min() const
Definition: AlignedBox.h:142
Definition: Constants.h:462
Definition: AlignedBox.h:88
VectorType corner(CornerType corner) const
Definition: AlignedBox.h:182
Definition: AlignedBox.h:95
void setNull()
Definition: AlignedBox.h:127
Definition: AlignedBox.h:87
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Index Index
Definition: AlignedBox.h:73
bool isApprox(const AlignedBox &other, const RealScalar &prec=ScalarTraits::dummy_precision()) const
Definition: AlignedBox.h:396
void transform(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform)
Definition: AlignedBox.h:339
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:361
Definition: AlignedBox.h:88
VectorType &() max()
Definition: AlignedBox.h:148
void transform(const typename Transform< Scalar, AmbientDimAtCompileTime, Mode, Options >::TranslationType &translation)
Definition: AlignedBox.h:326
AlignedBox & translate(const MatrixBase< Derived > &a_t)
Definition: AlignedBox.h:277
AlignedBox translated(const MatrixBase< Derived > &a_t) const
Definition: AlignedBox.h:287
Index dim() const
Definition: AlignedBox.h:121
VectorType &() min()
Definition: AlignedBox.h:144
AlignedBox(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:115
Definition: AlignedBox.h:94
Scalar volume() const
Definition: AlignedBox.h:163
AlignedBox(const OtherVectorType1 &_min, const OtherVectorType2 &_max)
Definition: AlignedBox.h:111
const int Dynamic
Definition: Constants.h:22
AlignedBox & extend(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:236
Definition: AlignedBox.h:94
AlignedBox transformed(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform) const
Definition: AlignedBox.h:364
Definition: AlignedBox.h:93
Definition: Constants.h:460
Definition: AlignedBox.h:92
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: AlignedBox.h:83
bool isEmpty() const
Definition: AlignedBox.h:131
const CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > sizes() const
Definition: AlignedBox.h:159
AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
Definition: AlignedBox.h:386
bool contains(const AlignedBox &b) const
Definition: AlignedBox.h:225
CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > diagonal() const
Definition: AlignedBox.h:170