graphene/auto/point3_d.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, Rect, Vec3};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A point with three components: X, Y, and Z.
10 pub struct Point3D(BoxedInline<ffi::graphene_point3d_t>);
11
12 match fn {
13 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_point3d_get_type(), ptr as *mut _) as *mut ffi::graphene_point3d_t,
14 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_point3d_get_type(), ptr as *mut _),
15 type_ => || ffi::graphene_point3d_get_type(),
16 }
17}
18
19impl Point3D {
20 /// Computes the cross product of the two given [`Point3D`][crate::Point3D].
21 /// ## `b`
22 /// a [`Point3D`][crate::Point3D]
23 ///
24 /// # Returns
25 ///
26 ///
27 /// ## `res`
28 /// return location for the cross
29 /// product
30 #[doc(alias = "graphene_point3d_cross")]
31 #[must_use]
32 pub fn cross(&self, b: &Point3D) -> Point3D {
33 unsafe {
34 let mut res = Point3D::uninitialized();
35 ffi::graphene_point3d_cross(
36 self.to_glib_none().0,
37 b.to_glib_none().0,
38 res.to_glib_none_mut().0,
39 );
40 res
41 }
42 }
43
44 /// Computes the distance between the two given [`Point3D`][crate::Point3D].
45 /// ## `b`
46 /// a [`Point3D`][crate::Point3D]
47 ///
48 /// # Returns
49 ///
50 /// the distance between two points
51 ///
52 /// ## `delta`
53 /// return location for the distance
54 /// components on the X, Y, and Z axis
55 #[doc(alias = "graphene_point3d_distance")]
56 pub fn distance(&self, b: &Point3D) -> (f32, Vec3) {
57 unsafe {
58 let mut delta = Vec3::uninitialized();
59 let ret = ffi::graphene_point3d_distance(
60 self.to_glib_none().0,
61 b.to_glib_none().0,
62 delta.to_glib_none_mut().0,
63 );
64 (ret, delta)
65 }
66 }
67
68 /// Computes the dot product of the two given [`Point3D`][crate::Point3D].
69 /// ## `b`
70 /// a [`Point3D`][crate::Point3D]
71 ///
72 /// # Returns
73 ///
74 /// the value of the dot product
75 #[doc(alias = "graphene_point3d_dot")]
76 pub fn dot(&self, b: &Point3D) -> f32 {
77 unsafe { ffi::graphene_point3d_dot(self.to_glib_none().0, b.to_glib_none().0) }
78 }
79
80 #[doc(alias = "graphene_point3d_equal")]
81 fn equal(&self, b: &Point3D) -> bool {
82 unsafe { ffi::graphene_point3d_equal(self.to_glib_none().0, b.to_glib_none().0) }
83 }
84
85 /// Linearly interpolates each component of `self` and `b` using the
86 /// provided `factor`, and places the result in `res`.
87 /// ## `b`
88 /// a [`Point3D`][crate::Point3D]
89 /// ## `factor`
90 /// the interpolation factor
91 ///
92 /// # Returns
93 ///
94 ///
95 /// ## `res`
96 /// the return location for the
97 /// interpolated [`Point3D`][crate::Point3D]
98 #[doc(alias = "graphene_point3d_interpolate")]
99 #[must_use]
100 pub fn interpolate(&self, b: &Point3D, factor: f64) -> Point3D {
101 unsafe {
102 let mut res = Point3D::uninitialized();
103 ffi::graphene_point3d_interpolate(
104 self.to_glib_none().0,
105 b.to_glib_none().0,
106 factor,
107 res.to_glib_none_mut().0,
108 );
109 res
110 }
111 }
112
113 /// Computes the length of the vector represented by the
114 /// coordinates of the given [`Point3D`][crate::Point3D].
115 ///
116 /// # Returns
117 ///
118 /// the length of the vector represented by the point
119 #[doc(alias = "graphene_point3d_length")]
120 pub fn length(&self) -> f32 {
121 unsafe { ffi::graphene_point3d_length(self.to_glib_none().0) }
122 }
123
124 /// Checks whether the two points are near each other, within
125 /// an `epsilon` factor.
126 /// ## `b`
127 /// a [`Point3D`][crate::Point3D]
128 /// ## `epsilon`
129 /// fuzzyness factor
130 ///
131 /// # Returns
132 ///
133 /// `true` if the points are near each other
134 #[doc(alias = "graphene_point3d_near")]
135 pub fn near(&self, b: &Point3D, epsilon: f32) -> bool {
136 unsafe { ffi::graphene_point3d_near(self.to_glib_none().0, b.to_glib_none().0, epsilon) }
137 }
138
139 /// Computes the normalization of the vector represented by the
140 /// coordinates of the given [`Point3D`][crate::Point3D].
141 ///
142 /// # Returns
143 ///
144 ///
145 /// ## `res`
146 /// return location for the normalized
147 /// [`Point3D`][crate::Point3D]
148 #[doc(alias = "graphene_point3d_normalize")]
149 #[must_use]
150 pub fn normalize(&self) -> Point3D {
151 unsafe {
152 let mut res = Point3D::uninitialized();
153 ffi::graphene_point3d_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
154 res
155 }
156 }
157
158 /// Normalizes the coordinates of a [`Point3D`][crate::Point3D] using the
159 /// given viewport and clipping planes.
160 ///
161 /// The coordinates of the resulting [`Point3D`][crate::Point3D] will be
162 /// in the [ -1, 1 ] range.
163 /// ## `viewport`
164 /// a [`Rect`][crate::Rect] representing a viewport
165 /// ## `z_near`
166 /// the coordinate of the near clipping plane, or 0 for
167 /// the default near clipping plane
168 /// ## `z_far`
169 /// the coordinate of the far clipping plane, or 1 for the
170 /// default far clipping plane
171 ///
172 /// # Returns
173 ///
174 ///
175 /// ## `res`
176 /// the return location for the
177 /// normalized [`Point3D`][crate::Point3D]
178 #[doc(alias = "graphene_point3d_normalize_viewport")]
179 #[must_use]
180 pub fn normalize_viewport(&self, viewport: &Rect, z_near: f32, z_far: f32) -> Point3D {
181 unsafe {
182 let mut res = Point3D::uninitialized();
183 ffi::graphene_point3d_normalize_viewport(
184 self.to_glib_none().0,
185 viewport.to_glib_none().0,
186 z_near,
187 z_far,
188 res.to_glib_none_mut().0,
189 );
190 res
191 }
192 }
193
194 /// Scales the coordinates of the given [`Point3D`][crate::Point3D] by
195 /// the given `factor`.
196 /// ## `factor`
197 /// the scaling factor
198 ///
199 /// # Returns
200 ///
201 ///
202 /// ## `res`
203 /// return location for the scaled point
204 #[doc(alias = "graphene_point3d_scale")]
205 #[must_use]
206 pub fn scale(&self, factor: f32) -> Point3D {
207 unsafe {
208 let mut res = Point3D::uninitialized();
209 ffi::graphene_point3d_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
210 res
211 }
212 }
213
214 /// Stores the coordinates of a [`Point3D`][crate::Point3D] into a
215 /// [`Vec3`][crate::Vec3].
216 ///
217 /// # Returns
218 ///
219 ///
220 /// ## `v`
221 /// return location for a [`Vec3`][crate::Vec3]
222 #[doc(alias = "graphene_point3d_to_vec3")]
223 pub fn to_vec3(&self) -> Vec3 {
224 unsafe {
225 let mut v = Vec3::uninitialized();
226 ffi::graphene_point3d_to_vec3(self.to_glib_none().0, v.to_glib_none_mut().0);
227 v
228 }
229 }
230
231 /// Retrieves a constant point with all three coordinates set to 0.
232 ///
233 /// # Returns
234 ///
235 /// a zero point
236 #[doc(alias = "graphene_point3d_zero")]
237 pub fn zero() -> Point3D {
238 assert_initialized_main_thread!();
239 unsafe { from_glib_none(ffi::graphene_point3d_zero()) }
240 }
241}
242
243impl PartialEq for Point3D {
244 #[inline]
245 fn eq(&self, other: &Self) -> bool {
246 self.equal(other)
247 }
248}
249
250impl Eq for Point3D {}