Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct Intersection<'a> {
- pub distance: f64,
- pub object: &'a Sphere,
- }
- impl<'a> Intersection<'a> {
- pub fn new<'b>(distance: f64, object: &'b Sphere) -> Intersection<'b> {
- // Elided
- }
- }
- impl Scene {
- pub fn trace(&self, ray: &Ray) -> Option<Intersection> {
- self.spheres
- .iter()
- .filter_map(|s| s.intersect(ray).map(|d| Intersection::new(d, s)))
- .min_by(|i1, i2| i1.distance.partial_cmp(&i2.distance).unwrap())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement