diff --git a/src/accel/bvh.rs b/src/accel/bvh.rs index b6b3fdf..d813ebb 100644 --- a/src/accel/bvh.rs +++ b/src/accel/bvh.rs @@ -1,19 +1,16 @@ #![allow(dead_code)] -use std; - use mem_arena::MemArena; -use crate::algorithm::partition; -use crate::bbox::BBox; -use crate::boundable::Boundable; -use crate::lerp::lerp_slice; -use crate::ray::AccelRay; -use crate::timer::Timer; +use crate::{ + algorithm::partition, bbox::BBox, boundable::Boundable, lerp::lerp_slice, ray::AccelRay, + timer::Timer, +}; -use super::bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}; -use super::ACCEL_NODE_RAY_TESTS; -use super::ACCEL_TRAV_TIME; +use super::{ + bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}, + ACCEL_NODE_RAY_TESTS, ACCEL_TRAV_TIME, +}; #[derive(Copy, Clone, Debug)] pub struct BVH<'a> { diff --git a/src/accel/bvh4.rs b/src/accel/bvh4.rs index e5ce96d..11766bc 100644 --- a/src/accel/bvh4.rs +++ b/src/accel/bvh4.rs @@ -1,20 +1,17 @@ #![allow(dead_code)] -use std; - +use bvh_order::{calc_traversal_code, SplitAxes, TRAVERSAL_TABLE}; use mem_arena::MemArena; -use crate::algorithm::partition; -use crate::bbox::BBox; -use crate::boundable::Boundable; -use crate::lerp::lerp_slice; -use crate::ray::AccelRay; -use crate::timer::Timer; +use crate::{ + algorithm::partition, bbox::BBox, boundable::Boundable, lerp::lerp_slice, ray::AccelRay, + timer::Timer, +}; -use super::bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}; -use super::ACCEL_NODE_RAY_TESTS; -use super::ACCEL_TRAV_TIME; -use bvh_order::{calc_traversal_code, SplitAxes, TRAVERSAL_TABLE}; +use super::{ + bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}, + ACCEL_NODE_RAY_TESTS, ACCEL_TRAV_TIME, +}; #[derive(Copy, Clone, Debug)] pub struct BVH4<'a> { diff --git a/src/accel/bvh_base.rs b/src/accel/bvh_base.rs index 57e836f..e72a4d9 100644 --- a/src/accel/bvh_base.rs +++ b/src/accel/bvh_base.rs @@ -1,9 +1,6 @@ #![allow(dead_code)] -use crate::algorithm::merge_slices_append; -use crate::bbox::BBox; -use crate::lerp::lerp_slice; -use crate::math::log2_64; +use crate::{algorithm::merge_slices_append, bbox::BBox, lerp::lerp_slice, math::log2_64}; use super::objects_split::{median_split, sah_split}; diff --git a/src/accel/light_array.rs b/src/accel/light_array.rs index a8b1a4e..5d22c9d 100644 --- a/src/accel/light_array.rs +++ b/src/accel/light_array.rs @@ -1,8 +1,10 @@ use mem_arena::MemArena; -use crate::bbox::BBox; -use crate::math::{Normal, Point, Vector}; -use crate::shading::surface_closure::SurfaceClosure; +use crate::{ + bbox::BBox, + math::{Normal, Point, Vector}, + shading::surface_closure::SurfaceClosure, +}; use super::LightAccel; diff --git a/src/accel/light_tree.rs b/src/accel/light_tree.rs index fb8f873..d236b43 100644 --- a/src/accel/light_tree.rs +++ b/src/accel/light_tree.rs @@ -1,13 +1,14 @@ use mem_arena::MemArena; -use crate::algorithm::merge_slices_append; -use crate::bbox::BBox; -use crate::lerp::lerp_slice; -use crate::math::{Normal, Point, Vector}; -use crate::shading::surface_closure::SurfaceClosure; +use crate::{ + algorithm::merge_slices_append, + bbox::BBox, + lerp::lerp_slice, + math::{Normal, Point, Vector}, + shading::surface_closure::SurfaceClosure, +}; -use super::objects_split::sah_split; -use super::LightAccel; +use super::{objects_split::sah_split, LightAccel}; const ARITY_LOG2: usize = 3; // Determines how much to collapse the binary tree, // implicitly defining the light tree's arity. 1 = no collapsing, leave as binary diff --git a/src/accel/mod.rs b/src/accel/mod.rs index a5d20cc..fe8ee3d 100644 --- a/src/accel/mod.rs +++ b/src/accel/mod.rs @@ -7,13 +7,17 @@ mod objects_split; use std::cell::Cell; -use crate::math::{Normal, Point, Vector}; -use crate::shading::surface_closure::SurfaceClosure; +use crate::{ + math::{Normal, Point, Vector}, + shading::surface_closure::SurfaceClosure, +}; -pub use self::bvh::{BVHNode, BVH}; -pub use self::bvh4::{BVH4Node, BVH4}; -pub use self::light_array::LightArray; -pub use self::light_tree::LightTree; +pub use self::{ + bvh::{BVHNode, BVH}, + bvh4::{BVH4Node, BVH4}, + light_array::LightArray, + light_tree::LightTree, +}; // Track BVH traversal time thread_local! { diff --git a/src/accel/objects_split.rs b/src/accel/objects_split.rs index f4f72c2..e7277d6 100644 --- a/src/accel/objects_split.rs +++ b/src/accel/objects_split.rs @@ -1,15 +1,14 @@ #![allow(dead_code)] -use std; use std::cmp::Ordering; -use halton; - -use crate::algorithm::{partition, quick_select}; -use crate::bbox::BBox; -use crate::lerp::lerp_slice; -use crate::math::{dot, Vector}; -use crate::sampling::uniform_sample_hemisphere; +use crate::{ + algorithm::{partition, quick_select}, + bbox::BBox, + lerp::lerp_slice, + math::{dot, Vector}, + sampling::uniform_sample_hemisphere, +}; const SAH_BIN_COUNT: usize = 13; // Prime numbers work best, for some reason const SPLIT_PLANE_COUNT: usize = 5; diff --git a/src/algorithm.rs b/src/algorithm.rs index 67f8535..aefb633 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -1,11 +1,11 @@ #![allow(dead_code)] -use std; -use std::cmp; -use std::cmp::Ordering; +use std::cmp::{self, Ordering}; -use crate::hash::hash_u64; -use crate::lerp::{lerp_slice, Lerp}; +use crate::{ + hash::hash_u64, + lerp::{lerp_slice, Lerp}, +}; /// Selects an item from a slice based on a weighting function and a /// number (n) between 0.0 and 1.0. Returns the index of the selected diff --git a/src/bbox.rs b/src/bbox.rs index 4e7cb83..33d3e6e 100644 --- a/src/bbox.rs +++ b/src/bbox.rs @@ -1,12 +1,15 @@ #![allow(dead_code)] -use std; -use std::iter::Iterator; -use std::ops::{BitOr, BitOrAssign}; +use std::{ + iter::Iterator, + ops::{BitOr, BitOrAssign}, +}; -use crate::lerp::{lerp, lerp_slice, Lerp}; -use crate::math::{fast_minf32, Matrix4x4, Point}; -use crate::ray::AccelRay; +use crate::{ + lerp::{lerp, lerp_slice, Lerp}, + math::{fast_minf32, Matrix4x4, Point}, + ray::AccelRay, +}; const BBOX_MAXT_ADJUST: f32 = 1.000_000_24; diff --git a/src/camera.rs b/src/camera.rs index ba4d879..e3ed8c5 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -2,10 +2,12 @@ use mem_arena::MemArena; -use crate::lerp::lerp_slice; -use crate::math::{Matrix4x4, Point, Vector}; -use crate::ray::Ray; -use crate::sampling::square_to_circle; +use crate::{ + lerp::lerp_slice, + math::{Matrix4x4, Point, Vector}, + ray::Ray, + sampling::square_to_circle, +}; #[derive(Copy, Clone, Debug)] pub struct Camera<'a> { diff --git a/src/color.rs b/src/color.rs index 8e9d711..3e1254d 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,12 +1,10 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign}; +pub use color::{rec709_e_to_xyz, rec709_to_xyz, xyz_to_rec709, xyz_to_rec709_e}; +use float4::Float4; use spectra_xyz::{spectrum_xyz_to_p_4, EQUAL_ENERGY_REFLECTANCE}; -use crate::lerp::Lerp; -use crate::math::fast_exp; -use float4::Float4; - -pub use crate::color_util::{rec709_e_to_xyz, rec709_to_xyz, xyz_to_rec709, xyz_to_rec709_e}; +use crate::{lerp::Lerp, math::fast_exp}; // Minimum and maximum wavelength of light we care about, in nanometers const WL_MIN: f32 = 380.0; diff --git a/src/hash.rs b/src/hash.rs index 3614bde..5a59340 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -1,5 +1,3 @@ -use std; - pub fn hash_u32(n: u32, seed: u32) -> u32 { let mut hash = n; for _ in 0..3 { diff --git a/src/image.rs b/src/image.rs index ec9ecf2..9b518f1 100644 --- a/src/image.rs +++ b/src/image.rs @@ -1,17 +1,17 @@ #![allow(dead_code)] -use std::cell::{RefCell, UnsafeCell}; -use std::cmp; -use std::fs::File; -use std::io; -use std::io::Write; -use std::marker::PhantomData; -use std::path::Path; -use std::sync::Mutex; +use std::{ + cell::{RefCell, UnsafeCell}, + cmp, + fs::File, + io, + io::Write, + marker::PhantomData, + path::Path, + sync::Mutex, +}; use half::f16; -use openexr; -use png_encode_mini; use crate::color::{xyz_to_rec709_e, XYZ}; diff --git a/src/lerp.rs b/src/lerp.rs index aef6db4..fbfa659 100644 --- a/src/lerp.rs +++ b/src/lerp.rs @@ -1,6 +1,5 @@ #![allow(dead_code)] -use float4; use math3d::{Matrix4x4, Normal, Point, Vector}; /// Trait for allowing a type to be linearly interpolated. diff --git a/src/light/distant_disk_light.rs b/src/light/distant_disk_light.rs index a3a59da..bb89f5d 100644 --- a/src/light/distant_disk_light.rs +++ b/src/light/distant_disk_light.rs @@ -2,10 +2,12 @@ use std::f64::consts::PI as PI_64; use mem_arena::MemArena; -use crate::color::{Color, SpectralSample, XYZ}; -use crate::lerp::lerp_slice; -use crate::math::{coordinate_system_from_vector, Vector}; -use crate::sampling::{uniform_sample_cone, uniform_sample_cone_pdf}; +use crate::{ + color::{Color, SpectralSample, XYZ}, + lerp::lerp_slice, + math::{coordinate_system_from_vector, Vector}, + sampling::{uniform_sample_cone, uniform_sample_cone_pdf}, +}; use super::WorldLightSource; diff --git a/src/light/mod.rs b/src/light/mod.rs index 3e74691..e38f53a 100644 --- a/src/light/mod.rs +++ b/src/light/mod.rs @@ -4,13 +4,16 @@ mod sphere_light; use std::fmt::Debug; -use crate::color::SpectralSample; -use crate::math::{Matrix4x4, Normal, Point, Vector}; -use crate::surface::Surface; +use crate::{ + color::SpectralSample, + math::{Matrix4x4, Normal, Point, Vector}, + surface::Surface, +}; -pub use self::distant_disk_light::DistantDiskLight; -pub use self::rectangle_light::RectangleLight; -pub use self::sphere_light::SphereLight; +pub use self::{ + distant_disk_light::DistantDiskLight, rectangle_light::RectangleLight, + sphere_light::SphereLight, +}; /// A finite light source that can be bounded in space. pub trait SurfaceLight: Surface { diff --git a/src/light/rectangle_light.rs b/src/light/rectangle_light.rs index e472039..edcb65c 100644 --- a/src/light/rectangle_light.rs +++ b/src/light/rectangle_light.rs @@ -1,18 +1,20 @@ use mem_arena::MemArena; -use crate::bbox::BBox; -use crate::boundable::Boundable; -use crate::color::{Color, SpectralSample, XYZ}; -use crate::lerp::lerp_slice; -use crate::math::{cross, dot, Matrix4x4, Normal, Point, Vector}; -use crate::ray::{AccelRay, Ray}; -use crate::sampling::{ - spherical_triangle_solid_angle, triangle_surface_area, uniform_sample_spherical_triangle, - uniform_sample_triangle, +use crate::{ + bbox::BBox, + boundable::Boundable, + color::{Color, SpectralSample, XYZ}, + lerp::lerp_slice, + math::{cross, dot, Matrix4x4, Normal, Point, Vector}, + ray::{AccelRay, Ray}, + sampling::{ + spherical_triangle_solid_angle, triangle_surface_area, uniform_sample_spherical_triangle, + uniform_sample_triangle, + }, + shading::surface_closure::{EmitClosure, SurfaceClosureUnion}, + shading::SurfaceShader, + surface::{triangle, Surface, SurfaceIntersection, SurfaceIntersectionData}, }; -use crate::shading::surface_closure::{EmitClosure, SurfaceClosureUnion}; -use crate::shading::SurfaceShader; -use crate::surface::{triangle, Surface, SurfaceIntersection, SurfaceIntersectionData}; use super::SurfaceLight; diff --git a/src/light/sphere_light.rs b/src/light/sphere_light.rs index ac04c60..008d689 100644 --- a/src/light/sphere_light.rs +++ b/src/light/sphere_light.rs @@ -2,16 +2,18 @@ use std::f64::consts::PI as PI_64; use mem_arena::MemArena; -use crate::bbox::BBox; -use crate::boundable::Boundable; -use crate::color::{Color, SpectralSample, XYZ}; -use crate::lerp::lerp_slice; -use crate::math::{coordinate_system_from_vector, dot, Matrix4x4, Normal, Point, Vector}; -use crate::ray::{AccelRay, Ray}; -use crate::sampling::{uniform_sample_cone, uniform_sample_cone_pdf, uniform_sample_sphere}; -use crate::shading::surface_closure::{EmitClosure, SurfaceClosureUnion}; -use crate::shading::SurfaceShader; -use crate::surface::{Surface, SurfaceIntersection, SurfaceIntersectionData}; +use crate::{ + bbox::BBox, + boundable::Boundable, + color::{Color, SpectralSample, XYZ}, + lerp::lerp_slice, + math::{coordinate_system_from_vector, dot, Matrix4x4, Normal, Point, Vector}, + ray::{AccelRay, Ray}, + sampling::{uniform_sample_cone, uniform_sample_cone_pdf, uniform_sample_sphere}, + shading::surface_closure::{EmitClosure, SurfaceClosureUnion}, + shading::SurfaceShader, + surface::{Surface, SurfaceIntersection, SurfaceIntersectionData}, +}; use super::SurfaceLight; diff --git a/src/main.rs b/src/main.rs index 89b05ee..c1f5cef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,28 +11,6 @@ #![allow(clippy::needless_range_loop)] #![allow(clippy::excessive_precision)] -extern crate bvh_order; -extern crate color as color_util; -extern crate float4; -extern crate halton; -extern crate math3d; -extern crate mem_arena; -extern crate spectra_xyz; - -extern crate base64; -extern crate clap; -extern crate crossbeam; -extern crate half; -extern crate num_cpus; -extern crate openexr; -extern crate png_encode_mini; -extern crate rustc_serialize; -extern crate scoped_threadpool; -extern crate time; - -#[macro_use] -extern crate nom; - #[macro_use] extern crate lazy_static; @@ -61,24 +39,22 @@ mod timer; mod tracer; mod transform_stack; -use std::fs::File; -use std::io; -use std::io::Read; -use std::mem; -use std::path::Path; -use std::str::FromStr; +use std::{fs::File, io, io::Read, mem, path::Path, str::FromStr}; use clap::{App, Arg}; +use nom::{error_position, take_until}; use mem_arena::MemArena; -use crate::accel::{BVH4Node, BVHNode}; -use crate::bbox::BBox; -use crate::parse::{parse_scene, DataTree}; -use crate::ray::{AccelRay, Ray}; -use crate::renderer::LightPath; -use crate::surface::SurfaceIntersection; -use crate::timer::Timer; +use crate::{ + accel::{BVH4Node, BVHNode}, + bbox::BBox, + parse::{parse_scene, DataTree}, + ray::{AccelRay, Ray}, + renderer::LightPath, + surface::SurfaceIntersection, + timer::Timer, +}; const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/src/parse/basics.rs b/src/parse/basics.rs index 94d4db3..2bd610f 100644 --- a/src/parse/basics.rs +++ b/src/parse/basics.rs @@ -3,8 +3,12 @@ use std::str; -use nom::IResult::*; -use nom::{digit, multispace, IResult, Needed}; +use nom::{ + call, complete, delimited, digit, do_parse, error_position, multispace, named, one_of, opt, + tag, tuple_parser, + IResult::{self, *}, + Needed, +}; // Consumes any whitespace, including zero whitespace named!(any_space>, opt!(complete!(multispace))); diff --git a/src/parse/data_tree.rs b/src/parse/data_tree.rs index 6f665ec..ace1aa0 100644 --- a/src/parse/data_tree.rs +++ b/src/parse/data_tree.rs @@ -1,8 +1,6 @@ #![allow(dead_code)] -use std::iter::Iterator; -use std::result::Result; -use std::slice; +use std::{iter::Iterator, result::Result, slice}; #[derive(Debug, Eq, PartialEq)] pub enum DataTree<'a> { diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 3e8a9c9..a76ad59 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -6,5 +6,4 @@ mod psy_light; mod psy_mesh_surface; mod psy_surface_shader; -pub use self::data_tree::DataTree; -pub use self::psy::parse_scene; +pub use self::{data_tree::DataTree, psy::parse_scene}; diff --git a/src/parse/psy.rs b/src/parse/psy.rs index 9b3e53e..77d7913 100644 --- a/src/parse/psy.rs +++ b/src/parse/psy.rs @@ -1,24 +1,27 @@ #![allow(dead_code)] -use std::f32; -use std::result::Result; +use std::{f32, result::Result}; -use nom::IResult; +use nom::{call, closure, eof, error_position, terminated, tuple, tuple_parser, IResult}; use mem_arena::MemArena; -use crate::camera::Camera; -use crate::color::{rec709_e_to_xyz, XYZ}; -use crate::light::WorldLightSource; -use crate::math::Matrix4x4; -use crate::renderer::Renderer; -use crate::scene::Scene; -use crate::scene::World; +use crate::{ + camera::Camera, + color::{rec709_e_to_xyz, XYZ}, + light::WorldLightSource, + math::Matrix4x4, + renderer::Renderer, + scene::Scene, + scene::World, +}; -use super::basics::{ws_f32, ws_u32}; -use super::psy_assembly::parse_assembly; -use super::psy_light::parse_distant_disk_light; -use super::DataTree; +use super::{ + basics::{ws_f32, ws_u32}, + psy_assembly::parse_assembly, + psy_light::parse_distant_disk_light, + DataTree, +}; #[derive(Debug)] pub enum PsyParseError { diff --git a/src/parse/psy_assembly.rs b/src/parse/psy_assembly.rs index cf603ff..e223a12 100644 --- a/src/parse/psy_assembly.rs +++ b/src/parse/psy_assembly.rs @@ -6,11 +6,13 @@ use mem_arena::MemArena; use crate::scene::{Assembly, AssemblyBuilder, Object}; -use super::psy::{parse_matrix, PsyParseError}; -use super::psy_light::{parse_rectangle_light, parse_sphere_light}; -use super::psy_mesh_surface::parse_mesh_surface; -use super::psy_surface_shader::parse_surface_shader; -use super::DataTree; +use super::{ + psy::{parse_matrix, PsyParseError}, + psy_light::{parse_rectangle_light, parse_sphere_light}, + psy_mesh_surface::parse_mesh_surface, + psy_surface_shader::parse_surface_shader, + DataTree, +}; pub fn parse_assembly<'a>( arena: &'a MemArena, diff --git a/src/parse/psy_light.rs b/src/parse/psy_light.rs index d13fe22..288cbd2 100644 --- a/src/parse/psy_light.rs +++ b/src/parse/psy_light.rs @@ -2,17 +2,17 @@ use std::result::Result; -use nom::IResult; +use nom::{call, closure, tuple, tuple_parser, IResult}; use mem_arena::MemArena; -use crate::color::{rec709_e_to_xyz, XYZ}; -use crate::light::{DistantDiskLight, RectangleLight, SphereLight}; -use crate::math::Vector; +use crate::{ + color::{rec709_e_to_xyz, XYZ}, + light::{DistantDiskLight, RectangleLight, SphereLight}, + math::Vector, +}; -use super::basics::ws_f32; -use super::psy::PsyParseError; -use super::DataTree; +use super::{basics::ws_f32, psy::PsyParseError, DataTree}; pub fn parse_distant_disk_light<'a>( arena: &'a MemArena, diff --git a/src/parse/psy_mesh_surface.rs b/src/parse/psy_mesh_surface.rs index b321464..d1388bc 100644 --- a/src/parse/psy_mesh_surface.rs +++ b/src/parse/psy_mesh_surface.rs @@ -2,16 +2,20 @@ use std::result::Result; -use nom::IResult; +use nom::{call, closure, tuple, tuple_parser, IResult}; use mem_arena::MemArena; -use crate::math::{Normal, Point}; -use crate::surface::triangle_mesh::TriangleMesh; +use crate::{ + math::{Normal, Point}, + surface::triangle_mesh::TriangleMesh, +}; -use super::basics::{ws_f32, ws_usize}; -use super::psy::PsyParseError; -use super::DataTree; +use super::{ + basics::{ws_f32, ws_usize}, + psy::PsyParseError, + DataTree, +}; // pub struct TriangleMesh { // time_samples: usize, diff --git a/src/parse/psy_surface_shader.rs b/src/parse/psy_surface_shader.rs index d117829..4aed1c7 100644 --- a/src/parse/psy_surface_shader.rs +++ b/src/parse/psy_surface_shader.rs @@ -2,16 +2,16 @@ use std::result::Result; -use nom::IResult; +use nom::{call, closure, tuple, tuple_parser, IResult}; use mem_arena::MemArena; -use crate::color::{rec709_e_to_xyz, XYZ}; -use crate::shading::{SimpleSurfaceShader, SurfaceShader}; +use crate::{ + color::{rec709_e_to_xyz, XYZ}, + shading::{SimpleSurfaceShader, SurfaceShader}, +}; -use super::basics::ws_f32; -use super::psy::PsyParseError; -use super::DataTree; +use super::{basics::ws_f32, psy::PsyParseError, DataTree}; // pub struct TriangleMesh { // time_samples: usize, diff --git a/src/ray.rs b/src/ray.rs index e7f9235..cf91b74 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -1,9 +1,8 @@ #![allow(dead_code)] -use std; +use float4::Float4; use crate::math::{Matrix4x4, Point, Vector}; -use float4::Float4; const OCCLUSION_FLAG: u32 = 1; const DONE_FLAG: u32 = 1 << 1; diff --git a/src/renderer.rs b/src/renderer.rs index 7fbbfa3..c1cc68c 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,32 +1,34 @@ -use std; -use std::cell::Cell; -use std::cmp; -use std::cmp::min; -use std::io::{self, Write}; -use std::sync::{Mutex, RwLock}; +use std::{ + cell::Cell, + cmp, + cmp::min, + io::{self, Write}, + sync::{Mutex, RwLock}, +}; use crossbeam::sync::MsQueue; use scoped_threadpool::Pool; -use halton; - -use crate::accel::{ACCEL_NODE_RAY_TESTS, ACCEL_TRAV_TIME}; -use crate::algorithm::partition_pair; -use crate::color::{map_0_1_to_wavelength, Color, SpectralSample, XYZ}; -use crate::fp_utils::robust_ray_origin; -use crate::hash::hash_u32; -use crate::hilbert; -use crate::image::Image; -use crate::math::{fast_logit, upper_power_of_two}; -use crate::mis::power_heuristic; -use crate::ray::Ray; -use crate::scene::{Scene, SceneLightSample}; -use crate::surface; -use crate::timer::Timer; -use crate::tracer::Tracer; -use crate::transform_stack::TransformStack; use float4::Float4; +use crate::{ + accel::{ACCEL_NODE_RAY_TESTS, ACCEL_TRAV_TIME}, + algorithm::partition_pair, + color::{map_0_1_to_wavelength, Color, SpectralSample, XYZ}, + fp_utils::robust_ray_origin, + hash::hash_u32, + hilbert, + image::Image, + math::{fast_logit, upper_power_of_two}, + mis::power_heuristic, + ray::Ray, + scene::{Scene, SceneLightSample}, + surface, + timer::Timer, + tracer::Tracer, + transform_stack::TransformStack, +}; + #[derive(Debug)] pub struct Renderer<'a> { pub output_file: String, diff --git a/src/sampling/monte_carlo.rs b/src/sampling/monte_carlo.rs index 71dfa18..a17072b 100644 --- a/src/sampling/monte_carlo.rs +++ b/src/sampling/monte_carlo.rs @@ -1,8 +1,6 @@ #![allow(dead_code)] -use std::f32::consts::FRAC_PI_4 as QPI_32; -use std::f32::consts::PI as PI_32; -use std::f64::consts::PI as PI_64; +use std::{f32::consts::FRAC_PI_4 as QPI_32, f32::consts::PI as PI_32, f64::consts::PI as PI_64}; use crate::math::{cross, dot, Point, Vector}; diff --git a/src/scene/assembly.rs b/src/scene/assembly.rs index 3092af0..0e52361 100644 --- a/src/scene/assembly.rs +++ b/src/scene/assembly.rs @@ -2,17 +2,19 @@ use std::collections::HashMap; use mem_arena::MemArena; -use crate::accel::BVH4; -use crate::accel::{LightAccel, LightTree}; -use crate::bbox::{transform_bbox_slice_from, BBox}; -use crate::boundable::Boundable; -use crate::color::SpectralSample; -use crate::lerp::lerp_slice; -use crate::light::SurfaceLight; -use crate::math::{Matrix4x4, Normal, Point}; -use crate::shading::SurfaceShader; -use crate::surface::{Surface, SurfaceIntersection}; -use crate::transform_stack::TransformStack; +use crate::{ + accel::BVH4, + accel::{LightAccel, LightTree}, + bbox::{transform_bbox_slice_from, BBox}, + boundable::Boundable, + color::SpectralSample, + lerp::lerp_slice, + light::SurfaceLight, + math::{Matrix4x4, Normal, Point}, + shading::SurfaceShader, + surface::{Surface, SurfaceIntersection}, + transform_stack::TransformStack, +}; #[derive(Copy, Clone, Debug)] pub struct Assembly<'a> { diff --git a/src/scene/mod.rs b/src/scene/mod.rs index b063324..3861c76 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -1,16 +1,20 @@ mod assembly; mod world; -use crate::accel::LightAccel; -use crate::algorithm::weighted_choice; -use crate::camera::Camera; -use crate::color::SpectralSample; -use crate::math::{Normal, Point, Vector}; -use crate::surface::SurfaceIntersection; -use crate::transform_stack::TransformStack; +use crate::{ + accel::LightAccel, + algorithm::weighted_choice, + camera::Camera, + color::SpectralSample, + math::{Normal, Point, Vector}, + surface::SurfaceIntersection, + transform_stack::TransformStack, +}; -pub use self::assembly::{Assembly, AssemblyBuilder, InstanceType, Object}; -pub use self::world::World; +pub use self::{ + assembly::{Assembly, AssemblyBuilder, InstanceType, Object}, + world::World, +}; #[derive(Debug)] pub struct Scene<'a> { diff --git a/src/scene/world.rs b/src/scene/world.rs index 2f6cdda..baf6615 100644 --- a/src/scene/world.rs +++ b/src/scene/world.rs @@ -1,5 +1,4 @@ -use crate::color::XYZ; -use crate::light::WorldLightSource; +use crate::{color::XYZ, light::WorldLightSource}; #[derive(Debug)] pub struct World<'a> { diff --git a/src/shading/mod.rs b/src/shading/mod.rs index 3cbb737..0c16bf4 100644 --- a/src/shading/mod.rs +++ b/src/shading/mod.rs @@ -2,11 +2,14 @@ pub mod surface_closure; use std::fmt::Debug; +use crate::{ + color::{Color, XYZ}, + surface::SurfaceIntersectionData, +}; + use self::surface_closure::{ EmitClosure, GGXClosure, GTRClosure, LambertClosure, SurfaceClosureUnion, }; -use crate::color::{Color, XYZ}; -use crate::surface::SurfaceIntersectionData; /// Trait for surface shaders. pub trait SurfaceShader: Debug + Sync { diff --git a/src/shading/surface_closure.rs b/src/shading/surface_closure.rs index 8b316d2..314d802 100644 --- a/src/shading/surface_closure.rs +++ b/src/shading/surface_closure.rs @@ -2,10 +2,12 @@ use std::f32::consts::PI as PI_32; -use crate::color::SpectralSample; -use crate::lerp::lerp; -use crate::math::{clamp, dot, zup_to_vec, Normal, Vector}; -use crate::sampling::cosine_sample_hemisphere; +use crate::{ + color::SpectralSample, + lerp::lerp, + math::{clamp, dot, zup_to_vec, Normal, Vector}, + sampling::cosine_sample_hemisphere, +}; const INV_PI: f32 = 1.0 / PI_32; const H_PI: f32 = PI_32 / 2.0; diff --git a/src/surface/mod.rs b/src/surface/mod.rs index acc77e3..5c746c6 100644 --- a/src/surface/mod.rs +++ b/src/surface/mod.rs @@ -5,11 +5,13 @@ pub mod triangle_mesh; use std::fmt::Debug; -use crate::boundable::Boundable; -use crate::math::{Matrix4x4, Normal, Point, Vector}; -use crate::ray::{AccelRay, Ray}; -use crate::shading::surface_closure::SurfaceClosureUnion; -use crate::shading::SurfaceShader; +use crate::{ + boundable::Boundable, + math::{Matrix4x4, Normal, Point, Vector}, + ray::{AccelRay, Ray}, + shading::surface_closure::SurfaceClosureUnion, + shading::SurfaceShader, +}; pub trait Surface: Boundable + Debug + Sync { fn intersect_rays( diff --git a/src/surface/triangle.rs b/src/surface/triangle.rs index cec17a1..c252e59 100644 --- a/src/surface/triangle.rs +++ b/src/surface/triangle.rs @@ -1,8 +1,6 @@ #![allow(dead_code)] -use crate::fp_utils::fp_gamma; -use crate::math::Point; -use crate::ray::Ray; +use crate::{fp_utils::fp_gamma, math::Point, ray::Ray}; /// Intersects `ray` with `tri`, returning `Some((t, b0, b1, b2))`, or `None` /// if no intersection. diff --git a/src/surface/triangle_mesh.rs b/src/surface/triangle_mesh.rs index f8cf490..4aa7940 100644 --- a/src/surface/triangle_mesh.rs +++ b/src/surface/triangle_mesh.rs @@ -1,19 +1,18 @@ #![allow(dead_code)] -use std; - use mem_arena::MemArena; -use crate::accel::BVH4; -use crate::bbox::BBox; -use crate::boundable::Boundable; -use crate::lerp::lerp_slice; -use crate::math::{cross, dot, Matrix4x4, Normal, Point}; -use crate::ray::{AccelRay, Ray}; -use crate::shading::SurfaceShader; +use crate::{ + accel::BVH4, + bbox::BBox, + boundable::Boundable, + lerp::lerp_slice, + math::{cross, dot, Matrix4x4, Normal, Point}, + ray::{AccelRay, Ray}, + shading::SurfaceShader, +}; -use super::triangle; -use super::{Surface, SurfaceIntersection, SurfaceIntersectionData}; +use super::{triangle, Surface, SurfaceIntersection, SurfaceIntersectionData}; #[derive(Copy, Clone, Debug)] pub struct TriangleMesh<'a> { diff --git a/src/timer.rs b/src/timer.rs index a42cae6..56f44ab 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,9 +1,6 @@ #![allow(dead_code)] -use std::thread; -use std::time::Duration; - -use time; +use std::{thread, time::Duration}; #[derive(Copy, Clone)] pub struct Timer { diff --git a/src/tracer.rs b/src/tracer.rs index 6f6f547..c3392be 100644 --- a/src/tracer.rs +++ b/src/tracer.rs @@ -1,13 +1,15 @@ use std::iter; -use crate::algorithm::partition; -use crate::color::{rec709_to_xyz, XYZ}; -use crate::lerp::lerp_slice; -use crate::ray::{AccelRay, Ray}; -use crate::scene::{Assembly, InstanceType, Object}; -use crate::shading::{SimpleSurfaceShader, SurfaceShader}; -use crate::surface::SurfaceIntersection; -use crate::transform_stack::TransformStack; +use crate::{ + algorithm::partition, + color::{rec709_to_xyz, XYZ}, + lerp::lerp_slice, + ray::{AccelRay, Ray}, + scene::{Assembly, InstanceType, Object}, + shading::{SimpleSurfaceShader, SurfaceShader}, + surface::SurfaceIntersection, + transform_stack::TransformStack, +}; pub struct Tracer<'a> { rays: Vec, diff --git a/src/transform_stack.rs b/src/transform_stack.rs index b425192..29951eb 100644 --- a/src/transform_stack.rs +++ b/src/transform_stack.rs @@ -1,7 +1,6 @@ use std::cmp; -use crate::algorithm::merge_slices_to; -use crate::math::Matrix4x4; +use crate::{algorithm::merge_slices_to, math::Matrix4x4}; pub struct TransformStack { stack: Vec,