From 85d20c4f4cf3656fbf7c27b6b8bbf9536e3ae04d Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 7 Dec 2022 17:16:40 +0100 Subject: refactor, matrix math --- evc/src/view.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'evc/src/view.rs') diff --git a/evc/src/view.rs b/evc/src/view.rs index 36cdf42..5596637 100644 --- a/evc/src/view.rs +++ b/evc/src/view.rs @@ -1,14 +1,14 @@ -use crate::{frame::Frame, pixel::Pixel, vec2::Vec2}; +use crate::{frame::Frame, helpers::vector::Vec2, pixel::Pixel}; use std::ops::{Index, IndexMut}; pub struct View { pub frame: T, - pub offset: Vec2, - pub size: Vec2, + pub offset: Vec2, + pub size: Vec2, } impl View { - pub fn new(frame: T, offset: Vec2, size: Vec2) -> Self { + pub fn new(frame: T, offset: Vec2, size: Vec2) -> Self { Self { frame, offset, @@ -18,7 +18,7 @@ impl View { pub fn area(&self) -> isize { self.size.x * self.size.y } - pub fn center(&self) -> Vec2 { + pub fn center(&self) -> Vec2 { self.offset + self.size.downscale(2) } } @@ -71,7 +71,7 @@ impl View<&mut T> { } } impl View { - pub fn offset(&self, offset: Vec2) -> Self { + pub fn offset(&self, offset: Vec2) -> Self { Self { frame: self.frame, offset: self.offset + offset, @@ -124,7 +124,7 @@ impl View { ] } } -impl> View<&T> { +impl, Output = Pixel>> View<&T> { pub fn diff(va: &Self, vb: &Self) -> f64 { assert_eq!(va.size, vb.size); let mut acc = 0; @@ -164,42 +164,42 @@ impl View<&mut Frame> { } } -impl> Index for View<&T> { +impl, Output = Pixel>> Index> for View<&T> { type Output = Pixel; #[inline] - fn index(&self, p: Vec2) -> &Self::Output { + fn index(&self, p: Vec2) -> &Self::Output { &self.frame[self.offset + p] } } -impl> Index for View<&mut T> { +impl, Output = Pixel>> Index> for View<&mut T> { type Output = Pixel; #[inline] - fn index(&self, p: Vec2) -> &Self::Output { + fn index(&self, p: Vec2) -> &Self::Output { &self.frame[self.offset + p] } } -impl> IndexMut for View<&mut T> { +impl, Output = Pixel>> IndexMut> for View<&mut T> { #[inline] - fn index_mut(&mut self, p: Vec2) -> &mut Self::Output { + fn index_mut(&mut self, p: Vec2) -> &mut Self::Output { &mut self.frame[self.offset + p] } } -impl> Index<(isize, isize)> for View<&T> { +impl, Output = Pixel>> Index<(isize, isize)> for View<&T> { type Output = Pixel; #[inline] fn index(&self, (x, y): (isize, isize)) -> &Self::Output { &self[Vec2 { x, y }] } } -impl> Index<(isize, isize)> for View<&mut T> { +impl, Output = Pixel>> Index<(isize, isize)> for View<&mut T> { type Output = Pixel; #[inline] fn index(&self, (x, y): (isize, isize)) -> &Self::Output { &self[Vec2 { x, y }] } } -impl> IndexMut<(isize, isize)> for View<&mut T> { +impl, Output = Pixel>> IndexMut<(isize, isize)> for View<&mut T> { #[inline] fn index_mut(&mut self, (x, y): (isize, isize)) -> &mut Self::Output { &mut self[Vec2 { x, y }] -- cgit v1.2.3-70-g09d2