vanrijn/src/sampler.rs

24 lines
625 B
Rust

use super::raycasting::{IntersectionInfo, Ray};
use super::scene::Scene;
use crate::Real;
pub struct Sampler<'a, T: Real> {
pub scene: &'a Scene<T>,
}
impl<'a, T: Real> Sampler<'a, T> {
pub fn sample(&self, ray: &Ray<T>) -> Option<IntersectionInfo<T>> {
self.scene
.objects
.iter()
.flat_map(|object| object.intersect(&ray))
.min_by(
|a, b| match PartialOrd::partial_cmp(&a.distance, &b.distance) {
None => std::cmp::Ordering::Less,
Some(ordering) => ordering,
},
)
}
}