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, 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    /// Checks whether the given [`Ray`][crate::Ray] `self` intersects the
149    /// given [`Box`][crate::Box] `b`.
150    ///
151    /// See also: [`intersect_box()`][Self::intersect_box()]
152    /// ## `b`
153    /// a [`Box`][crate::Box]
154    ///
155    /// # Returns
156    ///
157    /// `true` if the ray intersects the box
158    #[doc(alias = "graphene_ray_intersects_box")]
159    pub fn intersects_box(&self, b: &Box) -> bool {
160        unsafe { ffi::graphene_ray_intersects_box(self.to_glib_none().0, b.to_glib_none().0) }
161    }
162
163    /// Checks if the given [`Ray`][crate::Ray] `self` intersects the
164    /// given [`Sphere`][crate::Sphere] `s`.
165    ///
166    /// See also: [`intersect_sphere()`][Self::intersect_sphere()]
167    /// ## `s`
168    /// a [`Sphere`][crate::Sphere]
169    ///
170    /// # Returns
171    ///
172    /// `true` if the ray intersects the sphere
173    #[doc(alias = "graphene_ray_intersects_sphere")]
174    pub fn intersects_sphere(&self, s: &Sphere) -> bool {
175        unsafe { ffi::graphene_ray_intersects_sphere(self.to_glib_none().0, s.to_glib_none().0) }
176    }
177
178    /// Checks whether the given [`Ray`][crate::Ray] `self` intersects the
179    /// given [`Triangle`][crate::Triangle] `b`.
180    ///
181    /// See also: [`intersect_triangle()`][Self::intersect_triangle()]
182    /// ## `t`
183    /// a [`Triangle`][crate::Triangle]
184    ///
185    /// # Returns
186    ///
187    /// `true` if the ray intersects the triangle
188    #[doc(alias = "graphene_ray_intersects_triangle")]
189    pub fn intersects_triangle(&self, t: &Triangle) -> bool {
190        unsafe { ffi::graphene_ray_intersects_triangle(self.to_glib_none().0, t.to_glib_none().0) }
191    }
192}
193
194impl PartialEq for Ray {
195    #[inline]
196    fn eq(&self, other: &Self) -> bool {
197        self.equal(other)
198    }
199}
200
201impl Eq for Ray {}