math_adapter/plugin/cgmath/
x2.rs

1/// Internal namespace.
2pub( crate ) mod private
3{
4  use core::mem::size_of;
5  use crate::prelude::*;
6  use crate::{ X2, ScalarInterface };
7
8  //
9
10  macro_rules! impl_x2_for
11  {
12
13    ( $Struct1 : ident $( :: $Struct2 : ident )* < $Params : ident > ) =>
14    {
15
16      impl< Scalar > X2NominalInterface for $Struct1 $( :: $Struct2 )* < $Params >
17      where
18        Scalar : ScalarInterface,
19      {
20        type Scalar = Scalar;
21
22        #[ inline ]
23        fn _0( &self ) -> Self::Scalar
24        {
25          self.x
26        }
27
28        #[ inline ]
29        fn _1( &self ) -> Self::Scalar
30        {
31          self.y
32        }
33
34      }
35
36      impl< Scalar > X2BasicInterface for $Struct1 $( :: $Struct2 )* < $Params >
37      where
38        Scalar : ScalarInterface,
39      {
40
41        #[ inline ]
42        fn make( _0 : Self::Scalar, _1 : Self::Scalar ) -> Self
43        {
44          Self::new( _0, _1 )
45        }
46
47        // #[ inline ]
48        // fn make_nan() -> Self
49        // {
50        //   Self::make( num!( NaN ), num!( NaN ) )
51        // }
52
53      }
54
55      impl< Scalar > X2CanonicalInterface for $Struct1 $( :: $Struct2 )* < $Params >
56      where
57        Scalar : ScalarInterface,
58      {
59
60        /* */
61
62        #[ inline ]
63        fn _0_ref( &self ) -> &Self::Scalar
64        {
65          &self.x
66        }
67
68        #[ inline ]
69        fn _1_ref( &self ) -> &Self::Scalar
70        {
71          &self.y
72        }
73
74        /* */
75
76        #[ inline ]
77        fn _0_mut( &mut self ) -> &mut Self::Scalar
78        {
79          &mut self.x
80        }
81
82        #[ inline ]
83        fn _1_mut( &mut self ) -> &mut Self::Scalar
84        {
85          &mut self.y
86        }
87
88        /* */
89
90        #[ inline ]
91        fn as_canonical( &self ) -> &X2< Self::Scalar >
92        {
93          debug_assert_eq!( size_of::< Self >(), size_of::< X2< Self::Scalar > >() );
94          unsafe
95          {
96            std::mem::transmute::< _, _ >( self )
97          }
98        }
99
100        #[ inline ]
101        fn as_canonical_mut( &mut self ) -> &mut X2< Self::Scalar >
102        {
103          debug_assert_eq!( size_of::< Self >(), size_of::< X2< Self::Scalar > >() );
104          unsafe
105          {
106            std::mem::transmute::< _, _ >( self )
107          }
108        }
109
110      }
111
112    };
113
114  }
115
116  macro_rules! impl_x2_as_for
117  {
118
119    ( $Struct1 : ident $( :: $Struct2 : ident )* < $Params : ident > ) =>
120    {
121
122      //
123
124      impl< Scalar, Any > crate::AsCgmathNonCanonicalInterface< $Struct1 $( :: $Struct2 )* < $Params > >
125      for Any
126      where
127        Scalar : ScalarInterface,
128        Any : X2NominalInterface< Scalar = Scalar > + Copy,
129      {
130
131        fn clone_as_cgmath( &self ) -> $Struct1 $( :: $Struct2 )* < $Params >
132        {
133          $Struct1 $( :: $Struct2 )* :: < $Params > :: from2( *self )
134        }
135
136      }
137
138      //
139
140      impl< Scalar, Any > crate::AsCgmathCanonicalInterface< $Struct1 $( :: $Struct2 )* < $Params > >
141      for Any
142      where
143        Scalar : ScalarInterface,
144        Any : X2CanonicalInterface< Scalar = Scalar > + Copy,
145      {
146
147        fn as_cgmath( &self ) -> &$Struct1 $( :: $Struct2 )* < $Params >
148        {
149          unsafe
150          {
151            std::mem::transmute::< _, _ >( self )
152          }
153        }
154
155        fn as_cgmath_mut( &mut self ) -> &mut $Struct1 $( :: $Struct2 )* < $Params >
156        {
157          unsafe
158          {
159            std::mem::transmute::< _, _ >( self )
160          }
161        }
162
163      }
164
165    };
166
167  }
168
169  impl_x2_as_for!( cgmath::Vector2< Scalar > );
170  impl_x2_for!( cgmath::Vector2< Scalar > );
171  impl_x2_for!( cgmath::Point2< Scalar > );
172
173}
174
175crate::mod_interface!
176{
177
178}