Minor changes for speed up
This commit is contained in:
parent
8df48d3824
commit
b9ac41b453
2 changed files with 14 additions and 7 deletions
|
|
@ -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();
|
||||
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();
|
||||
|
|
|
|||
12
src/vec3.rs
12
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue