aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-10 23:06:48 +0100
committerJulian T <julian@jtle.dk>2021-02-10 23:06:48 +0100
commit49c6adb0db70ffc30eaac33b66eacf7574b34e26 (patch)
tree60f828ce8abf962fe2d88fdeb4e04db1d7663253 /src
parent3a144c8c1fc83150fc06d792082db5cc4bce3cc5 (diff)
Fixed most clippy warnings
Diffstat (limited to 'src')
-rw-r--r--src/camera/camera.rs2
-rw-r--r--src/camera/mod.rs2
-rw-r--r--src/core/bound.rs2
-rw-r--r--src/core/vector2.rs2
-rw-r--r--src/core/vector3.rs6
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs9
-rw-r--r--src/material/lambertian.rs2
-rw-r--r--src/sample/uniform.rs9
-rw-r--r--src/trace/mod.rs2
-rw-r--r--src/trace/pathtrace.rs2
-rw-r--r--src/world/mod.rs (renamed from src/scene/mod.rs)4
-rw-r--r--src/world/scene.rs (renamed from src/scene/scene.rs)11
-rw-r--r--src/world/shapes/mod.rs (renamed from src/scene/shapes/mod.rs)0
-rw-r--r--src/world/shapes/sphere.rs (renamed from src/scene/shapes/sphere.rs)2
15 files changed, 32 insertions, 25 deletions
diff --git a/src/camera/camera.rs b/src/camera/camera.rs
index 4d05e87..241d26b 100644
--- a/src/camera/camera.rs
+++ b/src/camera/camera.rs
@@ -79,7 +79,7 @@ impl Camera {
// Calculate translation vectors
let mut forward = set.target - set.origin;
- let focus = set.focus.unwrap_or(forward.len());
+ let focus = set.focus.unwrap_or_else(|| forward.length());
forward.norm_in();
diff --git a/src/camera/mod.rs b/src/camera/mod.rs
index 7c36307..999b5b5 100644
--- a/src/camera/mod.rs
+++ b/src/camera/mod.rs
@@ -7,7 +7,7 @@
pub mod film;
//pub mod filter;
-pub mod camera;
+mod camera;
pub use camera::{Camera, CameraSettings};
pub use film::Film;
diff --git a/src/core/bound.rs b/src/core/bound.rs
index 404424e..3978028 100644
--- a/src/core/bound.rs
+++ b/src/core/bound.rs
@@ -83,7 +83,7 @@ impl<T: Number> Bound2<T> {
/// ```
pub fn area(&self) -> T {
let diag = self.diagonal();
- return diag.x * diag.y;
+ diag.x * diag.y
}
}
diff --git a/src/core/vector2.rs b/src/core/vector2.rs
index 0e0165e..405b12a 100644
--- a/src/core/vector2.rs
+++ b/src/core/vector2.rs
@@ -112,7 +112,7 @@ impl Vector2i {
}
impl Vector2f {
- pub fn len(&self) -> Float {
+ pub fn length(&self) -> Float {
(self.x*self.x + self.y*self.y).sqrt()
}
diff --git a/src/core/vector3.rs b/src/core/vector3.rs
index 24b84e9..e26c07c 100644
--- a/src/core/vector3.rs
+++ b/src/core/vector3.rs
@@ -117,7 +117,7 @@ impl Vector3f {
self.x * self.x + self.y * self.y + self.z * self.z
}
- pub fn len(&self) -> Float {
+ pub fn length(&self) -> Float {
self.len_squared().sqrt()
}
@@ -137,7 +137,7 @@ impl Vector3f {
/// ```
pub fn norm_in(&mut self) {
// TODO Experiment with checking for normality with len_squared
- let len = self.len();
+ let len = self.length();
if len == 0.0 {
*self = Self::new(0.0);
}
@@ -146,7 +146,7 @@ impl Vector3f {
}
pub fn norm(&self) -> Self {
- let mut new = self.clone();
+ let mut new = *self;
new.norm_in();
new
}
diff --git a/src/lib.rs b/src/lib.rs
index f3047d6..a40e8e6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1,7 @@
pub mod core;
pub mod camera;
pub mod render;
-pub mod scene;
+pub mod world;
pub mod trace;
pub mod sample;
pub mod material;
diff --git a/src/main.rs b/src/main.rs
index 2247834..215e0d4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,6 @@
use rendering::camera::{Camera, Film, CameraSettings};
-use rendering::scene::{Scene, Object};
+use rendering::world::{Scene, Object, shapes::Sphere};
use rendering::trace::DefaultTracer;
-use rendering::scene::shapes::Sphere;
use rendering::core::{Vector2i, Vector3f, Spectrum};
use rendering::render::{RenderContext, RenderCoord};
use rendering::sample::UniformSampler;
@@ -28,9 +27,9 @@ fn main() {
let mut scn = Scene::new();
scn.add_objects(vec![
- Object::new(metal.clone(), Box::new(Sphere::new(0.5, Vector3f::new_xyz(0.0, 0.0, -1.0)))),
- Object::new(blue.clone(), Box::new(Sphere::new(0.5, Vector3f::new_xyz(1.0, 0.0, -1.0)))),
- Object::new(brown.clone(), Box::new(Sphere::new(100.0, Vector3f::new_xyz(0.0, -100.5, -1.0)))),
+ Object::new(metal, Box::new(Sphere::new(0.5, Vector3f::new_xyz(0.0, 0.0, -1.0)))),
+ Object::new(blue, Box::new(Sphere::new(0.5, Vector3f::new_xyz(1.0, 0.0, -1.0)))),
+ Object::new(brown, Box::new(Sphere::new(100.0, Vector3f::new_xyz(0.0, -100.5, -1.0)))),
]);
let tracer = DefaultTracer::new(&scn, Some(50));
diff --git a/src/material/lambertian.rs b/src/material/lambertian.rs
index 65a59cc..8ef5e50 100644
--- a/src/material/lambertian.rs
+++ b/src/material/lambertian.rs
@@ -32,6 +32,6 @@ impl Material for Lambertian {
newray.direction = i.n;
}
- Some((self.color.clone(), newray))
+ Some((self.color, newray))
}
}
diff --git a/src/sample/uniform.rs b/src/sample/uniform.rs
index e2f0b7c..2cd3156 100644
--- a/src/sample/uniform.rs
+++ b/src/sample/uniform.rs
@@ -13,6 +13,12 @@ pub struct UniformSampler {
impl UniformSampler {
pub fn new() -> Self {
+ Self::default()
+ }
+}
+
+impl Default for UniformSampler {
+ fn default() -> Self {
Self {
r: Pcg32::seed_from_u64(1),
d: Uniform::new(0.0, 1.0),
@@ -22,7 +28,6 @@ impl UniformSampler {
impl Sampler for UniformSampler {
fn get_sample(&mut self) -> Float {
- let sample = self.d.sample(&mut self.r);
- sample
+ self.d.sample(&mut self.r)
}
}
diff --git a/src/trace/mod.rs b/src/trace/mod.rs
index 6c2c9f3..b7de476 100644
--- a/src/trace/mod.rs
+++ b/src/trace/mod.rs
@@ -1,4 +1,4 @@
-use crate::scene::Scene;
+use crate::world::Scene;
use crate::core::{Spectrum, Ray, Vector3f};
use crate::sample::Sampler;
diff --git a/src/trace/pathtrace.rs b/src/trace/pathtrace.rs
index af24118..47c6835 100644
--- a/src/trace/pathtrace.rs
+++ b/src/trace/pathtrace.rs
@@ -1,4 +1,4 @@
-use crate::scene::Scene;
+use crate::world::Scene;
use crate::core::{Ray, Spectrum};
use crate::sample::Sampler;
use super::Tracer;
diff --git a/src/scene/mod.rs b/src/world/mod.rs
index cd07236..ef239db 100644
--- a/src/scene/mod.rs
+++ b/src/world/mod.rs
@@ -1,6 +1,4 @@
-//! Defines the scene type which contains all the objects in the scene.
-//!
-//! Also handles finding intersections between rays and shapes
+//! Manages world objects, and implements intersection
pub mod shapes;
mod scene;
diff --git a/src/scene/scene.rs b/src/world/scene.rs
index 83a43c7..444e915 100644
--- a/src/scene/scene.rs
+++ b/src/world/scene.rs
@@ -14,9 +14,7 @@ pub struct SceneIntersect<'a> {
impl Scene {
pub fn new() -> Self {
- Self {
- objs: Vec::new(),
- }
+ Self::default()
}
pub fn add_object(&mut self, obj: Object) {
@@ -45,3 +43,10 @@ impl Scene {
}
}
+impl Default for Scene {
+ fn default() -> Self {
+ Self {
+ objs: Vec::new(),
+ }
+ }
+}
diff --git a/src/scene/shapes/mod.rs b/src/world/shapes/mod.rs
index d7583ad..d7583ad 100644
--- a/src/scene/shapes/mod.rs
+++ b/src/world/shapes/mod.rs
diff --git a/src/scene/shapes/sphere.rs b/src/world/shapes/sphere.rs
index eaa6625..8e0816b 100644
--- a/src/scene/shapes/sphere.rs
+++ b/src/world/shapes/sphere.rs
@@ -34,7 +34,7 @@ impl Hittable for Sphere {
let disc = half_b*half_b - a*c;
if disc < 0.0 {
- return None
+ None
} else {
let distance = (-half_b - disc.sqrt()) / a;
if distance < 0.0 {