Debian Codegraph @

debian/missing-sources/glam-0.19.0/src/macros.rs

raw symbols SCIP
1 #[cfg(any(
2 all(debug_assertions, feature = "debug-glam-assert"),
3 feature = "glam-assert"
4 ))]
5 macro_rules! glam_assert {
6 ($($arg:tt)*) => ( assert!($($arg)*); )
7 }
8 #[cfg(not(any(
9 all(debug_assertions, feature = "debug-glam-assert"),
10 feature = "glam-assert"
11 )))]
12 macro_rules! glam_assert {
13 ($($arg:tt)*) => {};
14 }
15
16 macro_rules! const_assert {
17 ($x:expr $(,)?) => {
18 // FIXME: everything is align 16 on spirv - ignore for now
19 #[cfg(not(target_arch = "spirv"))]
20 #[allow(unknown_lints, clippy::eq_op)]
21 const _: [(); 0 - !{
22 const ASSERT: bool = $x;
23 ASSERT
24 } as usize] = [];
25 };
26 }
27
28 macro_rules! const_assert_eq {
29 ($x:expr, $y:expr $(,)?) => {
30 const_assert!($x == $y);
31 };
32 }
33
34 #[macro_export]
35 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
36 macro_rules! const_m128 {
37 ($fx4:expr) => {
38 unsafe { $crate::cast::Vec4Cast { fx4: $fx4 }.m128 }
39 };
40 }
41
42 #[cfg(all(target_feature = "sse2", not(feature = "scalar-math")))]
43 macro_rules! const_f32x4 {
44 ($fx4:expr) => {
45 unsafe { $crate::cast::Vec4Cast { fx4: $fx4 }.m128 }
46 };
47 }
48
49 #[cfg(all(target_feature = "simd128", not(feature = "scalar-math")))]
50 macro_rules! const_f32x4 {
51 ($fx4:expr) => {
52 unsafe { $crate::cast::Vec4Cast { fx4: $fx4 }.v128 }
53 };
54 }
55
56 /// Creates a `Vec2` that can be used to initialize a constant value.
57 ///
58 /// ```
59 /// use glam::{const_vec2, Vec2};
60 /// const ONE: Vec2 = const_vec2!([1.0; 2]);
61 /// const X: Vec2 = const_vec2!([1.0, 0.0]);
62 /// ```
63 #[macro_export]
64 macro_rules! const_vec2 {
65 ($fx2:expr) => {
66 unsafe { $crate::cast::Vec2Cast { fx2: $fx2 }.v2 }
67 };
68 }
69
70 /// Creates a `Vec3` that can be used to initialize a constant value.
71 ///
72 /// ```
73 /// use glam::{const_vec3, Vec3};
74 /// const ONE: Vec3 = const_vec3!([1.0; 3]);
75 /// const X: Vec3 = const_vec3!([1.0, 0.0, 0.0]);
76 /// ```
77 #[macro_export]
78 macro_rules! const_vec3 {
79 ($fx3:expr) => {
80 unsafe { $crate::cast::Vec3Cast { fx3: $fx3 }.v3 }
81 };
82 }
83
84 /// Creates a `Vec3A` that can be used to initialize a constant value.
85 ///
86 /// ```
87 /// use glam::{const_vec3a, Vec3A};
88 /// const ONE: Vec3A = const_vec3a!([1.0; 3]);
89 /// const X: Vec3A = const_vec3a!([1.0, 0.0, 0.0]);
90 /// ```
91 #[macro_export]
92 macro_rules! const_vec3a {
93 ($fx3:expr) => {
94 unsafe {
95 $crate::cast::Vec4Cast {
96 fx4: [$fx3[0], $fx3[1], $fx3[2], 0.0],
97 }
98 .v3a
99 }
100 };
101 }
102
103 /// Creates a `Vec4` that can be used to initialize a constant value.
104 ///
105 /// ```
106 /// use glam::{const_vec4, Vec4};
107 /// const ONE: Vec4 = const_vec4!([1.0; 4]);
108 /// const X: Vec4 = const_vec4!([1.0, 0.0, 0.0, 0.0]);
109 /// ```
110 #[macro_export]
111 macro_rules! const_vec4 {
112 ($fx4:expr) => {
113 unsafe { $crate::cast::Vec4Cast { fx4: $fx4 }.v4 }
114 };
115 }
116
117 /// Creates a `Mat2` from two column vectors that can be used to initialize a constant value.
118 ///
119 /// ```
120 /// use glam::{const_mat2, Mat2};
121 /// const ZERO: Mat2 = const_mat2!([0.0; 4]);
122 /// const IDENTITY: Mat2 = const_mat2!([1.0, 0.0], [0.0, 1.0]);
123 /// ```
124 #[macro_export]
125 macro_rules! const_mat2 {
126 ($col0:expr, $col1:expr) => {
127 unsafe {
128 $crate::cast::Mat2Cast {
129 v2x2: [$crate::const_vec2!($col0), $crate::const_vec2!($col1)],
130 }
131 .m2
132 }
133 };
134 ($fx4:expr) => {
135 $crate::const_mat2!(
136 $crate::cast::Vec4Cast { fx4: $fx4 }.fx2x2[0],
137 $crate::cast::Vec4Cast { fx4: $fx4 }.fx2x2[1]
138 )
139 };
140 }
141
142 /// Creates a `Mat3` from three column vectors that can be used to initialize a constant value.
143 ///
144 /// ```
145 /// use glam::{const_mat3, Mat3};
146 /// const ZERO: Mat3 = const_mat3!([0.0; 9]);
147 /// const IDENTITY: Mat3 = const_mat3!([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]);
148 /// ```
149 #[macro_export]
150 macro_rules! const_mat3 {
151 ($col0:expr, $col1:expr, $col2:expr) => {
152 unsafe {
153 $crate::cast::Mat3Cast {
154 v3x3: [
155 $crate::const_vec3!($col0),
156 $crate::const_vec3!($col1),
157 $crate::const_vec3!($col2),
158 ],
159 }
160 .m3
161 }
162 };
163 ($fx9:expr) => {
164 $crate::const_mat3!(
165 $crate::cast::F32x9Cast { fx9: $fx9 }.fx3x3[0],
166 $crate::cast::F32x9Cast { fx9: $fx9 }.fx3x3[1],
167 $crate::cast::F32x9Cast { fx9: $fx9 }.fx3x3[2]
168 )
169 };
170 }
171
172 /// Creates a `Mat3A` from three column vectors that can be used to initialize a constant value.
173 ///
174 /// ```
175 /// use glam::{const_mat3a, Mat3A};
176 /// const ZERO: Mat3A = const_mat3a!([0.0; 9]);
177 /// const IDENTITY: Mat3A = const_mat3a!([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]);
178 /// ```
179 #[macro_export]
180 macro_rules! const_mat3a {
181 ($col0:expr, $col1:expr, $col2:expr) => {
182 unsafe {
183 $crate::cast::Mat3ACast {
184 v3x3: [
185 $crate::const_vec3a!($col0),
186 $crate::const_vec3a!($col1),
187 $crate::const_vec3a!($col2),
188 ],
189 }
190 .m3
191 }
192 };
193 ($fx9:expr) => {
194 $crate::const_mat3a!(
195 $crate::cast::F32x9Cast { fx9: $fx9 }.fx3x3[0],
196 $crate::cast::F32x9Cast { fx9: $fx9 }.fx3x3[1],
197 $crate::cast::F32x9Cast { fx9: $fx9 }.fx3x3[2]
198 )
199 };
200 }
201
202 /// Creates a `Mat4` from four column vectors that can be used to initialize a constant value.
203 ///
204 /// ```
205 /// use glam::{const_mat4, Mat4};
206 /// const ZERO: Mat4 = const_mat4!([0.0; 16]);
207 /// const IDENTITY: Mat4 = const_mat4!(
208 /// [1.0, 0.0, 0.0, 0.0],
209 /// [0.0, 1.0, 0.0, 0.0],
210 /// [0.0, 0.0, 1.0, 0.0],
211 /// [0.0, 0.0, 0.0, 1.0]
212 /// );
213 /// ```
214 #[macro_export]
215 macro_rules! const_mat4 {
216 ($col0:expr, $col1:expr, $col2:expr, $col3:expr) => {
217 unsafe {
218 $crate::cast::Mat4Cast {
219 v4x4: [
220 $crate::const_vec4!($col0),
221 $crate::const_vec4!($col1),
222 $crate::const_vec4!($col2),
223 $crate::const_vec4!($col3),
224 ],
225 }
226 .m4
227 }
228 };
229 ($fx16:expr) => {
230 $crate::const_mat4!(
231 $crate::cast::F32x16Cast { fx16: $fx16 }.fx4x4[0],
232 $crate::cast::F32x16Cast { fx16: $fx16 }.fx4x4[1],
233 $crate::cast::F32x16Cast { fx16: $fx16 }.fx4x4[2],
234 $crate::cast::F32x16Cast { fx16: $fx16 }.fx4x4[3]
235 )
236 };
237 }
238
239 /// Creates a `Quat` from `x`, `y`, `z` and `w` values that can be used to initialize a constant
240 /// value.
241 ///
242 /// ```
243 /// use glam::{const_quat, Quat};
244 /// const IDENTITY: Quat = const_quat!([0.0, 0.0, 0.0, 1.0]);
245 /// ```
246 #[macro_export]
247 macro_rules! const_quat {
248 ($fx4:expr) => {
249 unsafe { $crate::cast::Vec4Cast { fx4: $fx4 }.q }
250 };
251 }
252
253 /// Creates a `DVec2` that can be used to initialize a constant value.
254 ///
255 /// ```
256 /// use glam::{const_dvec2, DVec2};
257 /// const ONE: DVec2 = const_dvec2!([1.0; 2]);
258 /// const X: DVec2 = const_dvec2!([1.0, 0.0]);
259 /// ```
260 #[macro_export]
261 macro_rules! const_dvec2 {
262 ($fx2:expr) => {
263 unsafe { $crate::cast::DVec2Cast { fx2: $fx2 }.v2 }
264 };
265 }
266
267 /// Creates a `DVec3` that can be used to initialize a constant value.
268 ///
269 /// ```
270 /// use glam::{const_dvec3, DVec3};
271 /// const ONE: DVec3 = const_dvec3!([1.0; 3]);
272 /// const X: DVec3 = const_dvec3!([1.0, 0.0, 0.0]);
273 /// ```
274 #[macro_export]
275 macro_rules! const_dvec3 {
276 ($fx3:expr) => {
277 unsafe { $crate::cast::DVec3Cast { fx3: $fx3 }.v3 }
278 };
279 }
280
281 /// Creates a `DVec4` that can be used to initialize a constant value.
282 ///
283 /// ```
284 /// use glam::{const_dvec4, DVec4};
285 /// const ONE: DVec4 = const_dvec4!([1.0; 4]);
286 /// const X: DVec4 = const_dvec4!([1.0, 0.0, 0.0, 0.0]);
287 /// ```
288 #[macro_export]
289 macro_rules! const_dvec4 {
290 ($fx4:expr) => {
291 unsafe { $crate::cast::DVec4Cast { fx4: $fx4 }.v4 }
292 };
293 }
294
295 /// Creates a `DMat2` from two column vectors that can be used to initialize a constant value.
296 ///
297 /// ```
298 /// use glam::{const_dmat2, DMat2};
299 /// const ZERO: DMat2 = const_dmat2!([0.0; 4]);
300 /// const IDENTITY: DMat2 = const_dmat2!([1.0, 0.0], [0.0, 1.0]);
301 /// ```
302 #[macro_export]
303 macro_rules! const_dmat2 {
304 ($col0:expr, $col1:expr) => {
305 unsafe {
306 $crate::cast::DMat2Cast {
307 v2x2: [$crate::const_dvec2!($col0), $crate::const_dvec2!($col1)],
308 }
309 .m2
310 }
311 };
312 ($fx4:expr) => {
313 $crate::const_dmat2!(
314 $crate::cast::DVec4Cast { fx4: $fx4 }.fx2x2[0],
315 $crate::cast::DVec4Cast { fx4: $fx4 }.fx2x2[1]
316 )
317 };
318 }
319
320 /// Creates a `DMat3` from three column vectors that can be used to initialize a constant value.
321 ///
322 /// ```
323 /// # #[macro_use] extern crate glam;
324 /// use glam::{const_dmat3, DMat3};
325 /// const ZERO: DMat3 = const_dmat3!([0.0; 9]);
326 /// const IDENTITY: DMat3 = const_dmat3!([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]);
327 /// ```
328 #[macro_export]
329 macro_rules! const_dmat3 {
330 ($col0:expr, $col1:expr, $col2:expr) => {
331 unsafe {
332 $crate::cast::DMat3Cast {
333 v3x3: [
334 $crate::const_dvec3!($col0),
335 $crate::const_dvec3!($col1),
336 $crate::const_dvec3!($col2),
337 ],
338 }
339 .m3
340 }
341 };
342 ($fx9:expr) => {
343 $crate::const_dmat3!(
344 $crate::cast::F64x9Cast { fx9: $fx9 }.fx3x3[0],
345 $crate::cast::F64x9Cast { fx9: $fx9 }.fx3x3[1],
346 $crate::cast::F64x9Cast { fx9: $fx9 }.fx3x3[2]
347 )
348 };
349 }
350
351 /// Creates a `DMat4` from four column vectors that can be used to initialize a constant value.
352 ///
353 /// ```
354 /// use glam::{const_dmat4, DMat4};
355 /// const ZERO: DMat4 = const_dmat4!([0.0; 16]);
356 /// const IDENTITY: DMat4 = const_dmat4!(
357 /// [1.0, 0.0, 0.0, 0.0],
358 /// [0.0, 1.0, 0.0, 0.0],
359 /// [0.0, 0.0, 1.0, 0.0],
360 /// [0.0, 0.0, 0.0, 1.0]
361 /// );
362 /// ```
363 #[macro_export]
364 macro_rules! const_dmat4 {
365 ($col0:expr, $col1:expr, $col2:expr, $col3:expr) => {
366 unsafe {
367 $crate::cast::DMat4Cast {
368 v4x4: [
369 $crate::const_dvec4!($col0),
370 $crate::const_dvec4!($col1),
371 $crate::const_dvec4!($col2),
372 $crate::const_dvec4!($col3),
373 ],
374 }
375 .m4
376 }
377 };
378 ($fx16:expr) => {
379 $crate::const_dmat4!(
380 $crate::cast::F64x16Cast { fx16: $fx16 }.fx4x4[0],
381 $crate::cast::F64x16Cast { fx16: $fx16 }.fx4x4[1],
382 $crate::cast::F64x16Cast { fx16: $fx16 }.fx4x4[2],
383 $crate::cast::F64x16Cast { fx16: $fx16 }.fx4x4[3]
384 )
385 };
386 }
387
388 /// Creates a `DQuat` from `x`, `y`, `z` and `w` values that can be used to initialize a constant
389 /// value.
390 ///
391 /// ```
392 /// use glam::{const_dquat, DQuat};
393 /// const IDENTITY: DQuat = const_dquat!([0.0, 0.0, 0.0, 1.0]);
394 /// ```
395 #[macro_export]
396 macro_rules! const_dquat {
397 ($fx4:expr) => {
398 unsafe { $crate::cast::DVec4Cast { fx4: $fx4 }.q }
399 };
400 }
401
402 /// Creates a `IVec2` that can be used to initialize a constant value.
403 ///
404 /// ```
405 /// use glam::{const_ivec2, IVec2};
406 /// const ONE: IVec2 = const_ivec2!([1; 2]);
407 /// const X: IVec2 = const_ivec2!([1, 0]);
408 /// ```
409 #[macro_export]
410 macro_rules! const_ivec2 {
411 ($ix2:expr) => {
412 unsafe { $crate::cast::IVec2Cast { ix2: $ix2 }.v2 }
413 };
414 }
415
416 /// Creates a `IVec3` that can be used to initialize a constant value.
417 ///
418 /// ```
419 /// use glam::{const_ivec3, IVec3};
420 /// const ONE: IVec3 = const_ivec3!([1; 3]);
421 /// const X: IVec3 = const_ivec3!([1, 0, 0]);
422 /// ```
423 #[macro_export]
424 macro_rules! const_ivec3 {
425 ($ix3:expr) => {
426 unsafe { $crate::cast::IVec3Cast { ix3: $ix3 }.v3 }
427 };
428 }
429
430 /// Creates a `IVec4` that can be used to initialize a constant value.
431 ///
432 /// ```
433 /// use glam::{const_ivec4, IVec4};
434 /// const ONE: IVec4 = const_ivec4!([1; 4]);
435 /// const X: IVec4 = const_ivec4!([1, 0, 0, 0]);
436 /// ```
437 #[macro_export]
438 macro_rules! const_ivec4 {
439 ($ix4:expr) => {
440 unsafe { $crate::cast::IVec4Cast { ix4: $ix4 }.v4 }
441 };
442 }
443
444 /// Creates a `UVec2` that can be used to initialize a constant value.
445 ///
446 /// ```
447 /// use glam::{const_uvec2, UVec2};
448 /// const ONE: UVec2 = const_uvec2!([1; 2]);
449 /// const X: UVec2 = const_uvec2!([1, 0]);
450 /// ```
451 #[macro_export]
452 macro_rules! const_uvec2 {
453 ($ux2:expr) => {
454 unsafe { $crate::cast::UVec2Cast { ux2: $ux2 }.v2 }
455 };
456 }
457
458 /// Creates a `UVec3` that can be used to initialize a constant value.
459 ///
460 /// ```
461 /// use glam::{const_uvec3, UVec3};
462 /// const ONE: UVec3 = const_uvec3!([1; 3]);
463 /// const X: UVec3 = const_uvec3!([1, 0, 0]);
464 /// ```
465 #[macro_export]
466 macro_rules! const_uvec3 {
467 ($ux3:expr) => {
468 unsafe { $crate::cast::UVec3Cast { ux3: $ux3 }.v3 }
469 };
470 }
471
472 /// Creates a `UVec4` that can be used to initialize a constant value.
473 ///
474 /// ```
475 /// use glam::{const_uvec4, UVec4};
476 /// const ONE: UVec4 = const_uvec4!([1; 4]);
477 /// const X: UVec4 = const_uvec4!([1, 0, 0, 0]);
478 /// ```
479 #[macro_export]
480 macro_rules! const_uvec4 {
481 ($ux4:expr) => {
482 unsafe { $crate::cast::UVec4Cast { ux4: $ux4 }.v4 }
483 };
484 }