From 87bf924094836169d7f7323da759bc29f7d4d492 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Fri, 16 Jul 2021 21:48:12 -0700 Subject: [PATCH] spheres: add transform member to Sphere --- rtchallenge/src/spheres.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/rtchallenge/src/spheres.rs b/rtchallenge/src/spheres.rs index cf16436..07cb282 100644 --- a/rtchallenge/src/spheres.rs +++ b/rtchallenge/src/spheres.rs @@ -1,12 +1,37 @@ use crate::{ intersections::Intersection, + matrices::Matrix4x4, rays::Ray, tuples::{dot, Tuple}, }; -#[derive(Default, Debug, PartialEq)] +#[derive(Debug, PartialEq)] /// Sphere represents the unit-sphere (radius of unit 1.) at the origin 0., 0., 0. -pub struct Sphere {} +pub struct Sphere { + pub transform: Matrix4x4, +} + +impl Default for Sphere { + /// # Examples + /// ``` + /// use rtchallenge::{matrices::Matrix4x4, spheres::Sphere}; + /// + /// // A sphere's default transform is the identity matrix. + /// let s = Sphere::default(); + /// assert_eq!(s.transform, Matrix4x4::identity()); + /// + /// // It can be changed by directly setting the transform member. + /// let mut s = Sphere::default(); + /// let t = Matrix4x4::translate(2., 3., 4.); + /// s.transform = t.clone(); + /// assert_eq!(s.transform, t); + /// ``` + fn default() -> Sphere { + Sphere { + transform: Matrix4x4::identity(), + } + } +} /// Intersect a ray with a sphere. ///