Minor changes for speed up
All checks were successful
CI / test (push) Successful in 26s
Render Image / render (push) Successful in 28s

This commit is contained in:
k 2026-04-28 19:32:16 -04:00
parent 8df48d3824
commit b9ac41b453
2 changed files with 14 additions and 7 deletions

View file

@ -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();

View file

@ -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 {