1.0.0 API documentation: type_vec2.hpp Source File

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