aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-01-28 23:53:56 +0100
committerJulian T <julian@jtle.dk>2021-01-28 23:53:56 +0100
commitf467334b26f31b19ebbd222de2b4167b1538ccee (patch)
treef58839dde3f299a7c67aa37f9c86bcf36aa4186e /src
parent33a35c50c20e863123642c8c9ea31dfc006945f6 (diff)
Unfinished film
Diffstat (limited to 'src')
-rw-r--r--src/bound.rs (renamed from src/bounding.rs)28
-rw-r--r--src/camera/film.rs14
-rw-r--r--src/camera/filter/mod.rs24
-rw-r--r--src/lib.rs2
-rw-r--r--src/vector.rs19
5 files changed, 72 insertions, 15 deletions
diff --git a/src/bounding.rs b/src/bound.rs
index d5a3ed0..b7ce05d 100644
--- a/src/bounding.rs
+++ b/src/bound.rs
@@ -1,6 +1,5 @@
use crate::{Number, Float};
-use crate::vector::Vector2;
-use std::cmp;
+use crate::vector::*;
pub struct Bound2<T: Number> {
pub min: Vector2<T>,
@@ -42,6 +41,31 @@ impl<T: Number> Bound2<T> {
}
}
+impl From<&Bound2i> for Bound2f {
+ fn from(b: &Bound2i) -> Self {
+ Self {
+ min: Vector2f::from(b.min),
+ max: Vector2f::from(b.max),
+ }
+ }
+}
+
+impl From<&Bound2f> for Bound2i {
+ fn from(b: &Bound2f) -> Self {
+ Self {
+ min: Vector2i::from(b.min),
+ max: Vector2i::from(b.max),
+ }
+ }
+}
+
+pub fn intersect<T: Number>(a: &Bound2<T>, b: &Bound2<T>) -> Bound2<T> {
+ Bound2::new(
+ &Vector2::from_xy(max(a.min.x, b.min.x), max(a.min.y, b.min.y)),
+ &Vector2::from_xy(min(a.max.x, b.max.x), min(a.max.y, b.max.y)),
+ )
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/camera/film.rs b/src/camera/film.rs
index c4a65ce..e31b760 100644
--- a/src/camera/film.rs
+++ b/src/camera/film.rs
@@ -1,6 +1,7 @@
use crate::vector::{Vector2, Vector2f};
use crate::Float;
-use crate::bounding::Bound2i;
+use crate::bound;
+use bound::{Bound2i, Bound2f};
use super::filter::Filter;
#[derive(Clone)]
@@ -12,8 +13,7 @@ pub struct Film<'a> {
pub resolution: Vector2<usize>,
pixels: Vec<Pixel>,
- filter: &'a dyn Filter,
- filter_radius: Vector2f,
+ filter: &'a Filter,
}
pub struct FilmTile {
@@ -27,19 +27,23 @@ impl Pixel {
}
impl Film<'_> {
- fn new(resolution: Vector2<usize>, filter: & dyn Filter) -> Film {
+ fn new(resolution: Vector2<usize>, filter: & Filter) -> Film {
let area = resolution.x * resolution.y;
Film {
resolution,
pixels: vec![Pixel::new(); area],
filter,
- filter_radius: filter.radius()
}
}
fn get_tile(bound: &Bound2i) {
// Used to calculate descrete coordinates into continues
let halfpixel = Vector2f::from_xy(0.5, 0.5);
+ let fbound = Bound2f::from(bound);
+
+
+
+ //let tilebound = bound::intersect(bound,
}
fn splat(&mut self, point: &Vector2<usize>, pixel: &Pixel) {
diff --git a/src/camera/filter/mod.rs b/src/camera/filter/mod.rs
index 93c6fc5..bfa17bb 100644
--- a/src/camera/filter/mod.rs
+++ b/src/camera/filter/mod.rs
@@ -1,22 +1,32 @@
use crate::vector::Vector2f;
use crate::Float;
-pub trait Filter {
+trait Eval {
fn eval(&self, point: &Vector2f) -> Float;
- fn radius(&self) -> Vector2f;
}
-pub struct BoxFilter {
- radius: Vector2f,
+pub struct Filter {
+ eval: Box<dyn Eval>,
+ pub radius: Vector2f,
}
+struct BoxFilter {}
+
// The same a no filter, and can give aliasing in final image
-impl Filter for BoxFilter {
+impl Eval for BoxFilter {
fn eval(&self, _: &Vector2f) -> Float {
1.0
}
+}
+
+impl Eval for Filter {
+ fn eval(&self, point: &Vector2f) -> Float {
+ self.eval.eval(point)
+ }
+}
- fn radius(&self) -> Vector2f {
- self.radius
+impl Filter {
+ fn new_box(radius: &Vector2f) -> Filter {
+ Filter { radius: radius.clone(), eval: Box::new(BoxFilter {}) }
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 1d43855..7066a80 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,5 @@
mod vector;
-mod bounding;
+mod bound;
mod camera;
mod spectrum;
diff --git a/src/vector.rs b/src/vector.rs
index 9b89168..ff443f5 100644
--- a/src/vector.rs
+++ b/src/vector.rs
@@ -30,6 +30,25 @@ impl<T: Number> Sub for Vector2<T> {
}
}
+impl From<Vector2i> for Vector2f {
+ fn from(v: Vector2i) -> Self {
+ Self {
+ x: v.x as Float,
+ y: v.y as Float,
+ }
+ }
+}
+
+impl From<Vector2f> for Vector2i {
+ fn from(v: Vector2f) -> Self {
+ Self {
+ x: v.x as i32,
+ y: v.y as i32,
+ }
+ }
+}
+
+
#[cfg(test)]
mod tests {
use super::*;