SHARE
TWEET

Untitled

a guest Mar 20th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pub struct Intersection<'a> {
  2.     pub distance: f64,
  3.     pub object: &'a Sphere,
  4. }
  5. impl<'a> Intersection<'a> {
  6.     pub fn new<'b>(distance: f64, object: &'b Sphere) -> Intersection<'b> {
  7.         // Elided
  8.     }
  9. }
  10. impl Scene {
  11.     pub fn trace(&self, ray: &Ray) -> Option<Intersection> {
  12.         self.spheres
  13.             .iter()
  14.             .filter_map(|s| s.intersect(ray).map(|d| Intersection::new(d, s)))
  15.             .min_by(|i1, i2| i1.distance.partial_cmp(&i2.distance).unwrap())
  16.     }
  17. }
RAW Paste Data
Top