diff --git a/benches/default_benchmark.rs b/benches/default_benchmark.rs index 31a88f1..3b1e6fa 100644 --- a/benches/default_benchmark.rs +++ b/benches/default_benchmark.rs @@ -5,8 +5,8 @@ use rand_distr::Uniform; use raytracer::bvh::aabb::Aabb; use raytracer::interval::Interval; -use raytracer::render::ray::Ray; use raytracer::linalg::vec3::Vec3; +use raytracer::render::ray::Ray; pub fn criterion_benchmark(c: &mut Criterion) { let bbox: Aabb = Aabb::new_from_points(Vec3::new(1.0, 1.0, 1.0), Vec3::new(2.0, 2.0, 2.0)); diff --git a/src/bvh/aabb.rs b/src/bvh/aabb.rs index 5d19e8a..7d2bcd3 100644 --- a/src/bvh/aabb.rs +++ b/src/bvh/aabb.rs @@ -1,7 +1,7 @@ use crate::elements::Hittable; use crate::interval::Interval; -use crate::render::Ray; use crate::linalg::Vec3; +use crate::render::Ray; use std::fmt; use std::ops::Index; @@ -172,8 +172,8 @@ impl Index for Aabb { mod tests { use crate::bvh::aabb::Aabb; use crate::interval::Interval; - use crate::render::Ray; use crate::linalg::Vec3; + use crate::render::Ray; use assert_approx_eq::assert_approx_eq; // Test creating a new aabb, taking intervals as an argument diff --git a/src/bvh/bvh_node.rs b/src/bvh/bvh_node.rs index 7b03222..0fe5c2a 100644 --- a/src/bvh/bvh_node.rs +++ b/src/bvh/bvh_node.rs @@ -4,8 +4,8 @@ use super::aabb::Aabb; use crate::elements::*; use crate::interval::Interval; -use crate::render::Ray; use crate::linalg::Vec3; +use crate::render::Ray; use rand::rngs::SmallRng; use rand::{Rng, SeedableRng}; diff --git a/src/bvh/mod.rs b/src/bvh/mod.rs index ea880e9..a17c2dd 100644 --- a/src/bvh/mod.rs +++ b/src/bvh/mod.rs @@ -2,4 +2,4 @@ mod aabb; pub use aabb::Aabb; mod bvh_node; -pub use bvh_node::BVHNode; \ No newline at end of file +pub use bvh_node::BVHNode; diff --git a/src/config.rs b/src/config.rs index 59b8c2f..4b8efd9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,8 @@ -use crate::render::camera::Camera; use crate::elements::*; use crate::interval::Interval; +use crate::render::camera::Camera; use crate::render::Ray; -use crate::{render::camera::JSONCamera, color::Color}; +use crate::{color::Color, render::camera::JSONCamera}; use serde::{Deserialize, Serialize}; diff --git a/src/elements.rs b/src/elements.rs index 7cfca56..585dd21 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -11,10 +11,13 @@ use serde::{Deserialize, Serialize}; extern crate wavefront_obj; use wavefront_obj::obj; -use crate::linalg::{Vec3, Onb, mat4::{Mat4, Vec4}}; -use crate::{bvh::Aabb, materials::*}; -use crate::render::Ray; use crate::interval::Interval; +use crate::linalg::{ + mat4::{Mat4, Vec4}, + Onb, Vec3, +}; +use crate::render::Ray; +use crate::{bvh::Aabb, materials::*}; // hitrecord gets returned on a hit, containting the point on the ray, the point in the global coordinate system, the normal and the material for the hit #[derive(Debug)] @@ -822,8 +825,8 @@ impl JSONObj { mod tests { use crate::color::Color; use crate::elements::*; - use crate::render::Ray; use crate::linalg::Vec3; + use crate::render::Ray; use assert_approx_eq::assert_approx_eq; #[test_log::test] diff --git a/src/lib.rs b/src/lib.rs index a01e660..06df07e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ -pub mod render; pub mod bvh; pub mod color; pub mod config; pub mod elements; pub mod interval; pub mod linalg; -pub mod materials; \ No newline at end of file +pub mod materials; +pub mod render; diff --git a/src/linalg/mat4.rs b/src/linalg/mat4.rs index 1ec903f..a7576a9 100644 --- a/src/linalg/mat4.rs +++ b/src/linalg/mat4.rs @@ -458,7 +458,10 @@ impl Div for Mat4 { #[cfg(test)] mod tests { - use crate::linalg::{vec3::Vec3, mat4::{Mat4, Vec4}}; + use crate::linalg::{ + mat4::{Mat4, Vec4}, + vec3::Vec3, + }; use assert_approx_eq::assert_approx_eq; // Test creating a new vector with three rows, taking floats as an argument diff --git a/src/linalg/mod.rs b/src/linalg/mod.rs index fe758d1..5c0a6fb 100644 --- a/src/linalg/mod.rs +++ b/src/linalg/mod.rs @@ -4,4 +4,4 @@ pub use vec3::Vec3; pub mod mat4; mod onb; -pub use onb::Onb; \ No newline at end of file +pub use onb::Onb; diff --git a/src/materials/dielectric.rs b/src/materials/dielectric.rs index 5458655..f089122 100644 --- a/src/materials/dielectric.rs +++ b/src/materials/dielectric.rs @@ -1,9 +1,9 @@ use rand::Rng; use serde::{Deserialize, Serialize}; -use crate::{color::Color, render::Ray, elements::HitRecord, linalg::Vec3}; +use crate::{color::Color, elements::HitRecord, linalg::Vec3, render::Ray}; -use super::{Refracts, RefractRecord}; +use super::{RefractRecord, Refracts}; #[derive(Serialize, Deserialize, Debug, Clone, Copy)] pub struct Dielectric { @@ -42,7 +42,9 @@ impl Refracts for Dielectric { let cannot_refract: bool = refraction_ratio * sin_theta > 1.0; - if cannot_refract || super::metal::reflectance(cos_theta, refraction_ratio) > rng.gen::() { + if cannot_refract + || super::metal::reflectance(cos_theta, refraction_ratio) > rng.gen::() + { let direction: Vec3 = super::metal::reflect_vector(&unit_direction, &hit_record.normal); let reflected_ray: Ray = Ray::new(hit_record.point, direction); let refract_record: RefractRecord = RefractRecord { @@ -61,4 +63,4 @@ impl Refracts for Dielectric { return Some(refract_record); } } -} \ No newline at end of file +} diff --git a/src/materials/diffuse_light.rs b/src/materials/diffuse_light.rs index 387b6d1..9091e96 100644 --- a/src/materials/diffuse_light.rs +++ b/src/materials/diffuse_light.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{elements::HitRecord, color::Color, render::Ray}; +use crate::{color::Color, elements::HitRecord, render::Ray}; use super::Emmits; @@ -26,4 +26,4 @@ impl Emmits for DiffuseLight { None } } -} \ No newline at end of file +} diff --git a/src/materials/lambertian.rs b/src/materials/lambertian.rs index 151248a..b9c25e4 100644 --- a/src/materials/lambertian.rs +++ b/src/materials/lambertian.rs @@ -1,9 +1,13 @@ use rand::Rng; use serde::{Deserialize, Serialize}; -use crate::{color::Color, render::{Ray, Pdf, CosinePDF}, elements::HitRecord}; +use crate::{ + color::Color, + elements::HitRecord, + render::{CosinePDF, Pdf, Ray}, +}; -use super::{Scatterable, ScatterRecord}; +use super::{ScatterRecord, Scatterable}; // Lambertian (diffuse) material, that scatters rays in a semi-random direction (lambertian distribution = more concentrated around the normal) #[derive(Serialize, Deserialize, Debug, Clone, Copy)] @@ -36,4 +40,4 @@ impl Scatterable for Lambertian { Some(scatter) } -} \ No newline at end of file +} diff --git a/src/materials/metal.rs b/src/materials/metal.rs index d43cd0c..41a4e12 100644 --- a/src/materials/metal.rs +++ b/src/materials/metal.rs @@ -1,9 +1,9 @@ use rand::Rng; use serde::{Deserialize, Serialize}; -use crate::{color::Color, render::Ray, elements::HitRecord, linalg::Vec3}; +use crate::{color::Color, elements::HitRecord, linalg::Vec3, render::Ray}; -use super::{Reflects, ReflectRecord}; +use super::{ReflectRecord, Reflects}; // Metal material, with a fuzz factor. Metal reflects all rays in a predictable way (normal reflection) #[derive(Serialize, Deserialize, Debug, Clone, Copy)] @@ -73,4 +73,4 @@ pub fn reflectance(cosine: f64, ref_idx: f64) -> f64 { let mut r0 = (1.0 - ref_idx) / (1.0 + ref_idx); r0 = r0 * r0; r0 + (1.0 - r0) * (1.0 - cosine).powi(5) -} \ No newline at end of file +} diff --git a/src/materials/mod.rs b/src/materials/mod.rs index 5584396..67d9b36 100644 --- a/src/materials/mod.rs +++ b/src/materials/mod.rs @@ -11,9 +11,13 @@ mod dielectric; pub use dielectric::Dielectric; use rand::Rng; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; -use crate::{elements::HitRecord, render::{Ray, Pdf}, color::Color}; +use crate::{ + color::Color, + elements::HitRecord, + render::{Pdf, Ray}, +}; #[derive(Serialize, Deserialize, Debug, Clone, Copy)] pub enum Material { @@ -128,4 +132,4 @@ impl Emmits for Material { _ => None, } } -} \ No newline at end of file +} diff --git a/src/render/camera.rs b/src/render/camera.rs index 1f20d6d..476efb4 100644 --- a/src/render/camera.rs +++ b/src/render/camera.rs @@ -1,7 +1,7 @@ use rand::Rng; use serde::{Deserialize, Serialize}; -use crate::{config::Config, render::ray::Ray, linalg::Vec3}; +use crate::{config::Config, linalg::Vec3, render::ray::Ray}; #[derive(Serialize, Deserialize, Debug)] pub struct JSONCamera { diff --git a/src/render/integrator.rs b/src/render/integrator.rs index cd0cdd6..eb202e6 100644 --- a/src/render/integrator.rs +++ b/src/render/integrator.rs @@ -6,12 +6,12 @@ use rayon::prelude::*; use crate::{ bvh::BVHNode, - render::camera::Camera, color::Color, config::{Config, JSONScene}, elements::{Element, Hittable, JSONElement}, interval::Interval, materials::{Emmits, Reflects, Refracts, Scatterable}, + render::camera::Camera, render::pdf::{HittablePDF, MixedPDF, PDFTrait, Pdf}, render::ray::Ray, }; @@ -274,4 +274,4 @@ mod tests { //render(scene, config)?; Ok(()) } -} \ No newline at end of file +} diff --git a/src/render/mod.rs b/src/render/mod.rs index dd2dcae..e74ca02 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1,8 +1,8 @@ -pub mod integrator; pub mod camera; +pub mod integrator; mod pdf; -pub use pdf::{Pdf, PDFTrait, CosinePDF, MixedPDF, HittablePDF}; +pub use pdf::{CosinePDF, HittablePDF, MixedPDF, PDFTrait, Pdf}; mod ray; -pub use ray::Ray; \ No newline at end of file +pub use ray::Ray; diff --git a/src/render/ray.rs b/src/render/ray.rs index 5eef367..8db1751 100644 --- a/src/render/ray.rs +++ b/src/render/ray.rs @@ -56,8 +56,8 @@ impl fmt::Display for Ray { #[cfg(test)] mod tests { - use crate::render::ray::Ray; use crate::linalg::Vec3; + use crate::render::ray::Ray; use assert_approx_eq::assert_approx_eq; #[test_log::test]