stocking

git clone https://git.bradleygannon.com/stocking.git
Log | Files | Refs

ray.rs (489B)


      1 use crate::vec3::Vec3;
      2 
      3 #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd)]
      4 pub struct Ray {
      5     origin: Vec3,
      6     direction: Vec3,
      7 }
      8 
      9 impl Ray {
     10     pub const fn new(origin: Vec3, direction: Vec3) -> Self {
     11         Ray { origin, direction }
     12     }
     13 
     14     pub const fn origin(&self) -> Vec3 {
     15         self.origin
     16     }
     17 
     18     pub const fn direction(&self) -> Vec3 {
     19         self.direction
     20     }
     21 
     22     pub fn at(&self, t: f64) -> Vec3 {
     23         self.origin + t * self.direction
     24     }
     25 }