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
use crate::geom::{self, Vector2, Vector3};
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Properties<S = geom::scalar::Default> {
pub x: Option<S>,
pub y: Option<S>,
pub z: Option<S>,
}
pub trait SetDimensions<S>: Sized {
fn properties(&mut self) -> &mut Properties<S>;
fn width(mut self, w: S) -> Self {
self.properties().x = Some(w);
self
}
fn height(mut self, h: S) -> Self {
self.properties().y = Some(h);
self
}
fn depth(mut self, d: S) -> Self {
self.properties().z = Some(d);
self
}
fn w(self, w: S) -> Self {
self.width(w)
}
fn h(self, h: S) -> Self {
self.height(h)
}
fn d(self, d: S) -> Self {
self.depth(d)
}
fn wh(self, v: Vector2<S>) -> Self {
self.w(v.x).h(v.y)
}
fn whd(self, v: Vector3<S>) -> Self {
self.w(v.x).h(v.y).d(v.z)
}
fn w_h(self, x: S, y: S) -> Self {
self.wh(Vector2 { x, y })
}
fn w_h_d(self, x: S, y: S, z: S) -> Self {
self.whd(Vector3 { x, y, z })
}
}
impl<S> SetDimensions<S> for Properties<S> {
fn properties(&mut self) -> &mut Properties<S> {
self
}
}
impl<S> Default for Properties<S> {
fn default() -> Self {
Self {
x: None,
y: None,
z: None,
}
}
}