graphene/auto/vec4.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Vec2, Vec3};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A structure capable of holding a vector with four dimensions: x, y, z, and w.
10 ///
11 /// The contents of the [`Vec4`][crate::Vec4] structure are private and should
12 /// never be accessed directly.
13 pub struct Vec4(BoxedInline<ffi::graphene_vec4_t>);
14
15 match fn {
16 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_vec4_get_type(), ptr as *mut _) as *mut ffi::graphene_vec4_t,
17 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_vec4_get_type(), ptr as *mut _),
18 type_ => || ffi::graphene_vec4_get_type(),
19 }
20}
21
22impl Vec4 {
23 /// Adds each component of the two given vectors.
24 /// ## `b`
25 /// a [`Vec4`][crate::Vec4]
26 ///
27 /// # Returns
28 ///
29 ///
30 /// ## `res`
31 /// return location for the resulting vector
32 #[doc(alias = "graphene_vec4_add")]
33 #[must_use]
34 pub fn add(&self, b: &Vec4) -> Vec4 {
35 unsafe {
36 let mut res = Vec4::uninitialized();
37 ffi::graphene_vec4_add(
38 self.to_glib_none().0,
39 b.to_glib_none().0,
40 res.to_glib_none_mut().0,
41 );
42 res
43 }
44 }
45
46 /// Divides each component of the first operand `self` by the corresponding
47 /// component of the second operand `b`, and places the results into the
48 /// vector `res`.
49 /// ## `b`
50 /// a [`Vec4`][crate::Vec4]
51 ///
52 /// # Returns
53 ///
54 ///
55 /// ## `res`
56 /// return location for the resulting vector
57 #[doc(alias = "graphene_vec4_divide")]
58 #[must_use]
59 pub fn divide(&self, b: &Vec4) -> Vec4 {
60 unsafe {
61 let mut res = Vec4::uninitialized();
62 ffi::graphene_vec4_divide(
63 self.to_glib_none().0,
64 b.to_glib_none().0,
65 res.to_glib_none_mut().0,
66 );
67 res
68 }
69 }
70
71 /// Computes the dot product of the two given vectors.
72 /// ## `b`
73 /// a [`Vec4`][crate::Vec4]
74 ///
75 /// # Returns
76 ///
77 /// the value of the dot product
78 #[doc(alias = "graphene_vec4_dot")]
79 pub fn dot(&self, b: &Vec4) -> f32 {
80 unsafe { ffi::graphene_vec4_dot(self.to_glib_none().0, b.to_glib_none().0) }
81 }
82
83 #[doc(alias = "graphene_vec4_equal")]
84 fn equal(&self, v2: &Vec4) -> bool {
85 unsafe { ffi::graphene_vec4_equal(self.to_glib_none().0, v2.to_glib_none().0) }
86 }
87
88 /// Retrieves the value of the fourth component of the given [`Vec4`][crate::Vec4].
89 ///
90 /// # Returns
91 ///
92 /// the value of the fourth component
93 #[doc(alias = "graphene_vec4_get_w")]
94 #[doc(alias = "get_w")]
95 pub fn w(&self) -> f32 {
96 unsafe { ffi::graphene_vec4_get_w(self.to_glib_none().0) }
97 }
98
99 /// Retrieves the value of the first component of the given [`Vec4`][crate::Vec4].
100 ///
101 /// # Returns
102 ///
103 /// the value of the first component
104 #[doc(alias = "graphene_vec4_get_x")]
105 #[doc(alias = "get_x")]
106 pub fn x(&self) -> f32 {
107 unsafe { ffi::graphene_vec4_get_x(self.to_glib_none().0) }
108 }
109
110 /// Creates a [`Vec2`][crate::Vec2] that contains the first two components
111 /// of the given [`Vec4`][crate::Vec4].
112 ///
113 /// # Returns
114 ///
115 ///
116 /// ## `res`
117 /// return location for a [`Vec2`][crate::Vec2]
118 #[doc(alias = "graphene_vec4_get_xy")]
119 #[doc(alias = "get_xy")]
120 pub fn xy(&self) -> Vec2 {
121 unsafe {
122 let mut res = Vec2::uninitialized();
123 ffi::graphene_vec4_get_xy(self.to_glib_none().0, res.to_glib_none_mut().0);
124 res
125 }
126 }
127
128 /// Creates a [`Vec3`][crate::Vec3] that contains the first three components
129 /// of the given [`Vec4`][crate::Vec4].
130 ///
131 /// # Returns
132 ///
133 ///
134 /// ## `res`
135 /// return location for a graphene_vec3_t
136 #[doc(alias = "graphene_vec4_get_xyz")]
137 #[doc(alias = "get_xyz")]
138 pub fn xyz(&self) -> Vec3 {
139 unsafe {
140 let mut res = Vec3::uninitialized();
141 ffi::graphene_vec4_get_xyz(self.to_glib_none().0, res.to_glib_none_mut().0);
142 res
143 }
144 }
145
146 /// Retrieves the value of the second component of the given [`Vec4`][crate::Vec4].
147 ///
148 /// # Returns
149 ///
150 /// the value of the second component
151 #[doc(alias = "graphene_vec4_get_y")]
152 #[doc(alias = "get_y")]
153 pub fn y(&self) -> f32 {
154 unsafe { ffi::graphene_vec4_get_y(self.to_glib_none().0) }
155 }
156
157 /// Retrieves the value of the third component of the given [`Vec4`][crate::Vec4].
158 ///
159 /// # Returns
160 ///
161 /// the value of the third component
162 #[doc(alias = "graphene_vec4_get_z")]
163 #[doc(alias = "get_z")]
164 pub fn z(&self) -> f32 {
165 unsafe { ffi::graphene_vec4_get_z(self.to_glib_none().0) }
166 }
167
168 /// Linearly interpolates `self` and `v2` using the given `factor`.
169 /// ## `v2`
170 /// a [`Vec4`][crate::Vec4]
171 /// ## `factor`
172 /// the interpolation factor
173 ///
174 /// # Returns
175 ///
176 ///
177 /// ## `res`
178 /// the interpolated vector
179 #[doc(alias = "graphene_vec4_interpolate")]
180 #[must_use]
181 pub fn interpolate(&self, v2: &Vec4, factor: f64) -> Vec4 {
182 unsafe {
183 let mut res = Vec4::uninitialized();
184 ffi::graphene_vec4_interpolate(
185 self.to_glib_none().0,
186 v2.to_glib_none().0,
187 factor,
188 res.to_glib_none_mut().0,
189 );
190 res
191 }
192 }
193
194 /// Computes the length of the given [`Vec4`][crate::Vec4].
195 ///
196 /// # Returns
197 ///
198 /// the length of the vector
199 #[doc(alias = "graphene_vec4_length")]
200 pub fn length(&self) -> f32 {
201 unsafe { ffi::graphene_vec4_length(self.to_glib_none().0) }
202 }
203
204 /// Compares each component of the two given vectors and creates a
205 /// vector that contains the maximum values.
206 /// ## `b`
207 /// a [`Vec4`][crate::Vec4]
208 ///
209 /// # Returns
210 ///
211 ///
212 /// ## `res`
213 /// return location for the result vector
214 #[doc(alias = "graphene_vec4_max")]
215 #[must_use]
216 pub fn max(&self, b: &Vec4) -> Vec4 {
217 unsafe {
218 let mut res = Vec4::uninitialized();
219 ffi::graphene_vec4_max(
220 self.to_glib_none().0,
221 b.to_glib_none().0,
222 res.to_glib_none_mut().0,
223 );
224 res
225 }
226 }
227
228 /// Compares each component of the two given vectors and creates a
229 /// vector that contains the minimum values.
230 /// ## `b`
231 /// a [`Vec4`][crate::Vec4]
232 ///
233 /// # Returns
234 ///
235 ///
236 /// ## `res`
237 /// return location for the result vector
238 #[doc(alias = "graphene_vec4_min")]
239 #[must_use]
240 pub fn min(&self, b: &Vec4) -> Vec4 {
241 unsafe {
242 let mut res = Vec4::uninitialized();
243 ffi::graphene_vec4_min(
244 self.to_glib_none().0,
245 b.to_glib_none().0,
246 res.to_glib_none_mut().0,
247 );
248 res
249 }
250 }
251
252 /// Multiplies each component of the two given vectors.
253 /// ## `b`
254 /// a [`Vec4`][crate::Vec4]
255 ///
256 /// # Returns
257 ///
258 ///
259 /// ## `res`
260 /// return location for the resulting vector
261 #[doc(alias = "graphene_vec4_multiply")]
262 #[must_use]
263 pub fn multiply(&self, b: &Vec4) -> Vec4 {
264 unsafe {
265 let mut res = Vec4::uninitialized();
266 ffi::graphene_vec4_multiply(
267 self.to_glib_none().0,
268 b.to_glib_none().0,
269 res.to_glib_none_mut().0,
270 );
271 res
272 }
273 }
274
275 /// Compares the two given [`Vec4`][crate::Vec4] vectors and checks
276 /// whether their values are within the given `epsilon`.
277 /// ## `v2`
278 /// a [`Vec4`][crate::Vec4]
279 /// ## `epsilon`
280 /// the threshold between the two vectors
281 ///
282 /// # Returns
283 ///
284 /// `true` if the two vectors are near each other
285 #[doc(alias = "graphene_vec4_near")]
286 pub fn near(&self, v2: &Vec4, epsilon: f32) -> bool {
287 unsafe { ffi::graphene_vec4_near(self.to_glib_none().0, v2.to_glib_none().0, epsilon) }
288 }
289
290 /// Negates the given [`Vec4`][crate::Vec4].
291 ///
292 /// # Returns
293 ///
294 ///
295 /// ## `res`
296 /// return location for the result vector
297 #[doc(alias = "graphene_vec4_negate")]
298 #[must_use]
299 pub fn negate(&self) -> Vec4 {
300 unsafe {
301 let mut res = Vec4::uninitialized();
302 ffi::graphene_vec4_negate(self.to_glib_none().0, res.to_glib_none_mut().0);
303 res
304 }
305 }
306
307 /// Normalizes the given [`Vec4`][crate::Vec4].
308 ///
309 /// # Returns
310 ///
311 ///
312 /// ## `res`
313 /// return location for the normalized
314 /// vector
315 #[doc(alias = "graphene_vec4_normalize")]
316 #[must_use]
317 pub fn normalize(&self) -> Vec4 {
318 unsafe {
319 let mut res = Vec4::uninitialized();
320 ffi::graphene_vec4_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
321 res
322 }
323 }
324
325 /// Multiplies all components of the given vector with the given scalar `factor`.
326 /// ## `factor`
327 /// the scalar factor
328 ///
329 /// # Returns
330 ///
331 ///
332 /// ## `res`
333 /// return location for the result vector
334 #[doc(alias = "graphene_vec4_scale")]
335 #[must_use]
336 pub fn scale(&self, factor: f32) -> Vec4 {
337 unsafe {
338 let mut res = Vec4::uninitialized();
339 ffi::graphene_vec4_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
340 res
341 }
342 }
343
344 /// Subtracts from each component of the first operand `self` the
345 /// corresponding component of the second operand `b` and places
346 /// each result into the components of `res`.
347 /// ## `b`
348 /// a [`Vec4`][crate::Vec4]
349 ///
350 /// # Returns
351 ///
352 ///
353 /// ## `res`
354 /// return location for the resulting vector
355 #[doc(alias = "graphene_vec4_subtract")]
356 #[must_use]
357 pub fn subtract(&self, b: &Vec4) -> Vec4 {
358 unsafe {
359 let mut res = Vec4::uninitialized();
360 ffi::graphene_vec4_subtract(
361 self.to_glib_none().0,
362 b.to_glib_none().0,
363 res.to_glib_none_mut().0,
364 );
365 res
366 }
367 }
368
369 /// Retrieves a pointer to a [`Vec4`][crate::Vec4] with all its
370 /// components set to 1.
371 ///
372 /// # Returns
373 ///
374 /// a constant vector
375 #[doc(alias = "graphene_vec4_one")]
376 pub fn one() -> Vec4 {
377 assert_initialized_main_thread!();
378 unsafe { from_glib_none(ffi::graphene_vec4_one()) }
379 }
380
381 /// Retrieves a pointer to a [`Vec4`][crate::Vec4] with its
382 /// components set to (0, 0, 0, 1).
383 ///
384 /// # Returns
385 ///
386 /// a constant vector
387 #[doc(alias = "graphene_vec4_w_axis")]
388 pub fn w_axis() -> Vec4 {
389 assert_initialized_main_thread!();
390 unsafe { from_glib_none(ffi::graphene_vec4_w_axis()) }
391 }
392
393 /// Retrieves a pointer to a [`Vec4`][crate::Vec4] with its
394 /// components set to (1, 0, 0, 0).
395 ///
396 /// # Returns
397 ///
398 /// a constant vector
399 #[doc(alias = "graphene_vec4_x_axis")]
400 pub fn x_axis() -> Vec4 {
401 assert_initialized_main_thread!();
402 unsafe { from_glib_none(ffi::graphene_vec4_x_axis()) }
403 }
404
405 /// Retrieves a pointer to a [`Vec4`][crate::Vec4] with its
406 /// components set to (0, 1, 0, 0).
407 ///
408 /// # Returns
409 ///
410 /// a constant vector
411 #[doc(alias = "graphene_vec4_y_axis")]
412 pub fn y_axis() -> Vec4 {
413 assert_initialized_main_thread!();
414 unsafe { from_glib_none(ffi::graphene_vec4_y_axis()) }
415 }
416
417 /// Retrieves a pointer to a [`Vec4`][crate::Vec4] with its
418 /// components set to (0, 0, 1, 0).
419 ///
420 /// # Returns
421 ///
422 /// a constant vector
423 #[doc(alias = "graphene_vec4_z_axis")]
424 pub fn z_axis() -> Vec4 {
425 assert_initialized_main_thread!();
426 unsafe { from_glib_none(ffi::graphene_vec4_z_axis()) }
427 }
428
429 /// Retrieves a pointer to a [`Vec4`][crate::Vec4] with all its
430 /// components set to 0.
431 ///
432 /// # Returns
433 ///
434 /// a constant vector
435 #[doc(alias = "graphene_vec4_zero")]
436 pub fn zero() -> Vec4 {
437 assert_initialized_main_thread!();
438 unsafe { from_glib_none(ffi::graphene_vec4_zero()) }
439 }
440}
441
442impl PartialEq for Vec4 {
443 #[inline]
444 fn eq(&self, other: &Self) -> bool {
445 self.equal(other)
446 }
447}
448
449impl Eq for Vec4 {}