1use crate::base::{Const, Scalar, ToTypenum};
2use crate::geometry::{Point, Point2, Point3};
3use typenum::{self, Cmp, Greater};
4
5macro_rules! impl_swizzle {
6 ($( where $BaseDim: ident: $( $name: ident() -> $Result: ident[$($i: expr),+] ),+ ;)* ) => {
7 $(
8 $(
9 #[inline]
11 #[must_use]
12 pub fn $name(&self) -> $Result<T>
13 where <Const<D> as ToTypenum>::Typenum: Cmp<typenum::$BaseDim, Output=Greater> {
14 $Result::new($(self[$i].clone()),*)
15 }
16 )*
17 )*
18 }
19}
20
21impl<T: Scalar, const D: usize> Point<T, D>
23where
24 Const<D>: ToTypenum,
25{
26 impl_swizzle!(
27 where U0: xx() -> Point2[0, 0],
28 xxx() -> Point3[0, 0, 0];
29
30 where U1: xy() -> Point2[0, 1],
31 yx() -> Point2[1, 0],
32 yy() -> Point2[1, 1],
33 xxy() -> Point3[0, 0, 1],
34 xyx() -> Point3[0, 1, 0],
35 xyy() -> Point3[0, 1, 1],
36 yxx() -> Point3[1, 0, 0],
37 yxy() -> Point3[1, 0, 1],
38 yyx() -> Point3[1, 1, 0],
39 yyy() -> Point3[1, 1, 1];
40
41 where U2: xz() -> Point2[0, 2],
42 yz() -> Point2[1, 2],
43 zx() -> Point2[2, 0],
44 zy() -> Point2[2, 1],
45 zz() -> Point2[2, 2],
46 xxz() -> Point3[0, 0, 2],
47 xyz() -> Point3[0, 1, 2],
48 xzx() -> Point3[0, 2, 0],
49 xzy() -> Point3[0, 2, 1],
50 xzz() -> Point3[0, 2, 2],
51 yxz() -> Point3[1, 0, 2],
52 yyz() -> Point3[1, 1, 2],
53 yzx() -> Point3[1, 2, 0],
54 yzy() -> Point3[1, 2, 1],
55 yzz() -> Point3[1, 2, 2],
56 zxx() -> Point3[2, 0, 0],
57 zxy() -> Point3[2, 0, 1],
58 zxz() -> Point3[2, 0, 2],
59 zyx() -> Point3[2, 1, 0],
60 zyy() -> Point3[2, 1, 1],
61 zyz() -> Point3[2, 1, 2],
62 zzx() -> Point3[2, 2, 0],
63 zzy() -> Point3[2, 2, 1],
64 zzz() -> Point3[2, 2, 2];
65 );
66}