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
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct OutputSettings {
pub scale: u32,
pub pixel_spacing: u32,
}
impl Default for OutputSettings {
fn default() -> Self {
OutputSettingsBuilder::new().build()
}
}
pub struct OutputSettingsBuilder {
scale: Option<u32>,
pixel_spacing: Option<u32>,
}
impl OutputSettingsBuilder {
pub fn new() -> Self {
Self {
scale: None,
pixel_spacing: None,
}
}
pub fn scale(mut self, scale: u32) -> Self {
if scale == 0 {
panic!("scale must be >= 0");
}
self.scale = Some(scale);
self
}
pub fn pixel_spacing(mut self, pixel_spacing: u32) -> Self {
self.pixel_spacing = Some(pixel_spacing);
self
}
pub fn build(self) -> OutputSettings {
OutputSettings {
scale: self.scale.unwrap_or(1),
pixel_spacing: self.pixel_spacing.unwrap_or(0),
}
}
}