diff --git a/src/render.rs b/src/render.rs index 142fcf4..9401573 100644 --- a/src/render.rs +++ b/src/render.rs @@ -122,9 +122,12 @@ impl Camera { for t in threads { for c in t { let ((x,y),rgb) = c; - let px = self.img.get_pixel(x,y).unwrap(); - let (r,g,b)= rgb; - px.set_color(r,g,b); + if let Some(px) = self.img.get_pixel(x,y){ + let (r,g,b)= rgb; + px.set_color(r,g,b); + } else { + eprintln!("Invalid pixel: ({} {})",x,y); + } } } self.img.save("./foo.ppm").unwrap(); diff --git a/src/vec3.rs b/src/vec3.rs index 0b4eaeb..56bc0b5 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -1,5 +1,6 @@ use std::ops::{Add, Div, Mul, Sub}; +#[repr(align(32))] #[derive(Clone, Copy)] pub struct Vec3 { x: f64, @@ -7,6 +8,7 @@ pub struct Vec3 { z: f64, } +#[repr(align(32))] #[derive(Clone, Copy)] pub struct Point3 { x: f64, @@ -132,6 +134,7 @@ impl Vec3 { z: self.z, } } + pub fn dot(self, other: Vec3) -> f64 { self.x * other.x + self.y * other.y + self.z * other.z } @@ -149,10 +152,11 @@ impl Vec3 { } pub fn cross(self, other: Vec3) -> Vec3 { - let x = self.y * other.z - self.z * other.y; - let y = self.z * other.x - self.x * other.z; - let z = self.x * other.y - self.y * other.x; - Vec3 { x, y, z } + Vec3{ + x: self.y * other.z - self.z * other.y, + y: self.z * other.x - self.x * other.z, + z: self.x * other.y - self.y * other.x, + } } pub fn length_squared(self) -> f64 {