AlignedBox.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
00011 
00012 namespace Eigen { 
00013 
00026 template <typename _Scalar, int _AmbientDim>
00027 class AlignedBox
00028 {
00029 public:
00030 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim==Dynamic ? Dynamic : _AmbientDim+1)
00031   enum { AmbientDimAtCompileTime = _AmbientDim };
00032   typedef _Scalar Scalar;
00033   typedef typename NumTraits<Scalar>::Real RealScalar;
00034   typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
00035 
00037   inline AlignedBox()
00038   { if (AmbientDimAtCompileTime!=Dynamic) setNull(); }
00039 
00041   inline explicit AlignedBox(int _dim) : m_min(_dim), m_max(_dim)
00042   { setNull(); }
00043 
00045   inline AlignedBox(const VectorType& _min, const VectorType& _max) : m_min(_min), m_max(_max) {}
00046 
00048   inline explicit AlignedBox(const VectorType& p) : m_min(p), m_max(p) {}
00049 
00050   ~AlignedBox() {}
00051 
00053   inline int dim() const { return AmbientDimAtCompileTime==Dynamic ? m_min.size()-1 : AmbientDimAtCompileTime; }
00054 
00056   inline bool isNull() const { return (m_min.cwise() > m_max).any(); }
00057 
00059   inline void setNull()
00060   {
00061     m_min.setConstant( (std::numeric_limits<Scalar>::max)());
00062     m_max.setConstant(-(std::numeric_limits<Scalar>::max)());
00063   }
00064 
00066   inline const VectorType& (min)() const { return m_min; }
00068   inline VectorType& (min)() { return m_min; }
00070   inline const VectorType& (max)() const { return m_max; }
00072   inline VectorType& (max)() { return m_max; }
00073 
00075   inline bool contains(const VectorType& p) const
00076   { return (m_min.cwise()<=p).all() && (p.cwise()<=m_max).all(); }
00077 
00079   inline bool contains(const AlignedBox& b) const
00080   { return (m_min.cwise()<=(b.min)()).all() && ((b.max)().cwise()<=m_max).all(); }
00081 
00083   inline AlignedBox& extend(const VectorType& p)
00084   { m_min = (m_min.cwise().min)(p); m_max = (m_max.cwise().max)(p); return *this; }
00085 
00087   inline AlignedBox& extend(const AlignedBox& b)
00088   { m_min = (m_min.cwise().min)(b.m_min); m_max = (m_max.cwise().max)(b.m_max); return *this; }
00089 
00091   inline AlignedBox& clamp(const AlignedBox& b)
00092   { m_min = (m_min.cwise().max)(b.m_min); m_max = (m_max.cwise().min)(b.m_max); return *this; }
00093 
00095   inline AlignedBox& translate(const VectorType& t)
00096   { m_min += t; m_max += t; return *this; }
00097 
00102   inline Scalar squaredExteriorDistance(const VectorType& p) const;
00103 
00108   inline Scalar exteriorDistance(const VectorType& p) const
00109   { return ei_sqrt(squaredExteriorDistance(p)); }
00110 
00116   template<typename NewScalarType>
00117   inline typename internal::cast_return_type<AlignedBox,
00118            AlignedBox<NewScalarType,AmbientDimAtCompileTime> >::type cast() const
00119   {
00120     return typename internal::cast_return_type<AlignedBox,
00121                     AlignedBox<NewScalarType,AmbientDimAtCompileTime> >::type(*this);
00122   }
00123 
00125   template<typename OtherScalarType>
00126   inline explicit AlignedBox(const AlignedBox<OtherScalarType,AmbientDimAtCompileTime>& other)
00127   {
00128     m_min = (other.min)().template cast<Scalar>();
00129     m_max = (other.max)().template cast<Scalar>();
00130   }
00131 
00136   bool isApprox(const AlignedBox& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00137   { return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); }
00138 
00139 protected:
00140 
00141   VectorType m_min, m_max;
00142 };
00143 
00144 template<typename Scalar,int AmbiantDim>
00145 inline Scalar AlignedBox<Scalar,AmbiantDim>::squaredExteriorDistance(const VectorType& p) const
00146 {
00147   Scalar dist2(0);
00148   Scalar aux;
00149   for (int k=0; k<dim(); ++k)
00150   {
00151     if ((aux = (p[k]-m_min[k]))<Scalar(0))
00152       dist2 += aux*aux;
00153     else if ( (aux = (m_max[k]-p[k]))<Scalar(0))
00154       dist2 += aux*aux;
00155   }
00156   return dist2;
00157 }
00158 
00159 } // end namespace Eigen


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:36:41