10 #ifndef EIGEN_ALIGNEDBOX_H
11 #define EIGEN_ALIGNEDBOX_H
27 template <
typename _Scalar,
int _AmbientDim>
31 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
32 enum { AmbientDimAtCompileTime = _AmbientDim };
33 typedef _Scalar Scalar;
35 typedef DenseIndex Index;
36 typedef typename ScalarTraits::Real RealScalar;
37 typedef typename ScalarTraits::NonInteger NonInteger;
48 TopLeft=2, TopRight=3,
52 TopLeftFloor=2, TopRightFloor=3,
53 BottomLeftCeil=4, BottomRightCeil=5,
54 TopLeftCeil=6, TopRightCeil=7
63 inline explicit AlignedBox(Index _dim) : m_min(_dim), m_max(_dim)
67 template<
typename OtherVectorType1,
typename OtherVectorType2>
68 inline AlignedBox(
const OtherVectorType1& _min,
const OtherVectorType2& _max) : m_min(_min), m_max(_max) {}
71 template<
typename Derived>
74 typename internal::nested<Derived,2>::type p(a_p.derived());
82 inline Index
dim()
const {
return AmbientDimAtCompileTime==
Dynamic ? m_min.size() : Index(AmbientDimAtCompileTime); }
91 inline bool isEmpty()
const {
return (m_min.array() > m_max.array()).any(); }
113 {
return (m_min+m_max)/2; }
120 {
return m_max - m_min; }
124 {
return sizes().prod(); }
144 EIGEN_STATIC_ASSERT(_AmbientDim <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
149 for(Index d=0; d<
dim(); ++d)
151 if( mult & corner ) res[d] = m_max[d];
152 else res[d] = m_min[d];
163 for(Index d=0; d<
dim(); ++d)
165 if(!ScalarTraits::IsInteger)
167 r[d] = m_min[d] + (m_max[d]-m_min[d])
168 * internal::random<Scalar>(Scalar(0), Scalar(1));
171 r[d] = internal::random(m_min[d], m_max[d]);
177 template<
typename Derived>
180 typename internal::nested<Derived,2>::type p(a_p.derived());
181 return (m_min.array()<=p.array()).all() && (p.array()<=m_max.array()).all();
186 {
return (m_min.array()<=(b.
min)().array()).all() && ((b.
max)().array()<=m_max.array()).all(); }
189 template<
typename Derived>
192 typename internal::nested<Derived,2>::type p(a_p.derived());
193 m_min = m_min.cwiseMin(p);
194 m_max = m_max.cwiseMax(p);
201 m_min = m_min.cwiseMin(b.m_min);
202 m_max = m_max.cwiseMax(b.m_max);
209 m_min = m_min.cwiseMax(b.m_min);
210 m_max = m_max.cwiseMin(b.m_max);
216 {
return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max)); }
220 {
return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max)); }
223 template<
typename Derived>
226 const typename internal::nested<Derived,2>::type t(a_t.derived());
236 template<
typename Derived>
249 template<
typename Derived>
265 template<
typename NewScalarType>
266 inline typename internal::cast_return_type<
AlignedBox,
269 return typename internal::cast_return_type<
AlignedBox,
274 template<
typename OtherScalarType>
277 m_min = (other.
min)().template cast<Scalar>();
278 m_max = (other.
max)().template cast<Scalar>();
285 bool isApprox(
const AlignedBox& other,
const RealScalar& prec = ScalarTraits::dummy_precision())
const
286 {
return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); }
290 VectorType m_min, m_max;
295 template<
typename Scalar,
int AmbientDim>
296 template<
typename Derived>
299 typename internal::nested<Derived,2*AmbientDim>::type p(a_p.derived());
302 for (Index k=0; k<dim(); ++k)
304 if( m_min[k] > p[k] )
306 aux = m_min[k] - p[k];
309 else if( p[k] > m_max[k] )
311 aux = p[k] - m_max[k];
318 template<
typename Scalar,
int AmbientDim>
323 for (Index k=0; k<dim(); ++k)
325 if( m_min[k] > b.m_max[k] )
327 aux = m_min[k] - b.m_max[k];
330 else if( b.m_min[k] > m_max[k] )
332 aux = b.m_min[k] - m_max[k];
355 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
357 typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix;
359 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
360 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \
361 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
362 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
363 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
364 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
366 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
int, i)
367 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
float, f)
368 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
double, d)
370 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
371 #undef EIGEN_MAKE_TYPEDEFS
375 #endif // EIGEN_ALIGNEDBOX_H
AlignedBox(const MatrixBase< Derived > &a_p)
Definition: AlignedBox.h:72
AlignedBox(const OtherVectorType1 &_min, const OtherVectorType2 &_max)
Definition: AlignedBox.h:68
CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const VectorType, const VectorType > diagonal() const
Definition: AlignedBox.h:130
CornerType
Definition: AlignedBox.h:41
bool contains(const AlignedBox &b) const
Definition: AlignedBox.h:185
AlignedBox()
Definition: AlignedBox.h:59
bool isNull() const
Definition: AlignedBox.h:85
AlignedBox & clamp(const AlignedBox &b)
Definition: AlignedBox.h:207
AlignedBox(Index _dim)
Definition: AlignedBox.h:63
const VectorType &() min() const
Definition: AlignedBox.h:101
VectorType &() max()
Definition: AlignedBox.h:107
VectorType sample() const
Definition: AlignedBox.h:160
Scalar volume() const
Definition: AlignedBox.h:123
const int Dynamic
Definition: Constants.h:21
AlignedBox & translate(const MatrixBase< Derived > &a_t)
Definition: AlignedBox.h:224
const CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const VectorType, const VectorType > sizes() const
Definition: AlignedBox.h:119
An axis aligned box.
Definition: AlignedBox.h:28
AlignedBox & extend(const MatrixBase< Derived > &a_p)
Definition: AlignedBox.h:190
bool isApprox(const AlignedBox &other, const RealScalar &prec=ScalarTraits::dummy_precision()) const
Definition: AlignedBox.h:285
void setEmpty()
Definition: AlignedBox.h:94
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:106
bool isEmpty() const
Definition: AlignedBox.h:91
AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
Definition: AlignedBox.h:275
const VectorType &() max() const
Definition: AlignedBox.h:105
Index dim() const
Definition: AlignedBox.h:82
Definition: AlignedBox.h:47
internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
Definition: AlignedBox.h:267
Definition: AlignedBox.h:44
const CwiseUnaryOp< internal::scalar_quotient1_op< Scalar >, const CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const VectorType, const VectorType > > center() const
Definition: AlignedBox.h:112
VectorType &() min()
Definition: AlignedBox.h:103
Derived & setConstant(Index size, const Scalar &value)
Definition: CwiseNullaryOp.h:348
AlignedBox intersection(const AlignedBox &b) const
Definition: AlignedBox.h:215
Scalar squaredExteriorDistance(const MatrixBase< Derived > &a_p) const
Definition: AlignedBox.h:297
VectorType corner(CornerType corner) const
Definition: AlignedBox.h:142
NonInteger exteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:250
bool contains(const MatrixBase< Derived > &a_p) const
Definition: AlignedBox.h:178
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
AlignedBox merged(const AlignedBox &b) const
Definition: AlignedBox.h:219
void setNull()
Definition: AlignedBox.h:88
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
AlignedBox & extend(const AlignedBox &b)
Definition: AlignedBox.h:199
NonInteger exteriorDistance(const AlignedBox &b) const
Definition: AlignedBox.h:257
Definition: AlignedBox.h:51