diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
commit | 306f96164784a8cbf405e72fa4364d6523366e95 (patch) | |
tree | 51717fc139871baa438aad806f4923669ae0896c /old/evc/src/helpers/matrix.rs | |
parent | 9cc089e2d6e841879e430b01d2f3d92c8820523e (diff) | |
download | video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.bz2 video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.zst |
old dir
Diffstat (limited to 'old/evc/src/helpers/matrix.rs')
-rw-r--r-- | old/evc/src/helpers/matrix.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/old/evc/src/helpers/matrix.rs b/old/evc/src/helpers/matrix.rs new file mode 100644 index 0000000..0007440 --- /dev/null +++ b/old/evc/src/helpers/matrix.rs @@ -0,0 +1,33 @@ +use crate::helpers::vector::Vec2; + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Mat2<T> { + pub a: T, + pub b: T, + pub c: T, + pub d: T, +} + +impl<T: std::ops::Mul<Output = T> + std::ops::Add<Output = T> + Copy> Mat2<T> { + #[inline] + pub fn transform(&self, v: Vec2<T>) -> Vec2<T> { + Vec2 { + x: self.a * v.x + self.b * v.y, + y: self.c * v.x + 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>; + #[inline] + 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, + } + } +} |