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 }
}
}