nannou/draw/properties/spatial/
position.rs1use crate::geom::{Point2, Point3};
4use crate::glam::Mat4;
5
6#[derive(Copy, Clone, Debug, PartialEq)]
8pub struct Properties {
9 pub point: Point3,
10}
11
12pub trait SetPosition: Sized {
14 fn properties(&mut self) -> &mut Properties;
16
17 fn x(mut self, x: f32) -> Self {
19 self.properties().point.x = x;
20 self
21 }
22
23 fn y(mut self, y: f32) -> Self {
25 self.properties().point.y = y;
26 self
27 }
28
29 fn z(mut self, z: f32) -> Self {
31 self.properties().point.z = z;
32 self
33 }
34
35 fn xy(self, p: Point2) -> Self {
37 self.x(p.x).y(p.y)
38 }
39
40 fn xyz(self, p: Point3) -> Self {
42 self.x(p.x).y(p.y).z(p.z)
43 }
44
45 fn x_y(self, x: f32, y: f32) -> Self {
47 self.xy([x, y].into())
48 }
49
50 fn x_y_z(self, x: f32, y: f32, z: f32) -> Self {
52 self.xyz([x, y, z].into())
53 }
54}
55
56impl Properties {
57 pub fn transform(&self) -> Mat4 {
58 Mat4::from_translation(self.point.into())
59 }
60}
61
62impl SetPosition for Properties {
63 fn properties(&mut self) -> &mut Properties {
64 self
65 }
66}
67
68impl Default for Properties {
69 fn default() -> Self {
70 let point = Point3::ZERO;
71 Self { point }
72 }
73}