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,
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())),
}
};

View File

@ -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],
}
}
}

View File

@ -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;
}

View File

@ -147,7 +147,7 @@ fn main() {
println!("Ray size: {} bytes", mem::size_of::<Ray>());
// 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...");

View File

@ -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<T: DotProduct>(a: T, b: T) -> f32 {
/// Trait for calculating cross products.
pub trait CrossProduct
{
pub trait CrossProduct {
fn cross(self, other: Self) -> Self;
}

View File

@ -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<DataTree<'a>>)> {
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..]));
}
}

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()));
// 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<Renderer, PsyParseError> {
// 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<Renderer, 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 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> {
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<Camera, PsyParseError> {
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,7 +281,7 @@ 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")
if let &DataTree::Leaf { contents, .. } = bgs.iter_children_with_type("Type")
.nth(0)
.unwrap() {
contents.trim()
@ -292,7 +291,7 @@ 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")
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,

View File

@ -16,7 +16,7 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
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<Assembly, PsyParseError> {
// 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))))

View File

@ -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: _,
if let &surface::SurfaceIntersection::Hit { t: _,
pos: _,
nor: _,
space: _,
uv,
} = isect {
uv } = isect {
r += uv.0;
g += uv.1;
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]) {
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)],
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))
(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 {