diff options
author | Julian T <julian@jtle.dk> | 2021-02-21 18:01:56 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-21 18:01:56 +0100 |
commit | da1c3949a449f3fafe579c62ff6b14ffd993a197 (patch) | |
tree | 754df5c9b5e9f0fa0a8bb7a8cd3dd4b12fe5ad89 /src/world/shapes/sphere.rs | |
parent | c695da871a75bb6786c08c3546ef71ed032bd61d (diff) |
Add 3d bounding box and merged SceneIntersection and Intersection
Diffstat (limited to 'src/world/shapes/sphere.rs')
-rw-r--r-- | src/world/shapes/sphere.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/world/shapes/sphere.rs b/src/world/shapes/sphere.rs index 8e0816b..55fc8b4 100644 --- a/src/world/shapes/sphere.rs +++ b/src/world/shapes/sphere.rs @@ -2,7 +2,8 @@ //! //! Spheres are relatively easy to calculate intersections between use crate::Float; -use crate::core::{Ray, Vector3f, Hittable, Intersection}; +use crate::core::{Ray, Vector3f, Bound3f}; +use crate::world::{Hittable, Intersection}; pub struct Sphere { radius: Float, @@ -45,10 +46,31 @@ impl Hittable for Sphere { n: self.norm_at(&w), p: w, t: distance, + m: None, }) } } + + /// Box containing the circle + /// + /// # Examples + /// + /// ``` + /// use rendering::core::{Vector3f, Hittable}; + /// use rendering::world::shapes::Sphere; + /// + /// let sph = Sphere::new(1.0, Vector3f::new(0.0)); + /// let b = sph.bounding_box().unwrap(); + /// + /// assert!(b.min.x == -1.0 && b.min.y == -1.0 && b.min.z == -1.0); + /// assert!(b.max.x == 1.0 && b.max.y == 1.0 && b.max.z == 1.0); + fn bounding_box(&self) -> Option<Bound3f> { + let offset = Vector3f::new(self.radius); + Some( + Bound3f::new(self.center - offset, self.center + offset) + ) + } } #[cfg(test)] |