From 306f96164784a8cbf405e72fa4364d6523366e95 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 5 May 2025 15:09:54 +0200 Subject: old dir --- old/evc/src/helpers/matrix.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 old/evc/src/helpers/matrix.rs (limited to 'old/evc/src/helpers/matrix.rs') 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 { + pub a: T, + pub b: T, + pub c: T, + pub d: T, +} + +impl + std::ops::Add + Copy> Mat2 { + #[inline] + pub fn transform(&self, v: Vec2) -> Vec2 { + Vec2 { + x: self.a * v.x + self.b * v.y, + y: self.c * v.x + self.d * v.y, + } + } +} + +impl + std::ops::Add + Copy> std::ops::Mul for Mat2 { + type Output = Mat2; + #[inline] + fn mul(self, rhs: Mat2) -> Mat2 { + 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, + } + } +} -- cgit v1.2.3-70-g09d2