vec2-ext.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. /*!
  8. * @brief SIMD like functions
  9. */
  10. /*
  11. Functions:
  12. CGLM_INLINE vec2s glms_vec2_fill(float val)
  13. CGLM_INLINE bool glms_vec2_eq(vec2s v, float val)
  14. CGLM_INLINE bool glms_vec2_eq_eps(vec2s v, float val)
  15. CGLM_INLINE bool glms_vec2_eq_all(vec2s v)
  16. CGLM_INLINE bool glms_vec2_eqv(vec2s a, vec2s b)
  17. CGLM_INLINE bool glms_vec2_eqv_eps(vec2s a, vec2s b)
  18. CGLM_INLINE float glms_vec2_max(vec2s v)
  19. CGLM_INLINE float glms_vec2_min(vec2s v)
  20. CGLM_INLINE bool glms_vec2_isnan(vec2s v)
  21. CGLM_INLINE bool glms_vec2_isinf(vec2s v)
  22. CGLM_INLINE bool glms_vec2_isvalid(vec2s v)
  23. CGLM_INLINE vec2s glms_vec2_sign(vec2s v)
  24. CGLM_INLINE vec2s glms_vec2_abs(vec2s v)
  25. CGLM_INLINE vec2s glms_vec2_fract(vec2s v)
  26. CGLM_INLINE vec2s glms_vec2_floor(vec2s v)
  27. CGLM_INLINE vec2s glms_vec2_mods(vec2s v, float s)
  28. CGLM_INLINE vec2s glms_vec2_steps(float edge, vec2s v)
  29. CGLM_INLINE vec2s glms_vec2_stepr(vec2s edge, float v)
  30. CGLM_INLINE vec2s glms_vec2_sqrt(vec2s v)
  31. */
  32. #ifndef cglms_vec2s_ext_h
  33. #define cglms_vec2s_ext_h
  34. #include "../common.h"
  35. #include "../types-struct.h"
  36. #include "../util.h"
  37. #include "../vec2-ext.h"
  38. /* api definition */
  39. #define glms_vec2_(NAME) CGLM_STRUCTAPI(vec2, NAME)
  40. /*!
  41. * @brief fill a vector with specified value
  42. *
  43. * @param[in] val value
  44. * @returns dest
  45. */
  46. CGLM_INLINE
  47. vec2s
  48. glms_vec2_(fill)(float val) {
  49. vec2s r;
  50. glm_vec2_fill(r.raw, val);
  51. return r;
  52. }
  53. /*!
  54. * @brief check if vector is equal to value (without epsilon)
  55. *
  56. * @param[in] v vector
  57. * @param[in] val value
  58. */
  59. CGLM_INLINE
  60. bool
  61. glms_vec2_(eq)(vec2s v, float val) {
  62. return glm_vec2_eq(v.raw, val);
  63. }
  64. /*!
  65. * @brief check if vector is equal to value (with epsilon)
  66. *
  67. * @param[in] v vector
  68. * @param[in] val value
  69. */
  70. CGLM_INLINE
  71. bool
  72. glms_vec2_(eq_eps)(vec2s v, float val) {
  73. return glm_vec2_eq_eps(v.raw, val);
  74. }
  75. /*!
  76. * @brief check if vector members are equal (without epsilon)
  77. *
  78. * @param[in] v vector
  79. */
  80. CGLM_INLINE
  81. bool
  82. glms_vec2_(eq_all)(vec2s v) {
  83. return glm_vec2_eq_all(v.raw);
  84. }
  85. /*!
  86. * @brief check if vector is equal to another (without epsilon)
  87. *
  88. * @param[in] a vector
  89. * @param[in] b vector
  90. */
  91. CGLM_INLINE
  92. bool
  93. glms_vec2_(eqv)(vec2s a, vec2s b) {
  94. return glm_vec2_eqv(a.raw, b.raw);
  95. }
  96. /*!
  97. * @brief check if vector is equal to another (with epsilon)
  98. *
  99. * @param[in] a vector
  100. * @param[in] b vector
  101. */
  102. CGLM_INLINE
  103. bool
  104. glms_vec2_(eqv_eps)(vec2s a, vec2s b) {
  105. return glm_vec2_eqv_eps(a.raw, b.raw);
  106. }
  107. /*!
  108. * @brief max value of vector
  109. *
  110. * @param[in] v vector
  111. */
  112. CGLM_INLINE
  113. float
  114. glms_vec2_(max)(vec2s v) {
  115. return glm_vec2_max(v.raw);
  116. }
  117. /*!
  118. * @brief min value of vector
  119. *
  120. * @param[in] v vector
  121. */
  122. CGLM_INLINE
  123. float
  124. glms_vec2_min(vec2s v) {
  125. return glm_vec2_min(v.raw);
  126. }
  127. /*!
  128. * @brief check if one of items is NaN (not a number)
  129. * you should only use this in DEBUG mode or very critical asserts
  130. *
  131. * @param[in] v vector
  132. */
  133. CGLM_INLINE
  134. bool
  135. glms_vec2_(isnan)(vec2s v) {
  136. return glm_vec2_isnan(v.raw);
  137. }
  138. /*!
  139. * @brief check if one of items is INFINITY
  140. * you should only use this in DEBUG mode or very critical asserts
  141. *
  142. * @param[in] v vector
  143. */
  144. CGLM_INLINE
  145. bool
  146. glms_vec2_(isinf)(vec2s v) {
  147. return glm_vec2_isinf(v.raw);
  148. }
  149. /*!
  150. * @brief check if all items are valid number
  151. * you should only use this in DEBUG mode or very critical asserts
  152. *
  153. * @param[in] v vector
  154. */
  155. CGLM_INLINE
  156. bool
  157. glms_vec2_isvalid(vec2s v) {
  158. return glm_vec2_isvalid(v.raw);
  159. }
  160. /*!
  161. * @brief get sign of 32 bit float as +1, -1, 0
  162. *
  163. * Important: It returns 0 for zero/NaN input
  164. *
  165. * @param v vector
  166. * @returns sign vector
  167. */
  168. CGLM_INLINE
  169. vec2s
  170. glms_vec2_(sign)(vec2s v) {
  171. vec2s r;
  172. glm_vec2_sign(v.raw, r.raw);
  173. return r;
  174. }
  175. /*!
  176. * @brief fractional part of each vector item
  177. *
  178. * @param v vector
  179. * @returns abs vector
  180. */
  181. CGLM_INLINE
  182. vec2s
  183. glms_vec2_(abs)(vec2s v) {
  184. vec2s r;
  185. glm_vec2_abs(v.raw, r.raw);
  186. return r;
  187. }
  188. /*!
  189. * @brief fractional part of each vector item
  190. *
  191. * @param[in] v vector
  192. * @returns destination vector
  193. */
  194. CGLM_INLINE
  195. vec2s
  196. glms_vec2_(fract)(vec2s v) {
  197. vec2s r;
  198. glm_vec2_fract(v.raw, r.raw);
  199. return r;
  200. }
  201. /*!
  202. * @brief floor of each vector item
  203. *
  204. * @param[in] v vector
  205. * @returns destination vector
  206. */
  207. CGLM_INLINE
  208. vec2s
  209. glms_vec2_(floor)(vec2s v) {
  210. vec2s r;
  211. glm_vec2_floor(v.raw, r.raw);
  212. return r;
  213. }
  214. /*!
  215. * @brief mod of each vector item by scalar
  216. *
  217. * @param[in] v vector
  218. * @param[in] s scalar
  219. * @returns destination vector
  220. */
  221. CGLM_INLINE
  222. vec2s
  223. glms_vec2_(mods)(vec2s v, float s) {
  224. vec2s r;
  225. glm_vec2_mods(v.raw, s, r.raw);
  226. return r;
  227. }
  228. /*!
  229. * @brief threshold each vector item with scalar
  230. * condition is: (x[i] < edge) ? 0.0 : 1.0
  231. *
  232. * @param[in] edge threshold
  233. * @param[in] x vector to test against threshold
  234. * @returns destination
  235. */
  236. CGLM_INLINE
  237. vec2s
  238. glms_vec2_(steps)(float edge, vec2s x) {
  239. vec2s r;
  240. glm_vec2_steps(edge, x.raw, r.raw);
  241. return r;
  242. }
  243. /*!
  244. * @brief threshold a value with *vector* as the threshold
  245. * condition is: (x < edge[i]) ? 0.0 : 1.0
  246. *
  247. * @param[in] edge threshold vector
  248. * @param[in] x value to test against threshold
  249. * @returns destination
  250. */
  251. CGLM_INLINE
  252. vec2s
  253. glms_vec2_(stepr)(vec2s edge, float x) {
  254. vec2s r;
  255. glm_vec2_stepr(edge.raw, x, r.raw);
  256. return r;
  257. }
  258. /*!
  259. * @brief square root of each vector item
  260. *
  261. * @param[in] v vector
  262. * @returns destination vector
  263. */
  264. CGLM_INLINE
  265. vec2s
  266. glms_vec2_(sqrt)(vec2s v) {
  267. vec2s r;
  268. glm_vec2_sqrt(v.raw, r.raw);
  269. return r;
  270. }
  271. /*!
  272. * @brief treat vectors as complex numbers and multiply them as such.
  273. *
  274. * @param[in] a left number
  275. * @param[in] b right number
  276. * @param[out] dest destination number
  277. */
  278. CGLM_INLINE
  279. vec2s
  280. glms_vec2_(complex_mul)(vec2s a, vec2s b, vec2s dest) {
  281. glm_vec2_complex_mul(a.raw, b.raw, dest.raw);
  282. return dest;
  283. }
  284. /*!
  285. * @brief treat vectors as complex numbers and divide them as such.
  286. *
  287. * @param[in] a left number (numerator)
  288. * @param[in] b right number (denominator)
  289. * @param[out] dest destination number
  290. */
  291. CGLM_INLINE
  292. vec2s
  293. glms_vec2_(complex_div)(vec2s a, vec2s b, vec2s dest) {
  294. glm_vec2_complex_div(a.raw, b.raw, dest.raw);
  295. return dest;
  296. }
  297. /*!
  298. * @brief treat the vector as a complex number and conjugate it as such.
  299. *
  300. * @param[in] a the number
  301. * @param[out] dest destination number
  302. */
  303. CGLM_INLINE
  304. vec2s
  305. glms_vec2_(complex_conjugate)(vec2s a, vec2s dest) {
  306. glm_vec2_complex_conjugate(a.raw, dest.raw);
  307. return dest;
  308. }
  309. #endif /* cglms_vec2s_ext_h */