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