1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Box;
use crate::Plane;
use crate::Point3D;
use crate::RayIntersectionKind;
use crate::Sphere;
use crate::Triangle;
use crate::Vec3;
use glib::translate::*;
use std::mem;

glib::wrapper! {
    /// A ray emitted from an origin in a given direction.
    ///
    /// The contents of the [`Ray`][crate::Ray] structure are private, and should not
    /// be modified directly.
    pub struct Ray(BoxedInline<ffi::graphene_ray_t>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_ray_get_type(), ptr as *mut _) as *mut ffi::graphene_ray_t,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_ray_get_type(), ptr as *mut _),
        type_ => || ffi::graphene_ray_get_type(),
    }
}

impl Ray {
    #[doc(alias = "graphene_ray_equal")]
    fn equal(&self, b: &Ray) -> bool {
        unsafe { ffi::graphene_ray_equal(self.to_glib_none().0, b.to_glib_none().0) }
    }

    /// Computes the point on the given [`Ray`][crate::Ray] that is closest to the
    /// given point `p`.
    /// ## `p`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the closest point3d
    #[doc(alias = "graphene_ray_get_closest_point_to_point")]
    #[doc(alias = "get_closest_point_to_point")]
    pub fn closest_point_to_point(&self, p: &Point3D) -> Point3D {
        unsafe {
            let mut res = Point3D::uninitialized();
            ffi::graphene_ray_get_closest_point_to_point(
                self.to_glib_none().0,
                p.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Retrieves the direction of the given [`Ray`][crate::Ray].
    ///
    /// # Returns
    ///
    ///
    /// ## `direction`
    /// return location for the direction
    #[doc(alias = "graphene_ray_get_direction")]
    #[doc(alias = "get_direction")]
    pub fn direction(&self) -> Vec3 {
        unsafe {
            let mut direction = Vec3::uninitialized();
            ffi::graphene_ray_get_direction(self.to_glib_none().0, direction.to_glib_none_mut().0);
            direction
        }
    }

    /// Computes the distance of the origin of the given [`Ray`][crate::Ray] from the
    /// given plane.
    ///
    /// If the ray does not intersect the plane, this function returns `INFINITY`.
    /// ## `p`
    /// a [`Plane`][crate::Plane]
    ///
    /// # Returns
    ///
    /// the distance of the origin of the ray from the plane
    #[doc(alias = "graphene_ray_get_distance_to_plane")]
    #[doc(alias = "get_distance_to_plane")]
    pub fn distance_to_plane(&self, p: &Plane) -> f32 {
        unsafe {
            ffi::graphene_ray_get_distance_to_plane(self.to_glib_none().0, p.to_glib_none().0)
        }
    }

    /// Computes the distance of the closest approach between the
    /// given [`Ray`][crate::Ray] `self` and the point `p`.
    ///
    /// The closest approach to a ray from a point is the distance
    /// between the point and the projection of the point on the
    /// ray itself.
    /// ## `p`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// the distance of the point
    #[doc(alias = "graphene_ray_get_distance_to_point")]
    #[doc(alias = "get_distance_to_point")]
    pub fn distance_to_point(&self, p: &Point3D) -> f32 {
        unsafe {
            ffi::graphene_ray_get_distance_to_point(self.to_glib_none().0, p.to_glib_none().0)
        }
    }

    /// Retrieves the origin of the given [`Ray`][crate::Ray].
    ///
    /// # Returns
    ///
    ///
    /// ## `origin`
    /// return location for the origin
    #[doc(alias = "graphene_ray_get_origin")]
    #[doc(alias = "get_origin")]
    pub fn origin(&self) -> Point3D {
        unsafe {
            let mut origin = Point3D::uninitialized();
            ffi::graphene_ray_get_origin(self.to_glib_none().0, origin.to_glib_none_mut().0);
            origin
        }
    }

    /// Retrieves the coordinates of a point at the distance `t` along the
    /// given [`Ray`][crate::Ray].
    /// ## `t`
    /// the distance along the ray
    ///
    /// # Returns
    ///
    ///
    /// ## `position`
    /// return location for the position
    #[doc(alias = "graphene_ray_get_position_at")]
    #[doc(alias = "get_position_at")]
    pub fn position_at(&self, t: f32) -> Point3D {
        unsafe {
            let mut position = Point3D::uninitialized();
            ffi::graphene_ray_get_position_at(
                self.to_glib_none().0,
                t,
                position.to_glib_none_mut().0,
            );
            position
        }
    }

    /// Intersects the given [`Ray`][crate::Ray] `self` with the given
    /// [`Box`][crate::Box] `b`.
    /// ## `b`
    /// a [`Box`][crate::Box]
    ///
    /// # Returns
    ///
    /// the type of intersection
    ///
    /// ## `t_out`
    /// the distance of the point on the ray that intersects the box
    #[doc(alias = "graphene_ray_intersect_box")]
    pub fn intersect_box(&self, b: &Box) -> (RayIntersectionKind, f32) {
        unsafe {
            let mut t_out = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::graphene_ray_intersect_box(
                self.to_glib_none().0,
                b.to_glib_none().0,
                t_out.as_mut_ptr(),
            ));
            let t_out = t_out.assume_init();
            (ret, t_out)
        }
    }

    /// Intersects the given [`Ray`][crate::Ray] `self` with the given
    /// [`Sphere`][crate::Sphere] `s`.
    /// ## `s`
    /// a [`Sphere`][crate::Sphere]
    ///
    /// # Returns
    ///
    /// the type of intersection
    ///
    /// ## `t_out`
    /// the distance of the point on the ray that intersects the sphere
    #[doc(alias = "graphene_ray_intersect_sphere")]
    pub fn intersect_sphere(&self, s: &Sphere) -> (RayIntersectionKind, f32) {
        unsafe {
            let mut t_out = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::graphene_ray_intersect_sphere(
                self.to_glib_none().0,
                s.to_glib_none().0,
                t_out.as_mut_ptr(),
            ));
            let t_out = t_out.assume_init();
            (ret, t_out)
        }
    }

    /// Intersects the given [`Ray`][crate::Ray] `self` with the given
    /// [`Triangle`][crate::Triangle] `t`.
    /// ## `t`
    /// a [`Triangle`][crate::Triangle]
    ///
    /// # Returns
    ///
    /// the type of intersection
    ///
    /// ## `t_out`
    /// the distance of the point on the ray that intersects the triangle
    #[doc(alias = "graphene_ray_intersect_triangle")]
    pub fn intersect_triangle(&self, t: &Triangle) -> (RayIntersectionKind, f32) {
        unsafe {
            let mut t_out = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::graphene_ray_intersect_triangle(
                self.to_glib_none().0,
                t.to_glib_none().0,
                t_out.as_mut_ptr(),
            ));
            let t_out = t_out.assume_init();
            (ret, t_out)
        }
    }

    /// Checks whether the given [`Ray`][crate::Ray] `self` intersects the
    /// given [`Box`][crate::Box] `b`.
    ///
    /// See also: [`intersect_box()`][Self::intersect_box()]
    /// ## `b`
    /// a [`Box`][crate::Box]
    ///
    /// # Returns
    ///
    /// `true` if the ray intersects the box
    #[doc(alias = "graphene_ray_intersects_box")]
    pub fn intersects_box(&self, b: &Box) -> bool {
        unsafe { ffi::graphene_ray_intersects_box(self.to_glib_none().0, b.to_glib_none().0) }
    }

    /// Checks if the given [`Ray`][crate::Ray] `self` intersects the
    /// given [`Sphere`][crate::Sphere] `s`.
    ///
    /// See also: [`intersect_sphere()`][Self::intersect_sphere()]
    /// ## `s`
    /// a [`Sphere`][crate::Sphere]
    ///
    /// # Returns
    ///
    /// `true` if the ray intersects the sphere
    #[doc(alias = "graphene_ray_intersects_sphere")]
    pub fn intersects_sphere(&self, s: &Sphere) -> bool {
        unsafe { ffi::graphene_ray_intersects_sphere(self.to_glib_none().0, s.to_glib_none().0) }
    }

    /// Checks whether the given [`Ray`][crate::Ray] `self` intersects the
    /// given [`Triangle`][crate::Triangle] `b`.
    ///
    /// See also: [`intersect_triangle()`][Self::intersect_triangle()]
    /// ## `t`
    /// a [`Triangle`][crate::Triangle]
    ///
    /// # Returns
    ///
    /// `true` if the ray intersects the triangle
    #[doc(alias = "graphene_ray_intersects_triangle")]
    pub fn intersects_triangle(&self, t: &Triangle) -> bool {
        unsafe { ffi::graphene_ray_intersects_triangle(self.to_glib_none().0, t.to_glib_none().0) }
    }
}

impl PartialEq for Ray {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Ray {}