graphene/auto/
triangle.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, Box, Plane, Point3D, Vec2, Vec3};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A triangle.
10    pub struct Triangle(BoxedInline<ffi::graphene_triangle_t>);
11
12    match fn {
13        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_triangle_get_type(), ptr as *mut _) as *mut ffi::graphene_triangle_t,
14        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_triangle_get_type(), ptr as *mut _),
15        type_ => || ffi::graphene_triangle_get_type(),
16    }
17}
18
19impl Triangle {
20    /// Checks whether the given triangle `self` contains the point `p`.
21    /// ## `p`
22    /// a [`Point3D`][crate::Point3D]
23    ///
24    /// # Returns
25    ///
26    /// `true` if the point is inside the triangle
27    #[doc(alias = "graphene_triangle_contains_point")]
28    pub fn contains_point(&self, p: &Point3D) -> bool {
29        unsafe { ffi::graphene_triangle_contains_point(self.to_glib_none().0, p.to_glib_none().0) }
30    }
31
32    #[doc(alias = "graphene_triangle_equal")]
33    fn equal(&self, b: &Triangle) -> bool {
34        unsafe { ffi::graphene_triangle_equal(self.to_glib_none().0, b.to_glib_none().0) }
35    }
36
37    /// Computes the area of the given [`Triangle`][crate::Triangle].
38    ///
39    /// # Returns
40    ///
41    /// the area of the triangle
42    #[doc(alias = "graphene_triangle_get_area")]
43    #[doc(alias = "get_area")]
44    pub fn area(&self) -> f32 {
45        unsafe { ffi::graphene_triangle_get_area(self.to_glib_none().0) }
46    }
47
48    /// Computes the [barycentric coordinates](http://en.wikipedia.org/wiki/Barycentric_coordinate_system)
49    /// of the given point `p`.
50    ///
51    /// The point `p` must lie on the same plane as the triangle `self`; if the
52    /// point is not coplanar, the result of this function is undefined.
53    ///
54    /// If we place the origin in the coordinates of the triangle's A point,
55    /// the barycentric coordinates are `u`, which is on the AC vector; and `v`
56    /// which is on the AB vector:
57    ///
58    /// ![](triangle-barycentric.png)
59    ///
60    /// The returned [`Vec2`][crate::Vec2] contains the following values, in order:
61    ///
62    ///  - `res.x = u`
63    ///  - `res.y = v`
64    /// ## `p`
65    /// a [`Point3D`][crate::Point3D]
66    ///
67    /// # Returns
68    ///
69    /// `true` if the barycentric coordinates are valid
70    ///
71    /// ## `res`
72    /// return location for the vector
73    ///  with the barycentric coordinates
74    #[doc(alias = "graphene_triangle_get_barycoords")]
75    #[doc(alias = "get_barycoords")]
76    pub fn barycoords(&self, p: Option<&Point3D>) -> Option<Vec2> {
77        unsafe {
78            let mut res = Vec2::uninitialized();
79            let ret = ffi::graphene_triangle_get_barycoords(
80                self.to_glib_none().0,
81                p.to_glib_none().0,
82                res.to_glib_none_mut().0,
83            );
84            if ret {
85                Some(res)
86            } else {
87                None
88            }
89        }
90    }
91
92    /// Computes the bounding box of the given [`Triangle`][crate::Triangle].
93    ///
94    /// # Returns
95    ///
96    ///
97    /// ## `res`
98    /// return location for the box
99    #[doc(alias = "graphene_triangle_get_bounding_box")]
100    #[doc(alias = "get_bounding_box")]
101    pub fn bounding_box(&self) -> Box {
102        unsafe {
103            let mut res = Box::uninitialized();
104            ffi::graphene_triangle_get_bounding_box(
105                self.to_glib_none().0,
106                res.to_glib_none_mut().0,
107            );
108            res
109        }
110    }
111
112    /// Computes the coordinates of the midpoint of the given [`Triangle`][crate::Triangle].
113    ///
114    /// The midpoint G is the [centroid](https://en.wikipedia.org/wiki/Centroid`Triangle_centroid`)
115    /// of the triangle, i.e. the intersection of its medians.
116    ///
117    /// # Returns
118    ///
119    ///
120    /// ## `res`
121    /// return location for the coordinates of
122    ///  the midpoint
123    #[doc(alias = "graphene_triangle_get_midpoint")]
124    #[doc(alias = "get_midpoint")]
125    pub fn midpoint(&self) -> Point3D {
126        unsafe {
127            let mut res = Point3D::uninitialized();
128            ffi::graphene_triangle_get_midpoint(self.to_glib_none().0, res.to_glib_none_mut().0);
129            res
130        }
131    }
132
133    /// Computes the normal vector of the given [`Triangle`][crate::Triangle].
134    ///
135    /// # Returns
136    ///
137    ///
138    /// ## `res`
139    /// return location for the normal vector
140    #[doc(alias = "graphene_triangle_get_normal")]
141    #[doc(alias = "get_normal")]
142    pub fn normal(&self) -> Vec3 {
143        unsafe {
144            let mut res = Vec3::uninitialized();
145            ffi::graphene_triangle_get_normal(self.to_glib_none().0, res.to_glib_none_mut().0);
146            res
147        }
148    }
149
150    /// Computes the plane based on the vertices of the given [`Triangle`][crate::Triangle].
151    ///
152    /// # Returns
153    ///
154    ///
155    /// ## `res`
156    /// return location for the plane
157    #[doc(alias = "graphene_triangle_get_plane")]
158    #[doc(alias = "get_plane")]
159    pub fn plane(&self) -> Plane {
160        unsafe {
161            let mut res = Plane::uninitialized();
162            ffi::graphene_triangle_get_plane(self.to_glib_none().0, res.to_glib_none_mut().0);
163            res
164        }
165    }
166
167    /// Retrieves the three vertices of the given [`Triangle`][crate::Triangle] and returns
168    /// their coordinates as [`Point3D`][crate::Point3D].
169    ///
170    /// # Returns
171    ///
172    ///
173    /// ## `a`
174    /// return location for the coordinates
175    ///  of the first vertex
176    ///
177    /// ## `b`
178    /// return location for the coordinates
179    ///  of the second vertex
180    ///
181    /// ## `c`
182    /// return location for the coordinates
183    ///  of the third vertex
184    #[doc(alias = "graphene_triangle_get_points")]
185    #[doc(alias = "get_points")]
186    pub fn points(&self) -> (Point3D, Point3D, Point3D) {
187        unsafe {
188            let mut a = Point3D::uninitialized();
189            let mut b = Point3D::uninitialized();
190            let mut c = Point3D::uninitialized();
191            ffi::graphene_triangle_get_points(
192                self.to_glib_none().0,
193                a.to_glib_none_mut().0,
194                b.to_glib_none_mut().0,
195                c.to_glib_none_mut().0,
196            );
197            (a, b, c)
198        }
199    }
200
201    /// Computes the UV coordinates of the given point `p`.
202    ///
203    /// The point `p` must lie on the same plane as the triangle `self`; if the point
204    /// is not coplanar, the result of this function is undefined. If `p` is [`None`],
205    /// the point will be set in (0, 0, 0).
206    ///
207    /// The UV coordinates will be placed in the `res` vector:
208    ///
209    ///  - `res.x = u`
210    ///  - `res.y = v`
211    ///
212    /// See also: [`barycoords()`][Self::barycoords()]
213    /// ## `p`
214    /// a [`Point3D`][crate::Point3D]
215    /// ## `uv_a`
216    /// the UV coordinates of the first point
217    /// ## `uv_b`
218    /// the UV coordinates of the second point
219    /// ## `uv_c`
220    /// the UV coordinates of the third point
221    ///
222    /// # Returns
223    ///
224    /// `true` if the coordinates are valid
225    ///
226    /// ## `res`
227    /// a vector containing the UV coordinates
228    ///  of the given point `p`
229    #[doc(alias = "graphene_triangle_get_uv")]
230    #[doc(alias = "get_uv")]
231    pub fn uv(&self, p: Option<&Point3D>, uv_a: &Vec2, uv_b: &Vec2, uv_c: &Vec2) -> Option<Vec2> {
232        unsafe {
233            let mut res = Vec2::uninitialized();
234            let ret = ffi::graphene_triangle_get_uv(
235                self.to_glib_none().0,
236                p.to_glib_none().0,
237                uv_a.to_glib_none().0,
238                uv_b.to_glib_none().0,
239                uv_c.to_glib_none().0,
240                res.to_glib_none_mut().0,
241            );
242            if ret {
243                Some(res)
244            } else {
245                None
246            }
247        }
248    }
249
250    /// Retrieves the three vertices of the given [`Triangle`][crate::Triangle].
251    ///
252    /// # Returns
253    ///
254    ///
255    /// ## `a`
256    /// return location for the first vertex
257    ///
258    /// ## `b`
259    /// return location for the second vertex
260    ///
261    /// ## `c`
262    /// return location for the third vertex
263    #[doc(alias = "graphene_triangle_get_vertices")]
264    #[doc(alias = "get_vertices")]
265    pub fn vertices(&self) -> (Vec3, Vec3, Vec3) {
266        unsafe {
267            let mut a = Vec3::uninitialized();
268            let mut b = Vec3::uninitialized();
269            let mut c = Vec3::uninitialized();
270            ffi::graphene_triangle_get_vertices(
271                self.to_glib_none().0,
272                a.to_glib_none_mut().0,
273                b.to_glib_none_mut().0,
274                c.to_glib_none_mut().0,
275            );
276            (a, b, c)
277        }
278    }
279}
280
281impl PartialEq for Triangle {
282    #[inline]
283    fn eq(&self, other: &Self) -> bool {
284        self.equal(other)
285    }
286}
287
288impl Eq for Triangle {}