graphene/auto/
ray.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, RayIntersectionKind, Sphere, Triangle, Vec3};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A ray emitted from an origin in a given direction.
10    ///
11    /// The contents of the [`Ray`][crate::Ray] structure are private, and should not
12    /// be modified directly.
13    pub struct Ray(BoxedInline<ffi::graphene_ray_t>);
14
15    match fn {
16        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_ray_get_type(), ptr as *mut _) as *mut ffi::graphene_ray_t,
17        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_ray_get_type(), ptr as *mut _),
18        type_ => || ffi::graphene_ray_get_type(),
19    }
20}
21
22impl Ray {
23    #[doc(alias = "graphene_ray_equal")]
24    fn equal(&self, b: &Ray) -> bool {
25        unsafe { ffi::graphene_ray_equal(self.to_glib_none().0, b.to_glib_none().0) }
26    }
27
28    /// Computes the point on the given [`Ray`][crate::Ray] that is closest to the
29    /// given point `p`.
30    /// ## `p`
31    /// a [`Point3D`][crate::Point3D]
32    ///
33    /// # Returns
34    ///
35    ///
36    /// ## `res`
37    /// return location for the closest point3d
38    #[doc(alias = "graphene_ray_get_closest_point_to_point")]
39    #[doc(alias = "get_closest_point_to_point")]
40    pub fn closest_point_to_point(&self, p: &Point3D) -> Point3D {
41        unsafe {
42            let mut res = Point3D::uninitialized();
43            ffi::graphene_ray_get_closest_point_to_point(
44                self.to_glib_none().0,
45                p.to_glib_none().0,
46                res.to_glib_none_mut().0,
47            );
48            res
49        }
50    }
51
52    /// Retrieves the direction of the given [`Ray`][crate::Ray].
53    ///
54    /// # Returns
55    ///
56    ///
57    /// ## `direction`
58    /// return location for the direction
59    #[doc(alias = "graphene_ray_get_direction")]
60    #[doc(alias = "get_direction")]
61    pub fn direction(&self) -> Vec3 {
62        unsafe {
63            let mut direction = Vec3::uninitialized();
64            ffi::graphene_ray_get_direction(self.to_glib_none().0, direction.to_glib_none_mut().0);
65            direction
66        }
67    }
68
69    /// Computes the distance of the origin of the given [`Ray`][crate::Ray] from the
70    /// given plane.
71    ///
72    /// If the ray does not intersect the plane, this function returns `INFINITY`.
73    /// ## `p`
74    /// a [`Plane`][crate::Plane]
75    ///
76    /// # Returns
77    ///
78    /// the distance of the origin of the ray from the plane
79    #[doc(alias = "graphene_ray_get_distance_to_plane")]
80    #[doc(alias = "get_distance_to_plane")]
81    pub fn distance_to_plane(&self, p: &Plane) -> f32 {
82        unsafe {
83            ffi::graphene_ray_get_distance_to_plane(self.to_glib_none().0, p.to_glib_none().0)
84        }
85    }
86
87    /// Computes the distance of the closest approach between the
88    /// given [`Ray`][crate::Ray] `self` and the point `p`.
89    ///
90    /// The closest approach to a ray from a point is the distance
91    /// between the point and the projection of the point on the
92    /// ray itself.
93    /// ## `p`
94    /// a [`Point3D`][crate::Point3D]
95    ///
96    /// # Returns
97    ///
98    /// the distance of the point
99    #[doc(alias = "graphene_ray_get_distance_to_point")]
100    #[doc(alias = "get_distance_to_point")]
101    pub fn distance_to_point(&self, p: &Point3D) -> f32 {
102        unsafe {
103            ffi::graphene_ray_get_distance_to_point(self.to_glib_none().0, p.to_glib_none().0)
104        }
105    }
106
107    /// Retrieves the origin of the given [`Ray`][crate::Ray].
108    ///
109    /// # Returns
110    ///
111    ///
112    /// ## `origin`
113    /// return location for the origin
114    #[doc(alias = "graphene_ray_get_origin")]
115    #[doc(alias = "get_origin")]
116    pub fn origin(&self) -> Point3D {
117        unsafe {
118            let mut origin = Point3D::uninitialized();
119            ffi::graphene_ray_get_origin(self.to_glib_none().0, origin.to_glib_none_mut().0);
120            origin
121        }
122    }
123
124    /// Retrieves the coordinates of a point at the distance `t` along the
125    /// given [`Ray`][crate::Ray].
126    /// ## `t`
127    /// the distance along the ray
128    ///
129    /// # Returns
130    ///
131    ///
132    /// ## `position`
133    /// return location for the position
134    #[doc(alias = "graphene_ray_get_position_at")]
135    #[doc(alias = "get_position_at")]
136    pub fn position_at(&self, t: f32) -> Point3D {
137        unsafe {
138            let mut position = Point3D::uninitialized();
139            ffi::graphene_ray_get_position_at(
140                self.to_glib_none().0,
141                t,
142                position.to_glib_none_mut().0,
143            );
144            position
145        }
146    }
147
148    /// Intersects the given [`Ray`][crate::Ray] `self` with the given
149    /// [`Box`][crate::Box] `b`.
150    /// ## `b`
151    /// a [`Box`][crate::Box]
152    ///
153    /// # Returns
154    ///
155    /// the type of intersection
156    ///
157    /// ## `t_out`
158    /// the distance of the point on the ray that intersects the box
159    #[doc(alias = "graphene_ray_intersect_box")]
160    pub fn intersect_box(&self, b: &Box) -> (RayIntersectionKind, f32) {
161        unsafe {
162            let mut t_out = std::mem::MaybeUninit::uninit();
163            let ret = from_glib(ffi::graphene_ray_intersect_box(
164                self.to_glib_none().0,
165                b.to_glib_none().0,
166                t_out.as_mut_ptr(),
167            ));
168            (ret, t_out.assume_init())
169        }
170    }
171
172    /// Intersects the given [`Ray`][crate::Ray] `self` with the given
173    /// [`Sphere`][crate::Sphere] `s`.
174    /// ## `s`
175    /// a [`Sphere`][crate::Sphere]
176    ///
177    /// # Returns
178    ///
179    /// the type of intersection
180    ///
181    /// ## `t_out`
182    /// the distance of the point on the ray that intersects the sphere
183    #[doc(alias = "graphene_ray_intersect_sphere")]
184    pub fn intersect_sphere(&self, s: &Sphere) -> (RayIntersectionKind, f32) {
185        unsafe {
186            let mut t_out = std::mem::MaybeUninit::uninit();
187            let ret = from_glib(ffi::graphene_ray_intersect_sphere(
188                self.to_glib_none().0,
189                s.to_glib_none().0,
190                t_out.as_mut_ptr(),
191            ));
192            (ret, t_out.assume_init())
193        }
194    }
195
196    /// Intersects the given [`Ray`][crate::Ray] `self` with the given
197    /// [`Triangle`][crate::Triangle] `t`.
198    /// ## `t`
199    /// a [`Triangle`][crate::Triangle]
200    ///
201    /// # Returns
202    ///
203    /// the type of intersection
204    ///
205    /// ## `t_out`
206    /// the distance of the point on the ray that intersects the triangle
207    #[doc(alias = "graphene_ray_intersect_triangle")]
208    pub fn intersect_triangle(&self, t: &Triangle) -> (RayIntersectionKind, f32) {
209        unsafe {
210            let mut t_out = std::mem::MaybeUninit::uninit();
211            let ret = from_glib(ffi::graphene_ray_intersect_triangle(
212                self.to_glib_none().0,
213                t.to_glib_none().0,
214                t_out.as_mut_ptr(),
215            ));
216            (ret, t_out.assume_init())
217        }
218    }
219
220    /// Checks whether the given [`Ray`][crate::Ray] `self` intersects the
221    /// given [`Box`][crate::Box] `b`.
222    ///
223    /// See also: [`intersect_box()`][Self::intersect_box()]
224    /// ## `b`
225    /// a [`Box`][crate::Box]
226    ///
227    /// # Returns
228    ///
229    /// `true` if the ray intersects the box
230    #[doc(alias = "graphene_ray_intersects_box")]
231    pub fn intersects_box(&self, b: &Box) -> bool {
232        unsafe { ffi::graphene_ray_intersects_box(self.to_glib_none().0, b.to_glib_none().0) }
233    }
234
235    /// Checks if the given [`Ray`][crate::Ray] `self` intersects the
236    /// given [`Sphere`][crate::Sphere] `s`.
237    ///
238    /// See also: [`intersect_sphere()`][Self::intersect_sphere()]
239    /// ## `s`
240    /// a [`Sphere`][crate::Sphere]
241    ///
242    /// # Returns
243    ///
244    /// `true` if the ray intersects the sphere
245    #[doc(alias = "graphene_ray_intersects_sphere")]
246    pub fn intersects_sphere(&self, s: &Sphere) -> bool {
247        unsafe { ffi::graphene_ray_intersects_sphere(self.to_glib_none().0, s.to_glib_none().0) }
248    }
249
250    /// Checks whether the given [`Ray`][crate::Ray] `self` intersects the
251    /// given [`Triangle`][crate::Triangle] `b`.
252    ///
253    /// See also: [`intersect_triangle()`][Self::intersect_triangle()]
254    /// ## `t`
255    /// a [`Triangle`][crate::Triangle]
256    ///
257    /// # Returns
258    ///
259    /// `true` if the ray intersects the triangle
260    #[doc(alias = "graphene_ray_intersects_triangle")]
261    pub fn intersects_triangle(&self, t: &Triangle) -> bool {
262        unsafe { ffi::graphene_ray_intersects_triangle(self.to_glib_none().0, t.to_glib_none().0) }
263    }
264}
265
266impl PartialEq for Ray {
267    #[inline]
268    fn eq(&self, other: &Self) -> bool {
269        self.equal(other)
270    }
271}
272
273impl Eq for Ray {}