47#ifndef EIGEN_ALIGNEDBOX_H
48#define EIGEN_ALIGNEDBOX_H
51#include "./InternalHeaderCheck.h"
69template <
typename Scalar_,
int AmbientDim_>
72 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar_, AmbientDim_)
73 enum { AmbientDimAtCompileTime = AmbientDim_ };
74 using Scalar = Scalar_;
77 using RealScalar =
typename ScalarTraits::Real;
78 using NonInteger =
typename ScalarTraits::NonInteger;
110 if (EIGEN_CONST_CONDITIONAL(AmbientDimAtCompileTime != Dynamic))
setEmpty();
119 template <
typename OtherVectorType1,
typename OtherVectorType2>
120 EIGEN_DEVICE_FUNC
inline AlignedBox(
const OtherVectorType1& _min,
const OtherVectorType2& _max)
121 : m_min(_min), m_max(_max) {}
124 template <
typename Derived>
129 return AmbientDimAtCompileTime == Dynamic ? m_min.size() :
Index(AmbientDimAtCompileTime);
140 EIGEN_DEVICE_FUNC
inline bool isEmpty()
const {
return (m_min.array() > m_max.array()).any(); }
145 m_min.setConstant(ScalarTraits::highest());
146 m_max.setConstant(ScalarTraits::lowest());
150 EIGEN_DEVICE_FUNC
inline const VectorType&(
min)()
const {
return m_min; }
152 EIGEN_DEVICE_FUNC
inline VectorType&(
min)() {
return m_min; }
154 EIGEN_DEVICE_FUNC
inline const VectorType&(
max)()
const {
return m_max; }
156 EIGEN_DEVICE_FUNC
inline VectorType&(
max)() {
return m_max; }
160 internal::scalar_quotient_op) center()
const {
161 return (m_min + m_max) / RealScalar(2);
171 return m_max - m_min;
197 EIGEN_STATIC_ASSERT(AmbientDim_ <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
214 EIGEN_DEVICE_FUNC
inline VectorType
sample()
const {
217 EIGEN_IF_CONSTEXPR (!ScalarTraits::IsInteger) {
218 r[d] = m_min[d] + (m_max[d] - m_min[d]) * internal::random<Scalar>(Scalar(0), Scalar(1));
220 r[d] = internal::random(m_min[d], m_max[d]);
226 template <
typename Derived>
228 typename internal::nested_eval<Derived, 2>::type p_n(p.derived());
229 return (m_min.array() <= p_n.array()).all() && (p_n.array() <= m_max.array()).all();
234 return (m_min.array() <= (b.
min)().array()).all() && ((b.
max)().array() <= m_max.array()).all();
240 return (m_min.array() <= (b.
max)().array()).all() && ((b.
min)().array() <= m_max.array()).all();
245 template <
typename Derived>
247 typename internal::nested_eval<Derived, 2>::type p_n(p.derived());
248 m_min = m_min.cwiseMin(p_n);
249 m_max = m_max.cwiseMax(p_n);
256 m_min = m_min.cwiseMin(b.m_min);
257 m_max = m_max.cwiseMax(b.m_max);
265 m_min = m_min.cwiseMax(b.m_min);
266 m_max = m_max.cwiseMin(b.m_max);
274 return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max));
281 return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max));
285 template <
typename Derived>
287 const typename internal::nested_eval<Derived, 2>::type t(a_t.derived());
294 template <
typename Derived>
305 template <
typename Derived>
318 template <
typename Derived>
334 template <
int Mode,
int Options>
346 template <
int Mode,
int Options>
350 THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS);
358 const VectorType rotated_extent_2 =
transform.linear().cwiseAbs() *
sizes();
360 const VectorType rotated_center_2 =
361 transform.linear() * (this->m_max + this->m_min) + Scalar(2) *
transform.translation();
363 this->m_max = (rotated_center_2 + rotated_extent_2) / Scalar(2);
364 this->m_min = (rotated_center_2 - rotated_extent_2) / Scalar(2);
371 template <
int Mode,
int Options>
384 template <
typename NewScalarType>
385 EIGEN_DEVICE_FUNC
inline
386 typename internal::cast_return_type<AlignedBox, AlignedBox<NewScalarType, AmbientDimAtCompileTime> >::type
388 return typename internal::cast_return_type<AlignedBox, AlignedBox<NewScalarType, AmbientDimAtCompileTime> >::type(
393 template <
typename OtherScalarType>
404 const RealScalar& prec = ScalarTraits::dummy_precision())
const {
405 return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec);
409 VectorType m_min, m_max;
412template <
typename Scalar,
int AmbientDim>
413template <
typename Derived>
416 typename internal::nested_eval<Derived, 2 * AmbientDim>::type p(a_p.derived());
420 if (m_min[k] > p[k]) {
421 aux = m_min[k] - p[k];
423 }
else if (p[k] > m_max[k]) {
424 aux = p[k] - m_max[k];
431template <
typename Scalar,
int AmbientDim>
436 if (m_min[k] > b.m_max[k]) {
437 aux = m_min[k] - b.m_max[k];
439 }
else if (b.m_min[k] > m_max[k]) {
440 aux = b.m_min[k] - m_max[k];
464#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
466 typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix;
468#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
469 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \
470 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
471 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
472 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
473 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
475EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
int, i)
476EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
float, f)
477EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
double, d)
479#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
480#undef EIGEN_MAKE_TYPEDEFS
An axis aligned box.
Definition AlignedBox.h:70
bool isApprox(const AlignedBox &other, const RealScalar &prec=ScalarTraits::dummy_precision()) const
Definition AlignedBox.h:403
AlignedBox intersection(const AlignedBox &b) const
Definition AlignedBox.h:273
const VectorType & max() const
Definition AlignedBox.h:154
AlignedBox(const OtherVectorType1 &_min, const OtherVectorType2 &_max)
Definition AlignedBox.h:120
void transform(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform)
Definition AlignedBox.h:347
bool isNull() const
Definition AlignedBox.h:133
VectorType sample() const
Definition AlignedBox.h:214
AlignedBox(const MatrixBase< Derived > &p)
Definition AlignedBox.h:125
bool contains(const AlignedBox &b) const
Definition AlignedBox.h:233
AlignedBox transformed(const Transform< Scalar, AmbientDimAtCompileTime, Mode, Options > &transform) const
Definition AlignedBox.h:373
bool intersects(const AlignedBox &b) const
Definition AlignedBox.h:239
AlignedBox merged(const AlignedBox &b) const
Definition AlignedBox.h:280
VectorType corner(CornerType corner) const
Definition AlignedBox.h:196
AlignedBox(Index _dim)
Definition AlignedBox.h:114
internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
Definition AlignedBox.h:387
AlignedBox & extend(const MatrixBase< Derived > &p)
Definition AlignedBox.h:246
AlignedBox translated(const MatrixBase< Derived > &a_t) const
Definition AlignedBox.h:295
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, internal::scalar_quotient_op) center() const
Definition AlignedBox.h:159
bool contains(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:227
Scalar squaredExteriorDistance(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:414
Eigen::Index Index
Definition AlignedBox.h:76
Index dim() const
Definition AlignedBox.h:128
CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > diagonal() const
Definition AlignedBox.h:183
AlignedBox()
Definition AlignedBox.h:109
AlignedBox & clamp(const AlignedBox &b)
Definition AlignedBox.h:264
bool isEmpty() const
Definition AlignedBox.h:140
Scalar squaredExteriorDistance(const AlignedBox &b) const
Definition AlignedBox.h:432
NonInteger exteriorDistance(const AlignedBox &b) const
Definition AlignedBox.h:327
const CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > sizes() const
Definition AlignedBox.h:170
void transform(const typename Transform< Scalar, AmbientDimAtCompileTime, Mode, Options >::TranslationType &translation)
Definition AlignedBox.h:335
NonInteger exteriorDistance(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:319
CornerType
Definition AlignedBox.h:83
@ Max
Definition AlignedBox.h:86
@ TopLeft
Definition AlignedBox.h:92
@ TopRight
Definition AlignedBox.h:93
@ TopLeftFloor
Definition AlignedBox.h:99
@ BottomRight
Definition AlignedBox.h:91
@ Min
Definition AlignedBox.h:85
@ TopLeftCeil
Definition AlignedBox.h:103
@ BottomLeft
Definition AlignedBox.h:90
@ BottomRightFloor
Definition AlignedBox.h:98
@ TopRightFloor
Definition AlignedBox.h:100
@ BottomLeftCeil
Definition AlignedBox.h:101
@ BottomRightCeil
Definition AlignedBox.h:102
@ TopRightCeil
Definition AlignedBox.h:104
@ BottomLeftFloor
Definition AlignedBox.h:97
AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
Definition AlignedBox.h:394
Scalar volume() const
Definition AlignedBox.h:175
void setEmpty()
Definition AlignedBox.h:144
void setNull()
Definition AlignedBox.h:136
AlignedBox & extend(const AlignedBox &b)
Definition AlignedBox.h:255
AlignedBox & translate(const MatrixBase< Derived > &a_t)
Definition AlignedBox.h:286
const VectorType & min() const
Definition AlignedBox.h:150
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:80
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
@ Affine
Definition Constants.h:475
@ AffineCompact
Definition Constants.h:477
@ Isometry
Definition Constants.h:472
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233