From 9bd29660ffb5de2c1a5ed59c7800b3e1644bb7e9 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Wed, 12 Sep 2018 20:11:11 -0700 Subject: [PATCH] Move Opt from library to CLI. --- rtiow/src/bin/tracer.rs | 21 ++++++++++++++++++++- rtiow/src/lib.rs | 2 -- rtiow/src/renderer.rs | 19 ------------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/rtiow/src/bin/tracer.rs b/rtiow/src/bin/tracer.rs index 4d46874..bc4b09a 100644 --- a/rtiow/src/bin/tracer.rs +++ b/rtiow/src/bin/tracer.rs @@ -1,7 +1,9 @@ extern crate rand; extern crate rtiow; +#[macro_use] extern crate structopt; +use std::path::PathBuf; use std::time::Instant; use rand::Rng; @@ -14,7 +16,6 @@ use rtiow::material::Dielectric; use rtiow::material::Lambertian; use rtiow::material::Metal; use rtiow::renderer::render; -use rtiow::renderer::Opt; use rtiow::renderer::Scene; use rtiow::sphere::Sphere; use rtiow::vec3::Vec3; @@ -159,6 +160,24 @@ fn build_scene(opt: &Opt) -> Scene { } } +#[derive(Debug, StructOpt)] +#[structopt(name = "tracert", about = "An experimental ray tracer.")] +pub struct Opt { + /// Image width + #[structopt(short = "w", long = "width", default_value = "1280")] + pub width: usize, + /// Image height + #[structopt(short = "h", long = "height", default_value = "720")] + pub height: usize, + /// Sub-samples per pixel + #[structopt(short = "s", long = "subsample", default_value = "10")] + pub subsamples: usize, + + /// Output file + #[structopt(parse(from_os_str))] + pub output: PathBuf, +} + fn main() -> Result<(), std::io::Error> { let start = Instant::now(); let opt = Opt::from_args(); diff --git a/rtiow/src/lib.rs b/rtiow/src/lib.rs index 7745230..9c7ccf1 100644 --- a/rtiow/src/lib.rs +++ b/rtiow/src/lib.rs @@ -10,5 +10,3 @@ pub mod vec3; extern crate image; extern crate rand; extern crate rayon; -#[macro_use] -extern crate structopt; diff --git a/rtiow/src/renderer.rs b/rtiow/src/renderer.rs index 3b8daa6..5ab5240 100644 --- a/rtiow/src/renderer.rs +++ b/rtiow/src/renderer.rs @@ -1,5 +1,4 @@ use std; -use std::path::PathBuf; use image; use image::RgbImage; @@ -13,24 +12,6 @@ use hitable_list::HitableList; use ray::Ray; use vec3::Vec3; -#[derive(Debug, StructOpt)] -#[structopt(name = "tracert", about = "An experimental ray tracer.")] -pub struct Opt { - /// Image width - #[structopt(short = "w", long = "width", default_value = "1280")] - pub width: usize, - /// Image height - #[structopt(short = "h", long = "height", default_value = "720")] - pub height: usize, - /// Sub-samples per pixel - #[structopt(short = "s", long = "subsample", default_value = "10")] - pub subsamples: usize, - - /// Output file - #[structopt(parse(from_os_str))] - pub output: PathBuf, -} - pub struct Scene { pub world: HitableList, pub camera: Camera,