1/// @ref gtx_vector_query 2/// @file glm/gtx/vector_query.inl 3 4#include <cassert> 5 6namespace glm{ 7namespace detail 8{ 9 template <typename T, precision P, template <typename, precision> class vecType> 10 struct compute_areCollinear{}; 11 12 template <typename T, precision P> 13 struct compute_areCollinear<T, P, tvec2> 14 { 15 GLM_FUNC_QUALIFIER static bool call(tvec2<T, P> const & v0, tvec2<T, P> const & v1, T const & epsilon) 16 { 17 return length(cross(tvec3<T, P>(v0, static_cast<T>(0)), tvec3<T, P>(v1, static_cast<T>(0)))) < epsilon; 18 } 19 }; 20 21 template <typename T, precision P> 22 struct compute_areCollinear<T, P, tvec3> 23 { 24 GLM_FUNC_QUALIFIER static bool call(tvec3<T, P> const & v0, tvec3<T, P> const & v1, T const & epsilon) 25 { 26 return length(cross(v0, v1)) < epsilon; 27 } 28 }; 29 30 template <typename T, precision P> 31 struct compute_areCollinear<T, P, tvec4> 32 { 33 GLM_FUNC_QUALIFIER static bool call(tvec4<T, P> const & v0, tvec4<T, P> const & v1, T const & epsilon) 34 { 35 return length(cross(tvec3<T, P>(v0), tvec3<T, P>(v1))) < epsilon; 36 } 37 }; 38 39 template <typename T, precision P, template <typename, precision> class vecType> 40 struct compute_isCompNull{}; 41 42 template <typename T, precision P> 43 struct compute_isCompNull<T, P, tvec2> 44 { 45 GLM_FUNC_QUALIFIER static tvec2<bool, P> call(tvec2<T, P> const & v, T const & epsilon) 46 { 47 return tvec2<bool, P>( 48 (abs(v.x) < epsilon), 49 (abs(v.y) < epsilon)); 50 } 51 }; 52 53 template <typename T, precision P> 54 struct compute_isCompNull<T, P, tvec3> 55 { 56 GLM_FUNC_QUALIFIER static tvec3<bool, P> call(tvec3<T, P> const & v, T const & epsilon) 57 { 58 return tvec3<bool, P>( 59 (abs(v.x) < epsilon), 60 (abs(v.y) < epsilon), 61 (abs(v.z) < epsilon)); 62 } 63 }; 64 65 template <typename T, precision P> 66 struct compute_isCompNull<T, P, tvec4> 67 { 68 GLM_FUNC_QUALIFIER static tvec4<bool, P> call(tvec4<T, P> const & v, T const & epsilon) 69 { 70 return tvec4<bool, P>( 71 (abs(v.x) < epsilon), 72 (abs(v.y) < epsilon), 73 (abs(v.z) < epsilon), 74 (abs(v.w) < epsilon)); 75 } 76 }; 77 78}//namespace detail 79 80 template <typename T, precision P, template <typename, precision> class vecType> 81 GLM_FUNC_QUALIFIER bool areCollinear 82 ( 83 vecType<T, P> const & v0, 84 vecType<T, P> const & v1, 85 T const & epsilon 86 ) 87 { 88 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'areCollinear' only accept floating-point inputs"); 89 90 return detail::compute_areCollinear<T, P, vecType>::call(v0, v1, epsilon); 91 } 92 93 template <typename T, precision P, template <typename, precision> class vecType> 94 GLM_FUNC_QUALIFIER bool areOrthogonal 95 ( 96 vecType<T, P> const & v0, 97 vecType<T, P> const & v1, 98 T const & epsilon 99 ) 100 { 101 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'areOrthogonal' only accept floating-point inputs"); 102 103 return abs(dot(v0, v1)) <= max( 104 static_cast<T>(1), 105 length(v0)) * max(static_cast<T>(1), length(v1)) * epsilon; 106 } 107 108 template <typename T, precision P, template <typename, precision> class vecType> 109 GLM_FUNC_QUALIFIER bool isNormalized 110 ( 111 vecType<T, P> const & v, 112 T const & epsilon 113 ) 114 { 115 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isNormalized' only accept floating-point inputs"); 116 117 return abs(length(v) - static_cast<T>(1)) <= static_cast<T>(2) * epsilon; 118 } 119 120 template <typename T, precision P, template <typename, precision> class vecType> 121 GLM_FUNC_QUALIFIER bool isNull 122 ( 123 vecType<T, P> const & v, 124 T const & epsilon 125 ) 126 { 127 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isNull' only accept floating-point inputs"); 128 129 return length(v) <= epsilon; 130 } 131 132 template <typename T, precision P, template <typename, precision> class vecType> 133 GLM_FUNC_QUALIFIER vecType<bool, P> isCompNull 134 ( 135 vecType<T, P> const & v, 136 T const & epsilon 137 ) 138 { 139 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isCompNull' only accept floating-point inputs"); 140 141 return detail::compute_isCompNull<T, P, vecType>::call(v, epsilon); 142 } 143 144 template <typename T, precision P> 145 GLM_FUNC_QUALIFIER tvec2<bool, P> isCompNull 146 ( 147 tvec2<T, P> const & v, 148 T const & epsilon) 149 { 150 return tvec2<bool, P>( 151 abs(v.x) < epsilon, 152 abs(v.y) < epsilon); 153 } 154 155 template <typename T, precision P> 156 GLM_FUNC_QUALIFIER tvec3<bool, P> isCompNull 157 ( 158 tvec3<T, P> const & v, 159 T const & epsilon 160 ) 161 { 162 return tvec3<bool, P>( 163 abs(v.x) < epsilon, 164 abs(v.y) < epsilon, 165 abs(v.z) < epsilon); 166 } 167 168 template <typename T, precision P> 169 GLM_FUNC_QUALIFIER tvec4<bool, P> isCompNull 170 ( 171 tvec4<T, P> const & v, 172 T const & epsilon 173 ) 174 { 175 return tvec4<bool, P>( 176 abs(v.x) < epsilon, 177 abs(v.y) < epsilon, 178 abs(v.z) < epsilon, 179 abs(v.w) < epsilon); 180 } 181 182 template <typename T, precision P, template <typename, precision> class vecType> 183 GLM_FUNC_QUALIFIER bool areOrthonormal 184 ( 185 vecType<T, P> const & v0, 186 vecType<T, P> const & v1, 187 T const & epsilon 188 ) 189 { 190 return isNormalized(v0, epsilon) && isNormalized(v1, epsilon) && (abs(dot(v0, v1)) <= epsilon); 191 } 192 193}//namespace glm 194