diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-07 17:16:40 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-07 17:16:40 +0100 |
commit | 85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d (patch) | |
tree | 06497577894131a66f3f4874a9865da5b814fe17 /evc/src/helpers/matrix.rs | |
parent | a713143ef9c1187c37004043b1d3322d773f9ea0 (diff) | |
download | video-codec-experiments-85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d.tar video-codec-experiments-85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d.tar.bz2 video-codec-experiments-85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d.tar.zst |
refactor, matrix math
Diffstat (limited to 'evc/src/helpers/matrix.rs')
-rw-r--r-- | evc/src/helpers/matrix.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/evc/src/helpers/matrix.rs b/evc/src/helpers/matrix.rs new file mode 100644 index 0000000..74d2ae4 --- /dev/null +++ b/evc/src/helpers/matrix.rs @@ -0,0 +1,30 @@ +use crate::helpers::vector::Vec2; + +pub struct Mat2<T> { + a: T, + b: T, + c: T, + d: T, +} + +impl<T: std::ops::Mul<Output = T> + std::ops::Add<Output = T> + Copy> Mat2<T> { + pub fn transform(&self, v: Vec2<T>) -> Vec2<T> { + Vec2 { + x: self.a * v.x + self.b * v.x, + y: self.c * v.y + self.d * v.y, + } + } +} + +impl<T: std::ops::Mul<Output = T> + std::ops::Add<Output = T> + Copy> std::ops::Mul for Mat2<T> { + type Output = Mat2<T>; + fn mul(self, rhs: Mat2<T>) -> Mat2<T> { + let (x, y) = (self, rhs); + Mat2 { + a: x.a * y.a + x.b * y.c, + b: x.a * y.b + x.b * y.d, + c: x.c * y.a + x.d * y.c, + d: x.c * y.b + x.d * y.d, + } + } +} |