type_vec2.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /// @ref core
  2. /// @file glm/detail/type_vec2.hpp
  3. #pragma once
  4. #include "type_vec.hpp"
  5. #if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
  6. # if GLM_HAS_UNRESTRICTED_UNIONS
  7. # include "_swizzle.hpp"
  8. # else
  9. # include "_swizzle_func.hpp"
  10. # endif
  11. #endif //GLM_SWIZZLE
  12. #include <cstddef>
  13. namespace glm
  14. {
  15. template <typename T, precision P = defaultp>
  16. struct tvec2
  17. {
  18. // -- Implementation detail --
  19. typedef T value_type;
  20. typedef tvec2<T, P> type;
  21. typedef tvec2<bool, P> bool_type;
  22. // -- Data --
  23. # if GLM_HAS_ONLY_XYZW
  24. T x, y;
  25. # elif GLM_HAS_ALIGNED_TYPE
  26. # if GLM_COMPILER & GLM_COMPILER_GCC
  27. # pragma GCC diagnostic push
  28. # pragma GCC diagnostic ignored "-Wpedantic"
  29. # endif
  30. # if GLM_COMPILER & GLM_COMPILER_CLANG
  31. # pragma clang diagnostic push
  32. # pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
  33. # pragma clang diagnostic ignored "-Wnested-anon-types"
  34. # endif
  35. union
  36. {
  37. struct{ T x, y; };
  38. struct{ T r, g; };
  39. struct{ T s, t; };
  40. # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
  41. _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, x, y)
  42. _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, r, g)
  43. _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, s, t)
  44. _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, x, y)
  45. _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, r, g)
  46. _GLM_SWIZZLE2_3_MEMBERS(T, P, glm::tvec3, s, t)
  47. _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, x, y)
  48. _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, r, g)
  49. _GLM_SWIZZLE2_4_MEMBERS(T, P, glm::tvec4, s, t)
  50. # endif//GLM_SWIZZLE
  51. };
  52. # if GLM_COMPILER & GLM_COMPILER_CLANG
  53. # pragma clang diagnostic pop
  54. # endif
  55. # if GLM_COMPILER & GLM_COMPILER_GCC
  56. # pragma GCC diagnostic pop
  57. # endif
  58. # else
  59. union {T x, r, s;};
  60. union {T y, g, t;};
  61. # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
  62. GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, tvec2, tvec2, tvec3, tvec4)
  63. # endif//GLM_SWIZZLE
  64. # endif
  65. // -- Component accesses --
  66. /// Return the count of components of the vector
  67. typedef length_t length_type;
  68. GLM_FUNC_DECL static length_type length(){return 2;}
  69. GLM_FUNC_DECL T & operator[](length_type i);
  70. GLM_FUNC_DECL T const & operator[](length_type i) const;
  71. // -- Implicit basic constructors --
  72. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2() GLM_DEFAULT_CTOR;
  73. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(tvec2<T, P> const& v) GLM_DEFAULT;
  74. template <precision Q>
  75. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(tvec2<T, Q> const& v);
  76. // -- Explicit basic constructors --
  77. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec2(ctor);
  78. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tvec2(T scalar);
  79. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(T s1, T s2);
  80. // -- Conversion constructors --
  81. /// Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  82. template <typename A, typename B>
  83. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(A x, B y);
  84. template <typename A, typename B>
  85. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR tvec2(tvec1<A, P> const & v1, tvec1<B, P> const & v2);
  86. // -- Conversion vector constructors --
  87. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  88. template <typename U, precision Q>
  89. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec2(tvec3<U, Q> const & v);
  90. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  91. template <typename U, precision Q>
  92. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec2(tvec4<U, Q> const & v);
  93. /// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  94. template <typename U, precision Q>
  95. GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT tvec2(tvec2<U, Q> const & v);
  96. // -- Swizzle constructors --
  97. # if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
  98. template <int E0, int E1>
  99. GLM_FUNC_DECL tvec2(detail::_swizzle<2, T, P, glm::tvec2, E0, E1,-1,-2> const& that)
  100. {
  101. *this = that();
  102. }
  103. # endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
  104. // -- Unary arithmetic operators --
  105. GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<T, P> const & v) GLM_DEFAULT;
  106. template <typename U>
  107. GLM_FUNC_DECL tvec2<T, P>& operator=(tvec2<U, P> const & v);
  108. template <typename U>
  109. GLM_FUNC_DECL tvec2<T, P>& operator+=(U scalar);
  110. template <typename U>
  111. GLM_FUNC_DECL tvec2<T, P>& operator+=(tvec1<U, P> const & v);
  112. template <typename U>
  113. GLM_FUNC_DECL tvec2<T, P>& operator+=(tvec2<U, P> const & v);
  114. template <typename U>
  115. GLM_FUNC_DECL tvec2<T, P>& operator-=(U scalar);
  116. template <typename U>
  117. GLM_FUNC_DECL tvec2<T, P>& operator-=(tvec1<U, P> const & v);
  118. template <typename U>
  119. GLM_FUNC_DECL tvec2<T, P>& operator-=(tvec2<U, P> const & v);
  120. template <typename U>
  121. GLM_FUNC_DECL tvec2<T, P>& operator*=(U scalar);
  122. template <typename U>
  123. GLM_FUNC_DECL tvec2<T, P>& operator*=(tvec1<U, P> const & v);
  124. template <typename U>
  125. GLM_FUNC_DECL tvec2<T, P>& operator*=(tvec2<U, P> const & v);
  126. template <typename U>
  127. GLM_FUNC_DECL tvec2<T, P>& operator/=(U scalar);
  128. template <typename U>
  129. GLM_FUNC_DECL tvec2<T, P>& operator/=(tvec1<U, P> const & v);
  130. template <typename U>
  131. GLM_FUNC_DECL tvec2<T, P>& operator/=(tvec2<U, P> const & v);
  132. // -- Increment and decrement operators --
  133. GLM_FUNC_DECL tvec2<T, P> & operator++();
  134. GLM_FUNC_DECL tvec2<T, P> & operator--();
  135. GLM_FUNC_DECL tvec2<T, P> operator++(int);
  136. GLM_FUNC_DECL tvec2<T, P> operator--(int);
  137. // -- Unary bit operators --
  138. template <typename U>
  139. GLM_FUNC_DECL tvec2<T, P> & operator%=(U scalar);
  140. template <typename U>
  141. GLM_FUNC_DECL tvec2<T, P> & operator%=(tvec1<U, P> const & v);
  142. template <typename U>
  143. GLM_FUNC_DECL tvec2<T, P> & operator%=(tvec2<U, P> const & v);
  144. template <typename U>
  145. GLM_FUNC_DECL tvec2<T, P> & operator&=(U scalar);
  146. template <typename U>
  147. GLM_FUNC_DECL tvec2<T, P> & operator&=(tvec1<U, P> const & v);
  148. template <typename U>
  149. GLM_FUNC_DECL tvec2<T, P> & operator&=(tvec2<U, P> const & v);
  150. template <typename U>
  151. GLM_FUNC_DECL tvec2<T, P> & operator|=(U scalar);
  152. template <typename U>
  153. GLM_FUNC_DECL tvec2<T, P> & operator|=(tvec1<U, P> const & v);
  154. template <typename U>
  155. GLM_FUNC_DECL tvec2<T, P> & operator|=(tvec2<U, P> const & v);
  156. template <typename U>
  157. GLM_FUNC_DECL tvec2<T, P> & operator^=(U scalar);
  158. template <typename U>
  159. GLM_FUNC_DECL tvec2<T, P> & operator^=(tvec1<U, P> const & v);
  160. template <typename U>
  161. GLM_FUNC_DECL tvec2<T, P> & operator^=(tvec2<U, P> const & v);
  162. template <typename U>
  163. GLM_FUNC_DECL tvec2<T, P> & operator<<=(U scalar);
  164. template <typename U>
  165. GLM_FUNC_DECL tvec2<T, P> & operator<<=(tvec1<U, P> const & v);
  166. template <typename U>
  167. GLM_FUNC_DECL tvec2<T, P> & operator<<=(tvec2<U, P> const & v);
  168. template <typename U>
  169. GLM_FUNC_DECL tvec2<T, P> & operator>>=(U scalar);
  170. template <typename U>
  171. GLM_FUNC_DECL tvec2<T, P> & operator>>=(tvec1<U, P> const & v);
  172. template <typename U>
  173. GLM_FUNC_DECL tvec2<T, P> & operator>>=(tvec2<U, P> const & v);
  174. };
  175. // -- Unary operators --
  176. template <typename T, precision P>
  177. GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v);
  178. template <typename T, precision P>
  179. GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v);
  180. // -- Binary operators --
  181. template <typename T, precision P>
  182. GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v, T scalar);
  183. template <typename T, precision P>
  184. GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  185. template <typename T, precision P>
  186. GLM_FUNC_DECL tvec2<T, P> operator+(T scalar, tvec2<T, P> const & v);
  187. template <typename T, precision P>
  188. GLM_FUNC_DECL tvec2<T, P> operator+(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  189. template <typename T, precision P>
  190. GLM_FUNC_DECL tvec2<T, P> operator+(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  191. template <typename T, precision P>
  192. GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v, T scalar);
  193. template <typename T, precision P>
  194. GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  195. template <typename T, precision P>
  196. GLM_FUNC_DECL tvec2<T, P> operator-(T scalar, tvec2<T, P> const & v);
  197. template <typename T, precision P>
  198. GLM_FUNC_DECL tvec2<T, P> operator-(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  199. template <typename T, precision P>
  200. GLM_FUNC_DECL tvec2<T, P> operator-(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  201. template <typename T, precision P>
  202. GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v, T scalar);
  203. template <typename T, precision P>
  204. GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  205. template <typename T, precision P>
  206. GLM_FUNC_DECL tvec2<T, P> operator*(T scalar, tvec2<T, P> const & v);
  207. template <typename T, precision P>
  208. GLM_FUNC_DECL tvec2<T, P> operator*(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  209. template <typename T, precision P>
  210. GLM_FUNC_DECL tvec2<T, P> operator*(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  211. template <typename T, precision P>
  212. GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v, T scalar);
  213. template <typename T, precision P>
  214. GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  215. template <typename T, precision P>
  216. GLM_FUNC_DECL tvec2<T, P> operator/(T scalar, tvec2<T, P> const & v);
  217. template <typename T, precision P>
  218. GLM_FUNC_DECL tvec2<T, P> operator/(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  219. template <typename T, precision P>
  220. GLM_FUNC_DECL tvec2<T, P> operator/(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  221. template <typename T, precision P>
  222. GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v, T scalar);
  223. template <typename T, precision P>
  224. GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  225. template <typename T, precision P>
  226. GLM_FUNC_DECL tvec2<T, P> operator%(T scalar, tvec2<T, P> const & v);
  227. template <typename T, precision P>
  228. GLM_FUNC_DECL tvec2<T, P> operator%(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  229. template <typename T, precision P>
  230. GLM_FUNC_DECL tvec2<T, P> operator%(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  231. template <typename T, precision P>
  232. GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v, T scalar);
  233. template <typename T, precision P>
  234. GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  235. template <typename T, precision P>
  236. GLM_FUNC_DECL tvec2<T, P> operator&(T scalar, tvec2<T, P> const & v);
  237. template <typename T, precision P>
  238. GLM_FUNC_DECL tvec2<T, P> operator&(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  239. template <typename T, precision P>
  240. GLM_FUNC_DECL tvec2<T, P> operator&(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  241. template <typename T, precision P>
  242. GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v, T scalar);
  243. template <typename T, precision P>
  244. GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  245. template <typename T, precision P>
  246. GLM_FUNC_DECL tvec2<T, P> operator|(T scalar, tvec2<T, P> const & v);
  247. template <typename T, precision P>
  248. GLM_FUNC_DECL tvec2<T, P> operator|(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  249. template <typename T, precision P>
  250. GLM_FUNC_DECL tvec2<T, P> operator|(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  251. template <typename T, precision P>
  252. GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v, T scalar);
  253. template <typename T, precision P>
  254. GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  255. template <typename T, precision P>
  256. GLM_FUNC_DECL tvec2<T, P> operator^(T scalar, tvec2<T, P> const & v);
  257. template <typename T, precision P>
  258. GLM_FUNC_DECL tvec2<T, P> operator^(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  259. template <typename T, precision P>
  260. GLM_FUNC_DECL tvec2<T, P> operator^(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  261. template <typename T, precision P>
  262. GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v, T scalar);
  263. template <typename T, precision P>
  264. GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  265. template <typename T, precision P>
  266. GLM_FUNC_DECL tvec2<T, P> operator<<(T scalar, tvec2<T, P> const & v);
  267. template <typename T, precision P>
  268. GLM_FUNC_DECL tvec2<T, P> operator<<(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  269. template <typename T, precision P>
  270. GLM_FUNC_DECL tvec2<T, P> operator<<(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  271. template <typename T, precision P>
  272. GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v, T scalar);
  273. template <typename T, precision P>
  274. GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v1, tvec1<T, P> const & v2);
  275. template <typename T, precision P>
  276. GLM_FUNC_DECL tvec2<T, P> operator>>(T scalar, tvec2<T, P> const & v);
  277. template <typename T, precision P>
  278. GLM_FUNC_DECL tvec2<T, P> operator>>(tvec1<T, P> const & v1, tvec2<T, P> const & v2);
  279. template <typename T, precision P>
  280. GLM_FUNC_DECL tvec2<T, P> operator>>(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  281. template <typename T, precision P>
  282. GLM_FUNC_DECL tvec2<T, P> operator~(tvec2<T, P> const & v);
  283. // -- Boolean operators --
  284. template <typename T, precision P>
  285. GLM_FUNC_DECL bool operator==(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  286. template <typename T, precision P>
  287. GLM_FUNC_DECL bool operator!=(tvec2<T, P> const & v1, tvec2<T, P> const & v2);
  288. template <precision P>
  289. GLM_FUNC_DECL tvec2<bool, P> operator&&(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2);
  290. template <precision P>
  291. GLM_FUNC_DECL tvec2<bool, P> operator||(tvec2<bool, P> const & v1, tvec2<bool, P> const & v2);
  292. }//namespace glm
  293. #ifndef GLM_EXTERNAL_TEMPLATE
  294. #include "type_vec2.inl"
  295. #endif//GLM_EXTERNAL_TEMPLATE