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
use super::{Rotator, Scalar, TransformTrait, Vector};
/// A trait that defines how a vertex payload can be linearly transformed.
pub trait Transformable<const D: usize>: Sized + Clone {
/// The transformation type used in the payload.
type Trans: TransformTrait<Self::S, D, Vec = Self::Vec, Rot = Self::Rot>;
/// The rotation type used in the payload.
type Rot: Rotator<Self::Vec>;
/// The vector type used in the payload.
type Vec: Vector<Self::S, D>;
/// The scalar type of the coordinates used in the payload. Mainly to choose between f32 and f64. But could also work with integers etc...
type S: Scalar;
/// Returns the coordinates of the payload as a reference.
fn transformed(&self, t: &Self::Trans) -> Self {
let mut c = self.clone();
c.transform(t);
c
}
/// Returns a translated clone of the payload.
fn translated(&self, v: &Self::Vec) -> Self {
let mut c = self.clone();
c.translate(v);
c
}
/// Returns the scaled clone of the payload.
fn scaled(&self, s: &Self::Vec) -> Self {
let mut c = self.clone();
c.scale(s);
c
}
/// Returns the rotated clone of the payload.
fn rotated(&self, r: &Self::Rot) -> Self {
let mut c = self.clone();
c.rotate(r);
c
}
/// Interpolates between two payloads.
fn lerped(&self, other: &Self, t: Self::S) -> Self {
let mut c = self.clone();
c.lerp(other, t);
c
}
/// Returns the coordinates of the payload as a reference.
fn transform(&mut self, t: &Self::Trans) -> &mut Self;
/// Returns a translated clone of the payload.
fn translate(&mut self, v: &Self::Vec) -> &mut Self {
self.transform(&Self::Trans::from_translation(*v))
}
/// Returns the scaled clone of the payload.
fn scale(&mut self, s: &Self::Vec) -> &mut Self {
self.transform(&Self::Trans::from_scale(*s))
}
/// Returns the rotated clone of the payload.
fn rotate(&mut self, r: &Self::Rot) -> &mut Self {
self.transform(&Self::Trans::from_rotation(r.clone()))
}
/// Interpolates between two payloads.
fn lerp(&mut self, other: &Self, t: Self::S) -> &mut Self;
}