diff --git a/.gitignore b/.gitignore
index 27aff38..bc2b56a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/target
*.lock
+*.log
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c21ec0d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,264 @@
+
+
+
+[![Contributors][contributors-shield]][contributors-url]
+[![Forks][forks-shield]][forks-url]
+[![Stargazers][stars-shield]][stars-url]
+[![Issues][issues-shield]][issues-url]
+[![Unlicense License][license-shield]][license-url]
+[![LinkedIn][linkedin-shield]][linkedin-url]
+
+
+
+
+
+
+
+
+
+
+
+ Table of Contents
+
+ -
+ About The Project
+
+
+ -
+ Getting Started
+
+
+ - Usage
+ - Roadmap
+ - Contributing
+ - License
+ - Contact
+ - Acknowledgments
+
+
+
+
+
+
+## About The Project
+
+[![Product Name Screen Shot][product-screenshot]](https://example.com)
+
+There are many great README templates available on GitHub; however, I didn't find one that really suited my needs so I created this enhanced one. I want to create a README template so amazing that it'll be the last one you ever need -- I think this is it.
+
+Here's why:
+* Your time should be focused on creating something amazing. A project that solves a problem and helps others
+* You shouldn't be doing the same tasks over and over like creating a README from scratch
+* You should implement DRY principles to the rest of your life :smile:
+
+Of course, no one template will serve all projects since your needs may be different. So I'll be adding more in the near future. You may also suggest changes by forking this repo and creating a pull request or opening an issue. Thanks to all the people have contributed to expanding this template!
+
+Use the `BLANK_README.md` to get started.
+
+(back to top)
+
+
+
+### Built With
+
+This section should list any major frameworks/libraries used to bootstrap your project. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
+
+* [![Next][Next.js]][Next-url]
+* [![React][React.js]][React-url]
+* [![Vue][Vue.js]][Vue-url]
+* [![Angular][Angular.io]][Angular-url]
+* [![Svelte][Svelte.dev]][Svelte-url]
+* [![Laravel][Laravel.com]][Laravel-url]
+* [![Bootstrap][Bootstrap.com]][Bootstrap-url]
+* [![JQuery][JQuery.com]][JQuery-url]
+
+(back to top)
+
+
+
+
+## Getting Started
+
+This is an example of how you may give instructions on setting up your project locally.
+To get a local copy up and running follow these simple example steps.
+
+### Prerequisites
+
+This is an example of how to list things you need to use the software and how to install them.
+* npm
+ ```sh
+ npm install npm@latest -g
+ ```
+
+### Installation
+
+_Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn't rely on any external dependencies or services._
+
+1. Get a free API Key at [https://example.com](https://example.com)
+2. Clone the repo
+ ```sh
+ git clone https://github.com/github_username/repo_name.git
+ ```
+3. Install NPM packages
+ ```sh
+ npm install
+ ```
+4. Enter your API in `config.js`
+ ```js
+ const API_KEY = 'ENTER YOUR API';
+ ```
+5. Change git remote url to avoid accidental pushes to base project
+ ```sh
+ git remote set-url origin github_username/repo_name
+ git remote -v # confirm the changes
+ ```
+
+(back to top)
+
+
+
+
+## Usage
+
+Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
+
+_For more examples, please refer to the [Documentation](https://example.com)_
+
+(back to top)
+
+
+
+
+## Roadmap
+
+- [x] Add Changelog
+- [x] Add back to top links
+- [ ] Add Additional Templates w/ Examples
+- [ ] Add "components" document to easily copy & paste sections of the readme
+- [ ] Multi-language Support
+ - [ ] Chinese
+ - [ ] Spanish
+
+See the [open issues](https://github.com/othneildrew/Best-README-Template/issues) for a full list of proposed features (and known issues).
+
+(back to top)
+
+
+
+
+## Contributing
+
+Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
+
+If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
+Don't forget to give the project a star! Thanks again!
+
+1. Fork the Project
+2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
+3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
+4. Push to the Branch (`git push origin feature/AmazingFeature`)
+5. Open a Pull Request
+
+### Top contributors:
+
+
+
+
+
+(back to top)
+
+
+
+
+## License
+
+Distributed under the Unlicense License. See `LICENSE.txt` for more information.
+
+(back to top)
+
+
+
+
+## Contact
+
+Your Name - [@your_twitter](https://twitter.com/your_username) - email@example.com
+
+Project Link: [https://github.com/your_username/repo_name](https://github.com/your_username/repo_name)
+
+(back to top)
+
+
+
+
+## Acknowledgments
+
+Use this space to list resources you find helpful and would like to give credit to. I've included a few of my favorites to kick things off!
+
+* [Choose an Open Source License](https://choosealicense.com)
+* [GitHub Emoji Cheat Sheet](https://www.webpagefx.com/tools/emoji-cheat-sheet)
+* [Malven's Flexbox Cheatsheet](https://flexbox.malven.co/)
+* [Malven's Grid Cheatsheet](https://grid.malven.co/)
+* [Img Shields](https://shields.io)
+* [GitHub Pages](https://pages.github.com)
+* [Font Awesome](https://fontawesome.com)
+* [React Icons](https://react-icons.github.io/react-icons/search)
+
+(back to top)
+
+
+
+
+
+[contributors-shield]: https://img.shields.io/github/contributors/othneildrew/Best-README-Template.svg?style=for-the-badge
+[contributors-url]: https://github.com/othneildrew/Best-README-Template/graphs/contributors
+[forks-shield]: https://img.shields.io/github/forks/othneildrew/Best-README-Template.svg?style=for-the-badge
+[forks-url]: https://github.com/othneildrew/Best-README-Template/network/members
+[stars-shield]: https://img.shields.io/github/stars/othneildrew/Best-README-Template.svg?style=for-the-badge
+[stars-url]: https://github.com/othneildrew/Best-README-Template/stargazers
+[issues-shield]: https://img.shields.io/github/issues/othneildrew/Best-README-Template.svg?style=for-the-badge
+[issues-url]: https://github.com/othneildrew/Best-README-Template/issues
+[license-shield]: https://img.shields.io/github/license/othneildrew/Best-README-Template.svg?style=for-the-badge
+[license-url]: https://github.com/othneildrew/Best-README-Template/blob/master/LICENSE.txt
+[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
+[linkedin-url]: https://linkedin.com/in/othneildrew
+[product-screenshot]: images/screenshot.png
+[Next.js]: https://img.shields.io/badge/next.js-000000?style=for-the-badge&logo=nextdotjs&logoColor=white
+[Next-url]: https://nextjs.org/
+[React.js]: https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
+[React-url]: https://reactjs.org/
+[Vue.js]: https://img.shields.io/badge/Vue.js-35495E?style=for-the-badge&logo=vuedotjs&logoColor=4FC08D
+[Vue-url]: https://vuejs.org/
+[Angular.io]: https://img.shields.io/badge/Angular-DD0031?style=for-the-badge&logo=angular&logoColor=white
+[Angular-url]: https://angular.io/
+[Svelte.dev]: https://img.shields.io/badge/Svelte-4A4A55?style=for-the-badge&logo=svelte&logoColor=FF3E00
+[Svelte-url]: https://svelte.dev/
+[Laravel.com]: https://img.shields.io/badge/Laravel-FF2D20?style=for-the-badge&logo=laravel&logoColor=white
+[Laravel-url]: https://laravel.com
+[Bootstrap.com]: https://img.shields.io/badge/Bootstrap-563D7C?style=for-the-badge&logo=bootstrap&logoColor=white
+[Bootstrap-url]: https://getbootstrap.com
+[JQuery.com]: https://img.shields.io/badge/jQuery-0769AD?style=for-the-badge&logo=jquery&logoColor=white
+[JQuery-url]: https://jquery.com
diff --git a/src/core/geometry.rs b/src/core/geometry.rs
index 3fb89e1..9ceba3b 100644
--- a/src/core/geometry.rs
+++ b/src/core/geometry.rs
@@ -1,320 +1,478 @@
+use num_traits::{Num, Bounded, Float as NumFloat};
use std::ops::{Sub, SubAssign, Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Index, IndexMut};
+use std::sync::Arc;
+use std::f32::consts::PI;
+
use crate::core::pbrt::Float;
-use num_traits::{Num, Bounded};
+use crate::core::pbrt;
+use crate::core::medium::Medium;
-pub trait Tuple : Index + IndexMut + Copy {
- fn get(&self, i: usize) -> T;
- fn set(&mut self, i: usize, val: T);
-}
-
-#[derive(Copy, Clone, PartialEq)]
-pub struct Vector2 { pub x: T, pub y: T }
-#[derive(Copy, Clone, PartialEq)]
-pub struct Point2 { pub x: T, pub y: T }
-#[derive(Copy, Clone, PartialEq)]
-pub struct Vector3 { pub x: T, pub y: T, pub z: T }
-#[derive(Copy, Clone, PartialEq)]
-pub struct Normal3 { pub x: T, pub y: T, pub z: T }
-#[derive(Debug, Copy, Clone, PartialEq)]
-pub struct Point3 { pub x: T, pub y: T, pub z : T }
-
-// Using macros to make this more concise
-// This is pretty useful, gotta use it more often
-macro_rules! impl_tuple_core {
- ($Struct:ident, [$($field:ident), +]) => {
- impl $Struct {
- pub fn new($($field: T), +) -> Self { Self { $($field), + }}
-
- pub fn has_nan(&self) -> bool where T: num_traits::Float {
- $(self.$field.is_nan())||+
- }
- }
-
- impl $Struct {
- pub fn dot(self, other: Self) -> T {
- let mut sum = T::zero();
- $( sum = sum + self.$field * other.$field; )+
- sum
- }
-
- pub fn abs_dot(self, other: Self) -> T {
- self.dot(other).abs()
- }
-
- pub fn length_squared(self) -> T {
- self.dot(self)
- }
- }
-
- impl $Struct {
- pub fn length(self) -> T {
- self.length_squared().sqrt()
- }
-
- pub fn normalize(self) -> Self {
- self / self.length()
- }
- }
-
- impl> Neg for $Struct {
- type Output = Self;
- fn neg(self) -> Self { Self::new($(-self.$field),+) }
- }
-
- impl + Copy> Mul for $Struct {
- type Output = Self;
- fn mul(self, s: T) -> Self { Self::new($(self.$field * s),+) }}
-
- impl MulAssign for $Struct {
- fn mul_assign(&mut self, s: T) { $(self.$field *= s;)+ }
- }
-
- impl + Copy> Div for $Struct {
- type Output = Self;
- fn div(self, s: T) -> Self { Self::new($(self.$field / s),+) }
- }
- impl DivAssign for $Struct {
- fn div_assign(&mut self, s: T) { $(self.$field /= s;)+ }
- }
-
- // Indexing
- impl Index for $Struct {
- type Output = T;
- fn index(&self, i: usize) -> &T {
- let mut idx = 0;
- $( if i == idx { return &self.$field; } idx += 1; )+
- panic!("Index out of bounds");
- }
- }
- impl IndexMut for $Struct {
- fn index_mut(&mut self, i: usize) -> &mut T {
- let mut idx = 0;
- $( if i == idx { return &mut self.$field; } idx += 1; )+
- panic!("Index out of bounds");
- }
- }
- };
-}
-
-macro_rules! impl_tuple_ops {
- ($Struct:ident) => {
- impl> Add for $Struct {
- type Output = Self;
- fn add(self, rhs: Self) -> Self { Self::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z) }
- }
- impl AddAssign for $Struct {
- fn add_assign(&mut self, rhs: Self)
- { self.x += rhs.x; self.y += rhs.y; self.z += rhs.z; }
- }
- impl> Sub for $Struct {
- type Output = Self;
- fn sub(self, rhs: Self) -> Self { Self::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z) }
- }
- impl SubAssign for $Struct {
- fn sub_assign(&mut self, rhs: Self) { self.x -= rhs.x; self.y -= rhs.y; self.z -= rhs.z; }
- }
- };
-}
-
-
-impl_tuple_core!(Vector3, [x, y, z]);
-impl_tuple_core!(Normal3, [x, y, z]);
-impl_tuple_core!(Point2, [x, y]);
-impl_tuple_core!(Point3, [x, y, z]);
-
-impl_tuple_ops!(Vector3);
-impl_tuple_ops!(Normal3);
-
-// Point - Point -> Vector
-impl> Sub> for Point3 {
- type Output = Vector3;
- fn sub(self, rhs: Point3) -> Vector3 {
- Vector3::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
- }
-}
-
-// Point + Vector -> Point
-impl> Add> for Point3 {
- type Output = Point3;
- fn add(self, rhs: Vector3) -> Point3 {
- Point3::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
- }
-}
-impl AddAssign> for Point3 {
- fn add_assign(&mut self, rhs: Vector3) {
- self.x += rhs.x;
- self.y += rhs.y;
- self.z += rhs.z;
- }
-}
-
-// Point - Vector -> Point
-impl> Sub> for Point3 {
- type Output = Point3;
- fn sub(self, rhs: Vector3) -> Point3 {
- Point3::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
- }
-}
-impl SubAssign> for Point3 {
- fn sub_assign(&mut self, rhs: Vector3) {
- self.x -= rhs.x;
- self.y -= rhs.y;
- self.z -= rhs.z;
- }
-}
-
-impl Vector3 {
- pub fn cross(self, other: Vector3) -> Vector3 {
- Vector3 {
- x: self.y * other.z - self.z * other.y,
- y: self.z * other.x - self.x * other.z,
- z: self.x * other.y - self.y * other.x,
- }
- }
-}
-
-pub trait Norm {
- type Scalar;
-
- fn norm(self) -> Self::Scalar;
- fn norm_squared(self) -> Self::Scalar;
-}
-
-impl Norm for Vector2 {
- type Scalar = T;
- fn norm(self) -> T { self.length_squared().sqrt() }
- fn norm_squared(self) -> T { self.length_squared }
-}
-
-pub fn distance(p1: Point2, p2: Point2) -> T
-where
- T: num_traits::Float,
- Point2: Sub