aboutsummaryrefslogtreecommitdiff
path: root/lvc/src/impls.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-03-07 21:52:04 +0100
committermetamuffin <metamuffin@disroot.org>2023-03-07 21:52:04 +0100
commit755325d6c8faa897ee686452831cb544d6c72d75 (patch)
tree7682fe2f18889fe95674f3de7242c5c1601b266d /lvc/src/impls.rs
parentda39ed55e1440fba61122c5fa2262ab9b0a9dd21 (diff)
downloadvideo-codec-experiments-755325d6c8faa897ee686452831cb544d6c72d75.tar
video-codec-experiments-755325d6c8faa897ee686452831cb544d6c72d75.tar.bz2
video-codec-experiments-755325d6c8faa897ee686452831cb544d6c72d75.tar.zst
more magic
Diffstat (limited to 'lvc/src/impls.rs')
-rw-r--r--lvc/src/impls.rs21
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]
}