1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 // File: vogl_vec_interval.h
30 #include "vogl_core.h"
48 typedef typename T::scalar_type scalar_type;
53 inline vec_interval(eInitExpand)
57 inline vec_interval(const T &v)
62 inline vec_interval(const T &low, const T &high)
74 inline const T &operator[](uint i) const
79 inline T &operator[](uint i)
85 inline T get_range() const
87 return m_bounds[1] - m_bounds[0];
89 inline scalar_type get_dimension(uint axis) const
91 return m_bounds[1][axis] - m_bounds[0][axis];
94 inline void init_expand()
96 m_bounds[0].set(std::numeric_limits<scalar_type>::max());
97 m_bounds[1].set(std::numeric_limits<scalar_type>::lowest());
100 inline void expand(const T &val)
102 m_bounds[0] = T::component_min(m_bounds[0], val);
103 m_bounds[1] = T::component_max(m_bounds[1], val);
106 inline bool is_null() const
108 for (uint i = 0; i < N; i++)
109 if (m_bounds[0][i] > m_bounds[1][i])
118 typedef vec_interval<vec1F> vec_interval1F;
119 typedef vec_interval<vec2I> vec_interval2I;
120 typedef vec_interval<vec2F> vec_interval2F;
121 typedef vec_interval<vec3F> vec_interval3F;
122 typedef vec_interval<vec4F> vec_interval4F;
124 typedef vec_interval2F aabb2F;
125 typedef vec_interval3F aabb3F;
127 template <typename T>
128 class scalar_interval
131 typedef T scalar_type;
133 inline scalar_interval()
136 inline scalar_interval(eInitExpand)
140 inline scalar_interval(const T v)
145 inline scalar_interval(const T low, const T high)
157 inline const T operator[](uint i) const
162 inline T &operator[](uint i)
168 inline T get_range() const
170 return m_bounds[1] - m_bounds[0];
172 inline T get_dimension() const
177 inline void init_expand()
179 m_bounds[0] = std::numeric_limits<scalar_type>::max();
180 m_bounds[1] = std::numeric_limits<scalar_type>::min();
183 inline void expand(const T val)
185 m_bounds[0] = math::minimum(m_bounds[0], val);
186 m_bounds[1] = math::maximum(m_bounds[1], val);
189 inline bool is_null() const
191 return m_bounds[0] > m_bounds[1];
198 typedef scalar_interval<float> scalar_intervalF;
199 typedef scalar_interval<double> scalar_intervalD;