You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
6.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 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 gtc_epsilon
  24. /// @file glm/gtc/epsilon.inl
  25. /// @date 2012-04-07 / 2012-04-07
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. namespace glm
  29. {
  30. GLM_FUNC_QUALIFIER bool epsilonEqual
  31. (
  32. glm::half const & x,
  33. glm::half const & y,
  34. glm::half const & epsilon
  35. )
  36. {
  37. return abs(x - y) < epsilon;
  38. }
  39. GLM_FUNC_QUALIFIER bool epsilonEqual
  40. (
  41. float const & x,
  42. float const & y,
  43. float const & epsilon
  44. )
  45. {
  46. return abs(x - y) < epsilon;
  47. }
  48. GLM_FUNC_QUALIFIER bool epsilonEqual
  49. (
  50. double const & x,
  51. double const & y,
  52. double const & epsilon
  53. )
  54. {
  55. return abs(x - y) < epsilon;
  56. }
  57. GLM_FUNC_QUALIFIER bool epsilonNotEqual
  58. (
  59. glm::half const & x,
  60. glm::half const & y,
  61. glm::half const & epsilon
  62. )
  63. {
  64. return abs(x - y) >= epsilon;
  65. }
  66. GLM_FUNC_QUALIFIER bool epsilonNotEqual
  67. (
  68. float const & x,
  69. float const & y,
  70. float const & epsilon
  71. )
  72. {
  73. return abs(x - y) >= epsilon;
  74. }
  75. GLM_FUNC_QUALIFIER bool epsilonNotEqual
  76. (
  77. double const & x,
  78. double const & y,
  79. double const & epsilon
  80. )
  81. {
  82. return abs(x - y) >= epsilon;
  83. }
  84. template <typename valType>
  85. GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonEqual
  86. (
  87. detail::tvec2<valType> const & x,
  88. detail::tvec2<valType> const & y,
  89. valType const & epsilon)
  90. {
  91. return detail::tvec2<bool>(
  92. abs(x.x - y.x) < epsilon,
  93. abs(x.y - y.y) < epsilon);
  94. }
  95. template <typename valType>
  96. GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonEqual
  97. (
  98. detail::tvec2<valType> const & x,
  99. detail::tvec2<valType> const & y,
  100. detail::tvec2<valType> const & epsilon
  101. )
  102. {
  103. return detail::tvec2<bool>(
  104. abs(x.x - y.x) < epsilon.x,
  105. abs(x.y - y.y) < epsilon.y);
  106. }
  107. template <typename valType>
  108. GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonEqual
  109. (
  110. detail::tvec3<valType> const & x,
  111. detail::tvec3<valType> const & y,
  112. valType const & epsilon)
  113. {
  114. return detail::tvec3<bool>(
  115. abs(x.x - y.x) < epsilon,
  116. abs(x.y - y.y) < epsilon,
  117. abs(x.z - y.z) < epsilon);
  118. }
  119. template <typename valType>
  120. GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonEqual
  121. (
  122. detail::tvec3<valType> const & x,
  123. detail::tvec3<valType> const & y,
  124. detail::tvec3<valType> const & epsilon
  125. )
  126. {
  127. return detail::tvec3<bool>(
  128. abs(x.x - y.x) < epsilon.x,
  129. abs(x.y - y.y) < epsilon.y,
  130. abs(x.z - y.z) < epsilon.z);
  131. }
  132. template <typename valType>
  133. GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonEqual
  134. (
  135. detail::tvec4<valType> const & x,
  136. detail::tvec4<valType> const & y,
  137. valType const & epsilon
  138. )
  139. {
  140. return detail::tvec4<bool>(
  141. abs(x.x - y.x) < epsilon,
  142. abs(x.y - y.y) < epsilon,
  143. abs(x.z - y.z) < epsilon,
  144. abs(x.w - y.w) < epsilon);
  145. }
  146. template <typename valType>
  147. GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonEqual
  148. (
  149. detail::tvec4<valType> const & x,
  150. detail::tvec4<valType> const & y,
  151. detail::tvec4<valType> const & epsilon
  152. )
  153. {
  154. return detail::tvec4<bool>(
  155. abs(x.x - y.x) < epsilon.x,
  156. abs(x.y - y.y) < epsilon.y,
  157. abs(x.z - y.z) < epsilon.z,
  158. abs(x.w - y.w) < epsilon.w);
  159. }
  160. template <typename valType>
  161. GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonNotEqual
  162. (
  163. detail::tvec2<valType> const & x,
  164. detail::tvec2<valType> const & y,
  165. valType const & epsilon
  166. )
  167. {
  168. return detail::tvec2<bool>(
  169. abs(x.x - y.x) >= epsilon,
  170. abs(x.y - y.y) >= epsilon);
  171. }
  172. template <typename valType>
  173. GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonNotEqual
  174. (
  175. detail::tvec2<valType> const & x,
  176. detail::tvec2<valType> const & y,
  177. detail::tvec2<valType> const & epsilon
  178. )
  179. {
  180. return detail::tvec2<bool>(
  181. abs(x.x - y.x) >= epsilon.x,
  182. abs(x.y - y.y) >= epsilon.y);
  183. }
  184. template <typename valType>
  185. GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonNotEqual
  186. (
  187. detail::tvec3<valType> const & x,
  188. detail::tvec3<valType> const & y,
  189. valType const & epsilon
  190. )
  191. {
  192. return detail::tvec3<bool>(
  193. abs(x.x - y.x) >= epsilon,
  194. abs(x.y - y.y) >= epsilon,
  195. abs(x.z - y.z) >= epsilon);
  196. }
  197. template <typename valType>
  198. GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonNotEqual
  199. (
  200. detail::tvec3<valType> const & x,
  201. detail::tvec3<valType> const & y,
  202. detail::tvec3<valType> const & epsilon
  203. )
  204. {
  205. return detail::tvec3<bool>(
  206. abs(x.x - y.x) >= epsilon.x,
  207. abs(x.y - y.y) >= epsilon.y,
  208. abs(x.z - y.z) >= epsilon.z);
  209. }
  210. template <typename valType>
  211. GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonNotEqual
  212. (
  213. detail::tvec4<valType> const & x,
  214. detail::tvec4<valType> const & y,
  215. valType const & epsilon
  216. )
  217. {
  218. return detail::tvec4<bool>(
  219. abs(x.x - y.x) >= epsilon,
  220. abs(x.y - y.y) >= epsilon,
  221. abs(x.z - y.z) >= epsilon,
  222. abs(x.w - y.w) >= epsilon);
  223. }
  224. template <typename valType>
  225. GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonNotEqual
  226. (
  227. detail::tvec4<valType> const & x,
  228. detail::tvec4<valType> const & y,
  229. detail::tvec4<valType> const & epsilon
  230. )
  231. {
  232. return detail::tvec4<bool>(
  233. abs(x.x - y.x) >= epsilon.x,
  234. abs(x.y - y.y) >= epsilon.y,
  235. abs(x.z - y.z) >= epsilon.z,
  236. abs(x.w - y.w) >= epsilon.w);
  237. }
  238. template <typename valType>
  239. GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonEqual
  240. (
  241. detail::tquat<valType> const & x,
  242. detail::tquat<valType> const & y,
  243. valType const & epsilon
  244. )
  245. {
  246. return detail::tvec4<bool>(
  247. abs(x.x - y.x) < epsilon,
  248. abs(x.y - y.y) < epsilon,
  249. abs(x.z - y.z) < epsilon,
  250. abs(x.w - y.w) < epsilon);
  251. }
  252. template <typename valType>
  253. GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonNotEqual
  254. (
  255. detail::tquat<valType> const & x,
  256. detail::tquat<valType> const & y,
  257. valType const & epsilon
  258. )
  259. {
  260. return detail::tvec4<bool>(
  261. abs(x.x - y.x) >= epsilon,
  262. abs(x.y - y.y) >= epsilon,
  263. abs(x.z - y.z) >= epsilon,
  264. abs(x.w - y.w) >= epsilon);
  265. }
  266. }//namespace glm