diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-07 17:16:40 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-07 17:16:40 +0100 |
commit | 85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d (patch) | |
tree | 06497577894131a66f3f4874a9865da5b814fe17 /evc/src/vec2.rs | |
parent | a713143ef9c1187c37004043b1d3322d773f9ea0 (diff) | |
download | video-codec-experiments-85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d.tar video-codec-experiments-85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d.tar.bz2 video-codec-experiments-85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d.tar.zst |
refactor, matrix math
Diffstat (limited to 'evc/src/vec2.rs')
-rw-r--r-- | evc/src/vec2.rs | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/evc/src/vec2.rs b/evc/src/vec2.rs deleted file mode 100644 index 5713d02..0000000 --- a/evc/src/vec2.rs +++ /dev/null @@ -1,82 +0,0 @@ -use crate::ser::{Ser, Sink, Source}; - -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub struct Vec2 { - pub x: isize, - pub y: isize, -} -impl Vec2 { - pub const ZERO: Vec2 = Vec2 { x: 0, y: 0 }; - pub const UP: Vec2 = Vec2 { x: 0, y: -1 }; - pub const LEFT: Vec2 = Vec2 { x: -1, y: 0 }; - pub fn downscale(&self, f: isize) -> Self { - Self { - x: self.x / f, - y: self.y / f, - } - } -} - -impl Ser for Vec2 { - fn write(&self, sink: &mut impl std::io::Write) -> anyhow::Result<()> { - sink.put((self.x, self.y)) - } - - fn read(source: &mut impl std::io::Read) -> anyhow::Result<Self> { - let (x, y) = source.get()?; - Ok(Vec2 { x, y }) - } -} - -pub struct Small<T>(pub T); -impl Ser for Small<Vec2> { - fn write(&self, sink: &mut impl std::io::Write) -> anyhow::Result<()> { - sink.put((self.0.x as i8, self.0.y as i8)) - } - - fn read(source: &mut impl std::io::Read) -> anyhow::Result<Self> { - let (x, y): (i8, i8) = source.get()?; - Ok(Small(Vec2 { - x: x as isize, - y: y as isize, - })) - } -} - -impl std::ops::Add for Vec2 { - type Output = Vec2; - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Vec2 { - x: self.x + rhs.x, - y: self.y + rhs.y, - } - } -} -impl std::ops::Sub for Vec2 { - type Output = Vec2; - #[inline] - fn sub(self, rhs: Self) -> Self::Output { - Vec2 { - x: self.x - rhs.x, - y: self.y - rhs.y, - } - } -} -impl std::ops::Mul for Vec2 { - type Output = Vec2; - #[inline] - fn mul(self, rhs: Self) -> Self::Output { - Vec2 { - x: self.x * rhs.x, - y: self.y * rhs.y, - } - } -} - -impl From<(isize, isize)> for Vec2 { - #[inline] - fn from((x, y): (isize, isize)) -> Self { - Vec2 { x, y } - } -} |