Fixed bug in kdtree that this uncovered. Marked Hit and it's dependencies as needing to implement the Debug trait.
36 lines
978 B
Rust
36 lines
978 B
Rust
use std::{fmt::Debug, sync::Arc};
|
|
|
|
use crate::{aabb::AABB, material::Material, ray::Ray, vec3::Vec3};
|
|
|
|
#[derive(Debug)]
|
|
pub struct HitRecord<'m> {
|
|
pub t: f32,
|
|
pub uv: (f32, f32),
|
|
pub p: Vec3,
|
|
pub normal: Vec3,
|
|
pub material: &'m dyn Material,
|
|
}
|
|
|
|
pub trait Hit: Send + Sync + Debug {
|
|
fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option<HitRecord>;
|
|
fn bounding_box(&self, t_min: f32, t_max: f32) -> Option<AABB>;
|
|
}
|
|
|
|
impl Hit for Arc<dyn Hit> {
|
|
fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
|
|
(**self).hit(r, t_min, t_max)
|
|
}
|
|
fn bounding_box(&self, t_min: f32, t_max: f32) -> Option<AABB> {
|
|
(**self).bounding_box(t_min, t_max)
|
|
}
|
|
}
|
|
|
|
impl Hit for Box<dyn Hit> {
|
|
fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
|
|
(**self).hit(r, t_min, t_max)
|
|
}
|
|
fn bounding_box(&self, t_min: f32, t_max: f32) -> Option<AABB> {
|
|
(**self).bounding_box(t_min, t_max)
|
|
}
|
|
}
|