diff options
Diffstat (limited to 'evc/src/helpers')
-rw-r--r-- | evc/src/helpers/matrix.rs | 2 | ||||
-rw-r--r-- | evc/src/helpers/pixel.rs | 8 | ||||
-rw-r--r-- | evc/src/helpers/vector.rs | 9 |
3 files changed, 16 insertions, 3 deletions
diff --git a/evc/src/helpers/matrix.rs b/evc/src/helpers/matrix.rs index 92f46b2..87c0e7d 100644 --- a/evc/src/helpers/matrix.rs +++ b/evc/src/helpers/matrix.rs @@ -9,6 +9,7 @@ pub struct Mat2<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.x, @@ -19,6 +20,7 @@ impl<T: std::ops::Mul<Output = T> + std::ops::Add<Output = T> + Copy> Mat2<T> { 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 { diff --git a/evc/src/helpers/pixel.rs b/evc/src/helpers/pixel.rs index 7b7c8d5..f7d6621 100644 --- a/evc/src/helpers/pixel.rs +++ b/evc/src/helpers/pixel.rs @@ -31,10 +31,12 @@ impl Pixel { } #[inline] pub fn average(a: Pixel, b: Pixel) -> Pixel { + //? this functions is broken + // TODO dont loose accuracy Pixel { - r: (a.r >> 2) + (b.r >> 2), - g: (a.g >> 2) + (b.g >> 2), - b: (a.b >> 2) + (b.b >> 2), + r: (a.r >> 1) + (b.r >> 1), + g: (a.g >> 1) + (b.g >> 1), + b: (a.b >> 1) + (b.b >> 1), } } pub fn scale(&self, factor: f32) -> Pixel { diff --git a/evc/src/helpers/vector.rs b/evc/src/helpers/vector.rs index 12243e4..f411832 100644 --- a/evc/src/helpers/vector.rs +++ b/evc/src/helpers/vector.rs @@ -24,6 +24,15 @@ impl<T: std::ops::Div<Output = T> + Copy> Vec2<T> { } } +impl<T: std::ops::Mul<Output = T> + Copy> Vec2<T> { + pub fn scale(&self, f: T) -> Self { + Self { + x: self.x * f, + y: self.y * f, + } + } +} + impl Vec2<isize> { pub fn x_only(&self) -> Self { Self { x: self.x, y: 0 } |