46 #ifndef EIGEN_ALIGNEDBOX_H
47 #define EIGEN_ALIGNEDBOX_H
49 #include "./InternalHeaderCheck.h"
67 template <
typename Scalar_,
int AmbientDim_>
71 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar_,AmbientDim_)
72 enum { AmbientDimAtCompileTime = AmbientDim_ };
73 typedef Scalar_ Scalar;
76 typedef typename ScalarTraits::Real RealScalar;
77 typedef typename ScalarTraits::NonInteger NonInteger;
104 {
if (EIGEN_CONST_CONDITIONAL(AmbientDimAtCompileTime!=
Dynamic))
setEmpty(); }
112 template<
typename OtherVectorType1,
typename OtherVectorType2>
113 EIGEN_DEVICE_FUNC
inline AlignedBox(
const OtherVectorType1& _min,
const OtherVectorType2& _max) : m_min(_min), m_max(_max) {}
116 template<
typename Derived>
123 EIGEN_DEVICE_FUNC
inline Index dim()
const {
return AmbientDimAtCompileTime==
Dynamic ? m_min.size() :
Index(AmbientDimAtCompileTime); }
133 EIGEN_DEVICE_FUNC
inline bool isEmpty()
const {
return (m_min.array() > m_max.array()).any(); }
155 {
return (m_min+m_max)/RealScalar(2); }
162 {
return m_max - m_min; }
165 EIGEN_DEVICE_FUNC
inline Scalar
volume()
const
166 {
return sizes().prod(); }
186 EIGEN_STATIC_ASSERT(AmbientDim_ <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
193 if( mult &
corner ) res[d] = m_max[d];
194 else res[d] = m_min[d];
207 if(!ScalarTraits::IsInteger)
209 r[d] = m_min[d] + (m_max[d]-m_min[d])
210 * internal::random<Scalar>(Scalar(0), Scalar(1));
213 r[d] = internal::random(m_min[d], m_max[d]);
219 template<
typename Derived>
222 typename internal::nested_eval<Derived,2>::type p_n(p.
derived());
223 return (m_min.array()<=p_n.array()).all() && (p_n.array()<=m_max.array()).
all();
228 {
return (m_min.array()<=(b.
min)().array()).all() && ((b.
max)().array()<=m_max.array()).
all(); }
233 {
return (m_min.array()<=(b.
max)().array()).all() && ((b.
min)().array()<=m_max.array()).
all(); }
237 template<
typename Derived>
240 typename internal::nested_eval<Derived,2>::type p_n(p.
derived());
241 m_min = m_min.cwiseMin(p_n);
242 m_max = m_max.cwiseMax(p_n);
250 m_min = m_min.cwiseMin(b.m_min);
251 m_max = m_max.cwiseMax(b.m_max);
260 m_min = m_min.cwiseMax(b.m_min);
261 m_max = m_max.cwiseMin(b.m_max);
269 {
return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max)); }
275 {
return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max)); }
278 template<
typename Derived>
281 const typename internal::nested_eval<Derived,2>::type t(a_t.
derived());
288 template<
typename Derived>
300 template<
typename Derived>
313 template<
typename Derived>
327 template<
int Mode,
int Options>
340 template<
int Mode,
int Options>
344 EIGEN_STATIC_ASSERT(Mode ==
Affine || Mode ==
AffineCompact || Mode ==
Isometry, THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS);
357 this->m_max = (rotated_center_2 + rotated_extent_2) / Scalar(2);
358 this->m_min = (rotated_center_2 - rotated_extent_2) / Scalar(2);
365 template<
int Mode,
int Options>
378 template<
typename NewScalarType>
379 EIGEN_DEVICE_FUNC
inline typename internal::cast_return_type<
AlignedBox,
382 return typename internal::cast_return_type<
AlignedBox,
387 template<
typename OtherScalarType>
390 m_min = (other.
min)().template cast<Scalar>();
391 m_max = (other.
max)().template cast<Scalar>();
398 EIGEN_DEVICE_FUNC
bool isApprox(
const AlignedBox& other,
const RealScalar& prec = ScalarTraits::dummy_precision())
const
399 {
return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); }
403 VectorType m_min, m_max;
408 template<
typename Scalar,
int AmbientDim>
409 template<
typename Derived>
412 typename internal::nested_eval<Derived,2*AmbientDim>::type p(a_p.
derived());
415 for (
Index k=0; k<dim(); ++k)
417 if( m_min[k] > p[k] )
419 aux = m_min[k] - p[k];
422 else if( p[k] > m_max[k] )
424 aux = p[k] - m_max[k];
431 template<
typename Scalar,
int AmbientDim>
436 for (
Index k=0; k<dim(); ++k)
438 if( m_min[k] > b.m_max[k] )
440 aux = m_min[k] - b.m_max[k];
443 else if( b.m_min[k] > m_max[k] )
445 aux = b.m_min[k] - m_max[k];
468 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
470 typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix;
472 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
473 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \
474 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
475 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
476 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
477 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
479 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
int, i)
480 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
float, f)
481 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
double, d)
483 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
484 #undef EIGEN_MAKE_TYPEDEFS
An axis aligned box.
Definition: AlignedBox.h:69
bool isApprox(const AlignedBox &other, const RealScalar &prec=ScalarTraits::dummy_precision()) const
Definition: AlignedBox.h:398
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient) center() const
Definition: AlignedBox.h:153
AlignedBox intersection(const AlignedBox &b) const
Definition: AlignedBox.h:268
AlignedBox(const OtherVectorType1 &_min, const OtherVectorType2 &_max)
Definition: AlignedBox.h:113
void transform(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform)
Definition: AlignedBox.h:341
bool isNull() const
Definition: AlignedBox.h:126
VectorType sample() const
Definition: AlignedBox.h:202
const VectorType &() max() const
Definition: AlignedBox.h:148
AlignedBox(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:117
AlignedBox & extend(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:238
bool contains(const AlignedBox &b) const
Definition: AlignedBox.h:227
AlignedBox transformed(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform) const
Definition: AlignedBox.h:366
bool intersects(const AlignedBox &b) const
Definition: AlignedBox.h:232
AlignedBox merged(const AlignedBox &b) const
Definition: AlignedBox.h:274
VectorType corner(CornerType corner) const
Definition: AlignedBox.h:184
Eigen::Index Index
Definition: AlignedBox.h:75
AlignedBox(Index _dim)
Definition: AlignedBox.h:107
AlignedBox translated(const MatrixBase< Derived > &a_t) const
Definition: AlignedBox.h:289
bool contains(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:220
AlignedBox & clamp(const AlignedBox &b)
Definition: AlignedBox.h:258
Scalar squaredExteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:410
VectorType &() max()
Definition: AlignedBox.h:150
VectorType &() min()
Definition: AlignedBox.h:146
Index dim() const
Definition: AlignedBox.h:123
AlignedBox & extend(const AlignedBox &b)
Definition: AlignedBox.h:248
AlignedBox()
Definition: AlignedBox.h:103
internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
Definition: AlignedBox.h:380
bool isEmpty() const
Definition: AlignedBox.h:133
NonInteger exteriorDistance(const AlignedBox &b) const
Definition: AlignedBox.h:321
void transform(const typename Transform< Scalar, AmbientDimAtCompileTime, Mode, Options >::TranslationType &translation)
Definition: AlignedBox.h:328
const VectorType &() min() const
Definition: AlignedBox.h:144
const CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > sizes() const
Definition: AlignedBox.h:161
NonInteger exteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:314
CornerType
Definition: AlignedBox.h:83
@ Max
Definition: AlignedBox.h:85
@ TopLeft
Definition: AlignedBox.h:90
@ TopRight
Definition: AlignedBox.h:90
@ TopLeftFloor
Definition: AlignedBox.h:95
@ BottomRight
Definition: AlignedBox.h:89
@ Min
Definition: AlignedBox.h:85
@ TopLeftCeil
Definition: AlignedBox.h:97
@ BottomLeft
Definition: AlignedBox.h:89
@ BottomRightFloor
Definition: AlignedBox.h:94
@ TopRightFloor
Definition: AlignedBox.h:95
@ BottomLeftCeil
Definition: AlignedBox.h:96
@ BottomRightCeil
Definition: AlignedBox.h:96
@ TopRightCeil
Definition: AlignedBox.h:97
@ BottomLeftFloor
Definition: AlignedBox.h:94
AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
Definition: AlignedBox.h:388
Scalar volume() const
Definition: AlignedBox.h:165
AlignedBox & translate(const MatrixBase< Derived > &a_t)
Definition: AlignedBox.h:279
void setEmpty()
Definition: AlignedBox.h:137
void setNull()
Definition: AlignedBox.h:129
CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > diagonal() const
Definition: AlignedBox.h:172
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:86
Derived & derived()
Definition: EigenBase.h:48
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:363
Represents a translation transformation.
Definition: Translation.h:33
static const Eigen::internal::all_t all
Definition: IndexedViewHelper.h:189
@ Affine
Definition: Constants.h:462
@ AffineCompact
Definition: Constants.h:464
@ Isometry
Definition: Constants.h:459
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)