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::{Box, Plane, Point3D, Vec2, Vec3, ffi};
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 { Some(res) } else { None }
85        }
86    }
87
88    /// Computes the bounding box of the given [`Triangle`][crate::Triangle].
89    ///
90    /// # Returns
91    ///
92    ///
93    /// ## `res`
94    /// return location for the box
95    #[doc(alias = "graphene_triangle_get_bounding_box")]
96    #[doc(alias = "get_bounding_box")]
97    pub fn bounding_box(&self) -> Box {
98        unsafe {
99            let mut res = Box::uninitialized();
100            ffi::graphene_triangle_get_bounding_box(
101                self.to_glib_none().0,
102                res.to_glib_none_mut().0,
103            );
104            res
105        }
106    }
107
108    /// Computes the coordinates of the midpoint of the given [`Triangle`][crate::Triangle].
109    ///
110    /// The midpoint G is the [centroid](https://en.wikipedia.org/wiki/Centroid`Triangle_centroid`)
111    /// of the triangle, i.e. the intersection of its medians.
112    ///
113    /// # Returns
114    ///
115    ///
116    /// ## `res`
117    /// return location for the coordinates of
118    ///  the midpoint
119    #[doc(alias = "graphene_triangle_get_midpoint")]
120    #[doc(alias = "get_midpoint")]
121    pub fn midpoint(&self) -> Point3D {
122        unsafe {
123            let mut res = Point3D::uninitialized();
124            ffi::graphene_triangle_get_midpoint(self.to_glib_none().0, res.to_glib_none_mut().0);
125            res
126        }
127    }
128
129    /// Computes the normal vector of the given [`Triangle`][crate::Triangle].
130    ///
131    /// # Returns
132    ///
133    ///
134    /// ## `res`
135    /// return location for the normal vector
136    #[doc(alias = "graphene_triangle_get_normal")]
137    #[doc(alias = "get_normal")]
138    pub fn normal(&self) -> Vec3 {
139        unsafe {
140            let mut res = Vec3::uninitialized();
141            ffi::graphene_triangle_get_normal(self.to_glib_none().0, res.to_glib_none_mut().0);
142            res
143        }
144    }
145
146    /// Computes the plane based on the vertices of the given [`Triangle`][crate::Triangle].
147    ///
148    /// # Returns
149    ///
150    ///
151    /// ## `res`
152    /// return location for the plane
153    #[doc(alias = "graphene_triangle_get_plane")]
154    #[doc(alias = "get_plane")]
155    pub fn plane(&self) -> Plane {
156        unsafe {
157            let mut res = Plane::uninitialized();
158            ffi::graphene_triangle_get_plane(self.to_glib_none().0, res.to_glib_none_mut().0);
159            res
160        }
161    }
162
163    /// Retrieves the three vertices of the given [`Triangle`][crate::Triangle] and returns
164    /// their coordinates as [`Point3D`][crate::Point3D].
165    ///
166    /// # Returns
167    ///
168    ///
169    /// ## `a`
170    /// return location for the coordinates
171    ///  of the first vertex
172    ///
173    /// ## `b`
174    /// return location for the coordinates
175    ///  of the second vertex
176    ///
177    /// ## `c`
178    /// return location for the coordinates
179    ///  of the third vertex
180    #[doc(alias = "graphene_triangle_get_points")]
181    #[doc(alias = "get_points")]
182    pub fn points(&self) -> (Point3D, Point3D, Point3D) {
183        unsafe {
184            let mut a = Point3D::uninitialized();
185            let mut b = Point3D::uninitialized();
186            let mut c = Point3D::uninitialized();
187            ffi::graphene_triangle_get_points(
188                self.to_glib_none().0,
189                a.to_glib_none_mut().0,
190                b.to_glib_none_mut().0,
191                c.to_glib_none_mut().0,
192            );
193            (a, b, c)
194        }
195    }
196
197    /// Computes the UV coordinates of the given point `p`.
198    ///
199    /// The point `p` must lie on the same plane as the triangle `self`; if the point
200    /// is not coplanar, the result of this function is undefined. If `p` is [`None`],
201    /// the point will be set in (0, 0, 0).
202    ///
203    /// The UV coordinates will be placed in the `res` vector:
204    ///
205    ///  - `res.x = u`
206    ///  - `res.y = v`
207    ///
208    /// See also: [`barycoords()`][Self::barycoords()]
209    /// ## `p`
210    /// a [`Point3D`][crate::Point3D]
211    /// ## `uv_a`
212    /// the UV coordinates of the first point
213    /// ## `uv_b`
214    /// the UV coordinates of the second point
215    /// ## `uv_c`
216    /// the UV coordinates of the third point
217    ///
218    /// # Returns
219    ///
220    /// `true` if the coordinates are valid
221    ///
222    /// ## `res`
223    /// a vector containing the UV coordinates
224    ///  of the given point `p`
225    #[doc(alias = "graphene_triangle_get_uv")]
226    #[doc(alias = "get_uv")]
227    pub fn uv(&self, p: Option<&Point3D>, uv_a: &Vec2, uv_b: &Vec2, uv_c: &Vec2) -> Option<Vec2> {
228        unsafe {
229            let mut res = Vec2::uninitialized();
230            let ret = ffi::graphene_triangle_get_uv(
231                self.to_glib_none().0,
232                p.to_glib_none().0,
233                uv_a.to_glib_none().0,
234                uv_b.to_glib_none().0,
235                uv_c.to_glib_none().0,
236                res.to_glib_none_mut().0,
237            );
238            if ret { Some(res) } else { None }
239        }
240    }
241
242    /// Retrieves the three vertices of the given [`Triangle`][crate::Triangle].
243    ///
244    /// # Returns
245    ///
246    ///
247    /// ## `a`
248    /// return location for the first vertex
249    ///
250    /// ## `b`
251    /// return location for the second vertex
252    ///
253    /// ## `c`
254    /// return location for the third vertex
255    #[doc(alias = "graphene_triangle_get_vertices")]
256    #[doc(alias = "get_vertices")]
257    pub fn vertices(&self) -> (Vec3, Vec3, Vec3) {
258        unsafe {
259            let mut a = Vec3::uninitialized();
260            let mut b = Vec3::uninitialized();
261            let mut c = Vec3::uninitialized();
262            ffi::graphene_triangle_get_vertices(
263                self.to_glib_none().0,
264                a.to_glib_none_mut().0,
265                b.to_glib_none_mut().0,
266                c.to_glib_none_mut().0,
267            );
268            (a, b, c)
269        }
270    }
271}
272
273impl PartialEq for Triangle {
274    #[inline]
275    fn eq(&self, other: &Self) -> bool {
276        self.equal(other)
277    }
278}
279
280impl Eq for Triangle {}