Fix 'dyn' lint on trait objects.
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::hitable::HitRecord;
|
||||
use crate::ray::Ray;
|
||||
|
||||
enum BVHNode {
|
||||
Leaf(Box<Hit>),
|
||||
Leaf(Box<dyn Hit>),
|
||||
Branch {
|
||||
left: Box<BVHNode>,
|
||||
right: Box<BVHNode>,
|
||||
@@ -43,7 +43,7 @@ impl fmt::Display for BVHNode {
|
||||
|
||||
// Lint is wrong when dealing with Box<Trait>
|
||||
#[allow(clippy::borrowed_box)]
|
||||
fn box_x_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
|
||||
fn box_x_compare(ah: &Box<dyn Hit>, bh: &Box<dyn Hit>) -> std::cmp::Ordering {
|
||||
match (ah.bounding_box(0., 0.), bh.bounding_box(0., 0.)) {
|
||||
(Some(box_left), Some(box_right)) => {
|
||||
box_left.min().x.partial_cmp(&box_right.min().x).unwrap()
|
||||
@@ -53,7 +53,7 @@ fn box_x_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
|
||||
}
|
||||
|
||||
#[allow(clippy::borrowed_box)]
|
||||
fn box_y_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
|
||||
fn box_y_compare(ah: &Box<dyn Hit>, bh: &Box<dyn Hit>) -> std::cmp::Ordering {
|
||||
match (ah.bounding_box(0., 0.), bh.bounding_box(0., 0.)) {
|
||||
(Some(box_left), Some(box_right)) => {
|
||||
box_left.min().y.partial_cmp(&box_right.min().y).unwrap()
|
||||
@@ -63,7 +63,7 @@ fn box_y_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
|
||||
}
|
||||
|
||||
#[allow(clippy::borrowed_box)]
|
||||
fn box_z_compare(ah: &Box<Hit>, bh: &Box<Hit>) -> std::cmp::Ordering {
|
||||
fn box_z_compare(ah: &Box<dyn Hit>, bh: &Box<dyn Hit>) -> std::cmp::Ordering {
|
||||
match (ah.bounding_box(0., 0.), bh.bounding_box(0., 0.)) {
|
||||
(Some(box_left), Some(box_right)) => {
|
||||
box_left.min().z.partial_cmp(&box_right.min().z).unwrap()
|
||||
@@ -99,11 +99,11 @@ 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 {
|
||||
fn new(l: Vec<Box<dyn Hit>>, t_min: f32, t_max: f32) -> BVHNode {
|
||||
if l.len() == 1 {
|
||||
BVHNode::Leaf(vec_first_into(l))
|
||||
} else {
|
||||
let mut l: Vec<Box<Hit>> = l.into_iter().collect();
|
||||
let mut l: Vec<Box<dyn Hit>> = l.into_iter().collect();
|
||||
let mut rng = rand::thread_rng();
|
||||
match rng.gen_range::<u16>(0, 3) {
|
||||
0 => l.sort_by(box_x_compare),
|
||||
@@ -121,7 +121,7 @@ impl BVHNode {
|
||||
}
|
||||
}
|
||||
|
||||
fn surrounding_box(left: &Hit, right: &Hit, t_min: f32, t_max: f32) -> Option<AABB> {
|
||||
fn surrounding_box(left: &dyn Hit, right: &dyn Hit, t_min: f32, t_max: f32) -> Option<AABB> {
|
||||
match (
|
||||
left.bounding_box(t_min, t_max),
|
||||
right.bounding_box(t_min, t_max),
|
||||
@@ -185,7 +185,7 @@ pub struct BVH {
|
||||
}
|
||||
|
||||
impl BVH {
|
||||
pub fn new(l: Vec<Box<Hit>>, t_min: f32, t_max: f32) -> BVH {
|
||||
pub fn new(l: Vec<Box<dyn Hit>>, t_min: f32, t_max: f32) -> BVH {
|
||||
let count = l.len();
|
||||
let start = Instant::now();
|
||||
let bvh = BVH {
|
||||
|
||||
Reference in New Issue
Block a user