Skip to content

Commit 6c50abc

Browse files
author
Peter Aarestad
committed
Rust 2024!
1 parent a16747e commit 6c50abc

File tree

15 files changed

+384
-481
lines changed

15 files changed

+384
-481
lines changed

Cargo.lock

Lines changed: 344 additions & 442 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
name = "ray-tracer"
33
version = "1.7.3"
44
authors = ["Peter Aarestad <aarestad@gmail.com>"]
5-
edition = "2021"
5+
edition = "2024"
66
description = "Trace some rays"
77
default-run = "ray-tracer"
88

99
[dependencies]
10-
rand = "0.8.5"
11-
rand_distr = "0.4.3"
12-
image = "0.25.1"
10+
rand = "0.9.0"
11+
rand_distr = "0.5.1"
12+
image = "0.25.5"
1313
threadpool = "1.8.1"
1414
num_cpus = "1.16.0"
1515
args = "2.2.0"
1616
getopts = "0.2.21"
1717
array-init = "2.1.0"
18-
nalgebra = "0.33.0"
19-
parry3d = "0.17.0"
18+
nalgebra = "0.33.2"
2019
approx = "0.5.1"
20+
#parry3d = "0.18.0"
2121

2222
[[bin]]
2323
name = "ppm_test"

src/camera.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Camera {
5959
direction: self.lower_left_corner + self.horizontal * s + self.vertical * t
6060
- self.origin
6161
- offset,
62-
exposure_time: rand::thread_rng().gen_range(self.exposure_time.clone()),
62+
exposure_time: rand::rng().random_range(self.exposure_time.clone()),
6363
}
6464
}
6565
}

src/data/ray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::data::color64::{Color64, BLACK};
1+
use crate::data::color64::{BLACK, Color64};
22
use crate::data::point64::Point64;
33
use crate::hittables::Hittable;
44
use std::ops::Add;

src/data/vector3.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::util::EPSILON;
99
pub type Vector = Vector3<f64>;
1010

1111
pub fn random_in_unit_sphere() -> Vector {
12-
let mut rng = rand::thread_rng();
12+
let mut rng = rand::rng();
1313

14-
let theta = TAU * rng.gen::<f64>();
15-
let phi = (1.0 - 2.0 * rng.gen::<f64>()).acos();
14+
let theta = TAU * rng.random::<f64>();
15+
let phi = (1.0 - 2.0 * rng.random::<f64>()).acos();
1616
let x = phi.sin() * theta.cos();
1717
let y = phi.sin() * theta.sin();
1818
let z = phi.cos();
@@ -21,18 +21,18 @@ pub fn random_in_unit_sphere() -> Vector {
2121
}
2222

2323
pub fn random_in_unit_disk() -> Vector {
24-
let mut rng = rand::thread_rng();
24+
let mut rng = rand::rng();
2525

26-
let sqrt_r: f64 = rng.gen::<f64>().sqrt();
27-
let theta: f64 = rng.gen_range(0.0..TAU);
26+
let sqrt_r: f64 = rng.random::<f64>().sqrt();
27+
let theta: f64 = rng.random_range(0.0..TAU);
2828

2929
Vector3::new(sqrt_r * theta.cos(), sqrt_r * theta.sin(), 0.)
3030
}
3131

3232
pub fn rand_range(min: f64, max: f64) -> Vector {
33-
let mut rng = rand::thread_rng();
33+
let mut rng = rand::rng();
3434

35-
let dist = Uniform::new_inclusive(min, max);
35+
let dist = Uniform::new_inclusive(min, max).unwrap();
3636

3737
Vector3::new(rng.sample(dist), rng.sample(dist), rng.sample(dist))
3838
}

src/hittables/bounded_volume_hierarchy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::data::ray::Ray;
22
use crate::hittables::axis_aligned_bounding_box::AxisAlignedBoundingBox;
33
use crate::hittables::bvh_comparators::BOX_COMPARATORS;
44
use crate::hittables::{HitRecord, Hittable};
5-
use rand::prelude::SliceRandom;
5+
use rand::prelude::IndexedRandom;
66
use std::sync::Arc;
77

88
pub struct BoundedVolumeHierarchy {
@@ -39,7 +39,7 @@ impl BoundedVolumeHierarchy {
3939
time0: f64,
4040
time1: f64,
4141
) -> Arc<dyn Hittable> {
42-
let comparator = BOX_COMPARATORS.choose(&mut rand::thread_rng()).unwrap();
42+
let comparator = BOX_COMPARATORS.choose(&mut rand::rng()).unwrap();
4343

4444
let left_child: Arc<dyn Hittable>;
4545
let right_child: Arc<dyn Hittable>;

src/hittables/triangle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use super::{axis_aligned_bounding_box::AxisAlignedBoundingBox, HitRecord, Hittable};
3+
use super::{HitRecord, Hittable, axis_aligned_bounding_box::AxisAlignedBoundingBox};
44
use crate::{
55
data::{point64::Point64, ray::Ray, vector3::Vector},
66
materials::Material,

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::sync::mpsc::channel;
21
use std::sync::Arc;
2+
use std::sync::mpsc::channel;
33

44
use image::{ImageResult, RgbImage};
55
use rand::Rng;
@@ -60,10 +60,10 @@ fn main() -> ImageResult<()> {
6060

6161
pool.execute(move || {
6262
let mut pixel_color = Color64::new(0., 0., 0.);
63-
let mut rng = rand::thread_rng();
63+
let mut rng = rand::rng();
6464

6565
for _ in 0..world.samples_per_pixel {
66-
let rands: [f64; 2] = rng.gen();
66+
let rands: [f64; 2] = rng.random();
6767

6868
let u = (x as f64 + rands[0]) / (world.image_width - 1) as f64;
6969
let v = (y as f64 + rands[1]) / (world.image_height - 1) as f64;

src/materials.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::data::color64::{Color64, BLACK};
1+
use crate::data::color64::{BLACK, Color64};
22
use crate::data::point64::Point64;
33
use crate::data::ray::Ray;
44
use crate::hittables::HitRecord;

src/materials/diffuse_light.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::data::point64::Point64;
33
use crate::data::ray::Ray;
44
use crate::hittables::HitRecord;
55
use crate::materials::{Material, ScatterRecord};
6-
use crate::textures::solid_color::SolidColor;
76
use crate::textures::Texture;
7+
use crate::textures::solid_color::SolidColor;
88
use std::sync::Arc;
99

1010
pub struct DiffuseLight {

0 commit comments

Comments
 (0)