@@ -4,17 +4,17 @@ use crate::{float::Fl, vec3::{Pos3, Vec3}};
44pub struct Ray {
55 origin : Pos3 ,
66 direction : Vec3 ,
7- pixel_x : usize ,
8- pixel_y : usize ,
7+ time : Fl ,
8+ pixel : Option < ( usize , usize ) > ,
99}
1010
1111impl Ray {
12- pub const fn new ( origin : Pos3 , direction : Vec3 , pixel_x : usize , pixel_y : usize ) -> Self {
12+ pub const fn new ( origin : Pos3 , direction : Vec3 ) -> Self {
1313 Self {
1414 origin,
1515 direction,
16- pixel_x ,
17- pixel_y ,
16+ time : 0. ,
17+ pixel : None ,
1818 }
1919 }
2020
@@ -26,16 +26,50 @@ impl Ray {
2626 & self . direction
2727 }
2828
29- pub const fn pixel_x ( & self ) -> usize {
30- self . pixel_x
29+ pub const fn at_time ( & self , time : Fl ) -> Self {
30+ Self {
31+ direction : self . direction ,
32+ origin : self . origin ,
33+ time,
34+ pixel : self . pixel ,
35+ }
36+ }
37+
38+ pub const fn at_time_of ( & self , other : & Self ) -> Self {
39+ self . at_time ( other. time )
40+ }
41+
42+ pub fn at_time_mut ( & mut self , time : Fl ) {
43+ self . time = time;
44+ }
45+
46+ pub const fn time ( & self ) -> Fl {
47+ self . time
48+ }
49+
50+ pub const fn for_pixel ( & self , pixel : ( usize , usize ) ) -> Self {
51+ Self {
52+ direction : self . direction ,
53+ origin : self . origin ,
54+ time : self . time ,
55+ pixel : Some ( pixel) ,
56+ }
57+ }
58+
59+ pub const fn for_pixel_of ( & self , other : & Self ) -> Self {
60+ if let Some ( p) = other. pixel {
61+ self . for_pixel ( p)
62+ } else {
63+ * self
64+ }
3165 }
3266
33- pub const fn pixel_y ( & self ) -> usize {
34- self . pixel_y
67+ pub fn for_pixel_mut ( & mut self , pixel : ( usize , usize ) ) {
68+ self . pixel = Some ( pixel ) ;
3569 }
3670
37- pub const fn is_pixel_at ( & self , x : usize , y : usize ) -> bool {
38- self . pixel_x == x && self . pixel_y == y
71+ pub const fn pixel ( & self ) -> Option < ( usize , usize ) > {
72+ self . pixel
3973 }
4074
4175 pub fn at ( & self , t : Fl ) -> Pos3 {
0 commit comments