From 755325d6c8faa897ee686452831cb544d6c72d75 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 7 Mar 2023 21:52:04 +0100 Subject: more magic --- lvc/src/impls.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lvc/src/impls.rs') diff --git a/lvc/src/impls.rs b/lvc/src/impls.rs index 00614c9..2a5a497 100644 --- a/lvc/src/impls.rs +++ b/lvc/src/impls.rs @@ -27,11 +27,18 @@ impl Frame { } } impl Ref { + #[inline] pub fn apply(mut self, f: F) -> Self { f(&mut self); self } } +impl Pixel { + pub const BLACK: Pixel = Pixel { r: 0, g: 0, b: 0 }; + pub const RED: Pixel = Pixel { r: 255, g: 0, b: 0 }; + pub const GREEN: Pixel = Pixel { r: 0, g: 255, b: 0 }; + pub const BLUE: Pixel = Pixel { r: 0, g: 0, b: 255 }; +} impl Add for Pixel { type Output = Pixel; #[inline] @@ -45,6 +52,9 @@ impl Add for Pixel { } impl P2 { pub const ZERO: P2 = P2 { x: 0, y: 0 }; + pub const X: P2 = P2 { x: 1, y: 0 }; + pub const Y: P2 = P2 { x: 0, y: 1 }; + #[inline] pub fn area(&self) -> usize { (self.x * self.y) as usize @@ -63,6 +73,16 @@ impl View { self.b - self.a } } +impl Add for View { + type Output = View; + #[inline] + fn add(self, rhs: P2) -> Self::Output { + View { + a: self.a + rhs, + b: self.b + rhs, + } + } +} impl Add for P2 { type Output = P2; #[inline] @@ -107,6 +127,7 @@ pub trait ToArray { } impl ToArray for (A, A) { type Output = A; + #[inline] fn to_array(self) -> [A; 2] { [self.0, self.1] } -- cgit v1.2.3-70-g09d2