Wrap comments

This commit is contained in:
Michael Zhang 2023-01-31 14:41:23 -06:00
parent 0000010056
commit 0000011089
5 changed files with 25 additions and 12 deletions

View file

@ -59,7 +59,7 @@ pub fn parse_input_file(path: impl AsRef<Path>) -> Result<Scene> {
let idx = scene.material_colors.len(); let idx = scene.material_colors.len();
material_color = Some(idx); material_color = Some(idx);
scene.material_colors.push(read_vec3()?); scene.material_colors.push(read_vec3()?);
}, }
"sphere" => scene.objects.push(Object::Sphere(Sphere { "sphere" => scene.objects.push(Object::Sphere(Sphere {
center: read_vec3()?, center: read_vec3()?,

View file

@ -35,8 +35,8 @@ struct Opt {
/// ///
/// imsize [width] [height] /// imsize [width] [height]
/// ///
/// Where `imsize' is a keyword, and `width' and `height' are integer values denoting the desired /// Where `imsize' is a keyword, and `width' and `height' are integer values
/// size of the image to be generated. /// denoting the desired size of the image to be generated.
#[clap()] #[clap()]
input_path: PathBuf, input_path: PathBuf,
@ -59,8 +59,8 @@ fn main() -> Result<()> {
// Compute dimensions of viewing window based on field of view // Compute dimensions of viewing window based on field of view
let viewing_width = { let viewing_width = {
// Divide the angle in 2 since we are trying to use trig rules so we must get it from a right // Divide the angle in 2 since we are trying to use trig rules so we must
// triangle // get it from a right triangle
let half_hfov = scene.hfov / 2.0; let half_hfov = scene.hfov / 2.0;
// tan(hfov / 2) = w / 2d // tan(hfov / 2) = w / 2d
@ -101,7 +101,9 @@ fn main() -> Result<()> {
// Loop through every single pixel of the output file // Loop through every single pixel of the output file
let mut pixels = let mut pixels =
vec![Pixel::default(); scene.image_width * scene.image_width]; 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 pixel_in_space = pixel_translation(px, py);
let ray = Ray::from_endpoints(scene.eye_pos, pixel_in_space); let ray = Ray::from_endpoints(scene.eye_pos, pixel_in_space);
@ -111,7 +113,8 @@ fn main() -> Result<()> {
.filter_map(|object| { .filter_map(|object| {
let sphere = match object { let sphere = match object {
Object::Sphere(v) => v, 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)) ray.intersects_at(sphere).map(|t| (t, sphere))
@ -120,7 +123,8 @@ fn main() -> Result<()> {
let pixel_color = match earliest_intersection { let pixel_color = match earliest_intersection {
Some((_, sphere)) => scene.material_colors[sphere.material], 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, None => scene.bkg_color,
}; };

View file

@ -3,8 +3,8 @@ use crate::vec3::Vec3;
/// A normalized parametric Ray of the form (origin + direction * time) /// 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 /// That means at any time t: f64, the point represented by origin + direction *
/// ray. /// time occurs on the ray.
#[derive(Debug)] #[derive(Debug)]
pub struct Ray { pub struct Ray {
origin: Vec3, origin: Vec3,
@ -26,7 +26,8 @@ impl Ray {
self.origin + self.direction * time 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. /// If there is no intersection point, returns None.
pub fn intersects_at(&self, sphere: &Sphere) -> Option<f64> { pub fn intersects_at(&self, sphere: &Sphere) -> Option<f64> {

View file

@ -14,7 +14,14 @@
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
packages = packages =
(with pkgs; [ cargo-watch cargo-deny cargo-edit zip unzip ]) (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"; CARGO_UNSTABLE_SPARSE_REGISTRY = "true";
}; };
}); });

View file

@ -1,2 +1,3 @@
max_width = 80 max_width = 80
tab_spaces = 2 tab_spaces = 2
wrap_comments = true