From 039943e0cbb6ca792d977e46d61465cb668ec101 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 2 Jun 2016 22:43:35 -0700 Subject: [PATCH] Auto-formatting code with new version of rustfmt. --- src/assembly.rs | 10 +++----- src/bbox.rs | 8 +++--- src/bvh.rs | 4 +-- src/camera.rs | 2 +- src/lerp.rs | 3 +-- src/main.rs | 6 ++--- src/math/mod.rs | 6 ++--- src/parse/data_tree.rs | 47 +++++++++++++++++------------------- src/parse/psy.rs | 23 +++++++++--------- src/parse/psy_assembly.rs | 4 +-- src/renderer.rs | 12 ++++----- src/surface/triangle_mesh.rs | 17 ++++++------- 12 files changed, 65 insertions(+), 77 deletions(-) diff --git a/src/assembly.rs b/src/assembly.rs index b3b8e1a..aae90f0 100644 --- a/src/assembly.rs +++ b/src/assembly.rs @@ -93,18 +93,16 @@ impl AssemblyBuilder { instance_type: InstanceType::Object, data_index: self.object_map[name], id: self.instances.len(), - transform_indices: xforms.map(|xf| { - (self.xforms.len(), self.xforms.len() + xf.len()) - }), + transform_indices: + xforms.map(|xf| (self.xforms.len(), self.xforms.len() + xf.len())), } } else { Instance { instance_type: InstanceType::Assembly, data_index: self.assembly_map[name], id: self.instances.len(), - transform_indices: xforms.map(|xf| { - (self.xforms.len(), self.xforms.len() + xf.len()) - }), + transform_indices: + xforms.map(|xf| (self.xforms.len(), self.xforms.len() + xf.len())), } }; diff --git a/src/bbox.rs b/src/bbox.rs index 85d3213..39bf9d8 100644 --- a/src/bbox.rs +++ b/src/bbox.rs @@ -45,11 +45,11 @@ impl BBox { // Find the far and near intersection let hitt0 = (t1[0].min(t2[0])) - .max(t1[1].min(t2[1])) - .max(t1[2].min(t2[2])); + .max(t1[1].min(t2[1])) + .max(t1[2].min(t2[2])); let hitt1 = (t1[0].max(t2[0])) - .min(t1[1].max(t2[1])) - .min(t1[2].max(t2[2])) * BBOX_MAXT_ADJUST; + .min(t1[1].max(t2[1])) + .min(t1[2].max(t2[2])) * BBOX_MAXT_ADJUST; // Did we hit? return hitt0.max(0.0) <= hitt1.min(ray.max_t); diff --git a/src/bvh.rs b/src/bvh.rs index 3b5b392..4cc8287 100644 --- a/src/bvh.rs +++ b/src/bvh.rs @@ -229,9 +229,9 @@ impl BVH { impl Boundable for BVH { fn bounds<'a>(&'a self) -> &'a [BBox] { match self.nodes[0] { - BVHNode::Internal{bounds_range, ..} => &self.bounds[bounds_range.0..bounds_range.1], + BVHNode::Internal { bounds_range, .. } => &self.bounds[bounds_range.0..bounds_range.1], - BVHNode::Leaf{bounds_range, ..} => &self.bounds[bounds_range.0..bounds_range.1], + BVHNode::Leaf { bounds_range, .. } => &self.bounds[bounds_range.0..bounds_range.1], } } } diff --git a/src/camera.rs b/src/camera.rs index 8156cad..35100c9 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -74,7 +74,7 @@ impl Camera { let dir = Vector::new((x * tfov) - (orig[0] / focus_distance), (y * tfov) - (orig[1] / focus_distance), 1.0) - .normalized(); + .normalized(); Ray::new(orig * transform, dir * transform, time) } diff --git a/src/lerp.rs b/src/lerp.rs index fdd8e26..a939b66 100644 --- a/src/lerp.rs +++ b/src/lerp.rs @@ -1,8 +1,7 @@ #![allow(dead_code)] /// Trait for allowing a type to be linearly interpolated. -pub trait Lerp -{ +pub trait Lerp { fn lerp(self, other: Self, alpha: f32) -> Self; } diff --git a/src/main.rs b/src/main.rs index 25b2e6c..d0c3f7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,8 +66,8 @@ struct Args { fn main() { // Parse command line arguments. let args: Args = Docopt::new(USAGE.replace("", VERSION)) - .and_then(|d| d.decode()) - .unwrap_or_else(|e| e.exit()); + .and_then(|d| d.decode()) + .unwrap_or_else(|e| e.exit()); // Print version and exit if requested. if args.flag_version { @@ -147,7 +147,7 @@ fn main() { println!("Ray size: {} bytes", mem::size_of::()); // Iterate through scenes and render them - if let DataTree::Internal{ref children, ..} = dt { + if let DataTree::Internal { ref children, .. } = dt { for child in children { if child.type_name() == "Scene" { println!("Parsing scene..."); diff --git a/src/math/mod.rs b/src/math/mod.rs index 3b5e154..6808924 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -11,8 +11,7 @@ pub use self::point::Point; pub use self::matrix::{Matrix4x4, multiply_matrix_slices}; /// Trait for calculating dot products. -pub trait DotProduct -{ +pub trait DotProduct { fn dot(self, other: Self) -> f32; } @@ -22,8 +21,7 @@ pub fn dot(a: T, b: T) -> f32 { /// Trait for calculating cross products. -pub trait CrossProduct -{ +pub trait CrossProduct { fn cross(self, other: Self) -> Self; } diff --git a/src/parse/data_tree.rs b/src/parse/data_tree.rs index 834eda1..17624b7 100644 --- a/src/parse/data_tree.rs +++ b/src/parse/data_tree.rs @@ -46,34 +46,34 @@ impl<'a> DataTree<'a> { pub fn type_name(&'a self) -> &'a str { match self { - &DataTree::Internal{type_name, ..} => type_name, - &DataTree::Leaf{type_name, ..} => type_name, + &DataTree::Internal { type_name, .. } => type_name, + &DataTree::Leaf { type_name, .. } => type_name, } } pub fn is_internal(&self) -> bool { match self { - &DataTree::Internal{..} => true, - &DataTree::Leaf{..} => false, + &DataTree::Internal { .. } => true, + &DataTree::Leaf { .. } => false, } } pub fn is_leaf(&self) -> bool { match self { - &DataTree::Internal{..} => false, - &DataTree::Leaf{..} => true, + &DataTree::Internal { .. } => false, + &DataTree::Leaf { .. } => true, } } pub fn leaf_contents(&'a self) -> Option<&'a str> { match self { - &DataTree::Internal{..} => None, - &DataTree::Leaf{contents, ..} => Some(contents), + &DataTree::Internal { .. } => None, + &DataTree::Leaf { contents, .. } => Some(contents), } } pub fn iter_children(&'a self) -> slice::Iter<'a, DataTree<'a>> { - if let &DataTree::Internal{ref children, ..} = self { + if let &DataTree::Internal { ref children, .. } = self { children.iter() } else { [].iter() @@ -81,7 +81,7 @@ impl<'a> DataTree<'a> { } pub fn iter_children_with_type(&'a self, type_name: &'static str) -> DataTreeFilterIter<'a> { - if let &DataTree::Internal{ref children, ..} = self { + if let &DataTree::Internal { ref children, .. } = self { DataTreeFilterIter { type_name: type_name, iter: children.iter(), @@ -97,7 +97,7 @@ impl<'a> DataTree<'a> { pub fn iter_internal_children_with_type(&'a self, type_name: &'static str) -> DataTreeFilterInternalIter<'a> { - if let &DataTree::Internal{ref children, ..} = self { + if let &DataTree::Internal { ref children, .. } = self { DataTreeFilterInternalIter { type_name: type_name, iter: children.iter(), @@ -113,7 +113,7 @@ impl<'a> DataTree<'a> { pub fn iter_leaf_children_with_type(&'a self, type_name: &'static str) -> DataTreeFilterLeafIter<'a> { - if let &DataTree::Internal{ref children, ..} = self { + if let &DataTree::Internal { ref children, .. } = self { DataTreeFilterLeafIter { type_name: type_name, iter: children.iter(), @@ -184,7 +184,7 @@ impl<'a> Iterator for DataTreeFilterInternalIter<'a> { fn next(&mut self) -> Option<(&'a str, Option<&'a str>, &'a Vec>)> { loop { match self.iter.next() { - Some(&DataTree::Internal{type_name, ident, ref children}) => { + Some(&DataTree::Internal { type_name, ident, ref children }) => { if type_name == self.type_name { return Some((type_name, ident, children)); } else { @@ -192,7 +192,7 @@ impl<'a> Iterator for DataTreeFilterInternalIter<'a> { } } - Some(&DataTree::Leaf{..}) => { + Some(&DataTree::Leaf { .. }) => { continue; } @@ -219,11 +219,11 @@ impl<'a> Iterator for DataTreeFilterLeafIter<'a> { fn next(&mut self) -> Option<(&'a str, &'a str)> { loop { match self.iter.next() { - Some(&DataTree::Internal{..}) => { + Some(&DataTree::Internal { .. }) => { continue; } - Some(&DataTree::Leaf{type_name, contents}) => { + Some(&DataTree::Leaf { type_name, contents }) => { if type_name == self.type_name { return Some((type_name, contents)); } else { @@ -366,8 +366,7 @@ fn parse_leaf_content<'a>(source_text: (usize, &'a str)) -> (&'a str, (usize, &' si = source_text.1.len(); } - return (&source_text.1[0..si], - (source_text.0 + si, &source_text.1[si..])); + return (&source_text.1[0..si], (source_text.0 + si, &source_text.1[si..])); } @@ -414,8 +413,7 @@ fn next_token<'a>(source_text: (usize, &'a str)) -> (Token<'a>, (usize, &'a str) si = text1.1.len(); } - return (Token::Ident(&text1.1[0..si]), - (text1.0 + si, &text1.1[si..])); + return (Token::Ident(&text1.1[0..si]), (text1.0 + si, &text1.1[si..])); } _ => { @@ -435,8 +433,7 @@ fn next_token<'a>(source_text: (usize, &'a str)) -> (Token<'a>, (usize, &'a str) si = text1.1.len(); } - return (Token::TypeName(&text1.1[0..si]), - (text1.0 + si, &text1.1[si..])); + return (Token::TypeName(&text1.1[0..si]), (text1.0 + si, &text1.1[si..])); } } @@ -653,7 +650,7 @@ mod tests { A {} B {} "#) - .unwrap(); + .unwrap(); let mut i = dt.iter_children_with_type("A"); assert_eq!(i.count(), 3); @@ -668,7 +665,7 @@ mod tests { A {} B {} "#) - .unwrap(); + .unwrap(); let mut i = dt.iter_internal_children_with_type("A"); assert_eq!(i.count(), 2); @@ -683,7 +680,7 @@ mod tests { A [] B {} "#) - .unwrap(); + .unwrap(); let mut i = dt.iter_leaf_children_with_type("A"); assert_eq!(i.count(), 2); diff --git a/src/parse/psy.rs b/src/parse/psy.rs index cdda1d5..90cbfb8 100644 --- a/src/parse/psy.rs +++ b/src/parse/psy.rs @@ -68,7 +68,7 @@ pub fn parse_scene(tree: &DataTree) -> Result { let assembly = try!(parse_assembly(tree.iter_children_with_type("Assembly").nth(0).unwrap())); // Put scene together - let scene_name = if let &DataTree::Internal{ident, ..} = tree { + let scene_name = if let &DataTree::Internal { ident, .. } = tree { if let Some(name) = ident { Some(name.to_string()) } else { @@ -87,8 +87,7 @@ pub fn parse_scene(tree: &DataTree) -> Result { // Put renderer together let renderer = Renderer { output_file: output_info.clone(), - resolution: ((render_settings.0).0 as usize, - (render_settings.0).1 as usize), + resolution: ((render_settings.0).0 as usize, (render_settings.0).1 as usize), spp: render_settings.1 as usize, scene: scene, }; @@ -100,7 +99,7 @@ pub fn parse_scene(tree: &DataTree) -> Result { fn parse_output_info(tree: &DataTree) -> Result { - if let &DataTree::Internal{ref children, ..} = tree { + if let &DataTree::Internal { ref children, .. } = tree { let mut found_path = false; let mut path = String::new(); @@ -144,7 +143,7 @@ fn parse_output_info(tree: &DataTree) -> Result { fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyParseError> { - if let &DataTree::Internal{ref children, ..} = tree { + if let &DataTree::Internal { ref children, .. } = tree { let mut found_res = false; let mut found_spp = false; let mut res = (0, 0); @@ -204,7 +203,7 @@ fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyP fn parse_camera(tree: &DataTree) -> Result { - if let &DataTree::Internal{ref children, ..} = tree { + if let &DataTree::Internal { ref children, .. } = tree { let mut mats = Vec::new(); let mut fovs = Vec::new(); let mut focus_distances = Vec::new(); @@ -282,9 +281,9 @@ fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> { if bgs.iter_children_with_type("Type").count() != 1 { return Err(PsyParseError::UnknownError); } - if let &DataTree::Leaf{contents, ..} = bgs.iter_children_with_type("Type") - .nth(0) - .unwrap() { + if let &DataTree::Leaf { contents, .. } = bgs.iter_children_with_type("Type") + .nth(0) + .unwrap() { contents.trim() } else { return Err(PsyParseError::UnknownError); @@ -292,12 +291,12 @@ fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> { }; match bgs_type { "Color" => { - if let Some(&DataTree::Leaf{contents, ..}) = bgs.iter_children_with_type("Color") - .nth(0) { + if let Some(&DataTree::Leaf { contents, .. }) = bgs.iter_children_with_type("Color") + .nth(0) { if let IResult::Done(_, color) = closure!(tuple!(ws_f32, ws_f32, ws_f32))(contents.trim() - .as_bytes()) { + .as_bytes()) { found_background_color = true; background_color = color; } else { diff --git a/src/parse/psy_assembly.rs b/src/parse/psy_assembly.rs index 90f0b92..9667630 100644 --- a/src/parse/psy_assembly.rs +++ b/src/parse/psy_assembly.rs @@ -16,7 +16,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result { match child.type_name() { // Sub-Assembly "Assembly" => { - if let &DataTree::Internal {ident: Some(ident), ..} = child { + if let &DataTree::Internal { ident: Some(ident), .. } = child { builder.add_assembly(ident, try!(parse_assembly(&child))); } else { // TODO: error condition of some kind, because no ident @@ -59,7 +59,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result { // MeshSurface "MeshSurface" => { - if let &DataTree::Internal {ident: Some(ident), ..} = child { + if let &DataTree::Internal { ident: Some(ident), .. } = child { builder.add_object( ident, Object::Surface(Box::new(try!(parse_mesh_surface(&child)))) diff --git a/src/renderer.rs b/src/renderer.rs index c53b317..31f1f81 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -66,13 +66,11 @@ impl Renderer { let mut g = 0.0; let mut b = 0.0; for isect in isects.iter() { - if let &surface::SurfaceIntersection::Hit{ - t: _, - pos: _, - nor: _, - space: _, - uv, - } = isect { + if let &surface::SurfaceIntersection::Hit { t: _, + pos: _, + nor: _, + space: _, + uv } = isect { r += uv.0; g += uv.1; b += (1.0 - uv.0 - uv.1).max(0.0); diff --git a/src/surface/triangle_mesh.rs b/src/surface/triangle_mesh.rs index 9878ac0..1fcbb18 100644 --- a/src/surface/triangle_mesh.rs +++ b/src/surface/triangle_mesh.rs @@ -25,8 +25,8 @@ impl TriangleMesh { assert!(triangles.len() % time_samples == 0); let mut indices: Vec = (0..(triangles.len() / time_samples)) - .map(|n| n * time_samples) - .collect(); + .map(|n| n * time_samples) + .collect(); let bounds = { let mut bounds = Vec::new(); @@ -62,13 +62,12 @@ impl Surface for TriangleMesh { fn intersect_rays(&self, rays: &mut [Ray], isects: &mut [SurfaceIntersection]) { self.accel.traverse(&mut rays[..], &self.indices, |tri_i, rs| { for r in rs { - let tri = lerp_slice_with(&self.geo[*tri_i..(*tri_i + self.time_samples)], - r.time, - |a, b, t| { - (lerp(a.0, b.0, t), - lerp(a.1, b.1, t), - lerp(a.2, b.2, t)) - }); + let tri = + lerp_slice_with(&self.geo[*tri_i..(*tri_i + self.time_samples)], + r.time, + |a, b, t| { + (lerp(a.0, b.0, t), lerp(a.1, b.1, t), lerp(a.2, b.2, t)) + }); if let Some((t, tri_u, tri_v)) = triangle::intersect_ray(r, tri) { if t < r.max_t { isects[r.id as usize] = SurfaceIntersection::Hit {