CMSC23700 Common Code Library
Support code for CS23700 programming projects
cs237-aabb.hxx
Go to the documentation of this file.
1 
6 /*
7  * COPYRIGHT (c) 2015 John Reppy (http://cs.uchicago.edu/~jhr)
8  * All rights reserved.
9  */
10 
11 #ifndef _CS237_AABB_HXX_
12 #define _CS237_AABB_HXX_
13 
14 #ifndef _CS237_HXX_
15 # error "c237-aabb.hxx should not be included directly"
16 #endif
17 
18 namespace cs237 {
19 
20  namespace __detail {
21 
23  template <typename T>
24  struct AABB {
26  bool _empty;
27 
28  AABB () : _min(), _max(), _empty(true) {}
29  AABB (AABB const & bbox) : _min(bbox._min), _max(bbox._max), _empty(bbox._empty) {}
30  AABB (vec3<T> const &pt) : _min(pt), _max(pt), _empty(false) {}
31  AABB (vec3<T> const &min, vec3<T> const &max) : _min(min), _max(max), _empty(false) {}
32 
34  bool isEmpty () const;
35 
37  void clear ();
38 
40  bool includesPt (vec3<T> const &pt) const;
41 
43  T distanceToPt (vec3<T> const &pt) const;
44 
46  void addPt (vec3<T> const &pt);
47 
50  AABB & operator+= (AABB const &bb);
51 
54  AABB & operator+= (vec3<T> const &pt);
55 
56  /***** Warning: the following functions are undefined on empty boxes! *****/
57 
59  vec3<T> const & min() const;
60 
62  vec3<T> const & max() const;
63 
65  vec3<T> center () const;
66 
68  T minX () const;
70  T minY () const;
72  T minZ () const;
74  T maxX () const;
76  T maxY () const;
78  T maxZ () const;
79 
82  vec3<T> corner (int i) const;
83  };
84 
86  template <typename T>
87  std::ostream& operator<< (std::ostream& s, __detail::AABB<T> const &bb);
88 
89  } // namespace __detail
90 
95 
96 } //namespace cs237
97 
98 #endif /* !_CS237_AABB_HXX_ */
T minX() const
minimum X-coordinate of the box
Definition: cs237-aabb.inl:100
bool _empty
Definition: cs237-aabb.hxx:26
T maxZ() const
maximum Z-coordinate of the box
Definition: cs237-aabb.inl:135
T maxY() const
maximum Y-coordinate of the box
Definition: cs237-aabb.inl:128
__detail::AABB< double > AABBd
Double-precision axis-aligned bounding boxes.
Definition: cs237-aabb.hxx:94
bool isEmpty() const
is the box empty
Definition: cs237-aabb.inl:23
vec3< T > corner(int i) const
Definition: cs237-aabb.inl:144
Axis-Aligned Bounding Box.
Definition: cs237-aabb.hxx:24
vec3< T > const & max() const
maximum extents of the box
Definition: cs237-aabb.inl:93
void addPt(vec3< T > const &pt)
extend this box as necessary to include the point
Definition: cs237-aabb.inl:62
AABB()
Definition: cs237-aabb.hxx:28
bool includesPt(vec3< T > const &pt) const
is a point inside the box?
Definition: cs237-aabb.inl:36
T minY() const
minimum Y-coordinate of the box
Definition: cs237-aabb.inl:107
vec3< T > const & min() const
minimum extents of the box
Definition: cs237-aabb.inl:86
T distanceToPt(vec3< T > const &pt) const
distance to a point; will be 0.0 if the point is inside the box
Definition: cs237-aabb.inl:45
AABB & operator+=(AABB const &bb)
Definition: cs237-aabb.inl:181
void clear()
clear the box (i.e., make it empty)
Definition: cs237-aabb.inl:30
T minZ() const
minimum Z-coordinate of the box
Definition: cs237-aabb.inl:114
Definition: cs237-aabb.hxx:18
template class for three-element vectors
Definition: cs237-types.hxx:26
T maxX() const
maximum X-coordinate of the box
Definition: cs237-aabb.inl:121
AABB(AABB const &bbox)
Definition: cs237-aabb.hxx:29
AABB(vec3< T > const &min, vec3< T > const &max)
Definition: cs237-aabb.hxx:31
vec3< T > _max
Definition: cs237-aabb.hxx:25
AABB(vec3< T > const &pt)
Definition: cs237-aabb.hxx:30
vec3< T > _min
Definition: cs237-aabb.hxx:25
vec3< T > center() const
center of the box
Definition: cs237-aabb.inl:79
__detail::AABB< float > AABBf
Single-precision axis-aligned bounding boxes.
Definition: cs237-aabb.hxx:92