1.0.2 API documentation: type_vec2.hpp Source File

| 1.0.2 API documentation

type_vec2.hpp
Go to the documentation of this file.
1
4 #pragma once
5
6 #include "qualifier.hpp"
7 #if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
8 # include "_swizzle.hpp"
9 #elif GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
10 # include "_swizzle_func.hpp"
11 #endif
12 #include <cstddef>
13
14 namespace glm
15 {
16 template<typename T, qualifier Q>
17 struct vec<2, T, Q>
18 {
19 // -- Implementation detail --
20
21 typedef T value_type;
22 typedef vec<2, T, Q> type;
23 typedef vec<2, bool, Q> bool_type;
24 enum is_aligned
25 {
26 value = false
27 };
28
29 // -- Data --
30
31 # if GLM_SILENT_WARNINGS == GLM_ENABLE
32 # if GLM_COMPILER & GLM_COMPILER_GCC
33 # pragma GCC diagnostic push
34 # pragma GCC diagnostic ignored "-Wpedantic"
35 # elif GLM_COMPILER & GLM_COMPILER_CLANG
36 # pragma clang diagnostic push
37 # pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
38 # pragma clang diagnostic ignored "-Wnested-anon-types"
39 # elif GLM_COMPILER & GLM_COMPILER_VC
40 # pragma warning(push)
41 # pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union
42 # endif
43 # endif
44
45 # if GLM_CONFIG_XYZW_ONLY
46 T x, y;
47 # if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
48 GLM_SWIZZLE_GEN_VEC_FROM_VEC2_COMP(T, Q, x, y)
49 # endif//GLM_CONFIG_SWIZZLE
50 # elif GLM_CONFIG_ANONYMOUS_STRUCT == GLM_ENABLE
51 union
52 {
53 struct{ T x, y; };
54 struct{ T r, g; };
55 struct{ T s, t; };
56
57 typename detail::storage<2, T, detail::is_aligned<Q>::value>::type data;
58
59 # if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
60 GLM_SWIZZLE2_2_MEMBERS(T, Q, x, y)
61 GLM_SWIZZLE2_2_MEMBERS(T, Q, r, g)
62 GLM_SWIZZLE2_2_MEMBERS(T, Q, s, t)
63 GLM_SWIZZLE2_3_MEMBERS(T, Q, x, y)
64 GLM_SWIZZLE2_3_MEMBERS(T, Q, r, g)
65 GLM_SWIZZLE2_3_MEMBERS(T, Q, s, t)
66 GLM_SWIZZLE2_4_MEMBERS(T, Q, x, y)
67 GLM_SWIZZLE2_4_MEMBERS(T, Q, r, g)
68 GLM_SWIZZLE2_4_MEMBERS(T, Q, s, t)
69 # endif
70 };
71 # else
72 union {T x, r, s;};
73 union {T y, g, t;};
74
75 # if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
76 GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, Q)
77 # endif//GLM_CONFIG_SWIZZLE
78 # endif
79
80 # if GLM_SILENT_WARNINGS == GLM_ENABLE
81 # if GLM_COMPILER & GLM_COMPILER_CLANG
82 # pragma clang diagnostic pop
83 # elif GLM_COMPILER & GLM_COMPILER_GCC
84 # pragma GCC diagnostic pop
85 # elif GLM_COMPILER & GLM_COMPILER_VC
86 # pragma warning(pop)
87 # endif
88 # endif
89
90 // -- Component accesses --
91
93 typedef length_t length_type;
94 GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 2;}
95
96 GLM_FUNC_DECL GLM_CONSTEXPR T& operator[](length_type i);
97 GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
98
99 // -- Implicit basic constructors --
100
101 GLM_DEFAULTED_DEFAULT_CTOR_DECL GLM_CONSTEXPR vec() GLM_DEFAULT_CTOR;
102 GLM_DEFAULTED_FUNC_DECL GLM_CONSTEXPR vec(vec const& v) GLM_DEFAULT;
103 template<qualifier P>
104 GLM_CTOR_DECL vec(vec<2, T, P> const& v);
105
106 // -- Explicit basic constructors --
107
108 GLM_CTOR_DECL explicit vec(T scalar);
109 GLM_CTOR_DECL vec(T x, T y);
110
111 // -- Conversion constructors --
112
113 template<typename U, qualifier P>
114 GLM_CTOR_DECL explicit vec(vec<1, U, P> const& v);
115
117 template<typename A, typename B>
118 GLM_CTOR_DECL vec(A x, B y);
119 template<typename A, typename B>
120 GLM_CTOR_DECL vec(vec<1, A, Q> const& x, B y);
121 template<typename A, typename B>
122 GLM_CTOR_DECL vec(A x, vec<1, B, Q> const& y);
123 template<typename A, typename B>
124 GLM_CTOR_DECL vec(vec<1, A, Q> const& x, vec<1, B, Q> const& y);
125
126 // -- Conversion vector constructors --
127
129 template<typename U, qualifier P>
130 GLM_CTOR_DECL GLM_EXPLICIT vec(vec<3, U, P> const& v);
132 template<typename U, qualifier P>
133 GLM_CTOR_DECL GLM_EXPLICIT vec(vec<4, U, P> const& v);
134
136 template<typename U, qualifier P>
137 GLM_CTOR_DECL GLM_EXPLICIT vec(vec<2, U, P> const& v);
138
139 // -- Swizzle constructors --
140 # if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
141 template<int E0, int E1>
142 GLM_FUNC_DISCARD_DECL vec(detail::_swizzle<2, T, Q, E0, E1,-1,-2> const& that)
143 {
144 *this = that();
145 }
146 # endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
147
148 // -- Unary arithmetic operators --
149
150 GLM_DEFAULTED_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> & operator=(vec const& v) GLM_DEFAULT;
151
152 template<typename U>
153 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator=(vec<2, U, Q> const& v);
154 template<typename U>
155 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator+=(U scalar);
156 template<typename U>
157 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator+=(vec<1, U, Q> const& v);
158 template<typename U>
159 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator+=(vec<2, U, Q> const& v);
160 template<typename U>
161 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator-=(U scalar);
162 template<typename U>
163 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator-=(vec<1, U, Q> const& v);
164 template<typename U>
165 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator-=(vec<2, U, Q> const& v);
166 template<typename U>
167 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator*=(U scalar);
168 template<typename U>
169 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator*=(vec<1, U, Q> const& v);
170 template<typename U>
171 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator*=(vec<2, U, Q> const& v);
172 template<typename U>
173 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator/=(U scalar);
174 template<typename U>
175 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator/=(vec<1, U, Q> const& v);
176 template<typename U>
177 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator/=(vec<2, U, Q> const& v);
178
179 // -- Increment and decrement operators --
180
181 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator++();
182 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator--();
183 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator++(int);
184 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator--(int);
185
186 // -- Unary bit operators --
187
188 template<typename U>
189 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator%=(U scalar);
190 template<typename U>
191 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator%=(vec<1, U, Q> const& v);
192 template<typename U>
193 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator%=(vec<2, U, Q> const& v);
194 template<typename U>
195 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator&=(U scalar);
196 template<typename U>
197 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator&=(vec<1, U, Q> const& v);
198 template<typename U>
199 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator&=(vec<2, U, Q> const& v);
200 template<typename U>
201 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator|=(U scalar);
202 template<typename U>
203 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator|=(vec<1, U, Q> const& v);
204 template<typename U>
205 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator|=(vec<2, U, Q> const& v);
206 template<typename U>
207 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator^=(U scalar);
208 template<typename U>
209 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator^=(vec<1, U, Q> const& v);
210 template<typename U>
211 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator^=(vec<2, U, Q> const& v);
212 template<typename U>
213 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator<<=(U scalar);
214 template<typename U>
215 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator<<=(vec<1, U, Q> const& v);
216 template<typename U>
217 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator<<=(vec<2, U, Q> const& v);
218 template<typename U>
219 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator>>=(U scalar);
220 template<typename U>
221 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator>>=(vec<1, U, Q> const& v);
222 template<typename U>
223 GLM_FUNC_DISCARD_DECL GLM_CONSTEXPR vec<2, T, Q> & operator>>=(vec<2, U, Q> const& v);
224 };
225
226 // -- Unary operators --
227
228 template<typename T, qualifier Q>
229 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v);
230
231 template<typename T, qualifier Q>
232 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v);
233
234 // -- Binary operators --
235
236 template<typename T, qualifier Q>
237 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v, T scalar);
238
239 template<typename T, qualifier Q>
240 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
241
242 template<typename T, qualifier Q>
243 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(T scalar, vec<2, T, Q> const& v);
244
245 template<typename T, qualifier Q>
246 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
247
248 template<typename T, qualifier Q>
249 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator+(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
250
251 template<typename T, qualifier Q>
252 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v, T scalar);
253
254 template<typename T, qualifier Q>
255 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
256
257 template<typename T, qualifier Q>
258 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(T scalar, vec<2, T, Q> const& v);
259
260 template<typename T, qualifier Q>
261 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
262
263 template<typename T, qualifier Q>
264 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator-(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
265
266 template<typename T, qualifier Q>
267 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator*(vec<2, T, Q> const& v, T scalar);
268
269 template<typename T, qualifier Q>
270 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator*(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
271
272 template<typename T, qualifier Q>
273 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator*(T scalar, vec<2, T, Q> const& v);
274
275 template<typename T, qualifier Q>
276 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator*(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
277
278 template<typename T, qualifier Q>
279 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator*(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
280
281 template<typename T, qualifier Q>
282 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator/(vec<2, T, Q> const& v, T scalar);
283
284 template<typename T, qualifier Q>
285 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator/(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
286
287 template<typename T, qualifier Q>
288 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator/(T scalar, vec<2, T, Q> const& v);
289
290 template<typename T, qualifier Q>
291 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator/(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
292
293 template<typename T, qualifier Q>
294 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator/(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
295
296 template<typename T, qualifier Q>
297 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator%(vec<2, T, Q> const& v, T scalar);
298
299 template<typename T, qualifier Q>
300 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator%(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
301
302 template<typename T, qualifier Q>
303 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator%(T scalar, vec<2, T, Q> const& v);
304
305 template<typename T, qualifier Q>
306 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator%(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
307
308 template<typename T, qualifier Q>
309 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator%(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
310
311 template<typename T, qualifier Q>
312 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator&(vec<2, T, Q> const& v, T scalar);
313
314 template<typename T, qualifier Q>
315 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator&(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
316
317 template<typename T, qualifier Q>
318 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator&(T scalar, vec<2, T, Q> const& v);
319
320 template<typename T, qualifier Q>
321 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator&(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
322
323 template<typename T, qualifier Q>
324 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator&(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
325
326 template<typename T, qualifier Q>
327 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator|(vec<2, T, Q> const& v, T scalar);
328
329 template<typename T, qualifier Q>
330 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator|(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
331
332 template<typename T, qualifier Q>
333 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator|(T scalar, vec<2, T, Q> const& v);
334
335 template<typename T, qualifier Q>
336 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator|(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
337
338 template<typename T, qualifier Q>
339 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator|(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
340
341 template<typename T, qualifier Q>
342 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator^(vec<2, T, Q> const& v, T scalar);
343
344 template<typename T, qualifier Q>
345 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator^(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
346
347 template<typename T, qualifier Q>
348 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator^(T scalar, vec<2, T, Q> const& v);
349
350 template<typename T, qualifier Q>
351 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator^(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
352
353 template<typename T, qualifier Q>
354 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator^(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
355
356 template<typename T, qualifier Q>
357 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator<<(vec<2, T, Q> const& v, T scalar);
358
359 template<typename T, qualifier Q>
360 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator<<(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
361
362 template<typename T, qualifier Q>
363 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator<<(T scalar, vec<2, T, Q> const& v);
364
365 template<typename T, qualifier Q>
366 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator<<(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
367
368 template<typename T, qualifier Q>
369 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator<<(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
370
371 template<typename T, qualifier Q>
372 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator>>(vec<2, T, Q> const& v, T scalar);
373
374 template<typename T, qualifier Q>
375 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator>>(vec<2, T, Q> const& v1, vec<1, T, Q> const& v2);
376
377 template<typename T, qualifier Q>
378 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator>>(T scalar, vec<2, T, Q> const& v);
379
380 template<typename T, qualifier Q>
381 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator>>(vec<1, T, Q> const& v1, vec<2, T, Q> const& v2);
382
383 template<typename T, qualifier Q>
384 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator>>(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
385
386 template<typename T, qualifier Q>
387 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, T, Q> operator~(vec<2, T, Q> const& v);
388
389 // -- Boolean operators --
390
391 template<typename T, qualifier Q>
392 GLM_FUNC_DECL GLM_CONSTEXPR bool operator==(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
393
394 template<typename T, qualifier Q>
395 GLM_FUNC_DECL GLM_CONSTEXPR bool operator!=(vec<2, T, Q> const& v1, vec<2, T, Q> const& v2);
396
397 template<qualifier Q>
398 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, bool, Q> operator&&(vec<2, bool, Q> const& v1, vec<2, bool, Q> const& v2);
399
400 template<qualifier Q>
401 GLM_FUNC_DECL GLM_CONSTEXPR vec<2, bool, Q> operator||(vec<2, bool, Q> const& v1, vec<2, bool, Q> const& v2);
402 }//namespace glm
403
404 #ifndef GLM_EXTERNAL_TEMPLATE
405 #include "type_vec2.inl"
406 #endif//GLM_EXTERNAL_TEMPLATE
glm::length
GLM_FUNC_DECL T length(qua< T, Q > const &q)
Returns the norm of a quaternions.