graphene/
point3_d.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, Vec3};
8
9impl Point3D {
10    /// Initializes a [`Point3D`][crate::Point3D] with the given coordinates.
11    /// ## `x`
12    /// the X coordinate of the point
13    /// ## `y`
14    /// the Y coordinate of the point
15    /// ## `z`
16    /// the Z coordinate of the point
17    ///
18    /// # Returns
19    ///
20    /// the initialized [`Point3D`][crate::Point3D]
21    #[doc(alias = "graphene_point3d_init")]
22    pub fn new(x: f32, y: f32, z: f32) -> Self {
23        assert_initialized_main_thread!();
24        unsafe {
25            let mut p = Self::uninitialized();
26            ffi::graphene_point3d_init(p.to_glib_none_mut().0, x, y, z);
27            p
28        }
29    }
30
31    /// Initializes a [`Point3D`][crate::Point3D] using the components
32    /// of a [`Vec3`][crate::Vec3].
33    /// ## `v`
34    /// a [`Vec3`][crate::Vec3]
35    ///
36    /// # Returns
37    ///
38    /// the initialized [`Point3D`][crate::Point3D]
39    #[doc(alias = "graphene_point3d_init_from_vec3")]
40    #[doc(alias = "init_from_vec3")]
41    pub fn from_vec3(v: &Vec3) -> Self {
42        assert_initialized_main_thread!();
43        unsafe {
44            let mut p = Self::uninitialized();
45            ffi::graphene_point3d_init_from_vec3(p.to_glib_none_mut().0, v.to_glib_none().0);
46            p
47        }
48    }
49
50    #[inline]
51    pub fn x(&self) -> f32 {
52        self.inner.x
53    }
54
55    #[inline]
56    pub fn set_x(&mut self, x: f32) {
57        self.inner.x = x;
58    }
59
60    #[inline]
61    pub fn y(&self) -> f32 {
62        self.inner.y
63    }
64
65    #[inline]
66    pub fn set_y(&mut self, y: f32) {
67        self.inner.y = y;
68    }
69
70    #[inline]
71    pub fn z(&self) -> f32 {
72        self.inner.z
73    }
74
75    #[inline]
76    pub fn set_z(&mut self, z: f32) {
77        self.inner.z = z;
78    }
79}
80
81impl fmt::Debug for Point3D {
82    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83        f.debug_struct("Point3D")
84            .field("x", &self.x())
85            .field("y", &self.y())
86            .field("z", &self.z())
87            .finish()
88    }
89}
90
91impl Default for Point3D {
92    fn default() -> Self {
93        Self::zero()
94    }
95}