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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// 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 `graphene_ray_t` structure are private, and should not
    /// be modified directly.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct Ray(Boxed<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 _),
        init => |_ptr| (),
        clear => |_ptr| (),
        type_ => || ffi::graphene_ray_get_type(),
    }
}

impl Ray {
    /// Checks whether the two given [`Ray`][crate::Ray] are equal.
    /// ## `b`
    /// a [`Ray`][crate::Ray]
    ///
    /// # Returns
    ///
    /// `true` if the given rays are equal
    #[doc(alias = "graphene_ray_equal")]
    fn equal(&self, b: &Ray) -> bool {
        unsafe {
            from_glib(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
        }
    }

    /// Initializes the given [`Ray`][crate::Ray] using the given `origin`
    /// and `direction` values.
    /// ## `origin`
    /// the origin of the ray
    /// ## `direction`
    /// the direction vector
    ///
    /// # Returns
    ///
    /// the initialized ray
    #[doc(alias = "graphene_ray_init")]
    pub fn init(&mut self, origin: Option<&Point3D>, direction: Option<&Vec3>) {
        unsafe {
            ffi::graphene_ray_init(
                self.to_glib_none_mut().0,
                origin.to_glib_none().0,
                direction.to_glib_none().0,
            );
        }
    }

    /// Initializes the given [`Ray`][crate::Ray] using the origin and direction
    /// values of another [`Ray`][crate::Ray].
    /// ## `src`
    /// a [`Ray`][crate::Ray]
    ///
    /// # Returns
    ///
    /// the initialized ray
    #[doc(alias = "graphene_ray_init_from_ray")]
    pub fn init_from_ray(&mut self, src: &Ray) {
        unsafe {
            ffi::graphene_ray_init_from_ray(self.to_glib_none_mut().0, src.to_glib_none().0);
        }
    }

    /// Initializes the given [`Ray`][crate::Ray] using the given vectors.
    /// ## `origin`
    /// a [`Vec3`][crate::Vec3]
    /// ## `direction`
    /// a [`Vec3`][crate::Vec3]
    ///
    /// # Returns
    ///
    /// the initialized ray
    #[doc(alias = "graphene_ray_init_from_vec3")]
    pub fn init_from_vec3(&mut self, origin: Option<&Vec3>, direction: Option<&Vec3>) {
        unsafe {
            ffi::graphene_ray_init_from_vec3(
                self.to_glib_none_mut().0,
                origin.to_glib_none().0,
                direction.to_glib_none().0,
            );
        }
    }

    /// 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 {
            from_glib(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 {
            from_glib(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 {
            from_glib(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 {}