diff --git a/rtchallenge/Cargo.toml b/rtchallenge/Cargo.toml index c7586a1..1cebed8 100644 --- a/rtchallenge/Cargo.toml +++ b/rtchallenge/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" [features] default = [ "float-as-double" ] -disable-inverse-cache = [] float-as-double = [] [dependencies] diff --git a/rtchallenge/src/camera.rs b/rtchallenge/src/camera.rs index b0342f1..12e1378 100644 --- a/rtchallenge/src/camera.rs +++ b/rtchallenge/src/camera.rs @@ -235,18 +235,17 @@ impl Camera { /// Tuple::vector((2. as Float).sqrt() / 2., 0., -(2. as Float).sqrt() / 2.) /// ); /// ``` - #[cfg(not(feature = "disable-inverse-cache"))] pub fn ray_for_pixel(&self, px: usize, py: usize) -> Ray { // The offset from the edge of the canvas to the pixel's corner. let xoffset = (px as Float + 0.5) * self.pixel_size; let yoffset = (py as Float + 0.5) * self.pixel_size; - // The untransformed coordinates of the pixle in world space. + // The untransformed coordinates of the pixel in world space. // (Remember that the camera looks toward -z, so +x is to the left.) let world_x = self.half_width - xoffset; let world_y = self.half_height - yoffset; - // Using the camera matrix, transofmrm the canvas point and the origin, + // Using the camera matrix, transform the canvas point and the origin, // and then compute the ray's direction vector. // (Remember that the canvas is at z>=-1). let pixel = self.inverse_transform * Tuple::point(world_x, world_y, -1.); @@ -255,26 +254,6 @@ impl Camera { Ray::new(origin, direction) } - #[cfg(feature = "disable-inverse-cache")] - pub fn ray_for_pixel(&self, px: usize, py: usize) -> Ray { - // The offset from the edge of the canvas to the pixel's corner. - let xoffset = (px as Float + 0.5) * self.pixel_size; - let yoffset = (py as Float + 0.5) * self.pixel_size; - - // The untransformed coordinates of the pixle in world space. - // (Remember that the camera looks toward -z, so +x is to the left.) - let world_x = self.half_width - xoffset; - let world_y = self.half_height - yoffset; - - // Using the camera matrix, transofmrm the canvas point and the origin, - // and then compute the ray's direction vector. - // (Remember that the canvas is at z>=-1). - let pixel = self.transform.inverse() * Tuple::point(world_x, world_y, -1.); - let origin = self.transform.inverse() * Tuple::point(0., 0., 0.); - let direction = (pixel - origin).normalize(); - - Ray::new(origin, direction) - } /// Use camera to render an image of the given world. /// # Examples diff --git a/rtchallenge/src/shapes.rs b/rtchallenge/src/shapes.rs index f2b02bd..a831907 100644 --- a/rtchallenge/src/shapes.rs +++ b/rtchallenge/src/shapes.rs @@ -318,7 +318,6 @@ impl Shape { /// Tuple::vector(0., 1., 0.) /// ); /// ``` - #[cfg(not(feature = "disable-inverse-cache"))] pub fn normal_at(&self, world_point: Tuple) -> Tuple { let object_point = self.inverse_transform * world_point; let object_normal = match self.geometry { @@ -330,18 +329,6 @@ impl Shape { world_normal.w = 0.; world_normal.normalize() } - #[cfg(feature = "disable-inverse-cache")] - pub fn normal_at(&self, world_point: Tuple) -> Tuple { - let object_point = self.transform.inverse() * world_point; - let object_normal = match self.geometry { - Geometry::Sphere => object_point - Tuple::point(0., 0., 0.), - Geometry::Plane => Tuple::vector(0., 1., 0.), - Geometry::TestShape(_) => todo!("test shape normal"), - }; - let mut world_normal = self.transform.inverse().transpose() * object_normal; - world_normal.w = 0.; - world_normal.normalize() - } pub fn transform(&self) -> Matrix4x4 { self.transform