Debian Codegraph @

debian/missing-sources/glam-0.18.0/src/vec2.rs

raw symbols SCIP
1 use craterust-analyzer cargo glam 0.18.0 crate/::corerust-analyzer cargo glam 0.18.0 core/::traitsrust-analyzer cargo glam 0.18.0 core/traits/::vectorrust-analyzer cargo glam 0.18.0 core/traits/vector/::*;
2 use craterust-analyzer cargo glam 0.18.0 crate/::{BVec2rust-analyzer cargo glam 0.18.0 vec_mask/BVec2#, DVec3rust-analyzer cargo glam 0.18.0 vec3/DVec3#, IVec3rust-analyzer cargo glam 0.18.0 vec3/IVec3#, UVec3rust-analyzer cargo glam 0.18.0 vec3/UVec3#, Vec3rust-analyzer cargo glam 0.18.0 vec3/Vec3#, XYrust-analyzer cargo glam 0.18.0 core/storage/XY#};
3 #[cfg(not(target_arch = "spirv"))]
4 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/;
5 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{f32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/, opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::*};
6
7 #[cfg(not(feature = "std"))]
8 use num_traits::Float;
9
10 #[cfg(feature = "std")]
11 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::{Productrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/accum/Product#, Sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/accum/Sum#};
12
13 macro_rules! impl_vec2_common_methodsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_common_methods! {
14 ($t:ty, $vec2:ident, $vec3:ident, $mask:ident, $inner:ident) => {
15 /// All zeroes.
16 pub const ZERO: Self = Self($inner::ZERO);
17
18 /// All ones.
19 pub const ONE: Self = Self($inner::ONE);
20
21 /// `[1, 0]`: a unit-length vector pointing along the positive X axis.
22 pub const X: Self = Self($inner::X);
23
24 /// `[0, 1]`: a unit-length vector pointing along the positive Y axis.
25 pub const Y: Self = Self($inner::Y);
26
27 /// The unit axes.
28 pub const AXES: [Self; 2] = [Self::X, Self::Y];
29
30 /// Creates a new vector.
31 #[inline(always)]
32 pub fn new(x: $t, y: $t) -> $vec2 {
33 Self(Vector2::new(x, y))
34 }
35
36 /// Creates a 3D vector from `self` and the given `z` value.
37 #[inline(always)]
38 pub fn extend(self, z: $t) -> $vec3 {
39 $vec3::new(self.x, self.y, z)
40 }
41
42 /// `[x, y]`
43 #[inline(always)]
44 pub fn to_array(&self) -> [$t; 2] {
45 [self.x, self.y]
46 }
47
48 impl_vecn_common_methods!($t, $vec2, $mask, $inner, Vector2);
49 };
50 }
51
52 macro_rules! impl_vec2_signed_methodsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_signed_methods! {
53 ($t:ty, $vec2:ident, $vec3:ident, $mask:ident, $inner:ident) => {
54 impl_vec2_common_methods!($t, $vec2, $vec3, $mask, $inner);
55 impl_vecn_signed_methods!($t, $vec2, $mask, $inner, SignedVector2);
56
57 /// Returns a vector that is equal to `self` rotated by 90 degrees.
58 #[inline(always)]
59 pub fn perp(self) -> Self {
60 Self(self.0.perp())
61 }
62
63 /// The perpendicular dot product of `self` and `other`.
64 /// Also known as the wedge product, 2d cross product, and determinant.
65 #[doc(alias = "wedge")]
66 #[doc(alias = "cross")]
67 #[doc(alias = "determinant")]
68 #[inline(always)]
69 pub fn perp_dot(self, other: $vec2) -> $t {
70 self.0.perp_dot(other.0)
71 }
72 };
73 }
74
75 macro_rules! impl_vec2_float_methodsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_float_methods! {
76 ($t:ty, $vec2:ident, $vec3:ident, $mask:ident, $inner:ident) => {
77 impl_vec2_signed_methods!($t, $vec2, $vec3, $mask, $inner);
78 impl_vecn_float_methods!($t, $vec2, $mask, $inner, FloatVector2);
79
80 /// Returns the angle (in radians) between `self` and `other`.
81 ///
82 /// The input vectors do not need to be unit length however they must be non-zero.
83 #[inline(always)]
84 pub fn angle_between(self, other: Self) -> $t {
85 self.0.angle_between(other.0)
86 }
87 };
88 }
89
90 macro_rules! impl_vec2_common_traitsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_common_traits! {
91 ($t:ty, $new:ident, $vec2:ident, $vec3:ident, $mask:ident, $inner:ident) => {
92 /// Creates a 2-dimensional vector.
93 #[inline(always)]
94 pub fn $new(x: $t, y: $t) -> $vec2 {
95 $vec2::new(x, y)
96 }
97
98 impl Index<usize> for $vec2 {
99 type Output = $t;
100 #[inline(always)]
101 fn index(&self, index: usize) -> &Self::Output {
102 match index {
103 0 => &self.x,
104 1 => &self.y,
105 _ => panic!("index out of bounds"),
106 }
107 }
108 }
109
110 impl IndexMut<usize> for $vec2 {
111 #[inline(always)]
112 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
113 match index {
114 0 => &mut self.x,
115 1 => &mut self.y,
116 _ => panic!("index out of bounds"),
117 }
118 }
119 }
120 #[cfg(not(target_arch = "spirv"))]
121 impl fmt::Display for $vec2 {
122 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123 write!(f, "[{}, {}]", self.x, self.y)
124 }
125 }
126
127 #[cfg(not(target_arch = "spirv"))]
128 impl fmt::Debug for $vec2 {
129 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
130 fmt.debug_tuple(stringify!($vec2))
131 .field(&self.x)
132 .field(&self.y)
133 .finish()
134 }
135 }
136
137 impl From<($t, $t)> for $vec2 {
138 #[inline(always)]
139 fn from(t: ($t, $t)) -> Self {
140 Self($inner::from_tuple(t))
141 }
142 }
143
144 impl From<$vec2> for ($t, $t) {
145 #[inline(always)]
146 fn from(v: $vec2) -> Self {
147 v.0.into_tuple()
148 }
149 }
150
151 impl Deref for $vec2 {
152 type Target = XY<$t>;
153 #[inline(always)]
154 fn deref(&self) -> &Self::Target {
155 self.0.as_ref_xy()
156 }
157 }
158
159 impl DerefMut for $vec2 {
160 #[inline(always)]
161 fn deref_mut(&mut self) -> &mut Self::Target {
162 self.0.as_mut_xy()
163 }
164 }
165
166 impl_vecn_common_traits!($t, 2, $vec2, $inner, Vector2);
167 };
168 }
169
170 macro_rules! impl_vec2_unsigned_traitsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_unsigned_traits! {
171 ($t:ty, $new:ident, $vec2:ident, $vec3:ident, $mask:ident, $inner:ident) => {
172 impl_vec2_common_traits!($t, $new, $vec2, $vec3, $mask, $inner);
173 };
174 }
175
176 macro_rules! impl_vec2_signed_traitsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_signed_traits! {
177 ($t:ty, $new:ident, $vec2:ident, $vec3:ident, $mask:ident, $inner:ident) => {
178 impl_vec2_common_traits!($t, $new, $vec2, $vec3, $mask, $inner);
179 impl_vecn_signed_traits!($t, 2, $vec2, $inner, SignedVector2);
180 };
181 }
182
183 type XYF32rust-analyzer cargo glam 0.18.0 vec2/XYF32# = XYrust-analyzer cargo glam 0.18.0 core/storage/XY#<f32>;
184
185 /// A 2-dimensional vector.
186 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
187 #[repr(transparent)]
188 pub struct Vec2rust-analyzer cargo glam 0.18.0 vec2/Vec2#(pub(craterust-analyzer cargo glam 0.18.0 crate/) XYF32rust-analyzer cargo glam 0.18.0 vec2/XYF32#);
189
190 impl Vec2rust-analyzer cargo glam 0.18.0 vec2/Vec2# {
191 impl_vec2_float_methodsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_float_methods!!(f32, Vec2rust-analyzer cargo glam 0.18.0 vec2/Vec2#, Vec3rust-analyzer cargo glam 0.18.0 vec3/Vec3#, BVec2rust-analyzer cargo glam 0.18.0 vec_mask/BVec2#, XYF32rust-analyzer cargo glam 0.18.0 vec2/XYF32#);
192 impl_as_dvec2rust-analyzer cargo glam 0.18.0 vec/impl_as_dvec2!!();
193 impl_as_ivec2rust-analyzer cargo glam 0.18.0 vec/impl_as_ivec2!!();
194 impl_as_uvec2rust-analyzer cargo glam 0.18.0 vec/impl_as_uvec2!!();
195 }
196 impl_vec2_signed_traitsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_signed_traits!!(f32, vec2rust-analyzer cargo glam 0.18.0 vec2/vec2()., Vec2rust-analyzer cargo glam 0.18.0 vec2/Vec2#, Vec3, BVec2, XYF32rust-analyzer cargo glam 0.18.0 vec2/XYF32#);
197
198 type XYF64rust-analyzer cargo glam 0.18.0 vec2/XYF64# = XYrust-analyzer cargo glam 0.18.0 core/storage/XY#<f64>;
199
200 /// A 2-dimensional vector.
201 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
202 #[repr(transparent)]
203 pub struct DVec2rust-analyzer cargo glam 0.18.0 vec2/DVec2#(pub(craterust-analyzer cargo glam 0.18.0 crate/) XYF64rust-analyzer cargo glam 0.18.0 vec2/XYF64#);
204
205 impl DVec2rust-analyzer cargo glam 0.18.0 vec2/DVec2# {
206 impl_vec2_float_methodsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_float_methods!!(f64, DVec2rust-analyzer cargo glam 0.18.0 vec2/DVec2#, DVec3rust-analyzer cargo glam 0.18.0 vec3/DVec3#, BVec2rust-analyzer cargo glam 0.18.0 vec_mask/BVec2#, XYF64rust-analyzer cargo glam 0.18.0 vec2/XYF64#);
207 impl_as_vec2rust-analyzer cargo glam 0.18.0 vec/impl_as_vec2!!();
208 impl_as_ivec2rust-analyzer cargo glam 0.18.0 vec/impl_as_ivec2!!();
209 impl_as_uvec2rust-analyzer cargo glam 0.18.0 vec/impl_as_uvec2!!();
210 }
211 impl_vec2_signed_traitsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_signed_traits!!(f64, dvec2rust-analyzer cargo glam 0.18.0 vec2/dvec2()., DVec2rust-analyzer cargo glam 0.18.0 vec2/DVec2#, DVec3, BVec2, XYF64rust-analyzer cargo glam 0.18.0 vec2/XYF64#);
212
213 type XYI32rust-analyzer cargo glam 0.18.0 vec2/XYI32# = XYrust-analyzer cargo glam 0.18.0 core/storage/XY#<i32>;
214
215 /// A 2-dimensional vector.
216 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
217 #[repr(transparent)]
218 pub struct IVec2rust-analyzer cargo glam 0.18.0 vec2/IVec2#(pub(craterust-analyzer cargo glam 0.18.0 crate/) XYI32rust-analyzer cargo glam 0.18.0 vec2/XYI32#);
219
220 impl IVec2rust-analyzer cargo glam 0.18.0 vec2/IVec2# {
221 impl_vec2_signed_methodsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_signed_methods!!(i32, IVec2rust-analyzer cargo glam 0.18.0 vec2/IVec2#, IVec3rust-analyzer cargo glam 0.18.0 vec3/IVec3#, BVec2rust-analyzer cargo glam 0.18.0 vec_mask/BVec2#, XYI32rust-analyzer cargo glam 0.18.0 vec2/XYI32#);
222 impl_as_vec2rust-analyzer cargo glam 0.18.0 vec/impl_as_vec2!!();
223 impl_as_dvec2rust-analyzer cargo glam 0.18.0 vec/impl_as_dvec2!!();
224 impl_as_uvec2rust-analyzer cargo glam 0.18.0 vec/impl_as_uvec2!!();
225 }
226 impl_vec2_signed_traitsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_signed_traits!!(i32, ivec2rust-analyzer cargo glam 0.18.0 vec2/ivec2()., IVec2rust-analyzer cargo glam 0.18.0 vec2/IVec2#, IVec3, BVec2, XYI32rust-analyzer cargo glam 0.18.0 vec2/XYI32#);
227 impl_vecn_eq_hash_traitsrust-analyzer cargo glam 0.18.0 vec/impl_vecn_eq_hash_traits!!(i32, 2, IVec2rust-analyzer cargo glam 0.18.0 vec2/IVec2#);
228
229 type XYU32rust-analyzer cargo glam 0.18.0 vec2/XYU32# = XYrust-analyzer cargo glam 0.18.0 core/storage/XY#<u32>;
230
231 /// A 2-dimensional vector.
232 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)]
233 #[repr(transparent)]
234 pub struct UVec2rust-analyzer cargo glam 0.18.0 vec2/UVec2#(pub(craterust-analyzer cargo glam 0.18.0 crate/) XYU32rust-analyzer cargo glam 0.18.0 vec2/XYU32#);
235
236 impl UVec2rust-analyzer cargo glam 0.18.0 vec2/UVec2# {
237 impl_vec2_common_methodsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_common_methods!!(u32, UVec2rust-analyzer cargo glam 0.18.0 vec2/UVec2#, UVec3rust-analyzer cargo glam 0.18.0 vec3/UVec3#, BVec2rust-analyzer cargo glam 0.18.0 vec_mask/BVec2#, XYU32rust-analyzer cargo glam 0.18.0 vec2/XYU32#);
238 impl_as_vec2rust-analyzer cargo glam 0.18.0 vec/impl_as_vec2!!();
239 impl_as_dvec2rust-analyzer cargo glam 0.18.0 vec/impl_as_dvec2!!();
240 impl_as_ivec2rust-analyzer cargo glam 0.18.0 vec/impl_as_ivec2!!();
241 }
242 impl_vec2_unsigned_traitsrust-analyzer cargo glam 0.18.0 vec2/impl_vec2_unsigned_traits!!(u32, uvec2rust-analyzer cargo glam 0.18.0 vec2/uvec2()., UVec2rust-analyzer cargo glam 0.18.0 vec2/UVec2#, UVec3, BVec2, XYU32rust-analyzer cargo glam 0.18.0 vec2/XYU32#);
243 impl_vecn_eq_hash_traitsrust-analyzer cargo glam 0.18.0 vec/impl_vecn_eq_hash_traits!!(u32, 2, UVec2rust-analyzer cargo glam 0.18.0 vec2/UVec2#);
244
245 mod const_test_vec2rust-analyzer cargo glam 0.18.0 vec2/const_test_vec2/ {
246 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(
247 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<f32>(),
248 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::Vec2rust-analyzer cargo glam 0.18.0 vec2/Vec2#>()
249 );
250 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(8, corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::Vec2rust-analyzer cargo glam 0.18.0 vec2/Vec2#>());
251 }
252
253 mod const_test_dvec2rust-analyzer cargo glam 0.18.0 vec2/const_test_dvec2/ {
254 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(
255 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<f64>(),
256 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::DVec2rust-analyzer cargo glam 0.18.0 vec2/DVec2#>()
257 );
258 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(16, corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::DVec2rust-analyzer cargo glam 0.18.0 vec2/DVec2#>());
259 }
260
261 mod const_test_ivec2rust-analyzer cargo glam 0.18.0 vec2/const_test_ivec2/ {
262 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(
263 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<i32>(),
264 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::IVec2rust-analyzer cargo glam 0.18.0 vec2/IVec2#>()
265 );
266 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(8, corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::IVec2rust-analyzer cargo glam 0.18.0 vec2/IVec2#>());
267 }
268
269 mod const_test_uvec2rust-analyzer cargo glam 0.18.0 vec2/const_test_uvec2/ {
270 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(
271 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<u32>(),
272 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::UVec2rust-analyzer cargo glam 0.18.0 vec2/UVec2#>()
273 );
274 const_assert_eqrust-analyzer cargo glam 0.18.0 macros/const_assert_eq!!(8, corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<superrust-analyzer cargo glam 0.18.0 vec2/::UVec2rust-analyzer cargo glam 0.18.0 vec2/UVec2#>());
275 }