1 // Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 _min(SGLimits<T>::max(), SGLimits<T>::max(), SGLimits<T>::max()),
26 _max(-SGLimits<T>::max(), -SGLimits<T>::max(), -SGLimits<T>::max())
28 void setMin(const SGVec3<T>& min)
30 const SGVec3<T>& getMin() const
33 void setMax(const SGVec3<T>& max)
35 const SGVec3<T>& getMax() const
38 // Only works for floating point types
39 SGVec3<T> getCenter() const
40 { return T(0.5)*(_min + _max); }
42 // Only valid for nonempty boxes
43 SGVec3<T> getSize() const
44 { return _max - _min; }
50 return (_max[0] - _min[0])*(_max[1] - _min[1])*(_max[2] - _min[2]);
53 const bool empty() const
58 if (_max[0] < _min[0])
60 if (_max[1] < _min[1])
62 if (_max[2] < _min[2])
69 _min[0] = SGLimits<T>::max();
70 _min[1] = SGLimits<T>::max();
71 _min[2] = SGLimits<T>::max();
72 _max[0] = -SGLimits<T>::max();
73 _max[1] = -SGLimits<T>::max();
74 _max[2] = -SGLimits<T>::max();
77 void expandBy(const SGVec3<T>& v)
78 { _min = min(_min, v); _max = max(_max, v); }
80 void expandBy(const SGBox<T>& b)
81 { _min = min(_min, b._min); _max = max(_max, b._max); }
83 // Note that this only works if the box is nonmepty
84 unsigned getBroadestAxis() const
86 SGVec3d size = getSize();
87 if (size[1] <= size[0] && size[2] <= size[0])
89 else if (size[2] <= size[1])
100 /// Output to an ostream
101 template<typename char_type, typename traits_type, typename T>
103 std::basic_ostream<char_type, traits_type>&
104 operator<<(std::basic_ostream<char_type, traits_type>& s, const SGBox<T>& box)
105 { return s << "min = " << box.getMin() << ", max = " << box.getMax(); }