graphene/
ray.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use glib::translate::*;
6
7use crate::{ffi, Point3D, Ray, Vec3};
8
9impl Ray {
10    /// Initializes the given [`Ray`][crate::Ray] using the given `origin`
11    /// and `direction` values.
12    /// ## `origin`
13    /// the origin of the ray
14    /// ## `direction`
15    /// the direction vector
16    ///
17    /// # Returns
18    ///
19    /// the initialized ray
20    #[doc(alias = "graphene_ray_init")]
21    pub fn new(origin: Option<&Point3D>, direction: Option<&Vec3>) -> Self {
22        assert_initialized_main_thread!();
23        unsafe {
24            let mut ray = Self::uninitialized();
25            ffi::graphene_ray_init(
26                ray.to_glib_none_mut().0,
27                origin.to_glib_none().0,
28                direction.to_glib_none().0,
29            );
30            ray
31        }
32    }
33
34    /// Initializes the given [`Ray`][crate::Ray] using the given vectors.
35    /// ## `origin`
36    /// a [`Vec3`][crate::Vec3]
37    /// ## `direction`
38    /// a [`Vec3`][crate::Vec3]
39    ///
40    /// # Returns
41    ///
42    /// the initialized ray
43    #[doc(alias = "graphene_ray_init_from_vec3")]
44    #[doc(alias = "init_from_vec3")]
45    pub fn from_vec3(origin: Option<&Vec3>, direction: Option<&Vec3>) -> Self {
46        assert_initialized_main_thread!();
47        unsafe {
48            let mut ray = Self::uninitialized();
49            ffi::graphene_ray_init_from_vec3(
50                ray.to_glib_none_mut().0,
51                origin.to_glib_none().0,
52                direction.to_glib_none().0,
53            );
54            ray
55        }
56    }
57}
58
59impl fmt::Debug for Ray {
60    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61        f.debug_struct("Ray")
62            .field("origin", &self.origin())
63            .field("direction", &self.direction())
64            .finish()
65    }
66}