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
use crate::geom::{self, Point2, Point3};
use crate::math::{BaseFloat, Zero};
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Properties<S = geom::scalar::Default> {
pub point: Point3<S>,
}
pub trait SetPosition<S>: Sized {
fn properties(&mut self) -> &mut Properties<S>;
fn x(mut self, x: S) -> Self {
self.properties().point.x = x;
self
}
fn y(mut self, y: S) -> Self {
self.properties().point.y = y;
self
}
fn z(mut self, z: S) -> Self {
self.properties().point.z = z;
self
}
fn xy(self, p: Point2<S>) -> Self {
self.x(p.x).y(p.y)
}
fn xyz(self, p: Point3<S>) -> Self {
self.x(p.x).y(p.y).z(p.z)
}
fn x_y(self, x: S, y: S) -> Self {
self.xy(Point2 { x, y })
}
fn x_y_z(self, x: S, y: S, z: S) -> Self {
self.xyz(Point3 { x, y, z })
}
}
impl<S> Properties<S> {
pub fn transform(&self) -> cgmath::Matrix4<S>
where
S: BaseFloat,
{
cgmath::Matrix4::from_translation(self.point.into())
}
}
impl<S> SetPosition<S> for Properties<S> {
fn properties(&mut self) -> &mut Properties<S> {
self
}
}
impl<S> Default for Properties<S>
where
S: Zero,
{
fn default() -> Self {
let point = Point3::zero();
Self { point }
}
}