AxisAlignedBox.h
1 /*
2  This file is part of the VRender library.
3  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4  Version 1.0.0, released on June 27, 2005.
5 
6  http://artis.imag.fr/Members/Cyril.Soler/VRender
7 
8  VRender is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  VRender is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with VRender; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 /****************************************************************************
24 
25  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.5.2.
28 
29  http://www.libqglviewer.com - contact@libqglviewer.com
30 
31  This file may be used under the terms of the GNU General Public License
32  versions 2.0 or 3.0 as published by the Free Software Foundation and
33  appearing in the LICENSE file included in the packaging of this file.
34  In addition, as a special exception, Gilles Debunne gives you certain
35  additional rights, described in the file GPL_EXCEPTION in this package.
36 
37  libQGLViewer uses dual licensing. Commercial/proprietary software must
38  purchase a libQGLViewer Commercial License.
39 
40  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 
43 *****************************************************************************/
44 
45 #ifndef _VRENDER_AXISALIGNEDBOX_H
46 #define _VRENDER_AXISALIGNEDBOX_H
47 
48 namespace vrender
49 {
50  class Vector2;
51  class Vector3;
52 
53  template<class T> class AxisAlignedBox
54  {
55  public:
56  AxisAlignedBox() ;
57  AxisAlignedBox(const T& v) ;
58  AxisAlignedBox(const T& v,const T& w) ;
59 
60  const T& mini() const { return _min ; }
61  const T& maxi() const { return _max ; }
62 
63  void include(const T& v) ;
64  void include(const AxisAlignedBox<T>& b) ;
65  private:
66  T _min ;
67  T _max ;
68  };
69 
72 
73  template<class T> AxisAlignedBox<T>::AxisAlignedBox()
74  : _min(T::inf), _max(-T::inf)
75  {
76  }
77 
78  template<class T> AxisAlignedBox<T>::AxisAlignedBox(const T& v)
79  : _min(v), _max(v)
80  {
81  }
82 
83  template<class T> AxisAlignedBox<T>::AxisAlignedBox(const T& v,const T& w)
84  : _min(v), _max(v)
85  {
86  include(w) ;
87  }
88 
89  template<class T> void AxisAlignedBox<T>::include(const T& v)
90  {
91  _min = T::mini(_min,v) ;
92  _max = T::maxi(_max,v) ;
93  }
94 
95  template<class T> void AxisAlignedBox<T>::include(const AxisAlignedBox<T>& b)
96  {
97  include(b._min) ;
98  include(b._max) ;
99  }
100 }
101 #endif