From 9badea407d6710c22c5e7e61b44ff6eca8fb868b Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 19 Aug 2023 20:01:33 -0500 Subject: [PATCH] Rect in primitives, collect the tests There's the rectangle! Also the tests. Cargo doesn't complain, but my YcmCompleter (so rust-analyze, I think) does. The tests are all one big slab again. --- src/main.rs | 10 +--------- src/primitives.rs | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 395e5db..b30562c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ mod material; mod hittable; mod thread_utils; -use crate::primitives::{Vec3, Ray}; +use crate::primitives::{Vec3, Ray, Rect}; use crate::hittable::Hittable; use crate::material::Material; use crate::camera::Camera; @@ -176,14 +176,6 @@ fn sample_pixel(x: i32, y: i32, small_rng: &mut SmallRng, context: &RenderContex ) } -#[derive (Copy, Clone)] -struct Rect { - x: i32, - y: i32, - w: i32, - h: i32, -} - /* Iterable that produces pixels left-to-right, top-to-bottom. * `Tile`s represent the render space, not the finished image. * There is no internal pixel buffer diff --git a/src/primitives.rs b/src/primitives.rs index da54ce0..dc165d7 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -288,6 +288,26 @@ impl Display for Vec3 { } } +#[derive(Copy, Clone)] +pub struct Ray{ + pub orig: Vec3, + pub dir: Vec3, +} + +impl Ray{ + pub fn at(&self, t: f32) -> Vec3 { + self.orig + self.dir*t + } +} + +#[derive (Copy, Clone)] +pub struct Rect { + pub x: i32, + pub y: i32, + pub w: i32, + pub h: i32, +} + #[cfg(test)] mod test{ use super::*; @@ -547,23 +567,6 @@ mod test{ eprintln!("Diff: {}", diff); assert!(Vec3::near_zero(&diff)); } -} - -#[derive(Copy, Clone)] -pub struct Ray{ - pub orig: Vec3, - pub dir: Vec3, -} - -impl Ray{ - pub fn at(&self, t: f32) -> Vec3 { - self.orig + self.dir*t - } -} - -#[cfg(test)] -mod test{ - use super::*; #[test] fn check_lerp(){