Numerous small changes suggested by clippy
This commit is contained in:
parent
6a1fe84af7
commit
fb744258b2
|
|
@ -47,7 +47,7 @@ impl AccumulationBuffer {
|
|||
let buffer_colour_bias = &mut self.colour_bias_buffer[row][column];
|
||||
let buffer_weight = &mut self.weight_buffer[row][column];
|
||||
let buffer_weight_bias = &mut self.weight_bias_buffer[row][column];
|
||||
let photon_colour = ColourXyz::from_photon(&photon);
|
||||
let photon_colour = ColourXyz::from_photon(photon);
|
||||
let weight_sum_y = weight - *buffer_weight_bias;
|
||||
let weight_sum_t = *buffer_weight + weight_sum_y;
|
||||
*buffer_weight_bias = (weight_sum_t - *buffer_weight) - weight_sum_y;
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ pub fn partial_render_scene(
|
|||
let mut output_image_tile = AccumulationBuffer::new(tile.width(), tile.height());
|
||||
let image_sampler = ImageSampler::new(width, height, scene.camera_location);
|
||||
let integrator = SimpleRandomIntegrator {};
|
||||
let sampler = Sampler { scene: &scene };
|
||||
let sampler = Sampler { scene };
|
||||
for column in 0..tile.width() {
|
||||
for row in 0..tile.height() {
|
||||
let ray = image_sampler.ray_for_pixel(tile.start_row + row, tile.start_column + column);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ impl Photon {
|
|||
pub fn set_intensity(&self, intensity: f64) -> Photon {
|
||||
Photon {
|
||||
wavelength: self.wavelength,
|
||||
intensity: intensity,
|
||||
intensity,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::convert::TryInto;
|
||||
use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::path::Path;
|
||||
|
|
@ -20,7 +19,7 @@ impl ImageRgbU8 {
|
|||
|
||||
pub fn get_colour(&self, row: usize, column: usize) -> ColourRgbU8 {
|
||||
ColourRgbU8 {
|
||||
values: self.data[row][column].try_into().expect("Wrong length."),
|
||||
values: self.data[row][column],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +51,7 @@ impl ImageRgbU8 {
|
|||
|
||||
pub fn write_png(&self, filename: &Path) -> Result<(), std::io::Error> {
|
||||
let file = File::create(filename)?;
|
||||
let ref mut file_buffer = BufWriter::new(file);
|
||||
let file_buffer = &mut BufWriter::new(file);
|
||||
|
||||
let mut encoder = png::Encoder::new(
|
||||
file_buffer,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ impl Integrator for SimpleRandomIntegrator {
|
|||
let MaterialSampleResult {
|
||||
direction: w_o,
|
||||
pdf: w_o_pdf,
|
||||
} = info.material.sample(&w_i, &photon);
|
||||
} = info.material.sample(&w_i, photon);
|
||||
let world_space_w_o = bsdf_to_world_space * w_o;
|
||||
info.material.bsdf()(
|
||||
&w_o,
|
||||
|
|
@ -45,7 +45,7 @@ impl Integrator for SimpleRandomIntegrator {
|
|||
photon.wavelength,
|
||||
)),
|
||||
Some(recursive_hit) => {
|
||||
self.integrate(&sampler, &recursive_hit, &photon, recursion_limit - 1)
|
||||
self.integrate(sampler, &recursive_hit, photon, recursion_limit - 1)
|
||||
}
|
||||
}
|
||||
.scale_intensity(w_o_pdf)
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ impl Integrator for WhittedIntegrator {
|
|||
.iter()
|
||||
.map(|light| {
|
||||
match sampler.sample(&Ray::new(info.location, light.direction).bias(0.000_000_1)) {
|
||||
Some(_) => self.ambient_light.emit_photon(&photon),
|
||||
Some(_) => self.ambient_light.emit_photon(photon),
|
||||
None => info.material.bsdf()(
|
||||
&(world_to_bsdf_space * info.retro),
|
||||
&(world_to_bsdf_space * light.direction),
|
||||
&light
|
||||
.spectrum
|
||||
.emit_photon(&photon)
|
||||
.emit_photon(photon)
|
||||
.scale_intensity(light.direction.dot(&info.normal).abs()),
|
||||
),
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ impl Integrator for WhittedIntegrator {
|
|||
.chain(
|
||||
[info
|
||||
.material
|
||||
.sample(&(world_to_bsdf_space * info.retro), &photon)]
|
||||
.sample(&(world_to_bsdf_space * info.retro), photon)]
|
||||
.iter()
|
||||
.map(|MaterialSampleResult { direction, pdf: _ }| {
|
||||
let world_space_direction = bsdf_to_world_space * direction;
|
||||
|
|
@ -62,9 +62,9 @@ impl Integrator for WhittedIntegrator {
|
|||
&(world_to_bsdf_space * info.retro),
|
||||
direction,
|
||||
&self.integrate(
|
||||
&sampler,
|
||||
sampler,
|
||||
&recursive_hit,
|
||||
&photon,
|
||||
photon,
|
||||
recursion_limit - 1,
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ impl Vec3 {
|
|||
}
|
||||
|
||||
pub fn norm_squared(&self) -> f64 {
|
||||
self.dot(&self)
|
||||
self.dot(self)
|
||||
}
|
||||
|
||||
pub fn norm(&self) -> f64 {
|
||||
|
|
@ -119,12 +119,10 @@ impl Vec3 {
|
|||
} else {
|
||||
2
|
||||
}
|
||||
} else if y < z {
|
||||
1
|
||||
} else {
|
||||
if y < z {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
}
|
||||
2
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,16 +47,16 @@ mod wavefront_obj {
|
|||
) -> Vec<Triangle> {
|
||||
if let Some(v0_index) = polygon.iter().next() {
|
||||
let (v0_vertex, v0_normal) =
|
||||
get_vertex_and_normal(v0_index, &vertex_positions, &normal_positions);
|
||||
get_vertex_and_normal(v0_index, &vertex_positions, normal_positions);
|
||||
polygon
|
||||
.iter()
|
||||
.skip(1)
|
||||
.zip(polygon.iter().skip(2))
|
||||
.map(|(v1_index, v2_index)| {
|
||||
let (v1_vertex, v1_normal) =
|
||||
get_vertex_and_normal(v1_index, &vertex_positions, &normal_positions);
|
||||
get_vertex_and_normal(v1_index, vertex_positions, normal_positions);
|
||||
let (v2_vertex, v2_normal) =
|
||||
get_vertex_and_normal(v2_index, &vertex_positions, &normal_positions);
|
||||
get_vertex_and_normal(v2_index, vertex_positions, normal_positions);
|
||||
let vertices = [v0_vertex, v1_vertex, v2_vertex];
|
||||
let normals = [v0_normal, v1_normal, v2_normal];
|
||||
Triangle {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use crate::math::Vec3;
|
|||
|
||||
use super::{RandomDistribution, UnitDisc};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CosineWeightedHemisphere {
|
||||
unit_disc: UnitDisc,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ impl SkyLightPdf {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for SkyLightPdf {
|
||||
fn default() -> SkyLightPdf {
|
||||
SkyLightPdf::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RandomDistribution<Vec3> for SkyLightPdf {
|
||||
fn value(&self) -> Vec3 {
|
||||
let mut rng = thread_rng();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use crate::math::Vec3;
|
|||
|
||||
use super::RandomDistribution;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UniformHemisphere {}
|
||||
|
||||
impl UniformHemisphere {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@ pub struct UnitDisc {
|
|||
square_distribution: UniformSquare,
|
||||
}
|
||||
|
||||
impl Default for UnitDisc {
|
||||
fn default() -> UnitDisc {
|
||||
UnitDisc::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl UnitDisc {
|
||||
pub fn new() -> UnitDisc {
|
||||
let square_distribution = UniformSquare::new(Vec2::new(-1.0, -1.0), 2.0);
|
||||
|
|
|
|||
|
|
@ -92,24 +92,24 @@ fn closest_intersection(
|
|||
}
|
||||
|
||||
impl Intersect for BoundingVolumeHierarchy {
|
||||
fn intersect<'a>(&'a self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
match self {
|
||||
BoundingVolumeHierarchy::Node {
|
||||
bounds,
|
||||
left,
|
||||
right,
|
||||
} => {
|
||||
if bounds.intersect(&ray) {
|
||||
closest_intersection(left.intersect(&ray), right.intersect(&ray))
|
||||
if bounds.intersect(ray) {
|
||||
closest_intersection(left.intersect(ray), right.intersect(ray))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
BoundingVolumeHierarchy::Leaf { bounds, primitives } => {
|
||||
if bounds.intersect(&ray) {
|
||||
if bounds.intersect(ray) {
|
||||
primitives
|
||||
.iter()
|
||||
.map(|elem| elem.intersect(&ray))
|
||||
.map(|elem| elem.intersect(ray))
|
||||
.fold(None, closest_intersection)
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ pub struct IntersectionInfo {
|
|||
/// intersected with a [Ray](Ray)
|
||||
pub trait Intersect: Send + Sync {
|
||||
/// Test if the ray intersects the object, and return information about the object and intersection.
|
||||
fn intersect<'a>(&'a self, ray: &Ray) -> Option<IntersectionInfo>;
|
||||
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo>;
|
||||
}
|
||||
|
||||
/// A geometric object that can be intersected with a ray
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl Plane {
|
|||
}*/
|
||||
|
||||
impl Intersect for Plane {
|
||||
fn intersect<'a>(&'a self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
let ray_direction_dot_plane_normal = ray.direction.dot(&self.normal);
|
||||
let point_on_plane = self.normal * self.distance_from_origin;
|
||||
let point_on_plane_minus_ray_origin_dot_normal =
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ impl Sphere {
|
|||
}*/
|
||||
|
||||
impl Intersect for Sphere {
|
||||
fn intersect<'a>(&'a self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
fn intersect<'a>(&'_ self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
let r_o = ray.origin;
|
||||
let centre_coords = self.centre;
|
||||
let a = ray
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ pub struct Triangle {
|
|||
}*/
|
||||
|
||||
impl Intersect for Triangle {
|
||||
fn intersect<'a>(&'a self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
let translation = -ray.origin;
|
||||
let indices = indices_with_index_of_largest_element_last(&ray.direction);
|
||||
let permuted_ray_direction = permute_vector_elements(&ray.direction, &indices);
|
||||
|
|
@ -126,7 +126,7 @@ fn is_valid_permutation(indices: &[usize; 3]) -> bool {
|
|||
}
|
||||
|
||||
fn permute_vector_elements(v: &Vec3, indices: &[usize; 3]) -> Vec3 {
|
||||
debug_assert!(is_valid_permutation(&indices));
|
||||
debug_assert!(is_valid_permutation(indices));
|
||||
Vec3::new(v[indices[0]], v[indices[1]], v[indices[2]])
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ impl HasBoundingBox for Vec<Box<dyn Primitive>> {
|
|||
}
|
||||
|
||||
impl Intersect for Vec<Box<dyn Primitive>> {
|
||||
fn intersect<'a>(&'a self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
self.iter()
|
||||
.flat_map(|primitive| primitive.intersect(&ray))
|
||||
.flat_map(|primitive| primitive.intersect(ray))
|
||||
.min_by(
|
||||
|a, b| match PartialOrd::partial_cmp(&a.distance, &b.distance) {
|
||||
None => std::cmp::Ordering::Less,
|
||||
|
|
@ -32,9 +32,9 @@ impl HasBoundingBox for Vec<Box<dyn Aggregate>> {
|
|||
}
|
||||
|
||||
impl Intersect for Vec<Box<dyn Aggregate>> {
|
||||
fn intersect<'a>(&'a self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo> {
|
||||
self.iter()
|
||||
.flat_map(|aggregate| aggregate.intersect(&ray))
|
||||
.flat_map(|aggregate| aggregate.intersect(ray))
|
||||
.min_by(
|
||||
|a, b| match PartialOrd::partial_cmp(&a.distance, &b.distance) {
|
||||
None => std::cmp::Ordering::Less,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ impl<'a> Sampler<'a> {
|
|||
self.scene
|
||||
.objects
|
||||
.iter()
|
||||
.flat_map(|object| object.intersect(&ray))
|
||||
.flat_map(|object| object.intersect(ray))
|
||||
.min_by(
|
||||
|a, b| match PartialOrd::partial_cmp(&a.distance, &b.distance) {
|
||||
None => std::cmp::Ordering::Less,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
pub enum BinaryTree<Value, LeafValue>
|
||||
{
|
||||
pub enum BinaryTree<Value, LeafValue> {
|
||||
Branch {
|
||||
value: Value,
|
||||
left: Box<Self>,
|
||||
|
|
@ -11,8 +10,7 @@ pub enum BinaryTree<Value, LeafValue>
|
|||
None,
|
||||
}
|
||||
|
||||
impl<Value, LeafValue> BinaryTree<Value, LeafValue>
|
||||
{
|
||||
impl<Value, LeafValue> BinaryTree<Value, LeafValue> {
|
||||
pub fn count_leaves(&self) -> usize {
|
||||
match self {
|
||||
Self::Branch {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::raycasting::{Primitive, Triangle};
|
|||
use std::sync::Arc;
|
||||
|
||||
pub fn triangulate_polygon(
|
||||
vertices: &Vec<Vec3>,
|
||||
vertices: &[Vec3],
|
||||
normal: &Vec3,
|
||||
material: Arc<dyn Material>,
|
||||
) -> Vec<Arc<dyn Primitive>> {
|
||||
|
|
@ -124,7 +124,7 @@ pub fn generate_dodecahedron(
|
|||
.iter()
|
||||
.flat_map(|face| {
|
||||
let normal = (face[1] - face[0]).cross(&(face[2] - face[1]));
|
||||
let transformed_face = face.iter().map(|v| centre + v * scale).collect();
|
||||
let transformed_face: Vec<_> = face.iter().map(|v| centre + v * scale).collect();
|
||||
triangulate_polygon(&transformed_face, &normal, Arc::clone(&material))
|
||||
})
|
||||
.collect()
|
||||
|
|
|
|||
Loading…
Reference in New Issue