Eigen2Support/Geometry/AlignedBox.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
11 
12 namespace Eigen {
13 
26 template <typename _Scalar, int _AmbientDim>
28 {
29 public:
31  enum { AmbientDimAtCompileTime = _AmbientDim };
32  typedef _Scalar Scalar;
35 
37  inline AlignedBox()
39 
41  inline explicit AlignedBox(int _dim) : m_min(_dim), m_max(_dim)
42  { setNull(); }
43 
45  inline AlignedBox(const VectorType& _min, const VectorType& _max) : m_min(_min), m_max(_max) {}
46 
48  inline explicit AlignedBox(const VectorType& p) : m_min(p), m_max(p) {}
49 
51 
53  inline int dim() const { return AmbientDimAtCompileTime==Dynamic ? m_min.size()-1 : AmbientDimAtCompileTime; }
54 
56  inline bool isNull() const { return (m_min.cwise() > m_max).any(); }
57 
59  inline void setNull()
60  {
61  m_min.setConstant( (std::numeric_limits<Scalar>::max)());
62  m_max.setConstant(-(std::numeric_limits<Scalar>::max)());
63  }
64 
66  inline const VectorType& (min)() const { return m_min; }
68  inline VectorType& (min)() { return m_min; }
70  inline const VectorType& (max)() const { return m_max; }
72  inline VectorType& (max)() { return m_max; }
73 
75  inline bool contains(const VectorType& p) const
76  { return (m_min.cwise()<=p).all() && (p.cwise()<=m_max).all(); }
77 
79  inline bool contains(const AlignedBox& b) const
80  { return (m_min.cwise()<=(b.min)()).all() && ((b.max)().cwise()<=m_max).all(); }
81 
83  inline AlignedBox& extend(const VectorType& p)
84  { m_min = (m_min.cwise().min)(p); m_max = (m_max.cwise().max)(p); return *this; }
85 
87  inline AlignedBox& extend(const AlignedBox& b)
88  { m_min = (m_min.cwise().min)(b.m_min); m_max = (m_max.cwise().max)(b.m_max); return *this; }
89 
91  inline AlignedBox& clamp(const AlignedBox& b)
92  { m_min = (m_min.cwise().max)(b.m_min); m_max = (m_max.cwise().min)(b.m_max); return *this; }
93 
95  inline AlignedBox& translate(const VectorType& t)
96  { m_min += t; m_max += t; return *this; }
97 
102  inline Scalar squaredExteriorDistance(const VectorType& p) const;
103 
108  inline Scalar exteriorDistance(const VectorType& p) const
109  { return ei_sqrt(squaredExteriorDistance(p)); }
110 
116  template<typename NewScalarType>
117  inline typename internal::cast_return_type<AlignedBox,
119  {
120  return typename internal::cast_return_type<AlignedBox,
122  }
123 
125  template<typename OtherScalarType>
127  {
128  m_min = (other.min)().template cast<Scalar>();
129  m_max = (other.max)().template cast<Scalar>();
130  }
131 
136  bool isApprox(const AlignedBox& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
137  { return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); }
138 
139 protected:
140 
141  VectorType m_min, m_max;
142 };
143 
144 template<typename Scalar,int AmbiantDim>
145 inline Scalar AlignedBox<Scalar,AmbiantDim>::squaredExteriorDistance(const VectorType& p) const
146 {
147  Scalar dist2(0);
148  Scalar aux;
149  for (int k=0; k<dim(); ++k)
150  {
151  if ((aux = (p[k]-m_min[k]))<Scalar(0))
152  dist2 += aux*aux;
153  else if ( (aux = (m_max[k]-p[k]))<Scalar(0))
154  dist2 += aux*aux;
155  }
156  return dist2;
157 }
158 
159 } // end namespace Eigen
AlignedBox & clamp(const AlignedBox &b)
internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Scalar squaredExteriorDistance(const VectorType &p) const
const VectorType &() max() const
AlignedBox & extend(const AlignedBox &b)
const VectorType &() min() const
NumTraits< Scalar >::Real RealScalar
bool contains(const VectorType &p) const
bool isApprox(const AlignedBox &other, typename NumTraits< Scalar >::Real prec=precision< Scalar >()) const
AlignedBox & translate(const VectorType &t)
Derived & setConstant(Index size, const Scalar &value)
AlignedBox & extend(const VectorType &p)
Scalar exteriorDistance(const VectorType &p) const
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
AlignedBox(const VectorType &_min, const VectorType &_max)
Matrix< Scalar, AmbientDimAtCompileTime, 1 > VectorType
AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
bool contains(const AlignedBox &b) const


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:27