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
31
32
33
34
35
36
//! Hit implementation.

use crate::{access, clone, geom::Side};

/// Hit collision information.
#[derive(Clone)]
pub struct Hit<T> {
    /// Hit tag.
    tag: T,
    /// Distance to the hit.
    dist: f64,
    /// Normal of the surface.
    side: Side,
}

impl<T> Hit<T> {
    access!(tag, T);
    clone!(dist, dist_mut, f64);
    access!(side, Side);

    /// Construct a new instance.
    #[inline]
    #[must_use]
    pub fn new(tag: T, dist: f64, side: Side) -> Self {
        debug_assert!(dist > 0.0);

        Self { tag, dist, side }
    }

    /// Flip the contained side.
    #[inline]
    pub fn flip_side(&mut self) {
        let s = self.side.clone().flip();
        self.side = s;
    }
}