Home | History | Annotate | Download | only in detail
      1 ///////////////////////////////////////////////////////////////////////////////////
      2 /// OpenGL Mathematics (glm.g-truc.net)
      3 ///
      4 /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
      5 /// Permission is hereby granted, free of charge, to any person obtaining a copy
      6 /// of this software and associated documentation files (the "Software"), to deal
      7 /// in the Software without restriction, including without limitation the rights
      8 /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9 /// copies of the Software, and to permit persons to whom the Software is
     10 /// furnished to do so, subject to the following conditions:
     11 /// 
     12 /// The above copyright notice and this permission notice shall be included in
     13 /// all copies or substantial portions of the Software.
     14 /// 
     15 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     21 /// THE SOFTWARE.
     22 ///
     23 /// @ref core
     24 /// @file glm/core/func_vector_relational.inl
     25 /// @date 2008-08-03 / 2011-09-09
     26 /// @author Christophe Riccio
     27 ///////////////////////////////////////////////////////////////////////////////////
     28 
     29 #include <limits>
     30 
     31 namespace glm
     32 {
     33 	template <typename T, precision P, template <typename, precision> class vecType>
     34 	GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type lessThan
     35 	(
     36 		vecType<T, P> const & x,
     37 		vecType<T, P> const & y
     38 	)
     39 	{
     40 		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
     41 			"Invalid template instantiation of 'lessThan', GLM vector types required floating-point or integer value types vectors");
     42 		assert(x.length() == y.length());
     43 
     44 		typename vecType<bool, P>::bool_type Result(vecType<bool, P>::_null);
     45 		for(int i = 0; i < x.length(); ++i)
     46 			Result[i] = x[i] < y[i];
     47 
     48 		return Result;
     49 	}
     50 
     51 	template <typename T, precision P, template <typename, precision> class vecType>
     52 	GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type lessThanEqual
     53 	(
     54 		vecType<T, P> const & x,
     55 		vecType<T, P> const & y
     56 	)
     57 	{
     58 		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
     59 			"Invalid template instantiation of 'lessThanEqual', GLM vector types required floating-point or integer value types vectors");
     60 		assert(x.length() == y.length());
     61 
     62 		typename vecType<bool, P>::bool_type Result(vecType<bool, P>::_null);
     63 		for(int i = 0; i < x.length(); ++i)
     64 			Result[i] = x[i] <= y[i];
     65 		return Result;
     66 	}
     67 
     68 	template <typename T, precision P, template <typename, precision> class vecType>
     69 	GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type greaterThan
     70 	(
     71 		vecType<T, P> const & x,
     72 		vecType<T, P> const & y
     73 	)
     74 	{
     75 		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
     76 			"Invalid template instantiation of 'greaterThan', GLM vector types required floating-point or integer value types vectors");
     77 		assert(x.length() == y.length());
     78 
     79 		typename vecType<bool, P>::bool_type Result(vecType<bool, P>::_null);
     80 		for(int i = 0; i < x.length(); ++i)
     81 			Result[i] = x[i] > y[i];
     82 		return Result;
     83 	}
     84 
     85 	template <typename T, precision P, template <typename, precision> class vecType>
     86 	GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type greaterThanEqual
     87 	(
     88 		vecType<T, P> const & x,
     89 		vecType<T, P> const & y
     90 	)
     91 	{
     92 		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
     93 			"Invalid template instantiation of 'greaterThanEqual', GLM vector types required floating-point or integer value types vectors");
     94 		assert(x.length() == y.length());
     95 
     96 		typename vecType<bool, P>::bool_type Result(vecType<bool, P>::_null);
     97 		for(int i = 0; i < x.length(); ++i)
     98 			Result[i] = x[i] >= y[i];
     99 		return Result;
    100 	}
    101 
    102 	template <typename T, precision P, template <typename, precision> class vecType>
    103 	GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type equal
    104 	(
    105 		vecType<T, P> const & x,
    106 		vecType<T, P> const & y
    107 	)
    108 	{
    109 		assert(x.length() == y.length());
    110 
    111 		typename vecType<bool, P>::bool_type Result(vecType<bool, P>::_null);
    112 		for(int i = 0; i < x.length(); ++i)
    113 			Result[i] = x[i] == y[i];
    114 		return Result;
    115 	}
    116 
    117 	template <typename T, precision P, template <typename, precision> class vecType>
    118 	GLM_FUNC_QUALIFIER typename vecType<T, P>::bool_type notEqual
    119 	(
    120 		vecType<T, P> const & x,
    121 		vecType<T, P> const & y
    122 	)
    123 	{
    124 		assert(x.length() == y.length());
    125 
    126 		typename vecType<bool, P>::bool_type Result(vecType<bool, P>::_null);
    127 		for(int i = 0; i < x.length(); ++i)
    128 			Result[i] = x[i] != y[i];
    129 		return Result;
    130 	}
    131 
    132 	template <precision P, template <typename, precision> class vecType>
    133 	GLM_FUNC_QUALIFIER bool any(vecType<bool, P> const & v)
    134 	{
    135 		bool Result = false;
    136 		for(int i = 0; i < v.length(); ++i)
    137 			Result = Result || v[i];
    138 		return Result;
    139 	}
    140 
    141 	template <precision P, template <typename, precision> class vecType>
    142 	GLM_FUNC_QUALIFIER bool all(vecType<bool, P> const & v)
    143 	{
    144 		bool Result = true;
    145 		for(int i = 0; i < v.length(); ++i)
    146 			Result = Result && v[i];
    147 		return Result;
    148 	}
    149 
    150 	template <precision P, template <typename, precision> class vecType>
    151 	GLM_FUNC_QUALIFIER vecType<bool, P> not_(vecType<bool, P> const & v)
    152 	{
    153 		typename vecType<bool, P>::bool_type Result(vecType<bool, P>::_null);
    154 		for(int i = 0; i < v.length(); ++i)
    155 			Result[i] = !v[i];
    156 		return Result;
    157 	}
    158 }//namespace glm
    159 
    160