summaryrefslogtreecommitdiff
path: root/src/calculus.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/calculus.rs')
-rw-r--r--src/calculus.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/calculus.rs b/src/calculus.rs
index c9b0574..a39c8a5 100644
--- a/src/calculus.rs
+++ b/src/calculus.rs
@@ -1,4 +1,6 @@
pub mod calculus {
+ use rand::Rng;
+
#[derive(Copy, Clone, Debug)]
pub struct Vec3 {
pub x: f32,
@@ -68,12 +70,12 @@ pub mod calculus {
}
}
- pub struct Ray<'a> {
- pub origin: &'a Point3,
- pub direction: &'a Vec3,
+ pub struct Ray {
+ pub origin: Point3,
+ pub direction: Vec3,
}
- impl<'a> Ray<'a> {
+ impl Ray {
pub fn at(&self, t: f32) -> Point3 {
// Get parametric location
self.origin.add(&self.direction.scalar_mul(t))
@@ -84,4 +86,13 @@ pub mod calculus {
deg * std::f32::consts::PI / 180.0
}
+ pub fn sample_square() -> Vec3 {
+ // Returns the vector to a random point in the [-.5,-.5]-[+.5,+.5] unit square.
+ let mut rng = rand::rng();
+ Vec3::new(
+ rng.random_range(0.0..1.0) - 0.5,
+ rng.random_range(0.0..1.0) - 0.5,
+ 0.0)
+ }
+
} \ No newline at end of file