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    #[doc(alias = "graphene_point3d_init")]
11    pub fn new(x: f32, y: f32, z: f32) -> Self {
12        assert_initialized_main_thread!();
13        unsafe {
14            let mut p = Self::uninitialized();
15            ffi::graphene_point3d_init(p.to_glib_none_mut().0, x, y, z);
16            p
17        }
18    }
19
20    #[doc(alias = "graphene_point3d_init_from_vec3")]
21    #[doc(alias = "init_from_vec3")]
22    pub fn from_vec3(v: &Vec3) -> Self {
23        assert_initialized_main_thread!();
24        unsafe {
25            let mut p = Self::uninitialized();
26            ffi::graphene_point3d_init_from_vec3(p.to_glib_none_mut().0, v.to_glib_none().0);
27            p
28        }
29    }
30
31    #[inline]
32    pub fn x(&self) -> f32 {
33        self.inner.x
34    }
35
36    #[inline]
37    pub fn set_x(&mut self, x: f32) {
38        self.inner.x = x;
39    }
40
41    #[inline]
42    pub fn y(&self) -> f32 {
43        self.inner.y
44    }
45
46    #[inline]
47    pub fn set_y(&mut self, y: f32) {
48        self.inner.y = y;
49    }
50
51    #[inline]
52    pub fn z(&self) -> f32 {
53        self.inner.z
54    }
55
56    #[inline]
57    pub fn set_z(&mut self, z: f32) {
58        self.inner.z = z;
59    }
60}
61
62impl fmt::Debug for Point3D {
63    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64        f.debug_struct("Point3D")
65            .field("x", &self.x())
66            .field("y", &self.y())
67            .field("z", &self.z())
68            .finish()
69    }
70}
71
72impl Default for Point3D {
73    fn default() -> Self {
74        Self::zero()
75    }
76}