diff --git a/src/accel/bvh.rs b/src/accel/bvh.rs index 65423f6..7f51d4d 100644 --- a/src/accel/bvh.rs +++ b/src/accel/bvh.rs @@ -12,8 +12,8 @@ use ray::AccelRay; use timer::Timer; use super::bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}; -use super::ACCEL_TRAV_TIME; use super::ACCEL_NODE_RAY_TESTS; +use super::ACCEL_TRAV_TIME; #[derive(Copy, Clone, Debug)] pub struct BVH<'a> { diff --git a/src/accel/bvh4.rs b/src/accel/bvh4.rs index 87163c4..881f390 100644 --- a/src/accel/bvh4.rs +++ b/src/accel/bvh4.rs @@ -11,10 +11,10 @@ use lerp::lerp_slice; use ray::AccelRay; use timer::Timer; -use bvh_order::{calc_traversal_code, SplitAxes, TRAVERSAL_TABLE}; use super::bvh_base::{BVHBase, BVHBaseNode, BVH_MAX_DEPTH}; -use super::ACCEL_TRAV_TIME; use super::ACCEL_NODE_RAY_TESTS; +use super::ACCEL_TRAV_TIME; +use bvh_order::{calc_traversal_code, SplitAxes, TRAVERSAL_TABLE}; #[derive(Copy, Clone, Debug)] pub struct BVH4<'a> { @@ -87,7 +87,8 @@ impl<'a> BVH4<'a> { rays[0].dir_inv.y() < 0.0, rays[0].dir_inv.z() < 0.0, ]; - let ray_code = ray_sign_is_neg[0] as usize + ((ray_sign_is_neg[1] as usize) << 1) + let ray_code = ray_sign_is_neg[0] as usize + + ((ray_sign_is_neg[1] as usize) << 1) + ((ray_sign_is_neg[2] as usize) << 2); &TRAVERSAL_TABLE[ray_code] }; diff --git a/src/accel/light_tree.rs b/src/accel/light_tree.rs index 4db2952..f8a2461 100644 --- a/src/accel/light_tree.rs +++ b/src/accel/light_tree.rs @@ -6,8 +6,8 @@ use lerp::lerp_slice; use math::{Normal, Point, Vector}; use shading::surface_closure::SurfaceClosure; -use super::LightAccel; use super::objects_split::sah_split; +use super::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 8619543..890518b 100644 --- a/src/accel/mod.rs +++ b/src/accel/mod.rs @@ -1,6 +1,6 @@ -mod bvh_base; mod bvh; mod bvh4; +mod bvh_base; mod light_array; mod light_tree; mod objects_split; @@ -12,8 +12,8 @@ use shading::surface_closure::SurfaceClosure; pub use self::bvh::{BVHNode, BVH}; pub use self::bvh4::{BVH4, BVH4Node}; -pub use self::light_tree::LightTree; pub use self::light_array::LightArray; +pub use self::light_tree::LightTree; // Track BVH traversal time thread_local! { diff --git a/src/algorithm.rs b/src/algorithm.rs index 7db1a75..bd28066 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -293,8 +293,8 @@ where #[cfg(test)] mod tests { - use std::cmp::Ordering; use super::*; + use std::cmp::Ordering; fn quick_select_ints(list: &mut [i32], i: usize) { quick_select(list, i, |a, b| { diff --git a/src/bbox.rs b/src/bbox.rs index 2a677c8..7dadc7a 100644 --- a/src/bbox.rs +++ b/src/bbox.rs @@ -5,7 +5,7 @@ use std::iter::Iterator; use std::ops::{BitOr, BitOrAssign}; use lerp::{lerp, lerp_slice, Lerp}; -use math::{Matrix4x4, Point, fast_minf32}; +use math::{fast_minf32, Matrix4x4, Point}; use ray::AccelRay; const BBOX_MAXT_ADJUST: f32 = 1.00000024; diff --git a/src/image.rs b/src/image.rs index a3738c9..ab3b527 100644 --- a/src/image.rs +++ b/src/image.rs @@ -11,8 +11,8 @@ use std::path::Path; use std::sync::Mutex; use half::f16; -use png_encode_mini; use openexr; +use png_encode_mini; use color::{xyz_to_rec709_e, XYZ}; @@ -259,7 +259,9 @@ impl<'a> Drop for Bucket<'a> { // Find matching bucket and remove it let i = bucket_list.iter().position(|bucket| { - (bucket.0).0 == self.min.0 && (bucket.0).1 == self.min.1 && (bucket.1).0 == self.max.0 + (bucket.0).0 == self.min.0 + && (bucket.0).1 == self.min.1 + && (bucket.1).0 == self.max.0 && (bucket.1).1 == self.max.1 }); bucket_list.swap_remove(i.unwrap()); diff --git a/src/lerp.rs b/src/lerp.rs index 7d8cfd7..aef6db4 100644 --- a/src/lerp.rs +++ b/src/lerp.rs @@ -198,95 +198,22 @@ mod tests { #[test] fn lerp_matrix() { let a = Matrix4x4::new_from_values( - 0.0, - 2.0, - 2.0, - 3.0, - 4.0, - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 15.0, + 0.0, 2.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, ); let b = Matrix4x4::new_from_values( - -1.0, - 1.0, - 3.0, - 4.0, - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 15.0, - 16.0, + -1.0, 1.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, ); let c1 = Matrix4x4::new_from_values( - -0.25, - 1.75, - 2.25, - 3.25, - 4.25, - 5.25, - 6.25, - 7.25, - 8.25, - 9.25, - 10.25, - 11.25, - 12.25, - 13.25, - 14.25, - 15.25, + -0.25, 1.75, 2.25, 3.25, 4.25, 5.25, 6.25, 7.25, 8.25, 9.25, 10.25, 11.25, 12.25, + 13.25, 14.25, 15.25, ); let c2 = Matrix4x4::new_from_values( - -0.5, - 1.5, - 2.5, - 3.5, - 4.5, - 5.5, - 6.5, - 7.5, - 8.5, - 9.5, - 10.5, - 11.5, - 12.5, - 13.5, - 14.5, - 15.5, + -0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, ); let c3 = Matrix4x4::new_from_values( - -0.75, - 1.25, - 2.75, - 3.75, - 4.75, - 5.75, - 6.75, - 7.75, - 8.75, - 9.75, - 10.75, - 11.75, - 12.75, - 13.75, - 14.75, - 15.75, + -0.75, 1.25, 2.75, 3.75, 4.75, 5.75, 6.75, 7.75, 8.75, 9.75, 10.75, 11.75, 12.75, + 13.75, 14.75, 15.75, ); assert_eq!(a.lerp(b, 0.0), a); diff --git a/src/light/rectangle_light.rs b/src/light/rectangle_light.rs index 343b187..27e23e8 100644 --- a/src/light/rectangle_light.rs +++ b/src/light/rectangle_light.rs @@ -6,8 +6,10 @@ use color::{Color, SpectralSample, XYZ}; use lerp::lerp_slice; use math::{cross, dot, Matrix4x4, Normal, Point, Vector}; use ray::{AccelRay, Ray}; -use sampling::{spherical_triangle_solid_angle, triangle_surface_area, - uniform_sample_spherical_triangle, uniform_sample_triangle}; +use sampling::{ + spherical_triangle_solid_angle, triangle_surface_area, uniform_sample_spherical_triangle, + uniform_sample_triangle, +}; use shading::surface_closure::{EmitClosure, SurfaceClosureUnion}; use shading::SurfaceShader; use surface::{triangle, Surface, SurfaceIntersection, SurfaceIntersectionData}; diff --git a/src/main.rs b/src/main.rs index 26c879c..b1cde9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,12 +66,12 @@ use clap::{App, Arg}; use mem_arena::MemArena; +use accel::{BVH4Node, BVHNode}; +use bbox::BBox; use parse::{parse_scene, DataTree}; use ray::{AccelRay, Ray}; -use surface::SurfaceIntersection; use renderer::LightPath; -use bbox::BBox; -use accel::{BVH4Node, BVHNode}; +use surface::SurfaceIntersection; use timer::Timer; const VERSION: &'static str = env!("CARGO_PKG_VERSION"); diff --git a/src/parse/basics.rs b/src/parse/basics.rs index 2e9d472..1da2e24 100644 --- a/src/parse/basics.rs +++ b/src/parse/basics.rs @@ -3,8 +3,8 @@ use std::str; -use nom::{digit, multispace, IResult, Needed}; use nom::IResult::*; +use nom::{digit, multispace, IResult, Needed}; // Consumes any whitespace, including zero whitespace named!(any_space>, opt!(complete!(multispace))); @@ -154,9 +154,9 @@ fn take_decimal_real(i: &[u8]) -> IResult<&[u8], &[u8]> { #[cfg(test)] mod test { - use nom::IResult::*; use super::take_decimal_real; use super::*; + use nom::IResult::*; #[test] fn ws_u32_1() { diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 2405194..3e8a9c9 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -1,10 +1,10 @@ +pub mod basics; mod data_tree; +mod psy; mod psy_assembly; mod psy_light; mod psy_mesh_surface; mod psy_surface_shader; -mod psy; -pub mod basics; pub use self::data_tree::DataTree; pub use self::psy::parse_scene; diff --git a/src/parse/psy.rs b/src/parse/psy.rs index cd03b55..289c38e 100644 --- a/src/parse/psy.rs +++ b/src/parse/psy.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] -use std::result::Result; use std::f32; +use std::result::Result; use nom::IResult; @@ -16,9 +16,9 @@ use scene::Scene; use scene::World; use super::basics::{ws_f32, ws_u32}; -use super::DataTree; use super::psy_assembly::parse_assembly; use super::psy_light::parse_distant_disk_light; +use super::DataTree; #[derive(Debug)] pub enum PsyParseError { @@ -565,43 +565,15 @@ fn parse_world<'a>(arena: &'a MemArena, tree: &'a DataTree) -> Result, pub fn parse_matrix(contents: &str) -> Result { if let IResult::Done(_, ns) = closure!(terminated!( tuple!( - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32, - ws_f32 + ws_f32, ws_f32, ws_f32, ws_f32, ws_f32, ws_f32, ws_f32, ws_f32, ws_f32, ws_f32, ws_f32, + ws_f32, ws_f32, ws_f32, ws_f32, ws_f32 ), eof!() ))(contents.as_bytes()) { return Ok(Matrix4x4::new_from_values( - ns.0, - ns.4, - ns.8, - ns.12, - ns.1, - ns.5, - ns.9, - ns.13, - ns.2, - ns.6, - ns.10, - ns.14, - ns.3, - ns.7, - ns.11, - ns.15, + ns.0, ns.4, ns.8, ns.12, ns.1, ns.5, ns.9, ns.13, ns.2, ns.6, ns.10, ns.14, ns.3, ns.7, + ns.11, ns.15, )); } else { return Err(PsyParseError::UnknownError(0)); diff --git a/src/parse/psy_assembly.rs b/src/parse/psy_assembly.rs index 4ea3207..c60763d 100644 --- a/src/parse/psy_assembly.rs +++ b/src/parse/psy_assembly.rs @@ -6,11 +6,11 @@ use mem_arena::MemArena; use scene::{Assembly, AssemblyBuilder, Object}; -use super::DataTree; +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::psy::{parse_matrix, PsyParseError}; +use super::DataTree; pub fn parse_assembly<'a>( arena: &'a MemArena, diff --git a/src/parse/psy_light.rs b/src/parse/psy_light.rs index a16d8dc..27a61dd 100644 --- a/src/parse/psy_light.rs +++ b/src/parse/psy_light.rs @@ -6,13 +6,13 @@ use nom::IResult; use mem_arena::MemArena; -use math::Vector; use color::{rec709_e_to_xyz, XYZ}; use light::{DistantDiskLight, RectangleLight, SphereLight}; +use math::Vector; use super::basics::ws_f32; -use super::DataTree; use super::psy::PsyParseError; +use super::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 aa61fca..3d9a61b 100644 --- a/src/parse/psy_mesh_surface.rs +++ b/src/parse/psy_mesh_surface.rs @@ -9,9 +9,9 @@ use mem_arena::MemArena; use math::{Normal, Point}; use surface::triangle_mesh::TriangleMesh; -use super::basics::{ws_usize, ws_f32}; -use super::DataTree; +use super::basics::{ws_f32, ws_usize}; use super::psy::PsyParseError; +use super::DataTree; // pub struct TriangleMesh { // time_samples: usize, diff --git a/src/parse/psy_surface_shader.rs b/src/parse/psy_surface_shader.rs index a687940..0cbf91d 100644 --- a/src/parse/psy_surface_shader.rs +++ b/src/parse/psy_surface_shader.rs @@ -10,8 +10,8 @@ use color::{rec709_e_to_xyz, XYZ}; use shading::{SimpleSurfaceShader, SurfaceShader}; use super::basics::ws_f32; -use super::DataTree; use super::psy::PsyParseError; +use super::DataTree; // pub struct TriangleMesh { // time_samples: usize, diff --git a/src/renderer.rs b/src/renderer.rs index e595790..832c14f 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -12,7 +12,7 @@ use halton; use accel::{ACCEL_NODE_RAY_TESTS, ACCEL_TRAV_TIME}; use algorithm::partition_pair; -use color::{Color, SpectralSample, map_0_1_to_wavelength, XYZ}; +use color::{map_0_1_to_wavelength, Color, SpectralSample, XYZ}; use float4::Float4; use fp_utils::robust_ray_origin; use hash::hash_u32; @@ -476,7 +476,8 @@ impl LightPath { self.time, isect, ); - let found_light = if light_info.is_none() || light_info.pdf() <= 0.0 + let found_light = if light_info.is_none() + || light_info.pdf() <= 0.0 || light_info.selection_pdf() <= 0.0 { false @@ -558,9 +559,9 @@ impl LightPath { // Calculate and store the light that will be contributed // to the film plane if the light is not in shadow. let light_mis_pdf = power_heuristic(light_pdf, closure_pdf); - self.pending_color_addition = light_info.color().e * attenuation.e - * self.light_attenuation - / (light_mis_pdf * light_sel_pdf); + self.pending_color_addition = + light_info.color().e * attenuation.e * self.light_attenuation + / (light_mis_pdf * light_sel_pdf); *ray = shadow_ray; diff --git a/src/sampling/mod.rs b/src/sampling/mod.rs index ced027a..0e6a1a8 100644 --- a/src/sampling/mod.rs +++ b/src/sampling/mod.rs @@ -1,7 +1,7 @@ mod monte_carlo; -pub use self::monte_carlo::{cosine_sample_hemisphere, spherical_triangle_solid_angle, - square_to_circle, triangle_surface_area, uniform_sample_cone, - uniform_sample_cone_pdf, uniform_sample_hemisphere, - uniform_sample_sphere, uniform_sample_spherical_triangle, - uniform_sample_triangle}; +pub use self::monte_carlo::{ + cosine_sample_hemisphere, spherical_triangle_solid_angle, square_to_circle, + triangle_surface_area, uniform_sample_cone, uniform_sample_cone_pdf, uniform_sample_hemisphere, + uniform_sample_sphere, uniform_sample_spherical_triangle, uniform_sample_triangle, +}; diff --git a/src/scene/assembly.rs b/src/scene/assembly.rs index de5cd18..3ad2a01 100644 --- a/src/scene/assembly.rs +++ b/src/scene/assembly.rs @@ -2,16 +2,16 @@ use std::collections::HashMap; use mem_arena::MemArena; -use accel::{LightAccel, LightTree}; use accel::BVH4; +use accel::{LightAccel, LightTree}; use bbox::{transform_bbox_slice_from, BBox}; use boundable::Boundable; use color::SpectralSample; use lerp::lerp_slice; use light::SurfaceLight; use math::{Matrix4x4, Normal, Point}; -use surface::{Surface, SurfaceIntersection}; use shading::SurfaceShader; +use surface::{Surface, SurfaceIntersection}; use transform_stack::TransformStack; #[derive(Copy, Clone, Debug)] @@ -92,12 +92,7 @@ impl<'a> Assembly<'a> { // Sample the light let (color, sample_geo, pdf) = light.sample_from_point( - &xform, - idata.pos, - uvw.0, - uvw.1, - wavelength, - time, + &xform, idata.pos, uvw.0, uvw.1, wavelength, time, ); return Some((color, sample_geo, pdf, sel_pdf)); } diff --git a/src/shading/mod.rs b/src/shading/mod.rs index b7e9d60..b055a39 100644 --- a/src/shading/mod.rs +++ b/src/shading/mod.rs @@ -2,8 +2,8 @@ pub mod surface_closure; use std::fmt::Debug; -use color::{Color, XYZ}; use self::surface_closure::{EmitClosure, GTRClosure, LambertClosure, SurfaceClosureUnion}; +use color::{Color, XYZ}; use surface::SurfaceIntersectionData; /// Trait for surface shaders. diff --git a/src/shading/surface_closure.rs b/src/shading/surface_closure.rs index 54b2f37..93470a9 100644 --- a/src/shading/surface_closure.rs +++ b/src/shading/surface_closure.rs @@ -3,9 +3,9 @@ use std::f32::consts::PI as PI_32; use color::SpectralSample; +use lerp::lerp; use math::{clamp, dot, zup_to_vec, Normal, Vector}; use sampling::cosine_sample_hemisphere; -use lerp::lerp; const INV_PI: f32 = 1.0 / PI_32; const H_PI: f32 = PI_32 / 2.0; @@ -430,9 +430,8 @@ impl GTRClosure { let roughness2 = self.roughness * self.roughness; // Calculate top half of equation - let top = 1.0 - - ((roughness2.powf(1.0 - self.tail_shape) * (1.0 - u)) + u) - .powf(1.0 / (1.0 - self.tail_shape)); + let top = 1.0 - ((roughness2.powf(1.0 - self.tail_shape) * (1.0 - u)) + u) + .powf(1.0 / (1.0 - self.tail_shape)); // Calculate bottom half of equation let bottom = 1.0 - roughness2; diff --git a/src/surface/triangle.rs b/src/surface/triangle.rs index b58c28a..c0088ea 100644 --- a/src/surface/triangle.rs +++ b/src/surface/triangle.rs @@ -132,11 +132,13 @@ pub fn intersect_ray(ray: &Ray, tri: (Point, Point, Point)) -> Option<(f32, f32, /// /// Returns the point and the error magnitude of the point. pub fn surface_point(tri: (Point, Point, Point), bary: (f32, f32, f32)) -> (Point, f32) { - let pos = ((tri.0.into_vector() * bary.0) + (tri.1.into_vector() * bary.1) + let pos = ((tri.0.into_vector() * bary.0) + + (tri.1.into_vector() * bary.1) + (tri.2.into_vector() * bary.2)) .into_point(); - let pos_err = (((tri.0.into_vector().abs() * bary.0) + (tri.1.into_vector().abs() * bary.1) + let pos_err = (((tri.0.into_vector().abs() * bary.0) + + (tri.1.into_vector().abs() * bary.1) + (tri.2.into_vector().abs() * bary.2)) * fp_gamma(7)) .co .h_max(); diff --git a/src/surface/triangle_mesh.rs b/src/surface/triangle_mesh.rs index ea4df3c..a0edcda 100644 --- a/src/surface/triangle_mesh.rs +++ b/src/surface/triangle_mesh.rs @@ -10,8 +10,8 @@ use math::{cross, dot, Matrix4x4, Normal, Point}; use ray::{AccelRay, Ray}; use shading::SurfaceShader; -use super::{Surface, SurfaceIntersection, SurfaceIntersectionData}; use super::triangle; +use super::{Surface, SurfaceIntersection, SurfaceIntersectionData}; #[derive(Copy, Clone, Debug)] pub struct TriangleMesh<'a> { diff --git a/src/tracer.rs b/src/tracer.rs index bebb4cf..b5d9c42 100644 --- a/src/tracer.rs +++ b/src/tracer.rs @@ -1,13 +1,13 @@ use std::iter; use algorithm::partition; +use color::{rec709_to_xyz, XYZ}; use lerp::lerp_slice; use ray::{AccelRay, Ray}; use scene::{Assembly, InstanceType, Object}; +use shading::{SimpleSurfaceShader, SurfaceShader}; use surface::SurfaceIntersection; use transform_stack::TransformStack; -use shading::{SimpleSurfaceShader, SurfaceShader}; -use color::{rec709_to_xyz, XYZ}; pub struct Tracer<'a> { rays: Vec, diff --git a/sub_crates/color/build.rs b/sub_crates/color/build.rs index e61b616..7d247ca 100644 --- a/sub_crates/color/build.rs +++ b/sub_crates/color/build.rs @@ -195,7 +195,8 @@ fn rgb_to_xyz(chroma: Chromaticities, y: f64) -> [[f64; 3]; 3] { let z = (1.0 - chroma.w.0 - chroma.w.1) * y / chroma.w.1; // Scale factors for matrix rows - let d = chroma.r.0 * (chroma.b.1 - chroma.g.1) + chroma.b.0 * (chroma.g.1 - chroma.r.1) + let d = chroma.r.0 * (chroma.b.1 - chroma.g.1) + + chroma.b.0 * (chroma.g.1 - chroma.r.1) + chroma.g.0 * (chroma.r.1 - chroma.b.1); let sr = (x * (chroma.b.1 - chroma.g.1) diff --git a/sub_crates/math3d/src/matrix.rs b/sub_crates/math3d/src/matrix.rs index 0d9b03c..594cba7 100644 --- a/sub_crates/math3d/src/matrix.rs +++ b/sub_crates/math3d/src/matrix.rs @@ -3,7 +3,7 @@ use std; use std::ops::{Index, IndexMut, Mul}; -use float4::{Float4, transpose, invert}; +use float4::{invert, transpose, Float4}; use super::Point; @@ -202,22 +202,7 @@ mod tests { let a = Matrix4x4::new(); let b = Matrix4x4::new(); let c = Matrix4x4::new_from_values( - 1.1, - 0.0, - 0.0, - 0.0, - 0.0, - 1.1, - 0.0, - 0.0, - 0.0, - 0.0, - 1.1, - 0.0, - 0.0, - 0.0, - 0.0, - 1.1, + 1.1, 0.0, 0.0, 0.0, 0.0, 1.1, 0.0, 0.0, 0.0, 0.0, 1.1, 0.0, 0.0, 0.0, 0.0, 1.1, ); assert_eq!(a, b); @@ -228,57 +213,13 @@ mod tests { fn aproximate_equality_test() { let a = Matrix4x4::new(); let b = Matrix4x4::new_from_values( - 1.001, - 0.0, - 0.0, - 0.0, - 0.0, - 1.001, - 0.0, - 0.0, - 0.0, - 0.0, - 1.001, - 0.0, - 0.0, - 0.0, - 0.0, - 1.001, + 1.001, 0.0, 0.0, 0.0, 0.0, 1.001, 0.0, 0.0, 0.0, 0.0, 1.001, 0.0, 0.0, 0.0, 0.0, 1.001, ); let c = Matrix4x4::new_from_values( - 1.003, - 0.0, - 0.0, - 0.0, - 0.0, - 1.003, - 0.0, - 0.0, - 0.0, - 0.0, - 1.003, - 0.0, - 0.0, - 0.0, - 0.0, - 1.003, + 1.003, 0.0, 0.0, 0.0, 0.0, 1.003, 0.0, 0.0, 0.0, 0.0, 1.003, 0.0, 0.0, 0.0, 0.0, 1.003, ); let d = Matrix4x4::new_from_values( - -1.001, - 0.0, - 0.0, - 0.0, - 0.0, - -1.001, - 0.0, - 0.0, - 0.0, - 0.0, - -1.001, - 0.0, - 0.0, - 0.0, - 0.0, + -1.001, 0.0, 0.0, 0.0, 0.0, -1.001, 0.0, 0.0, 0.0, 0.0, -1.001, 0.0, 0.0, 0.0, 0.0, -1.001, ); @@ -290,58 +231,14 @@ mod tests { #[test] fn multiply_test() { let a = Matrix4x4::new_from_values( - 1.0, - 2.0, - 2.0, - 1.5, - 3.0, - 6.0, - 7.0, - 8.0, - 9.0, - 2.0, - 11.0, - 12.0, - 13.0, - 7.0, - 15.0, - 3.0, + 1.0, 2.0, 2.0, 1.5, 3.0, 6.0, 7.0, 8.0, 9.0, 2.0, 11.0, 12.0, 13.0, 7.0, 15.0, 3.0, ); let b = Matrix4x4::new_from_values( - 1.0, - 5.0, - 9.0, - 13.0, - 2.0, - 6.0, - 10.0, - 14.0, - 3.0, - 7.0, - 11.0, - 15.0, - 4.0, - 8.0, - 12.0, - 16.0, + 1.0, 5.0, 9.0, 13.0, 2.0, 6.0, 10.0, 14.0, 3.0, 7.0, 11.0, 15.0, 4.0, 8.0, 12.0, 16.0, ); let c = Matrix4x4::new_from_values( - 266.0, - 141.0, - 331.0, - 188.5, - 292.0, - 158.0, - 366.0, - 213.0, - 318.0, - 175.0, - 401.0, - 237.5, - 344.0, - 192.0, - 436.0, - 262.0, + 266.0, 141.0, 331.0, 188.5, 292.0, 158.0, 366.0, 213.0, 318.0, 175.0, 401.0, 237.5, + 344.0, 192.0, 436.0, 262.0, ); assert_eq!(a * b, c); @@ -350,22 +247,7 @@ mod tests { #[test] fn inverse_test() { let a = Matrix4x4::new_from_values( - 1.0, - 0.33, - 0.0, - -2.0, - 0.0, - 1.0, - 0.0, - 0.0, - 2.1, - 0.7, - 1.3, - 0.0, - 0.0, - 0.0, - 0.0, - -1.0, + 1.0, 0.33, 0.0, -2.0, 0.0, 1.0, 0.0, 0.0, 2.1, 0.7, 1.3, 0.0, 0.0, 0.0, 0.0, -1.0, ); let b = a.inverse(); let c = Matrix4x4::new(); @@ -376,40 +258,10 @@ mod tests { #[test] fn transpose_test() { let a = Matrix4x4::new_from_values( - 1.0, - 2.0, - 3.0, - 4.0, - 5.0, - 6.0, - 7.0, - 8.0, - 9.0, - 10.0, - 11.0, - 12.0, - 13.0, - 14.0, - 15.0, - 16.0, + 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, ); let b = Matrix4x4::new_from_values( - 1.0, - 5.0, - 9.0, - 13.0, - 2.0, - 6.0, - 10.0, - 14.0, - 3.0, - 7.0, - 11.0, - 15.0, - 4.0, - 8.0, - 12.0, - 16.0, + 1.0, 5.0, 9.0, 13.0, 2.0, 6.0, 10.0, 14.0, 3.0, 7.0, 11.0, 15.0, 4.0, 8.0, 12.0, 16.0, ); let c = a.transposed(); diff --git a/sub_crates/math3d/src/normal.rs b/sub_crates/math3d/src/normal.rs index 116f411..70c4f05 100644 --- a/sub_crates/math3d/src/normal.rs +++ b/sub_crates/math3d/src/normal.rs @@ -183,8 +183,8 @@ impl CrossProduct for Normal { #[cfg(test)] mod tests { - use super::*; use super::super::{CrossProduct, DotProduct, Matrix4x4}; + use super::*; #[test] fn add() { @@ -217,22 +217,7 @@ mod tests { fn mul_matrix_1() { let n = Normal::new(1.0, 2.5, 4.0); let m = Matrix4x4::new_from_values( - 1.0, - 2.0, - 2.0, - 1.5, - 3.0, - 6.0, - 7.0, - 8.0, - 9.0, - 2.0, - 11.0, - 12.0, - 13.0, - 7.0, - 15.0, - 3.0, + 1.0, 2.0, 2.0, 1.5, 3.0, 6.0, 7.0, 8.0, 9.0, 2.0, 11.0, 12.0, 13.0, 7.0, 15.0, 3.0, ); let nm = Normal::new(-19.258825, 5.717648, -1.770588); assert!(((n * m) - nm).length2() < 0.00001); diff --git a/sub_crates/math3d/src/point.rs b/sub_crates/math3d/src/point.rs index 25ea710..aad0238 100644 --- a/sub_crates/math3d/src/point.rs +++ b/sub_crates/math3d/src/point.rs @@ -155,8 +155,8 @@ impl Mul for Point { #[cfg(test)] mod tests { - use super::*; use super::super::{Matrix4x4, Vector}; + use super::*; #[test] fn norm() { @@ -189,22 +189,7 @@ mod tests { fn mul_matrix_1() { let p = Point::new(1.0, 2.5, 4.0); let m = Matrix4x4::new_from_values( - 1.0, - 2.0, - 2.0, - 1.5, - 3.0, - 6.0, - 7.0, - 8.0, - 9.0, - 2.0, - 11.0, - 12.0, - 0.0, - 0.0, - 0.0, - 1.0, + 1.0, 2.0, 2.0, 1.5, 3.0, 6.0, 7.0, 8.0, 9.0, 2.0, 11.0, 12.0, 0.0, 0.0, 0.0, 1.0, ); let pm = Point::new(15.5, 54.0, 70.0); assert_eq!(p * m, pm); @@ -214,22 +199,7 @@ mod tests { fn mul_matrix_2() { let p = Point::new(1.0, 2.5, 4.0); let m = Matrix4x4::new_from_values( - 1.0, - 2.0, - 2.0, - 1.5, - 3.0, - 6.0, - 7.0, - 8.0, - 9.0, - 2.0, - 11.0, - 12.0, - 2.0, - 3.0, - 1.0, - 5.0, + 1.0, 2.0, 2.0, 1.5, 3.0, 6.0, 7.0, 8.0, 9.0, 2.0, 11.0, 12.0, 2.0, 3.0, 1.0, 5.0, ); let mut pm = Point::new(15.5, 54.0, 70.0); pm.co.set_3(18.5); @@ -241,40 +211,10 @@ mod tests { // Make sure matrix multiplication composes the way one would expect let p = Point::new(1.0, 2.5, 4.0); let m1 = Matrix4x4::new_from_values( - 1.0, - 2.0, - 2.0, - 1.5, - 3.0, - 6.0, - 7.0, - 8.0, - 9.0, - 2.0, - 11.0, - 12.0, - 13.0, - 7.0, - 15.0, - 3.0, + 1.0, 2.0, 2.0, 1.5, 3.0, 6.0, 7.0, 8.0, 9.0, 2.0, 11.0, 12.0, 13.0, 7.0, 15.0, 3.0, ); let m2 = Matrix4x4::new_from_values( - 4.0, - 1.0, - 2.0, - 3.5, - 3.0, - 6.0, - 5.0, - 2.0, - 2.0, - 2.0, - 4.0, - 12.0, - 5.0, - 7.0, - 8.0, - 11.0, + 4.0, 1.0, 2.0, 3.5, 3.0, 6.0, 5.0, 2.0, 2.0, 2.0, 4.0, 12.0, 5.0, 7.0, 8.0, 11.0, ); println!("{:?}", m1 * m2); diff --git a/sub_crates/math3d/src/vector.rs b/sub_crates/math3d/src/vector.rs index 2e440dd..04ab7ea 100644 --- a/sub_crates/math3d/src/vector.rs +++ b/sub_crates/math3d/src/vector.rs @@ -192,8 +192,8 @@ impl CrossProduct for Vector { #[cfg(test)] mod tests { - use super::*; use super::super::{CrossProduct, DotProduct, Matrix4x4}; + use super::*; #[test] fn add() { @@ -226,22 +226,7 @@ mod tests { fn mul_matrix_1() { let v = Vector::new(1.0, 2.5, 4.0); let m = Matrix4x4::new_from_values( - 1.0, - 2.0, - 2.0, - 1.5, - 3.0, - 6.0, - 7.0, - 8.0, - 9.0, - 2.0, - 11.0, - 12.0, - 13.0, - 7.0, - 15.0, - 3.0, + 1.0, 2.0, 2.0, 1.5, 3.0, 6.0, 7.0, 8.0, 9.0, 2.0, 11.0, 12.0, 13.0, 7.0, 15.0, 3.0, ); let mut vm = Vector::new(14.0, 46.0, 58.0); vm.co.set_3(90.5); @@ -252,22 +237,7 @@ mod tests { fn mul_matrix_2() { let v = Vector::new(1.0, 2.5, 4.0); let m = Matrix4x4::new_from_values( - 1.0, - 2.0, - 2.0, - 1.5, - 3.0, - 6.0, - 7.0, - 8.0, - 9.0, - 2.0, - 11.0, - 12.0, - 0.0, - 0.0, - 0.0, - 1.0, + 1.0, 2.0, 2.0, 1.5, 3.0, 6.0, 7.0, 8.0, 9.0, 2.0, 11.0, 12.0, 0.0, 0.0, 0.0, 1.0, ); let vm = Vector::new(14.0, 46.0, 58.0); assert_eq!(v * m, vm); diff --git a/sub_crates/mem_arena/src/lib.rs b/sub_crates/mem_arena/src/lib.rs index e8b02a2..5fd8cd4 100644 --- a/sub_crates/mem_arena/src/lib.rs +++ b/sub_crates/mem_arena/src/lib.rs @@ -1,7 +1,7 @@ -use std::slice; use std::cell::{Cell, RefCell}; -use std::mem::{align_of, size_of}; use std::cmp::max; +use std::mem::{align_of, size_of}; +use std::slice; const GROWTH_FRACTION: usize = 8; // 1/N (smaller number leads to bigger allocations) const DEFAULT_MIN_BLOCK_SIZE: usize = 1 << 10; // 1 KiB