Compare commits
3 Commits
c1a79e7893
...
d43cf2feeb
| Author | SHA1 | Date |
|---|---|---|
|
|
d43cf2feeb | |
|
|
406f347971 | |
|
|
07651817dc |
|
|
@ -56,7 +56,7 @@ impl AccumulationBuffer {
|
||||||
let colour_sum_t = buffer_colour_sum.values + colour_sum_y;
|
let colour_sum_t = buffer_colour_sum.values + colour_sum_y;
|
||||||
buffer_colour_bias.values = (colour_sum_t - buffer_colour_sum.values) - colour_sum_y;
|
buffer_colour_bias.values = (colour_sum_t - buffer_colour_sum.values) - colour_sum_y;
|
||||||
buffer_colour_sum.values = colour_sum_t;
|
buffer_colour_sum.values = colour_sum_t;
|
||||||
buffer_colour.values = buffer_colour_sum.values * (1.0 / *buffer_weight);
|
buffer_colour.values = buffer_colour_sum.values / *buffer_weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn merge_tile(&mut self, tile: &Tile, src: &AccumulationBuffer) {
|
pub fn merge_tile(&mut self, tile: &Tile, src: &AccumulationBuffer) {
|
||||||
|
|
|
||||||
|
|
@ -175,10 +175,10 @@ mod tests {
|
||||||
};
|
};
|
||||||
let expected_x: f64 =
|
let expected_x: f64 =
|
||||||
ImageSampler::scale(200, 800, target.film_width) - target.film_width * 0.5;
|
ImageSampler::scale(200, 800, target.film_width) - target.film_width * 0.5;
|
||||||
assert!((point_on_film_plane.x() - expected_x).abs() < 0.5 / 200.0);
|
assert!((point_on_film_plane.x() - expected_x).abs() < 0.5 / 800.0);
|
||||||
let expected_y =
|
let expected_y =
|
||||||
-ImageSampler::scale(100, 600, target.film_height) + target.film_height * 0.5;
|
-ImageSampler::scale(100, 600, target.film_height) + target.film_height * 0.5;
|
||||||
assert!((point_on_film_plane.y() - expected_y).abs() < 0.5 / 800.0);
|
assert!((point_on_film_plane.y() - expected_y).abs() < 0.5 / 600.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use super::Mat3;
|
||||||
|
|
||||||
use itertools::izip;
|
use itertools::izip;
|
||||||
|
|
||||||
use std::ops::{Add, AddAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign};
|
use std::ops::{Add, AddAssign, Div, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug, Default)]
|
#[derive(Copy, Clone, PartialEq, Debug, Default)]
|
||||||
pub struct Vec3 {
|
pub struct Vec3 {
|
||||||
|
|
@ -316,6 +316,30 @@ impl Mul<&Vec3> for f64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Div<f64> for &Vec3 {
|
||||||
|
type Output = Vec3;
|
||||||
|
|
||||||
|
fn div(self, rhs: f64) -> Vec3 {
|
||||||
|
let mut coords = [0.0; 3];
|
||||||
|
for (r, a) in coords.iter_mut().zip(self.coords.iter()) {
|
||||||
|
*r = a / rhs;
|
||||||
|
}
|
||||||
|
Vec3 { coords }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Div<f64> for Vec3 {
|
||||||
|
type Output = Vec3;
|
||||||
|
|
||||||
|
fn div(self, rhs: f64) -> Vec3 {
|
||||||
|
let mut coords = [0.0; 3];
|
||||||
|
for (r, a) in coords.iter_mut().zip(self.coords.iter()) {
|
||||||
|
*r = a / rhs;
|
||||||
|
}
|
||||||
|
Vec3 { coords }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -459,6 +483,14 @@ mod tests {
|
||||||
assert!(a * b == c);
|
assert!(a * b == c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn div_by_scalar_returns_correct_result() {
|
||||||
|
let a = Vec3::new(1.0, 2.0, 3.0);
|
||||||
|
let b = 2.0;
|
||||||
|
let c = Vec3::new(0.5, 1.0, 1.5);
|
||||||
|
assert!(dbg!(a / b) == dbg!(c));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mul_assign_by_scalar_returns_correct_result() {
|
fn mul_assign_by_scalar_returns_correct_result() {
|
||||||
let mut a = Vec3::new(1.0, 2.0, 3.0);
|
let mut a = Vec3::new(1.0, 2.0, 3.0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue