wedged/subspace/
constructors.rs

1
2use super::*;
3
4macro_rules! impl_specific_constructors {
5    ($($ty:ident::new($($arg:ident),*);)*) => {
6        $(
7            impl<T> $ty<T> {
8                #[doc = new_docs!($ty::new($($arg),*);)]
9                pub const fn new($($arg: T),*) -> $ty<T> {
10                    $ty { data: <Self as Deref>::Target::new($($arg),*) }
11                }
12            }
13        )*
14    }
15}
16
17impl_specific_constructors!{
18
19    SimpleVec1::new(x);
20    SimpleVec2::new(x,y);
21    SimpleVec3::new(x,y,z);
22    SimpleVec4::new(x,y,z,w);
23    SimpleVec5::new(x,y,z,w,a);
24    SimpleVec6::new(x,y,z,w,a,b);
25
26    SimpleBiVec3::new(x,y,z);
27    SimpleTriVec4::new(x,y,z,w);
28    SimpleQuadVec5::new(x,y,z,w,a);
29    SimplePentVec6::new(x,y,z,w,a,b);
30
31    SimpleBiVec2::new(x);
32    SimpleTriVec3::new(x);
33    SimpleQuadVec4::new(x);
34    SimplePentVec5::new(x);
35    SimpleHexVec6::new(x);
36
37}
38
39impl<T:AllocBlade<N,U0>, N:DimName> SimpleScalar<T,N> {
40
41    /// Creates a new `SimpleScalar` directly from its component
42    ///
43    /// ```
44    /// use wedged::subspace::*;
45    /// use wedged::base::U1;
46    ///
47    /// let x = 6.2831;
48    /// let s = SimpleScalar::<_,U1>::new(x);
49    ///
50    /// assert_eq!(s.value, x);
51    /// ```
52    ///
53    pub fn new(x:T) -> Self {
54        Self::from_inner_unchecked(Scalar::new(x))
55    }
56
57}
58
59impl<T:AllocBlade<N,N>, N:DimName> SimplePsuedoScalar<T,N> {
60
61    /// Creates a psuedoscalar directly from its component
62    ///
63    /// ```
64    /// use wedged::subspace::*;
65    /// use wedged::base::U3;
66    ///
67    /// let x = 6.2831;
68    /// let s = SimpleBlade::<_,U3,U3>::new_psuedoscalar(x);
69    ///
70    /// assert_eq!(s.value, x);
71    /// assert_eq!(s.grade(), 3);
72    /// ```
73    ///
74    pub fn new_psuedoscalar(x:T) -> Self {
75        Self::from_inner_unchecked(PsuedoScalar::new_psuedoscalar(x))
76    }
77
78    /// Returns the unit psuedoscalar in dimension `N`
79    pub fn unit_psuedoscalar() -> Self where T:One {
80        Self::from_inner_unchecked(PsuedoScalar::unit_psuedoscalar())
81    }
82
83}
84
85impl<T:AllocBlade<N,N>, N:DimName> UnitPsuedoScalar<T,N> {
86
87    /// Returns the unit psuedoscalar in dimension `N`
88    pub fn unit_psuedoscalar() -> Self where T:One {
89        Self::from_inner_unchecked(PsuedoScalar::unit_psuedoscalar())
90    }
91
92}