Skip to content

Commit

Permalink
Add dyn keyword to trait usage
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wicks committed Jun 15, 2020
1 parent 648d5ea commit 9de8797
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion README.md
@@ -1,6 +1,11 @@
# Path Tracer

A simple path tracer implemented in Rust following [Ray Tracing in One Weekend](https://github.com/petershirley/raytracinginoneweekend). This is a learning project for both Rust and ray tracing.
A simple path tracer implemented in Rust following the C++ book [Ray Tracing in One Weekend](https://github.com/petershirley/raytracinginoneweekend). This is a learning project for both Rust and ray tracing.

Scene output (fewer pixels and more samples than the end-of-book code):
![mapped-image](https://user-images.githubusercontent.com/81553/51091108-eac4c800-1753-11e9-8ed0-08aa7495bef9.png)

## Building and running

Run in release mode to avoid having your render take all day:
`cargo run --release`
2 changes: 1 addition & 1 deletion path_tracing/src/hitable.rs
Expand Up @@ -8,7 +8,7 @@ pub struct HitRecord<'a> {
pub t: f64,
pub p: Vec3,
pub normal: Vec3,
pub material: &'a Scattering,
pub material: &'a dyn Scattering,
}

impl<'a> HitRecord<'a> {
Expand Down
11 changes: 0 additions & 11 deletions path_tracing/src/lib.rs
Expand Up @@ -81,14 +81,3 @@ pub fn trace_scene(

colors
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn mapping_a_collection() {
let columns = 4;
let rows = 2;
}
}
2 changes: 1 addition & 1 deletion path_tracing/src/sphere.rs
Expand Up @@ -5,7 +5,7 @@ use super::{HitRecord, Hitable, Scattering};
pub struct Sphere {
pub center: Vec3,
pub radius: f64,
pub material: Box<Scattering + Sync>, // for testability, would be easier not to complect with materials
pub material: Box<dyn Scattering + Sync>, // for testability, would be easier not to complect with materials
}

impl Hitable for Sphere {
Expand Down
4 changes: 2 additions & 2 deletions path_tracing/src/world.rs
@@ -1,7 +1,7 @@
use super::hitable::*;
use super::Ray;

pub struct World(Vec<Box<Hitable + Sync>>);
pub struct World(Vec<Box<dyn Hitable + Sync>>);

impl Hitable for World {
fn hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord> {
Expand All @@ -22,7 +22,7 @@ impl World {
World(vec![])
}

pub fn push(&mut self, item: Box<Hitable + Sync>) {
pub fn push(&mut self, item: Box<dyn Hitable + Sync>) {
self.0.push(item);
}
}

0 comments on commit 9de8797

Please sign in to comment.