From e694cc8863360d1a87b3e0e0d41d235094bd21f8 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 31 Jan 2023 14:41:23 -0600 Subject: [PATCH] Wrap comments --- assignment-1/src/input_file.rs | 2 +- assignment-1/src/main.rs | 18 +++++++++++------- assignment-1/src/ray.rs | 7 ++++--- flake.nix | 9 ++++++++- rustfmt.toml | 1 + 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/assignment-1/src/input_file.rs b/assignment-1/src/input_file.rs index 7eb1312..d9ff82c 100644 --- a/assignment-1/src/input_file.rs +++ b/assignment-1/src/input_file.rs @@ -59,7 +59,7 @@ pub fn parse_input_file(path: impl AsRef) -> Result { let idx = scene.material_colors.len(); material_color = Some(idx); scene.material_colors.push(read_vec3()?); - }, + } "sphere" => scene.objects.push(Object::Sphere(Sphere { center: read_vec3()?, diff --git a/assignment-1/src/main.rs b/assignment-1/src/main.rs index 32fc938..be49e50 100644 --- a/assignment-1/src/main.rs +++ b/assignment-1/src/main.rs @@ -35,8 +35,8 @@ struct Opt { /// /// imsize [width] [height] /// - /// Where `imsize' is a keyword, and `width' and `height' are integer values denoting the desired - /// size of the image to be generated. + /// Where `imsize' is a keyword, and `width' and `height' are integer values + /// denoting the desired size of the image to be generated. #[clap()] input_path: PathBuf, @@ -59,8 +59,8 @@ fn main() -> Result<()> { // Compute dimensions of viewing window based on field of view let viewing_width = { - // Divide the angle in 2 since we are trying to use trig rules so we must get it from a right - // triangle + // Divide the angle in 2 since we are trying to use trig rules so we must + // get it from a right triangle let half_hfov = scene.hfov / 2.0; // tan(hfov / 2) = w / 2d @@ -101,7 +101,9 @@ fn main() -> Result<()> { // Loop through every single pixel of the output file let mut pixels = vec![Pixel::default(); scene.image_width * scene.image_width]; - for (px, py) in (0..scene.image_width).cartesian_product(0..scene.image_height) { + for (px, py) in + (0..scene.image_width).cartesian_product(0..scene.image_height) + { let pixel_in_space = pixel_translation(px, py); let ray = Ray::from_endpoints(scene.eye_pos, pixel_in_space); @@ -111,7 +113,8 @@ fn main() -> Result<()> { .filter_map(|object| { let sphere = match object { Object::Sphere(v) => v, - _ => return None, // TODO: Handle other object types for intersection as well + _ => return None, /* TODO: Handle other object types for + * intersection as well */ }; ray.intersects_at(sphere).map(|t| (t, sphere)) @@ -120,7 +123,8 @@ fn main() -> Result<()> { let pixel_color = match earliest_intersection { Some((_, sphere)) => scene.material_colors[sphere.material], - // There was no intersection, so this should default to the background color + // There was no intersection, so this should default to the background + // color None => scene.bkg_color, }; diff --git a/assignment-1/src/ray.rs b/assignment-1/src/ray.rs index 64b1d65..f2cf85d 100644 --- a/assignment-1/src/ray.rs +++ b/assignment-1/src/ray.rs @@ -3,8 +3,8 @@ use crate::vec3::Vec3; /// A normalized parametric Ray of the form (origin + direction * time) /// -/// That means at any time t: f64, the point represented by origin + direction * time occurs on the -/// ray. +/// That means at any time t: f64, the point represented by origin + direction * +/// time occurs on the ray. #[derive(Debug)] pub struct Ray { origin: Vec3, @@ -26,7 +26,8 @@ impl Ray { self.origin + self.direction * time } - /// Given a sphere, returns the first time at which this ray intersects the sphere. + /// Given a sphere, returns the first time at which this ray intersects the + /// sphere. /// /// If there is no intersection point, returns None. pub fn intersects_at(&self, sphere: &Sphere) -> Option { diff --git a/flake.nix b/flake.nix index 78974e9..9bbd77b 100644 --- a/flake.nix +++ b/flake.nix @@ -14,7 +14,14 @@ devShell = pkgs.mkShell { packages = (with pkgs; [ cargo-watch cargo-deny cargo-edit zip unzip ]) - ++ (with toolchain; [ cargo rustc rustfmt clippy ]); + ++ (with toolchain; [ + cargo + rustc + clippy + + # Get the nightly version of rustfmt so we can wrap comments + pkgs.fenix.default.rustfmt + ]); CARGO_UNSTABLE_SPARSE_REGISTRY = "true"; }; }); diff --git a/rustfmt.toml b/rustfmt.toml index 4c1eefa..a3be6a8 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,3 @@ max_width = 80 tab_spaces = 2 +wrap_comments = true