00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_2D_H
00069 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_2D_H
00070
00071
00072
00073 #include "min_max_policy.h"
00074 #include "point_2dh.h"
00075 #include "../io/matlab_o_stream.h"
00076
00077 namespace lass
00078 {
00079
00080 namespace prim
00081 {
00082
00083 template
00084 <
00085 typename T,
00086 class MinMaxPolicy = StrictMinMax
00087 >
00088 class Aabb2D
00089 {
00090 public:
00091
00092 typedef Aabb2D<T, MinMaxPolicy> TSelf;
00093 typedef MinMaxPolicy TMinMaxPolicy;
00094
00095 typedef Point2D<T> TPoint;
00096 typedef Point2DH<T> TPointH;
00097 typedef typename TPoint::TVector TVector;
00098
00099 typedef typename TPoint::TValue TValue;
00100 typedef typename TPoint::TParam TParam;
00101 typedef typename TPoint::TReference TReference;
00102 typedef typename TPoint::TConstReference TConstReference;
00103 typedef typename TPoint::TNumTraits TNumTraits;
00104
00105 enum { dimension = TPoint::dimension };
00106
00107 template <typename U> struct Rebind
00108 {
00109 typedef Aabb2D<U, MinMaxPolicy> Type;
00110 };
00111
00112 Aabb2D();
00113 Aabb2D(const TPoint& min, const TPoint& max);
00114 explicit Aabb2D(const TPoint& point);
00115 template <class MMP2> Aabb2D(const Aabb2D<T, MMP2>& other);
00116
00117 const TPoint& min() const;
00118 const TPoint& max() const;
00119 void setMin(const TPoint& min);
00120 void setMax(const TPoint& max);
00121
00122 template <class MMP2> TSelf& operator=(const Aabb2D<T, MMP2>& other);
00123
00124 TSelf& operator+=(const TPoint& point);
00125 template<class MMP2> TSelf& operator+=(const Aabb2D<T, MMP2>& other);
00126 void grow(TParam iDistance);
00127 void scale(TParam iScale);
00128
00129 const TPointH center() const;
00130 const TVector size() const;
00131 const TValue perimeter() const;
00132 const TValue area() const;
00133
00134 const Side classify(const TPoint& point) const;
00135 const bool contains(const TPoint& point) const;
00136 template <class MMP2> const bool contains(const Aabb2D<T, MMP2>& other) const;
00137 template <class MMP2> const bool intersects(const Aabb2D<T, MMP2>& other) const;
00138 template <class MMP2> const bool collides(const Aabb2D<T, MMP2>& other) const;
00139
00140 template <class RandomGenerator> const TPoint random(RandomGenerator& random) const;
00141
00142 void clear();
00143 const bool isEmpty() const;
00144 const bool isValid() const;
00145
00146 template <typename MMP2> void swap(Aabb2D<T, MMP2>& other);
00147
00148 private:
00149
00150 TPoint min_;
00151 TPoint max_;
00152 };
00153
00154 template <typename T, class MMPa, class MMPb>
00155 const Aabb2D<T, MMPa> operator+(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
00156
00157 template <typename T, class MMP>
00158 const Aabb2D<T, MMP> operator+(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
00159
00160 template <typename T, class MMP>
00161 const Aabb2D<T, MMP> operator+(const Point2D<T>& a, const Aabb2D<T, MMP>& b);
00162
00163 template <typename T>
00164 const Aabb2D<T> aabb(const Point2D<T>& point);
00165
00166 template <typename T, class MMP>
00167 T distance(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
00168
00169 template <typename T, class MMPa, class MMPb>
00170 T distance(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
00171
00172 template <typename T, class MMPa, class MMPb, class MMPr>
00173 Result intersect(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b, Aabb2D<T, MMPr>& result);
00174
00175 template <typename T, class MMPa, class MMPb>
00176 const bool intersects(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
00177
00178 template <typename T, class MMP>
00179 const bool intersects(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
00180
00181 template <typename T, class MMP>
00182 const bool intersects(const Point2D<T>& a, const Aabb2D<T, MMP>& b);
00183
00184 template <typename T, class MMPa, class MMPb>
00185 const bool collides(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
00186
00187 template <typename T, class MMP>
00188 const bool collides(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
00189
00190 template <typename T, class MMP>
00191 const bool collides(const Point2D<T>& a, const Aabb2D<T, MMP>& b);
00192
00193 template <typename T, class MMP>
00194 std::ostream& operator<<(std::ostream& ioOStream, const Aabb2D<T, MMP>& aabb);
00195
00196 template <typename T, class MMP>
00197 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Aabb2D<T, MMP>& aabb);
00198
00199 template <typename T, class MMP>
00200 io::MatlabOStream& operator<<(io::MatlabOStream& ioOStream, const Aabb2D<T, MMP>& aabb);
00201
00202 }
00203
00204 }
00205
00206 #include "aabb_2d.inl"
00207
00208 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_AABB_2D
00209 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
00210 # include "pyobject_util.h"
00211 #endif
00212
00213 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_2D_H
00214 # include "aabb_2d_ray_2d.h"
00215 #endif
00216
00217 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_POLYGON_2D_H
00218 # include "aabb_2d_simple_polygon_2d.h"
00219 #endif
00220
00221 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_2D_H
00222 # include "aabb_2d_triangle_2d.h"
00223 #endif
00224
00225 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_2D_H
00226 # include "aabb_2d_transformation_2d.h"
00227 #endif
00228
00229 #endif