diff --git a/assignment-1b/Cargo.lock b/assignment-1b/Cargo.lock
index e61aaab..4d21e1b 100644
--- a/assignment-1b/Cargo.lock
+++ b/assignment-1b/Cargo.lock
@@ -28,6 +28,7 @@ dependencies = [
"num",
"ordered-float",
"rayon",
+ "tracing",
]
[[package]]
@@ -388,6 +389,12 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba"
+[[package]]
+name = "pin-project-lite"
+version = "0.2.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
+
[[package]]
name = "proc-macro-error"
version = "1.0.4"
@@ -532,6 +539,38 @@ dependencies = [
"winapi-util",
]
+[[package]]
+name = "tracing"
+version = "0.1.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
+dependencies = [
+ "cfg-if",
+ "pin-project-lite",
+ "tracing-attributes",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-attributes"
+version = "0.1.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "tracing-core"
+version = "0.1.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
+dependencies = [
+ "once_cell",
+]
+
[[package]]
name = "typenum"
version = "1.16.0"
diff --git a/assignment-1b/Cargo.toml b/assignment-1b/Cargo.toml
index 78b50df..6adca8d 100644
--- a/assignment-1b/Cargo.toml
+++ b/assignment-1b/Cargo.toml
@@ -16,3 +16,4 @@ nalgebra = "0.32.1"
num = { version = "0.4.0", features = ["serde"] }
ordered-float = "3.4.0"
rayon = "1.6.1"
+tracing = "0.1.37"
diff --git a/assignment-1b/examples/objects.txt b/assignment-1b/examples/objects.txt
index f7ba514..cabaccf 100644
--- a/assignment-1b/examples/objects.txt
+++ b/assignment-1b/examples/objects.txt
@@ -5,7 +5,7 @@ hfov 60
updir 0 1 0
bkgcolor 0.1 0.1 0.1
-depthcueing 0.1 0.1 0.1 1 0.2 100 5
+depthcueing 0.1 0.1 0.1 1 0.2 100 0
light -10 10 -3 0 0.8 0.8 0.8
light -10 10 -3 1 0.8 0.8 0.8
diff --git a/assignment-1b/src/lib.rs b/assignment-1b/src/lib.rs
index a9d997a..8fe737c 100644
--- a/assignment-1b/src/lib.rs
+++ b/assignment-1b/src/lib.rs
@@ -4,6 +4,8 @@
extern crate anyhow;
#[macro_use]
extern crate derivative;
+#[macro_use]
+extern crate tracing;
pub mod image;
pub mod ray;
diff --git a/assignment-1b/src/main.rs b/assignment-1b/src/main.rs
index ff8c9b9..bd2a51b 100644
--- a/assignment-1b/src/main.rs
+++ b/assignment-1b/src/main.rs
@@ -98,12 +98,13 @@ fn main() -> Result<()> {
let intersections = scene
.objects
.iter()
- .filter_map(|object| {
+ .enumerate()
+ .filter_map(|(i, object)| {
match object.kind.intersects_ray_at(&ray) {
Ok(Some(t)) => {
// Return both the t and the sphere, because we want to sort on
// the t but later retrieve attributes from the sphere
- Some(Ok((t, object)))
+ Some(Ok((i, t, object)))
}
Ok(None) => None,
Err(e) => Some(Err(e)),
@@ -113,13 +114,12 @@ fn main() -> Result<()> {
// Sort the list of intersection times by the lowest one.
let earliest_intersection =
- intersections.into_iter().min_by_key(|(t, _)| t.time);
+ intersections.into_iter().min_by_key(|(_, t, _)| t.time);
Ok(match earliest_intersection {
// Take the object's material color
- Some((intersection_context, object)) => {
- scene.compute_pixel_color(object.material, intersection_context)
- }
+ Some((obj_idx, intersection_context, object)) => scene
+ .compute_pixel_color(obj_idx, object.material, intersection_context),
// There was no intersection, so this should default to the scene's
// background color
diff --git a/assignment-1b/src/scene/cylinder.rs b/assignment-1b/src/scene/cylinder.rs
index 632fc30..5e1b6ea 100644
--- a/assignment-1b/src/scene/cylinder.rs
+++ b/assignment-1b/src/scene/cylinder.rs
@@ -15,12 +15,12 @@ pub struct Cylinder {
pub length: f64,
}
-impl ObjectKind for Cylinder {
+impl Cylinder {
/// Given a cylinder, returns the first time at which this ray intersects the
/// cylinder.
///
/// If there is no intersection point, returns None.
- fn intersects_ray_at(
+ pub fn intersects_ray_at(
&self,
ray: &Ray,
) -> Result