aboutsummaryrefslogtreecommitdiff
path: root/evc/src/view.rs
diff options
context:
space:
mode:
Diffstat (limited to 'evc/src/view.rs')
-rw-r--r--evc/src/view.rs32
1 files changed, 16 insertions, 16 deletions
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<T> {
pub frame: T,
- pub offset: Vec2,
- pub size: Vec2,
+ pub offset: Vec2<isize>,
+ pub size: Vec2<isize>,
}
impl<T> View<T> {
- pub fn new(frame: T, offset: Vec2, size: Vec2) -> Self {
+ pub fn new(frame: T, offset: Vec2<isize>, size: Vec2<isize>) -> Self {
Self {
frame,
offset,
@@ -18,7 +18,7 @@ impl<T> View<T> {
pub fn area(&self) -> isize {
self.size.x * self.size.y
}
- pub fn center(&self) -> Vec2 {
+ pub fn center(&self) -> Vec2<isize> {
self.offset + self.size.downscale(2)
}
}
@@ -71,7 +71,7 @@ impl<T> View<&mut T> {
}
}
impl<T: Copy> View<T> {
- pub fn offset(&self, offset: Vec2) -> Self {
+ pub fn offset(&self, offset: Vec2<isize>) -> Self {
Self {
frame: self.frame,
offset: self.offset + offset,
@@ -124,7 +124,7 @@ impl<T: Copy> View<T> {
]
}
}
-impl<T: Index<Vec2, Output = Pixel>> View<&T> {
+impl<T: Index<Vec2<isize>, 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<T: Index<Vec2, Output = Pixel>> Index<Vec2> for View<&T> {
+impl<T: Index<Vec2<isize>, Output = Pixel>> Index<Vec2<isize>> for View<&T> {
type Output = Pixel;
#[inline]
- fn index(&self, p: Vec2) -> &Self::Output {
+ fn index(&self, p: Vec2<isize>) -> &Self::Output {
&self.frame[self.offset + p]
}
}
-impl<T: Index<Vec2, Output = Pixel>> Index<Vec2> for View<&mut T> {
+impl<T: Index<Vec2<isize>, Output = Pixel>> Index<Vec2<isize>> for View<&mut T> {
type Output = Pixel;
#[inline]
- fn index(&self, p: Vec2) -> &Self::Output {
+ fn index(&self, p: Vec2<isize>) -> &Self::Output {
&self.frame[self.offset + p]
}
}
-impl<T: IndexMut<Vec2, Output = Pixel>> IndexMut<Vec2> for View<&mut T> {
+impl<T: IndexMut<Vec2<isize>, Output = Pixel>> IndexMut<Vec2<isize>> for View<&mut T> {
#[inline]
- fn index_mut(&mut self, p: Vec2) -> &mut Self::Output {
+ fn index_mut(&mut self, p: Vec2<isize>) -> &mut Self::Output {
&mut self.frame[self.offset + p]
}
}
-impl<T: Index<Vec2, Output = Pixel>> Index<(isize, isize)> for View<&T> {
+impl<T: Index<Vec2<isize>, 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<T: Index<Vec2, Output = Pixel>> Index<(isize, isize)> for View<&mut T> {
+impl<T: Index<Vec2<isize>, 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<T: IndexMut<Vec2, Output = Pixel>> IndexMut<(isize, isize)> for View<&mut T> {
+impl<T: IndexMut<Vec2<isize>, 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 }]