From 2167abcf72d978b4ac2f08fa7cbbddaada01f165 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 7 Mar 2023 08:00:00 +0100 Subject: a --- lvc/src/impls.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lvc/src/impls.rs (limited to 'lvc/src/impls.rs') diff --git a/lvc/src/impls.rs b/lvc/src/impls.rs new file mode 100644 index 0000000..01eb1c6 --- /dev/null +++ b/lvc/src/impls.rs @@ -0,0 +1,68 @@ +use crate::{Frame, Pixel, View, P2}; +use std::ops::{Add, Index, IndexMut, Sub}; + +impl Add for Pixel { + type Output = Pixel; + #[inline] + fn add(self, rhs: Self) -> Self::Output { + Self { + r: self.r + rhs.r, + g: self.g + rhs.g, + b: self.b + rhs.b, + } + } +} +impl P2 { + pub const ZERO: P2 = P2 { x: 0, y: 0 }; + #[inline] + pub fn area(&self) -> usize { + (self.x * self.y) as usize + } +} +impl View { + #[inline] + pub fn all(b: P2) -> Self { + Self { + a: P2::default(), + b, + } + } + #[inline] + pub fn size(&self) -> P2 { + self.b - self.a + } +} +impl Add for P2 { + type Output = P2; + #[inline] + fn add(self, rhs: Self) -> Self::Output { + Self { + x: self.x + rhs.x, + y: self.y + rhs.y, + } + } +} +impl Sub for P2 { + type Output = P2; + #[inline] + fn sub(self, rhs: Self) -> Self::Output { + Self { + x: self.x - rhs.x, + y: self.y - rhs.y, + } + } +} + +impl Index for Frame { + type Output = Pixel; + #[inline] + fn index(&self, P2 { x, y }: P2) -> &Self::Output { + &self.pixels[x as usize + (y as usize * self.size.x as usize)] + } +} +impl IndexMut for Frame { + #[inline] + fn index_mut(&mut self, P2 { x, y }: P2) -> &mut Self::Output { + &mut self.pixels[x as usize + (y as usize * self.size.x as usize)] + } +} -- cgit v1.2.3-70-g09d2