graphene/auto/vec2.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;
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A structure capable of holding a vector with two dimensions, x and y.
10 ///
11 /// The contents of the [`Vec2`][crate::Vec2] structure are private and should
12 /// never be accessed directly.
13 pub struct Vec2(BoxedInline<ffi::graphene_vec2_t>);
14
15 match fn {
16 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_vec2_get_type(), ptr as *mut _) as *mut ffi::graphene_vec2_t,
17 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_vec2_get_type(), ptr as *mut _),
18 type_ => || ffi::graphene_vec2_get_type(),
19 }
20}
21
22impl Vec2 {
23 /// Adds each component of the two passed vectors and places
24 /// each result into the components of `res`.
25 /// ## `b`
26 /// a [`Vec2`][crate::Vec2]
27 ///
28 /// # Returns
29 ///
30 ///
31 /// ## `res`
32 /// return location for the result
33 #[doc(alias = "graphene_vec2_add")]
34 #[must_use]
35 pub fn add(&self, b: &Vec2) -> Vec2 {
36 unsafe {
37 let mut res = Vec2::uninitialized();
38 ffi::graphene_vec2_add(
39 self.to_glib_none().0,
40 b.to_glib_none().0,
41 res.to_glib_none_mut().0,
42 );
43 res
44 }
45 }
46
47 /// Divides each component of the first operand `self` by the corresponding
48 /// component of the second operand `b`, and places the results into the
49 /// vector `res`.
50 /// ## `b`
51 /// a [`Vec2`][crate::Vec2]
52 ///
53 /// # Returns
54 ///
55 ///
56 /// ## `res`
57 /// return location for the result
58 #[doc(alias = "graphene_vec2_divide")]
59 #[must_use]
60 pub fn divide(&self, b: &Vec2) -> Vec2 {
61 unsafe {
62 let mut res = Vec2::uninitialized();
63 ffi::graphene_vec2_divide(
64 self.to_glib_none().0,
65 b.to_glib_none().0,
66 res.to_glib_none_mut().0,
67 );
68 res
69 }
70 }
71
72 /// Computes the dot product of the two given vectors.
73 /// ## `b`
74 /// a [`Vec2`][crate::Vec2]
75 ///
76 /// # Returns
77 ///
78 /// the dot product of the vectors
79 #[doc(alias = "graphene_vec2_dot")]
80 pub fn dot(&self, b: &Vec2) -> f32 {
81 unsafe { ffi::graphene_vec2_dot(self.to_glib_none().0, b.to_glib_none().0) }
82 }
83
84 #[doc(alias = "graphene_vec2_equal")]
85 fn equal(&self, v2: &Vec2) -> bool {
86 unsafe { ffi::graphene_vec2_equal(self.to_glib_none().0, v2.to_glib_none().0) }
87 }
88
89 /// Retrieves the X component of the [`Vec2`][crate::Vec2].
90 ///
91 /// # Returns
92 ///
93 /// the value of the X component
94 #[doc(alias = "graphene_vec2_get_x")]
95 #[doc(alias = "get_x")]
96 pub fn x(&self) -> f32 {
97 unsafe { ffi::graphene_vec2_get_x(self.to_glib_none().0) }
98 }
99
100 /// Retrieves the Y component of the [`Vec2`][crate::Vec2].
101 ///
102 /// # Returns
103 ///
104 /// the value of the Y component
105 #[doc(alias = "graphene_vec2_get_y")]
106 #[doc(alias = "get_y")]
107 pub fn y(&self) -> f32 {
108 unsafe { ffi::graphene_vec2_get_y(self.to_glib_none().0) }
109 }
110
111 /// Linearly interpolates `self` and `v2` using the given `factor`.
112 /// ## `v2`
113 /// a [`Vec2`][crate::Vec2]
114 /// ## `factor`
115 /// the interpolation factor
116 ///
117 /// # Returns
118 ///
119 ///
120 /// ## `res`
121 /// the interpolated vector
122 #[doc(alias = "graphene_vec2_interpolate")]
123 #[must_use]
124 pub fn interpolate(&self, v2: &Vec2, factor: f64) -> Vec2 {
125 unsafe {
126 let mut res = Vec2::uninitialized();
127 ffi::graphene_vec2_interpolate(
128 self.to_glib_none().0,
129 v2.to_glib_none().0,
130 factor,
131 res.to_glib_none_mut().0,
132 );
133 res
134 }
135 }
136
137 /// Computes the length of the given vector.
138 ///
139 /// # Returns
140 ///
141 /// the length of the vector
142 #[doc(alias = "graphene_vec2_length")]
143 pub fn length(&self) -> f32 {
144 unsafe { ffi::graphene_vec2_length(self.to_glib_none().0) }
145 }
146
147 /// Compares the two given vectors and places the maximum
148 /// values of each component into `res`.
149 /// ## `b`
150 /// a [`Vec2`][crate::Vec2]
151 ///
152 /// # Returns
153 ///
154 ///
155 /// ## `res`
156 /// the resulting vector
157 #[doc(alias = "graphene_vec2_max")]
158 #[must_use]
159 pub fn max(&self, b: &Vec2) -> Vec2 {
160 unsafe {
161 let mut res = Vec2::uninitialized();
162 ffi::graphene_vec2_max(
163 self.to_glib_none().0,
164 b.to_glib_none().0,
165 res.to_glib_none_mut().0,
166 );
167 res
168 }
169 }
170
171 /// Compares the two given vectors and places the minimum
172 /// values of each component into `res`.
173 /// ## `b`
174 /// a [`Vec2`][crate::Vec2]
175 ///
176 /// # Returns
177 ///
178 ///
179 /// ## `res`
180 /// the resulting vector
181 #[doc(alias = "graphene_vec2_min")]
182 #[must_use]
183 pub fn min(&self, b: &Vec2) -> Vec2 {
184 unsafe {
185 let mut res = Vec2::uninitialized();
186 ffi::graphene_vec2_min(
187 self.to_glib_none().0,
188 b.to_glib_none().0,
189 res.to_glib_none_mut().0,
190 );
191 res
192 }
193 }
194
195 /// Multiplies each component of the two passed vectors and places
196 /// each result into the components of `res`.
197 /// ## `b`
198 /// a [`Vec2`][crate::Vec2]
199 ///
200 /// # Returns
201 ///
202 ///
203 /// ## `res`
204 /// return location for the result
205 #[doc(alias = "graphene_vec2_multiply")]
206 #[must_use]
207 pub fn multiply(&self, b: &Vec2) -> Vec2 {
208 unsafe {
209 let mut res = Vec2::uninitialized();
210 ffi::graphene_vec2_multiply(
211 self.to_glib_none().0,
212 b.to_glib_none().0,
213 res.to_glib_none_mut().0,
214 );
215 res
216 }
217 }
218
219 /// Compares the two given [`Vec2`][crate::Vec2] vectors and checks
220 /// whether their values are within the given `epsilon`.
221 /// ## `v2`
222 /// a [`Vec2`][crate::Vec2]
223 /// ## `epsilon`
224 /// the threshold between the two vectors
225 ///
226 /// # Returns
227 ///
228 /// `true` if the two vectors are near each other
229 #[doc(alias = "graphene_vec2_near")]
230 pub fn near(&self, v2: &Vec2, epsilon: f32) -> bool {
231 unsafe { ffi::graphene_vec2_near(self.to_glib_none().0, v2.to_glib_none().0, epsilon) }
232 }
233
234 /// Negates the given [`Vec2`][crate::Vec2].
235 ///
236 /// # Returns
237 ///
238 ///
239 /// ## `res`
240 /// return location for the result vector
241 #[doc(alias = "graphene_vec2_negate")]
242 #[must_use]
243 pub fn negate(&self) -> Vec2 {
244 unsafe {
245 let mut res = Vec2::uninitialized();
246 ffi::graphene_vec2_negate(self.to_glib_none().0, res.to_glib_none_mut().0);
247 res
248 }
249 }
250
251 /// Computes the normalized vector for the given vector `self`.
252 ///
253 /// # Returns
254 ///
255 ///
256 /// ## `res`
257 /// return location for the
258 /// normalized vector
259 #[doc(alias = "graphene_vec2_normalize")]
260 #[must_use]
261 pub fn normalize(&self) -> Vec2 {
262 unsafe {
263 let mut res = Vec2::uninitialized();
264 ffi::graphene_vec2_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
265 res
266 }
267 }
268
269 /// Multiplies all components of the given vector with the given scalar `factor`.
270 /// ## `factor`
271 /// the scalar factor
272 ///
273 /// # Returns
274 ///
275 ///
276 /// ## `res`
277 /// return location for the result vector
278 #[doc(alias = "graphene_vec2_scale")]
279 #[must_use]
280 pub fn scale(&self, factor: f32) -> Vec2 {
281 unsafe {
282 let mut res = Vec2::uninitialized();
283 ffi::graphene_vec2_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
284 res
285 }
286 }
287
288 /// Subtracts from each component of the first operand `self` the
289 /// corresponding component of the second operand `b` and places
290 /// each result into the components of `res`.
291 /// ## `b`
292 /// a [`Vec2`][crate::Vec2]
293 ///
294 /// # Returns
295 ///
296 ///
297 /// ## `res`
298 /// return location for the result
299 #[doc(alias = "graphene_vec2_subtract")]
300 #[must_use]
301 pub fn subtract(&self, b: &Vec2) -> Vec2 {
302 unsafe {
303 let mut res = Vec2::uninitialized();
304 ffi::graphene_vec2_subtract(
305 self.to_glib_none().0,
306 b.to_glib_none().0,
307 res.to_glib_none_mut().0,
308 );
309 res
310 }
311 }
312
313 /// Retrieves a constant vector with (1, 1) components.
314 ///
315 /// # Returns
316 ///
317 /// the one vector
318 #[doc(alias = "graphene_vec2_one")]
319 pub fn one() -> Vec2 {
320 assert_initialized_main_thread!();
321 unsafe { from_glib_none(ffi::graphene_vec2_one()) }
322 }
323
324 /// Retrieves a constant vector with (1, 0) components.
325 ///
326 /// # Returns
327 ///
328 /// the X axis vector
329 #[doc(alias = "graphene_vec2_x_axis")]
330 pub fn x_axis() -> Vec2 {
331 assert_initialized_main_thread!();
332 unsafe { from_glib_none(ffi::graphene_vec2_x_axis()) }
333 }
334
335 /// Retrieves a constant vector with (0, 1) components.
336 ///
337 /// # Returns
338 ///
339 /// the Y axis vector
340 #[doc(alias = "graphene_vec2_y_axis")]
341 pub fn y_axis() -> Vec2 {
342 assert_initialized_main_thread!();
343 unsafe { from_glib_none(ffi::graphene_vec2_y_axis()) }
344 }
345
346 /// Retrieves a constant vector with (0, 0) components.
347 ///
348 /// # Returns
349 ///
350 /// the zero vector
351 #[doc(alias = "graphene_vec2_zero")]
352 pub fn zero() -> Vec2 {
353 assert_initialized_main_thread!();
354 unsafe { from_glib_none(ffi::graphene_vec2_zero()) }
355 }
356}
357
358impl PartialEq for Vec2 {
359 #[inline]
360 fn eq(&self, other: &Self) -> bool {
361 self.equal(other)
362 }
363}
364
365impl Eq for Vec2 {}