Auto-formatting code with new version of rustfmt.

This commit is contained in:
Nathan Vegdahl 2016-06-02 22:43:35 -07:00
parent c3d3145817
commit 039943e0cb
12 changed files with 65 additions and 77 deletions

View File

@ -93,18 +93,16 @@ impl AssemblyBuilder {
instance_type: InstanceType::Object, instance_type: InstanceType::Object,
data_index: self.object_map[name], data_index: self.object_map[name],
id: self.instances.len(), id: self.instances.len(),
transform_indices: xforms.map(|xf| { transform_indices:
(self.xforms.len(), self.xforms.len() + xf.len()) xforms.map(|xf| (self.xforms.len(), self.xforms.len() + xf.len())),
}),
} }
} else { } else {
Instance { Instance {
instance_type: InstanceType::Assembly, instance_type: InstanceType::Assembly,
data_index: self.assembly_map[name], data_index: self.assembly_map[name],
id: self.instances.len(), id: self.instances.len(),
transform_indices: xforms.map(|xf| { transform_indices:
(self.xforms.len(), self.xforms.len() + xf.len()) xforms.map(|xf| (self.xforms.len(), self.xforms.len() + xf.len())),
}),
} }
}; };

View File

@ -229,9 +229,9 @@ impl BVH {
impl Boundable for BVH { impl Boundable for BVH {
fn bounds<'a>(&'a self) -> &'a [BBox] { fn bounds<'a>(&'a self) -> &'a [BBox] {
match self.nodes[0] { 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],
} }
} }
} }

View File

@ -1,8 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
/// Trait for allowing a type to be linearly interpolated. /// Trait for allowing a type to be linearly interpolated.
pub trait Lerp pub trait Lerp {
{
fn lerp(self, other: Self, alpha: f32) -> Self; fn lerp(self, other: Self, alpha: f32) -> Self;
} }

View File

@ -147,7 +147,7 @@ fn main() {
println!("Ray size: {} bytes", mem::size_of::<Ray>()); println!("Ray size: {} bytes", mem::size_of::<Ray>());
// Iterate through scenes and render them // Iterate through scenes and render them
if let DataTree::Internal{ref children, ..} = dt { if let DataTree::Internal { ref children, .. } = dt {
for child in children { for child in children {
if child.type_name() == "Scene" { if child.type_name() == "Scene" {
println!("Parsing scene..."); println!("Parsing scene...");

View File

@ -11,8 +11,7 @@ pub use self::point::Point;
pub use self::matrix::{Matrix4x4, multiply_matrix_slices}; pub use self::matrix::{Matrix4x4, multiply_matrix_slices};
/// Trait for calculating dot products. /// Trait for calculating dot products.
pub trait DotProduct pub trait DotProduct {
{
fn dot(self, other: Self) -> f32; fn dot(self, other: Self) -> f32;
} }
@ -22,8 +21,7 @@ pub fn dot<T: DotProduct>(a: T, b: T) -> f32 {
/// Trait for calculating cross products. /// Trait for calculating cross products.
pub trait CrossProduct pub trait CrossProduct {
{
fn cross(self, other: Self) -> Self; fn cross(self, other: Self) -> Self;
} }

View File

@ -46,34 +46,34 @@ impl<'a> DataTree<'a> {
pub fn type_name(&'a self) -> &'a str { pub fn type_name(&'a self) -> &'a str {
match self { match self {
&DataTree::Internal{type_name, ..} => type_name, &DataTree::Internal { type_name, .. } => type_name,
&DataTree::Leaf{type_name, ..} => type_name, &DataTree::Leaf { type_name, .. } => type_name,
} }
} }
pub fn is_internal(&self) -> bool { pub fn is_internal(&self) -> bool {
match self { match self {
&DataTree::Internal{..} => true, &DataTree::Internal { .. } => true,
&DataTree::Leaf{..} => false, &DataTree::Leaf { .. } => false,
} }
} }
pub fn is_leaf(&self) -> bool { pub fn is_leaf(&self) -> bool {
match self { match self {
&DataTree::Internal{..} => false, &DataTree::Internal { .. } => false,
&DataTree::Leaf{..} => true, &DataTree::Leaf { .. } => true,
} }
} }
pub fn leaf_contents(&'a self) -> Option<&'a str> { pub fn leaf_contents(&'a self) -> Option<&'a str> {
match self { match self {
&DataTree::Internal{..} => None, &DataTree::Internal { .. } => None,
&DataTree::Leaf{contents, ..} => Some(contents), &DataTree::Leaf { contents, .. } => Some(contents),
} }
} }
pub fn iter_children(&'a self) -> slice::Iter<'a, DataTree<'a>> { 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() children.iter()
} else { } else {
[].iter() [].iter()
@ -81,7 +81,7 @@ impl<'a> DataTree<'a> {
} }
pub fn iter_children_with_type(&'a self, type_name: &'static str) -> DataTreeFilterIter<'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 { DataTreeFilterIter {
type_name: type_name, type_name: type_name,
iter: children.iter(), iter: children.iter(),
@ -97,7 +97,7 @@ impl<'a> DataTree<'a> {
pub fn iter_internal_children_with_type(&'a self, pub fn iter_internal_children_with_type(&'a self,
type_name: &'static str) type_name: &'static str)
-> DataTreeFilterInternalIter<'a> { -> DataTreeFilterInternalIter<'a> {
if let &DataTree::Internal{ref children, ..} = self { if let &DataTree::Internal { ref children, .. } = self {
DataTreeFilterInternalIter { DataTreeFilterInternalIter {
type_name: type_name, type_name: type_name,
iter: children.iter(), iter: children.iter(),
@ -113,7 +113,7 @@ impl<'a> DataTree<'a> {
pub fn iter_leaf_children_with_type(&'a self, pub fn iter_leaf_children_with_type(&'a self,
type_name: &'static str) type_name: &'static str)
-> DataTreeFilterLeafIter<'a> { -> DataTreeFilterLeafIter<'a> {
if let &DataTree::Internal{ref children, ..} = self { if let &DataTree::Internal { ref children, .. } = self {
DataTreeFilterLeafIter { DataTreeFilterLeafIter {
type_name: type_name, type_name: type_name,
iter: children.iter(), 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<DataTree<'a>>)> { fn next(&mut self) -> Option<(&'a str, Option<&'a str>, &'a Vec<DataTree<'a>>)> {
loop { loop {
match self.iter.next() { 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 { if type_name == self.type_name {
return Some((type_name, ident, children)); return Some((type_name, ident, children));
} else { } else {
@ -192,7 +192,7 @@ impl<'a> Iterator for DataTreeFilterInternalIter<'a> {
} }
} }
Some(&DataTree::Leaf{..}) => { Some(&DataTree::Leaf { .. }) => {
continue; continue;
} }
@ -219,11 +219,11 @@ impl<'a> Iterator for DataTreeFilterLeafIter<'a> {
fn next(&mut self) -> Option<(&'a str, &'a str)> { fn next(&mut self) -> Option<(&'a str, &'a str)> {
loop { loop {
match self.iter.next() { match self.iter.next() {
Some(&DataTree::Internal{..}) => { Some(&DataTree::Internal { .. }) => {
continue; continue;
} }
Some(&DataTree::Leaf{type_name, contents}) => { Some(&DataTree::Leaf { type_name, contents }) => {
if type_name == self.type_name { if type_name == self.type_name {
return Some((type_name, contents)); return Some((type_name, contents));
} else { } else {
@ -366,8 +366,7 @@ fn parse_leaf_content<'a>(source_text: (usize, &'a str)) -> (&'a str, (usize, &'
si = source_text.1.len(); si = source_text.1.len();
} }
return (&source_text.1[0..si], return (&source_text.1[0..si], (source_text.0 + si, &source_text.1[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(); si = text1.1.len();
} }
return (Token::Ident(&text1.1[0..si]), return (Token::Ident(&text1.1[0..si]), (text1.0 + si, &text1.1[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(); si = text1.1.len();
} }
return (Token::TypeName(&text1.1[0..si]), return (Token::TypeName(&text1.1[0..si]), (text1.0 + si, &text1.1[si..]));
(text1.0 + si, &text1.1[si..]));
} }
} }

View File

@ -68,7 +68,7 @@ pub fn parse_scene(tree: &DataTree) -> Result<Renderer, PsyParseError> {
let assembly = try!(parse_assembly(tree.iter_children_with_type("Assembly").nth(0).unwrap())); let assembly = try!(parse_assembly(tree.iter_children_with_type("Assembly").nth(0).unwrap()));
// Put scene together // 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 { if let Some(name) = ident {
Some(name.to_string()) Some(name.to_string())
} else { } else {
@ -87,8 +87,7 @@ pub fn parse_scene(tree: &DataTree) -> Result<Renderer, PsyParseError> {
// Put renderer together // Put renderer together
let renderer = Renderer { let renderer = Renderer {
output_file: output_info.clone(), output_file: output_info.clone(),
resolution: ((render_settings.0).0 as usize, resolution: ((render_settings.0).0 as usize, (render_settings.0).1 as usize),
(render_settings.0).1 as usize),
spp: render_settings.1 as usize, spp: render_settings.1 as usize,
scene: scene, scene: scene,
}; };
@ -100,7 +99,7 @@ pub fn parse_scene(tree: &DataTree) -> Result<Renderer, PsyParseError> {
fn parse_output_info(tree: &DataTree) -> Result<String, PsyParseError> { fn parse_output_info(tree: &DataTree) -> Result<String, PsyParseError> {
if let &DataTree::Internal{ref children, ..} = tree { if let &DataTree::Internal { ref children, .. } = tree {
let mut found_path = false; let mut found_path = false;
let mut path = String::new(); let mut path = String::new();
@ -144,7 +143,7 @@ fn parse_output_info(tree: &DataTree) -> Result<String, PsyParseError> {
fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyParseError> { 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_res = false;
let mut found_spp = false; let mut found_spp = false;
let mut res = (0, 0); 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<Camera, PsyParseError> { fn parse_camera(tree: &DataTree) -> Result<Camera, PsyParseError> {
if let &DataTree::Internal{ref children, ..} = tree { if let &DataTree::Internal { ref children, .. } = tree {
let mut mats = Vec::new(); let mut mats = Vec::new();
let mut fovs = Vec::new(); let mut fovs = Vec::new();
let mut focus_distances = Vec::new(); let mut focus_distances = Vec::new();
@ -282,7 +281,7 @@ fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> {
if bgs.iter_children_with_type("Type").count() != 1 { if bgs.iter_children_with_type("Type").count() != 1 {
return Err(PsyParseError::UnknownError); return Err(PsyParseError::UnknownError);
} }
if let &DataTree::Leaf{contents, ..} = bgs.iter_children_with_type("Type") if let &DataTree::Leaf { contents, .. } = bgs.iter_children_with_type("Type")
.nth(0) .nth(0)
.unwrap() { .unwrap() {
contents.trim() contents.trim()
@ -292,7 +291,7 @@ fn parse_world(tree: &DataTree) -> Result<(f32, f32, f32), PsyParseError> {
}; };
match bgs_type { match bgs_type {
"Color" => { "Color" => {
if let Some(&DataTree::Leaf{contents, ..}) = bgs.iter_children_with_type("Color") if let Some(&DataTree::Leaf { contents, .. }) = bgs.iter_children_with_type("Color")
.nth(0) { .nth(0) {
if let IResult::Done(_, color) = closure!(tuple!(ws_f32, if let IResult::Done(_, color) = closure!(tuple!(ws_f32,
ws_f32, ws_f32,

View File

@ -16,7 +16,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
match child.type_name() { match child.type_name() {
// Sub-Assembly // Sub-Assembly
"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))); builder.add_assembly(ident, try!(parse_assembly(&child)));
} else { } else {
// TODO: error condition of some kind, because no ident // TODO: error condition of some kind, because no ident
@ -59,7 +59,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
// MeshSurface // MeshSurface
"MeshSurface" => { "MeshSurface" => {
if let &DataTree::Internal {ident: Some(ident), ..} = child { if let &DataTree::Internal { ident: Some(ident), .. } = child {
builder.add_object( builder.add_object(
ident, ident,
Object::Surface(Box::new(try!(parse_mesh_surface(&child)))) Object::Surface(Box::new(try!(parse_mesh_surface(&child))))

View File

@ -66,13 +66,11 @@ impl Renderer {
let mut g = 0.0; let mut g = 0.0;
let mut b = 0.0; let mut b = 0.0;
for isect in isects.iter() { for isect in isects.iter() {
if let &surface::SurfaceIntersection::Hit{ if let &surface::SurfaceIntersection::Hit { t: _,
t: _,
pos: _, pos: _,
nor: _, nor: _,
space: _, space: _,
uv, uv } = isect {
} = isect {
r += uv.0; r += uv.0;
g += uv.1; g += uv.1;
b += (1.0 - uv.0 - uv.1).max(0.0); b += (1.0 - uv.0 - uv.1).max(0.0);

View File

@ -62,12 +62,11 @@ impl Surface for TriangleMesh {
fn intersect_rays(&self, rays: &mut [Ray], isects: &mut [SurfaceIntersection]) { fn intersect_rays(&self, rays: &mut [Ray], isects: &mut [SurfaceIntersection]) {
self.accel.traverse(&mut rays[..], &self.indices, |tri_i, rs| { self.accel.traverse(&mut rays[..], &self.indices, |tri_i, rs| {
for r in rs { for r in rs {
let tri = lerp_slice_with(&self.geo[*tri_i..(*tri_i + self.time_samples)], let tri =
lerp_slice_with(&self.geo[*tri_i..(*tri_i + self.time_samples)],
r.time, r.time,
|a, b, t| { |a, b, t| {
(lerp(a.0, b.0, t), (lerp(a.0, b.0, t), lerp(a.1, b.1, t), lerp(a.2, b.2, 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 let Some((t, tri_u, tri_v)) = triangle::intersect_ray(r, tri) {
if t < r.max_t { if t < r.max_t {