-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_surface_geometry.rs
More file actions
138 lines (120 loc) · 4.16 KB
/
test_surface_geometry.rs
File metadata and controls
138 lines (120 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use plotpy::{Plot, StrError, Surface};
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
const OUT_DIR: &str = "/tmp/plotpy/integ_tests";
#[test]
fn test_surface_geometry() -> Result<(), StrError> {
// plane
let mut plane = Surface::new();
plane.set_colormap_name("terrain").draw_plane_nzz(
&[-1.0, 1.0, 1.0],
&[1.0, -1.0, 1.0],
-1.0,
1.0,
-1.0,
1.0,
3,
3,
)?;
// cap and cup
let mut cap = Surface::new();
let mut cup = Surface::new();
let (x, y, z, r) = (-1.0, -1.0, -1.0, 0.5);
cap.set_wire_line_color("red")
.set_with_surface(false)
.set_with_wireframe(true)
.draw_hemisphere(&[x, y, z], r, -180.0, 180.0, 10, 10, false)?;
cup.draw_hemisphere(&[x, y, z], r, -180.0, 180.0, 10, 10, true)?;
// add features to plot
let mut plot = Plot::new();
plot.add(&plane).add(&cap).add(&cup);
// save figure
let path = Path::new(OUT_DIR).join("integ_surface_geometry.svg");
plot.set_equal_axes(true).save(&path)?;
// check number of lines
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
assert!(lines_iter.count() > 1690);
Ok(())
}
#[test]
fn test_surface_cylinder() -> Result<(), StrError> {
let mut surface = Surface::new();
surface.set_surf_color("red");
surface.draw_cylinder(&[0.0, 0.0, 0.0], &[5.0, 0.0, 0.0], 0.5, 1, 20)?;
surface.set_surf_color("green");
surface.draw_cylinder(&[0.0, 0.0, 0.0], &[0.0, 5.0, 0.0], 0.5, 1, 20)?;
surface.set_surf_color("blue");
surface.draw_cylinder(&[0.0, 0.0, 0.0], &[0.0, 0.0, 5.0], 0.5, 1, 20)?;
surface.set_surf_color("gold");
surface.draw_cylinder(&[0.0, 0.0, 0.0], &[5.0, 5.0, 5.0], 0.5, 1, 20)?;
surface.set_surf_color("magenta");
surface.draw_cylinder(&[5.0, 5.0, 0.0], &[5.0, 5.0, 5.0], 0.5, 1, 20)?;
// add surface to plot
let mut plot = Plot::new();
plot.add(&surface);
// save figure
let path = Path::new(OUT_DIR).join("integ_surface_cylinder.svg");
plot.set_range_3d(-1.0, 6.0, -1.0, 6.0, -1.0, 6.0).set_equal_axes(true);
plot.save(&path)?;
// plot.save_and_show(&path)?;
// check number of lines
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
assert!(lines_iter.count() > 1340);
Ok(())
}
#[test]
fn test_surface_superquadric() -> Result<(), StrError> {
// star
let r = &[1.0, 1.0, 1.0];
let c = &[-1.0, -1.0, -1.0];
let k = &[0.5, 0.5, 0.5];
let mut star = Surface::new();
star.set_colormap_name("jet")
.draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;
// pyramids
let c = &[1.0, -1.0, -1.0];
let k = &[1.0, 1.0, 1.0];
let mut pyramids = Surface::new();
pyramids
.set_colormap_name("inferno")
.draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;
// rounded cube
let c = &[-1.0, 1.0, 1.0];
let k = &[4.0, 4.0, 4.0];
let mut cube = Surface::new();
cube.set_surf_color("#ee29f2")
.draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;
// sphere
let c = &[0.0, 0.0, 0.0];
let k = &[2.0, 2.0, 2.0];
let mut sphere = Surface::new();
sphere
.set_colormap_name("rainbow")
.draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;
// sphere (direct)
let mut sphere_direct = Surface::new();
sphere_direct.draw_sphere(&[1.0, 1.0, 1.0], 1.0, 40, 20)?;
// add features to plot
let mut plot = Plot::new();
plot.add(&star)
.add(&pyramids)
.add(&cube)
.add(&sphere)
.add(&sphere_direct);
// save figure
let path = Path::new(OUT_DIR).join("integ_surface_superquadric.svg");
plot.set_equal_axes(true)
.set_figure_size_points(600.0, 600.0)
.save(&path)?;
// check number of lines
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
assert!(lines_iter.count() > 24780);
Ok(())
}