aboutsummaryrefslogtreecommitdiff
path: root/lvc/src/impls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lvc/src/impls.rs')
-rw-r--r--lvc/src/impls.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/lvc/src/impls.rs b/lvc/src/impls.rs
index 0801361..00614c9 100644
--- a/lvc/src/impls.rs
+++ b/lvc/src/impls.rs
@@ -88,7 +88,10 @@ impl Index<P2> for Frame {
type Output = Pixel;
#[inline]
fn index(&self, P2 { x, y }: P2) -> &Self::Output {
- &self.pixels[x as usize + (y as usize * self.size.x as usize)]
+ &self
+ .pixels
+ .get(x as usize + (y as usize * self.size.x as usize))
+ .unwrap_or(&Pixel { r: 0, g: 0, b: 0 })
}
}
impl IndexMut<P2> for Frame {
@@ -97,3 +100,14 @@ impl IndexMut<P2> for Frame {
&mut self.pixels[x as usize + (y as usize * self.size.x as usize)]
}
}
+
+pub trait ToArray {
+ type Output;
+ fn to_array(self) -> [Self::Output; 2];
+}
+impl<A> ToArray for (A, A) {
+ type Output = A;
+ fn to_array(self) -> [A; 2] {
+ [self.0, self.1]
+ }
+}