library of assembled shared sources

http://lass.cocamware.com

aabb_2d.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 /** @class lass::prim::Aabb2D
00046  *  @brief your momma's axis aligned bounding box.
00047  *  @author Bram de Greve [BdG]
00048  *  @date 2003
00049  *
00050  *  An AABB (Axis Aligned Bounding Box) is a rectangular box of a given dimension
00051  *  (in this case a 2D rectangle), that is often used as a simple bounding volume of another
00052  *  primitive or data structure.
00053  *
00054  *  <i>"A form of a bounding box where the box is aligned to the axis therefore only
00055  *  two points in space are needed to define it. AABB's are much faster to use, and
00056  *  take up less memory, but are very limited in the sense that they can only be
00057  *  aligned to the axis."</i>, http://www.gamedev.net/dict/term.asp?TermID=525
00058  *
00059  *  The way an AABB handles its minima and maxima can be set by the @c MinMaxPolicy.
00060  *  On policy StrictPolicy will enforce you to use correct minima and maxima, and on
00061  *  any suspicious behaviour, it will throw an exception.  The other policy AutoPolicy
00062  *  will try to correct misbehaviour without your notice.  For more information on
00063  *  these policies, I refer to the documentation compagning these policies.
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 }; /**< number of dimensions of vector */
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

Generated on Mon Nov 10 14:19:57 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo