vtk_rs/
vtk_sphere_source.rs1#[cxx::bridge]
2mod ffi {
3 unsafe extern "C++" {
4 include!("vtk_sphere_source.h");
5
6 type vtkSphereSource;
7
8 fn vtk_sphere_source_new() -> *mut vtkSphereSource;
9 fn vtk_sphere_source_delete(ptr: Pin<&mut vtkSphereSource>);
10 fn vtk_sphere_source_set_radius(sphere_source: Pin<&mut vtkSphereSource>, radius: f64);
11 fn vtk_sphere_source_get_radius(sphere_source: &vtkSphereSource) -> f64;
12 fn vtk_sphere_source_set_center(sphere_source: Pin<&mut vtkSphereSource>, center: [f64; 3]);
13 fn vtk_sphere_source_get_center(sphere_source: &vtkSphereSource) -> [f64; 3];
14 fn vtk_sphere_source_set_phi_resolution(
15 sphere_source: Pin<&mut vtkSphereSource>,
16 resolution: i64,
17 );
18 fn vtk_sphere_source_get_phi_resolution(sphere_source: &vtkSphereSource) -> i64;
19 fn vtk_sphere_source_set_theta_resolution(
20 sphere_source: Pin<&mut vtkSphereSource>,
21 resolution: i64,
22 );
23 fn vtk_sphere_source_get_theta_resolution(sphere_source: &vtkSphereSource) -> i64;
24 }
25}
26
27crate::define_object!(
28 "https://vtk.org/doc/nightly/html/classvtkNamedColors.html",
29 @name SphereSource, ffi::vtkSphereSource,
30 @new ffi::vtk_sphere_source_new,
31 @delete ffi::vtk_sphere_source_delete,
32 @inherit vtkPolyDataAlgorithm
33);
34
35impl SphereSource {
36 #[doc(alias = "SetRadius")]
37 pub fn set_radius(&mut self, radius: f64) {
38 ffi::vtk_sphere_source_set_radius(self.ptr.as_mut(), radius)
39 }
40
41 #[doc(alias = "GetRadius")]
42 pub fn get_radius(&self) -> f64 {
43 ffi::vtk_sphere_source_get_radius(&self.ptr.as_ref())
44 }
45
46 #[doc(alias = "SetCenter")]
47 pub fn set_center(&mut self, center: [f64; 3]) {
48 ffi::vtk_sphere_source_set_center(self.ptr.as_mut(), center)
49 }
50
51 #[doc(alias = "GetCenter")]
52 pub fn get_center(&self) -> [f64; 3] {
53 ffi::vtk_sphere_source_get_center(&self.ptr.as_ref())
54 }
55
56 #[doc(alias = "GetPhiResolution")]
57 pub fn get_phi_resolution(&self) -> i64 {
58 ffi::vtk_sphere_source_get_phi_resolution(&self.ptr.as_ref())
59 }
60
61 #[doc(alias = "SetPhiResolution")]
62 pub fn set_phi_resolution(&mut self, phi_resolution: i64) {
63 ffi::vtk_sphere_source_set_phi_resolution(self.ptr.as_mut(), phi_resolution)
64 }
65
66 #[doc(alias = "GetThetaResolution")]
67 pub fn get_theta_resolution(&self) -> i64 {
68 ffi::vtk_sphere_source_get_theta_resolution(&self.ptr.as_ref())
69 }
70
71 #[doc(alias = "SetThetaResolution")]
72 pub fn set_theta_resolution(&mut self, theta_resolution: i64) {
73 ffi::vtk_sphere_source_set_theta_resolution(self.ptr.as_mut(), theta_resolution)
74 }
75}
76
77#[cfg(test)]
78mod test {
79 use super::*;
80 use approx::*;
81
82 #[test]
83 fn get_set_radius() {
84 let mut sphere = SphereSource::new();
85 let r1 = sphere.get_radius();
86 assert_abs_diff_eq!(r1, 0.5);
87 sphere.set_radius(1.0);
88 let r2 = sphere.get_radius();
89 assert_abs_diff_eq!(r2, 1.0);
90 }
91
92 #[test]
93 fn get_set_center() {
94 let mut sphere = SphereSource::new();
95 let c1 = sphere.get_center();
96 assert_abs_diff_eq!(c1, [0.0; 3]);
97 sphere.set_center([1., 2., 3.]);
98 let c2 = sphere.get_center();
99 assert_abs_diff_eq!(c2, [1., 2., 3.]);
100 }
101
102 #[test]
103 fn get_set_resolution() {
104 let mut sphere = SphereSource::new();
105 sphere.set_theta_resolution(20);
106 assert_eq!(sphere.get_theta_resolution(), 20);
107 sphere.set_phi_resolution(245);
108 assert_eq!(sphere.get_phi_resolution(), 245);
109 }
110
111 #[test]
112 fn print_self() {
113 use crate::vtk_object_base::*;
114 let sphere = SphereSource::new();
115 let string = sphere.print_self(3);
116 assert!(string.contains(" Debug"));
117 assert!(string.contains(" Reference Count: 2"));
118 assert!(string.contains(" Registered Events"));
119 assert!(string.contains(" Executive"));
120 assert!(string.contains(" Phi"));
121 assert!(string.contains(" Theta"));
122 assert!(string.contains(" Phi Resolution"));
123 assert!(string.contains(" Theta Resolution"));
124 }
125}