46#ifndef EIGEN_ALIGNEDBOX_H
47#define EIGEN_ALIGNEDBOX_H
50#include "./InternalHeaderCheck.h"
68template <
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;
109 if (EIGEN_CONST_CONDITIONAL(AmbientDimAtCompileTime !=
Dynamic))
setEmpty();
118 template <
typename OtherVectorType1,
typename OtherVectorType2>
119 EIGEN_DEVICE_FUNC
inline AlignedBox(
const OtherVectorType1& _min,
const OtherVectorType2& _max)
120 : m_min(_min), m_max(_max) {}
123 template <
typename Derived>
130 return AmbientDimAtCompileTime ==
Dynamic ? m_min.size() :
Index(AmbientDimAtCompileTime);
141 EIGEN_DEVICE_FUNC
inline bool isEmpty()
const {
return (m_min.array() > m_max.array()).any(); }
146 m_min.setConstant(ScalarTraits::highest());
147 m_max.setConstant(ScalarTraits::lowest());
151 EIGEN_DEVICE_FUNC
inline const VectorType&(
min)()
const {
return m_min; }
153 EIGEN_DEVICE_FUNC
inline VectorType&(
min)() {
return m_min; }
155 EIGEN_DEVICE_FUNC
inline const VectorType&(
max)()
const {
return m_max; }
157 EIGEN_DEVICE_FUNC
inline VectorType&(
max)() {
return m_max; }
162 return (m_min + m_max) / RealScalar(2);
172 return m_max - m_min;
198 EIGEN_STATIC_ASSERT(AmbientDim_ <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
215 EIGEN_DEVICE_FUNC
inline VectorType
sample()
const {
218 if (!ScalarTraits::IsInteger) {
219 r[d] = m_min[d] + (m_max[d] - m_min[d]) * internal::random<Scalar>(Scalar(0), Scalar(1));
221 r[d] = internal::random(m_min[d], m_max[d]);
227 template <
typename Derived>
229 typename internal::nested_eval<Derived, 2>::type p_n(p.derived());
230 return (m_min.array() <= p_n.array()).all() && (p_n.array() <= m_max.array()).all();
235 return (m_min.array() <= (b.
min)().array()).all() && ((b.
max)().array() <= m_max.array()).all();
241 return (m_min.array() <= (b.
max)().array()).all() && ((b.
min)().array() <= m_max.array()).all();
246 template <
typename Derived>
248 typename internal::nested_eval<Derived, 2>::type p_n(p.derived());
249 m_min = m_min.cwiseMin(p_n);
250 m_max = m_max.cwiseMax(p_n);
257 m_min = m_min.cwiseMin(b.m_min);
258 m_max = m_max.cwiseMax(b.m_max);
266 m_min = m_min.cwiseMax(b.m_min);
267 m_max = m_max.cwiseMin(b.m_max);
275 return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max));
282 return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max));
286 template <
typename Derived>
288 const typename internal::nested_eval<Derived, 2>::type t(a_t.derived());
295 template <
typename Derived>
306 template <
typename Derived>
319 template <
typename Derived>
335 template <
int Mode,
int Options>
347 template <
int Mode,
int Options>
351 THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS);
359 const VectorType rotated_extent_2 =
transform.linear().cwiseAbs() *
sizes();
361 const VectorType rotated_center_2 =
362 transform.linear() * (this->m_max + this->m_min) + Scalar(2) *
transform.translation();
364 this->m_max = (rotated_center_2 + rotated_extent_2) / Scalar(2);
365 this->m_min = (rotated_center_2 - rotated_extent_2) / Scalar(2);
372 template <
int Mode,
int Options>
385 template <
typename NewScalarType>
386 EIGEN_DEVICE_FUNC
inline
387 typename internal::cast_return_type<AlignedBox, AlignedBox<NewScalarType, AmbientDimAtCompileTime> >::type
389 return typename internal::cast_return_type<AlignedBox, AlignedBox<NewScalarType, AmbientDimAtCompileTime> >::type(
394 template <
typename OtherScalarType>
405 const RealScalar& prec = ScalarTraits::dummy_precision())
const {
406 return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec);
410 VectorType m_min, m_max;
413template <
typename Scalar,
int AmbientDim>
414template <
typename Derived>
417 typename internal::nested_eval<Derived, 2 * AmbientDim>::type p(a_p.derived());
421 if (m_min[k] > p[k]) {
422 aux = m_min[k] - p[k];
424 }
else if (p[k] > m_max[k]) {
425 aux = p[k] - m_max[k];
432template <
typename Scalar,
int AmbientDim>
437 if (m_min[k] > b.m_max[k]) {
438 aux = m_min[k] - b.m_max[k];
440 }
else if (b.m_min[k] > m_max[k]) {
441 aux = b.m_min[k] - m_max[k];
465#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
467 typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix;
469#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
470 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \
471 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
472 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
473 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
474 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
476EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
int, i)
477EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
float, f)
478EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
double, d)
480#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
481#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:404
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient) center() const
Definition AlignedBox.h:160
AlignedBox intersection(const AlignedBox &b) const
Definition AlignedBox.h:274
const VectorType & max() const
Definition AlignedBox.h:155
AlignedBox(const OtherVectorType1 &_min, const OtherVectorType2 &_max)
Definition AlignedBox.h:119
void transform(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform)
Definition AlignedBox.h:348
bool isNull() const
Definition AlignedBox.h:134
VectorType sample() const
Definition AlignedBox.h:215
AlignedBox(const MatrixBase< Derived > &p)
Definition AlignedBox.h:124
bool contains(const AlignedBox &b) const
Definition AlignedBox.h:234
AlignedBox transformed(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform) const
Definition AlignedBox.h:374
bool intersects(const AlignedBox &b) const
Definition AlignedBox.h:240
AlignedBox merged(const AlignedBox &b) const
Definition AlignedBox.h:281
VectorType corner(CornerType corner) const
Definition AlignedBox.h:197
Eigen::Index Index
Definition AlignedBox.h:75
AlignedBox(Index _dim)
Definition AlignedBox.h:113
internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
Definition AlignedBox.h:388
AlignedBox & extend(const MatrixBase< Derived > &p)
Definition AlignedBox.h:247
AlignedBox translated(const MatrixBase< Derived > &a_t) const
Definition AlignedBox.h:296
bool contains(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:228
Scalar squaredExteriorDistance(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:415
Index dim() const
Definition AlignedBox.h:129
CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > diagonal() const
Definition AlignedBox.h:184
AlignedBox()
Definition AlignedBox.h:108
AlignedBox & clamp(const AlignedBox &b)
Definition AlignedBox.h:265
bool isEmpty() const
Definition AlignedBox.h:141
Scalar squaredExteriorDistance(const AlignedBox &b) const
Definition AlignedBox.h:433
NonInteger exteriorDistance(const AlignedBox &b) const
Definition AlignedBox.h:328
const CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > sizes() const
Definition AlignedBox.h:171
void transform(const typename Transform< Scalar, AmbientDimAtCompileTime, Mode, Options >::TranslationType &translation)
Definition AlignedBox.h:336
NonInteger exteriorDistance(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:320
CornerType
Definition AlignedBox.h:82
@ Max
Definition AlignedBox.h:85
@ TopLeft
Definition AlignedBox.h:91
@ TopRight
Definition AlignedBox.h:92
@ TopLeftFloor
Definition AlignedBox.h:98
@ BottomRight
Definition AlignedBox.h:90
@ Min
Definition AlignedBox.h:84
@ TopLeftCeil
Definition AlignedBox.h:102
@ BottomLeft
Definition AlignedBox.h:89
@ BottomRightFloor
Definition AlignedBox.h:97
@ TopRightFloor
Definition AlignedBox.h:99
@ BottomLeftCeil
Definition AlignedBox.h:100
@ BottomRightCeil
Definition AlignedBox.h:101
@ TopRightCeil
Definition AlignedBox.h:103
@ BottomLeftFloor
Definition AlignedBox.h:96
AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
Definition AlignedBox.h:395
Scalar volume() const
Definition AlignedBox.h:176
void setEmpty()
Definition AlignedBox.h:145
void setNull()
Definition AlignedBox.h:137
AlignedBox & extend(const AlignedBox &b)
Definition AlignedBox.h:256
AlignedBox & translate(const MatrixBase< Derived > &a_t)
Definition AlignedBox.h:287
const VectorType & min() const
Definition AlignedBox.h:151
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:79
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
@ Affine
Definition Constants.h:458
@ AffineCompact
Definition Constants.h:460
@ Isometry
Definition Constants.h:455
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
const int Dynamic
Definition Constants.h:25
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:232