1use std::fmt;
4
5use glib::translate::*;
6
7use crate::{ffi, Point3D, Sphere, Vec3};
8
9impl Sphere {
10 #[doc(alias = "graphene_sphere_init")]
11 pub fn new(center: Option<&Point3D>, radius: f32) -> Self {
12 assert_initialized_main_thread!();
13 unsafe {
14 let mut sph = Self::uninitialized();
15 ffi::graphene_sphere_init(sph.to_glib_none_mut().0, center.to_glib_none().0, radius);
16 sph
17 }
18 }
19
20 #[doc(alias = "graphene_sphere_init_from_points")]
21 #[doc(alias = "init_from_points")]
22 pub fn from_points(points: &[Point3D], center: Option<&Point3D>) -> Self {
23 assert_initialized_main_thread!();
24
25 let n = points.len() as u32;
26
27 unsafe {
28 let mut sph = Self::uninitialized();
29 ffi::graphene_sphere_init_from_points(
30 sph.to_glib_none_mut().0,
31 n,
32 points.to_glib_none().0,
33 center.to_glib_none().0,
34 );
35 sph
36 }
37 }
38
39 #[doc(alias = "graphene_sphere_init_from_vectors")]
40 #[doc(alias = "init_from_vectors")]
41 pub fn from_vectors(vectors: &[Vec3], center: Option<&Point3D>) -> Self {
42 assert_initialized_main_thread!();
43
44 let n = vectors.len() as u32;
45
46 unsafe {
47 let mut sph = Self::uninitialized();
48 ffi::graphene_sphere_init_from_vectors(
49 sph.to_glib_none_mut().0,
50 n,
51 vectors.to_glib_none().0,
52 center.to_glib_none().0,
53 );
54 sph
55 }
56 }
57}
58
59impl fmt::Debug for Sphere {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 f.debug_struct("Sphere")
62 .field("radius", &self.radius())
63 .field("center", &self.center())
64 .finish()
65 }
66}