Library of Assembled Shared Sources
aabb_2d.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @class lass::prim::Aabb2D
46 * @brief your momma's axis aligned bounding box.
47 * @author Bram de Greve [BdG]
48 * @date 2003
49 *
50 * An AABB (Axis Aligned Bounding Box) is a rectangular box of a given dimension
51 * (in this case a 2D rectangle), that is often used as a simple bounding volume of another
52 * primitive or data structure.
53 *
54 * <i>"A form of a bounding box where the box is aligned to the axis therefore only
55 * two points in space are needed to define it. AABB's are much faster to use, and
56 * take up less memory, but are very limited in the sense that they can only be
57 * aligned to the axis."</i>, http://www.gamedev.net/dict/term.asp?TermID=525
58 *
59 * The way an AABB handles its minima and maxima can be set by the @c MinMaxPolicy.
60 * On policy StrictPolicy will enforce you to use correct minima and maxima, and on
61 * any suspicious behaviour, it will throw an exception. The other policy AutoPolicy
62 * will try to correct misbehaviour without your notice. For more information on
63 * these policies, I refer to the documentation compagning these policies.
64 */
65
66
67
68#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_2D_H
69#define LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_2D_H
70
71
72
73#include "min_max_policy.h"
74#include "point_2dh.h"
76
77namespace lass
78{
79
80namespace prim
81{
82
83template
84<
85 typename T,
86 class MinMaxPolicy = StrictMinMax
87>
89{
90public:
91
92 typedef Aabb2D<T, MinMaxPolicy> TSelf;
93 typedef MinMaxPolicy TMinMaxPolicy;
94
95 typedef Point2D<T> TPoint;
96 typedef Point2DH<T> TPointH;
97 typedef typename TPoint::TVector TVector;
98
99 typedef typename TPoint::TValue TValue;
100 typedef typename TPoint::TParam TParam;
101 typedef typename TPoint::TReference TReference;
102 typedef typename TPoint::TConstReference TConstReference;
103 typedef typename TPoint::TNumTraits TNumTraits;
104
105 enum { dimension = TPoint::dimension }; /**< number of dimensions of vector */
106
107 template <typename U> struct Rebind
108 {
109 typedef Aabb2D<U, MinMaxPolicy> Type;
110 };
111
113 Aabb2D(const TPoint& min, const TPoint& max);
114 explicit Aabb2D(const TPoint& point);
115 template <class MMP2> Aabb2D(const Aabb2D<T, MMP2>& other);
116
117 const TPoint& min() const;
118 const TPoint& max() const;
119 void setMin(const TPoint& min);
120 void setMax(const TPoint& max);
121
122 template <class MMP2> TSelf& operator=(const Aabb2D<T, MMP2>& other);
123
124 TSelf& operator+=(const TPoint& point);
125 template<class MMP2> TSelf& operator+=(const Aabb2D<T, MMP2>& other);
126 void grow(TParam iDistance);
127 void scale(TParam iScale);
128
129 const TPointH center() const;
130 const TVector size() const;
131 const TValue perimeter() const;
132 const TValue area() const;
133
134 Side classify(const TPoint& point) const;
135 bool contains(const TPoint& point) const;
136 template <class MMP2> bool contains(const Aabb2D<T, MMP2>& other) const;
137 template <class MMP2> bool intersects(const Aabb2D<T, MMP2>& other) const;
138 template <class MMP2> bool collides(const Aabb2D<T, MMP2>& other) const;
139
140 template <class RandomGenerator> const TPoint random(RandomGenerator& random) const;
141
142 void clear();
143 bool isEmpty() const;
144 bool isValid() const;
145
146 template <typename MMP2> void swap(Aabb2D<T, MMP2>& other);
147
148private:
149
150 TPoint min_;
151 TPoint max_;
152};
153
154template <typename T, class MMPa, class MMPb>
155const Aabb2D<T, MMPa> operator+(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
156
157template <typename T, class MMP>
158const Aabb2D<T, MMP> operator+(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
159
160template <typename T, class MMP>
161const Aabb2D<T, MMP> operator+(const Point2D<T>& a, const Aabb2D<T, MMP>& b);
162
163template <typename T>
164const Aabb2D<T> aabb(const Point2D<T>& point);
165
166template <typename T, class MMP>
167T distance(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
168
169template <typename T, class MMPa, class MMPb>
170T distance(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
171
172template <typename T, class MMPa, class MMPb, class MMPr>
173Result intersect(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b, Aabb2D<T, MMPr>& result);
174
175template <typename T, class MMPa, class MMPb>
176bool intersects(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
177
178template <typename T, class MMP>
179bool intersects(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
180
181template <typename T, class MMP>
182bool intersects(const Point2D<T>& a, const Aabb2D<T, MMP>& b);
183
184template <typename T, class MMPa, class MMPb>
185bool collides(const Aabb2D<T, MMPa>& a, const Aabb2D<T, MMPb>& b);
186
187template <typename T, class MMP>
188bool collides(const Aabb2D<T, MMP>& a, const Point2D<T>& b);
189
190template <typename T, class MMP>
191bool collides(const Point2D<T>& a, const Aabb2D<T, MMP>& b);
192
193template <typename T, class MMP>
194std::ostream& operator<<(std::ostream& ioOStream, const Aabb2D<T, MMP>& aabb);
195
196template <typename T, class MMP>
197io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Aabb2D<T, MMP>& aabb);
198
199template <typename T, class MMP>
200io::MatlabOStream& operator<<(io::MatlabOStream& ioOStream, const Aabb2D<T, MMP>& aabb);
201
202}
203
204}
205
206#include "aabb_2d.inl"
207
208#define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_AABB_2D
209#ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
211#endif
212
213#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_2D_H
214# include "aabb_2d_ray_2d.h"
215#endif
216
217#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_POLYGON_2D_H
219#endif
220
221#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_2D_H
222# include "aabb_2d_triangle_2d.h"
223#endif
224
225#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_2D_H
227#endif
228
229#endif
Output stream for writing a selection of geometric primitives to matlab M files.
Output stream for writing a selection of geometric primitives to XML files.
your momma's axis aligned bounding box.
Definition aabb_2d.h:89
Aabb2D(const TPoint &min, const TPoint &max)
Construct bounding box, spanned by min and max.
Definition aabb_2d.inl:75
TSelf & operator+=(const Aabb2D< T, MMP2 > &other)
Expand bounding box so it contains the other bounding box.
Definition aabb_2d.inl:205
TSelf & operator=(const Aabb2D< T, MMP2 > &other)
assign one bounding box to another.
Definition aabb_2d.inl:177
void clear()
set AABB to an empty box
Definition aabb_2d.inl:445
TSelf & operator+=(const TPoint &point)
Expand bounding box so it contains point.
Definition aabb_2d.inl:190
Aabb2D(const TPoint &point)
Construct bounding box around a single point (min == max)
Definition aabb_2d.inl:88
bool isValid() const
internal check to see if AABB is valid.
Definition aabb_2d.inl:481
const TValue perimeter() const
Returns perimeter of bounding box.
Definition aabb_2d.inl:282
void setMin(const TPoint &min)
set corner with smallest component values
Definition aabb_2d.inl:137
bool intersects(const Aabb2D< T, MMP2 > &other) const
Check if two axis-aligned bounding boxes do intersect.
Definition aabb_2d.inl:384
bool isEmpty() const
Return true if bounding box contains no points.
Definition aabb_2d.inl:459
bool collides(const Aabb2D< T, MMP2 > &other) const
Check if two axis-aligned bounding boxes do dollide.
Definition aabb_2d.inl:415
const TPointH center() const
Return the center point of the bounding box.
Definition aabb_2d.inl:255
const TValue area() const
Returns area of bounding box.
Definition aabb_2d.inl:298
const TVector size() const
Return size of bounding box per axis, max - min.
Definition aabb_2d.inl:267
void grow(TParam iDistance)
Expand bounding box by distance iDistance.
Definition aabb_2d.inl:219
const TPoint random(RandomGenerator &random) const
Return a random point so that bounding box contains it.
Definition aabb_2d.inl:430
void swap(Aabb2D< T, MMP2 > &other)
swap two bounding boxes.
Definition aabb_2d.inl:492
Side classify(const TPoint &point) const
Classify if a point is in or outside the bounding box, or on its surface.
Definition aabb_2d.inl:313
bool contains(const TPoint &point) const
Returns true if point is inside bounding box or on its surface.
Definition aabb_2d.inl:338
void scale(TParam iScale)
Scale bounding box by scale iScale.
Definition aabb_2d.inl:239
Aabb2D()
Construct an empty bounding box.
Definition aabb_2d.inl:63
Aabb2D(const Aabb2D< T, MMP2 > &other)
copy constructor.
Definition aabb_2d.inl:101
bool contains(const Aabb2D< T, MMP2 > &other) const
Returns true if the AABB other is inside (or on its surface) this AABB.
Definition aabb_2d.inl:354
void setMax(const TPoint &max)
set corner with larges component values
Definition aabb_2d.inl:156
#define LASS_SIMD_ALIGN
if LASS_SIMD_ALIGNMENT is set, use LASS_SIMD_ALIGN to align some structures on SIMD alignment boundar...
set of geometrical primitives
Definition aabb_2d.h:81
Side
Different sides of a surface.
Definition side.h:79
Result
meta information on the result you have from an operation like an intersection ...
Definition result.h:74
Library for Assembled Shared Sources.
Definition config.h:53
homogenous 2D Point
Definition point_2dh.h:63
MinMaxPolicy enforcing strict rules for the minima and maxima.