diff options
Diffstat (limited to 'lvc/src/impls.rs')
-rw-r--r-- | lvc/src/impls.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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<F: Fn(&mut Self)>(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<P2> 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<A> ToArray for (A, A) { type Output = A; + #[inline] fn to_array(self) -> [A; 2] { [self.0, self.1] } |