Fix all clippy warnings or block them.

This commit is contained in:
2018-10-11 19:53:07 -07:00
parent fa7d79b112
commit 66d599b50d
13 changed files with 60 additions and 80 deletions

View File

@@ -41,28 +41,32 @@ impl fmt::Display for BVHNode {
}
}
// Lint is wrong when dealing with Box<Trait>
#[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))]
fn box_x_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
match (ah.bounding_box(0., 0.), bh.bounding_box(0., 0.)) {
(Some(box_left), Some(box_right)) => {
return box_left.min().x.partial_cmp(&box_right.min().x).unwrap();
box_left.min().x.partial_cmp(&box_right.min().x).unwrap()
}
_ => panic!("hit missing bounding box"),
}
}
#[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))]
fn box_y_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
match (ah.bounding_box(0., 0.), bh.bounding_box(0., 0.)) {
(Some(box_left), Some(box_right)) => {
return box_left.min().y.partial_cmp(&box_right.min().y).unwrap();
box_left.min().y.partial_cmp(&box_right.min().y).unwrap()
}
_ => panic!("hit missing bounding box"),
}
}
#[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))]
fn box_z_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
match (ah.bounding_box(0., 0.), bh.bounding_box(0., 0.)) {
(Some(box_left), Some(box_right)) => {
return box_left.min().z.partial_cmp(&box_right.min().z).unwrap();
box_left.min().z.partial_cmp(&box_right.min().z).unwrap()
}
_ => panic!("hit missing bounding box"),
}
@@ -78,10 +82,7 @@ fn vec_first_into<T>(v: Vec<T>) -> T {
v.len()
));
}
for i in v.into_iter() {
return i;
}
panic!("Unreachable");
v.into_iter().next().unwrap()
}
fn vec_split_into<T>(v: Vec<T>, offset: usize) -> (Vec<T>, Vec<T>) {
@@ -100,7 +101,7 @@ fn vec_split_into<T>(v: Vec<T>, offset: usize) -> (Vec<T>, Vec<T>) {
impl BVHNode {
fn new(l: Vec<Box<Hit>>, t_min: f32, t_max: f32) -> BVHNode {
if l.len() == 1 {
return BVHNode::Leaf(vec_first_into(l));
BVHNode::Leaf(vec_first_into(l))
} else {
let mut l: Vec<Box<Hit>> = l.into_iter().collect();
let mut rng = rand::thread_rng();
@@ -108,7 +109,7 @@ impl BVHNode {
0 => l.sort_by(box_x_compare),
1 => l.sort_by(box_y_compare),
2 => l.sort_by(box_z_compare),
val @ _ => panic!("unknown axis {}", val),
val => panic!("unknown axis {}", val),
}
let half = l.len() / 2;
@@ -116,7 +117,7 @@ impl BVHNode {
let left = Box::new(BVHNode::new(left_half, t_min, t_max));
let right = Box::new(BVHNode::new(right_half, t_min, t_max));
let bbox = BVHNode::surrounding_box(left.as_ref(), right.as_ref(), t_min, t_max);
return BVHNode::Branch { left, right, bbox };
BVHNode::Branch { left, right, bbox }
}
}
@@ -144,7 +145,6 @@ impl Hit for BVHNode {
fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
match self {
BVHNode::Leaf(ref hit) => hit.hit(r, t_min, t_max),
// TODO(wathiede): call bbox.hit() before recursing down both paths of tree.
BVHNode::Branch {
ref left,
ref right,
@@ -154,17 +154,16 @@ impl Hit for BVHNode {
if bbox.hit(r, t_min, t_max) {
match (left.hit(r, t_min, t_max), right.hit(r, t_min, t_max)) {
(Some(hit_left), Some(hit_right)) => if hit_left.t < hit_right.t {
return Some(hit_left);
Some(hit_left)
} else {
return Some(hit_right);
Some(hit_right)
},
(Some(hit_left), None) => return Some(hit_left),
(None, Some(hit_right)) => return Some(hit_right),
(None, None) => return None,
(Some(hit_left), None) => Some(hit_left),
(None, Some(hit_right)) => Some(hit_right),
(None, None) => None,
};
} else {
return None;
}
None
}
None => None,
},
@@ -203,7 +202,7 @@ impl BVH {
fn print_tree(f: &mut fmt::Formatter, depth: usize, bvhn: &BVHNode) -> fmt::Result {
let vol = bvhn.volume();
write!(f, "{:.*}{}{}\n", 2, vol, " ".repeat(depth * 2), bvhn)?;
writeln!(f, "{:.*}{}{}", 2, vol, " ".repeat(depth * 2), bvhn)?;
if let BVHNode::Branch { left, right, .. } = bvhn {
print_tree(f, depth + 1, left)?;
print_tree(f, depth + 1, right)?;
@@ -213,7 +212,7 @@ fn print_tree(f: &mut fmt::Formatter, depth: usize, bvhn: &BVHNode) -> fmt::Resu
impl fmt::Display for BVH {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Root\n")?;
writeln!(f, "Root")?;
print_tree(f, 1, &self.root)
}
}