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 t in threads {
|
||||||
for c in t {
|
for c in t {
|
||||||
let ((x,y),rgb) = c;
|
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;
|
let (r,g,b)= rgb;
|
||||||
px.set_color(r,g,b);
|
px.set_color(r,g,b);
|
||||||
|
} else {
|
||||||
|
eprintln!("Invalid pixel: ({} {})",x,y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.img.save("./foo.ppm").unwrap();
|
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};
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
|
|
||||||
|
#[repr(align(32))]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Vec3 {
|
pub struct Vec3 {
|
||||||
x: f64,
|
x: f64,
|
||||||
|
|
@ -7,6 +8,7 @@ pub struct Vec3 {
|
||||||
z: f64,
|
z: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(align(32))]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Point3 {
|
pub struct Point3 {
|
||||||
x: f64,
|
x: f64,
|
||||||
|
|
@ -132,6 +134,7 @@ impl Vec3 {
|
||||||
z: self.z,
|
z: self.z,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dot(self, other: Vec3) -> f64 {
|
pub fn dot(self, other: Vec3) -> f64 {
|
||||||
self.x * other.x + self.y * other.y + self.z * other.z
|
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 {
|
pub fn cross(self, other: Vec3) -> Vec3 {
|
||||||
let x = self.y * other.z - self.z * other.y;
|
Vec3{
|
||||||
let y = self.z * other.x - self.x * other.z;
|
x: self.y * other.z - self.z * other.y,
|
||||||
let z = self.x * other.y - self.y * other.x;
|
y: self.z * other.x - self.x * other.z,
|
||||||
Vec3 { x, y, z }
|
z: self.x * other.y - self.y * other.x,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn length_squared(self) -> f64 {
|
pub fn length_squared(self) -> f64 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue