1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Defines the Intersection type which stores information about
//! a full intersection, eg. hit info about the geometry and instance
//! that was intersected

use geometry::{Instance, DifferentialGeometry};
use material::Material;

/// Stores information about an intersection that occured with some instance
/// of geometry in the scene
#[derive(Clone, Copy)]
pub struct Intersection<'a, 'b> {
    /// The differential geometry holding information about the piece of geometry
    /// that was hit
    pub dg: DifferentialGeometry<'a>,
    /// The instance of geometry that was hit
    pub instance: &'b Instance,
    /// The material of the instance that was hit
    pub material: &'b Material,
}

impl<'a, 'b> Intersection<'a, 'b> {
    /// Construct the Intersection from a potential hit stored in a
    /// Option<DifferentialGeometry>. Returns None if `dg` is None
    /// or if the instance member of `dg` is None
    pub fn new(dg: DifferentialGeometry<'a>, inst: &'b Instance, mat: &'b Material)
        -> Intersection<'a, 'b> {
        Intersection { dg: dg, instance: inst, material: mat }
    }
}