aboutsummaryrefslogtreecommitdiff
path: root/src/core/spectrum.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-01-30 15:37:07 +0100
committerJulian T <julian@jtle.dk>2021-01-30 15:37:07 +0100
commit86303936ab3180828b984ebb256bab8e69dab5cf (patch)
treee4bfb08d9c73edd12aef944e0d698c03753032da /src/core/spectrum.rs
parentfdb3e8cb8d53449c107388e143345beae162f95e (diff)
Finished initial film, reorganization and started work on shapes
Diffstat (limited to 'src/core/spectrum.rs')
-rw-r--r--src/core/spectrum.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/core/spectrum.rs b/src/core/spectrum.rs
new file mode 100644
index 0000000..604c8c0
--- /dev/null
+++ b/src/core/spectrum.rs
@@ -0,0 +1,35 @@
+use crate::Float;
+use std::ops;
+
+// TODO implement SampledSpectrum instead for nicer images
+
+#[derive(Clone, Default)]
+pub struct Spectrum {
+ c: [Float; 3],
+}
+
+impl Spectrum {
+ fn new_rgb(r: Float, g: Float, b: Float) -> Spectrum {
+ Spectrum { c: [r, g, b] }
+ }
+}
+
+impl std::ops::Mul<Float> for &Spectrum {
+ type Output = Spectrum;
+
+ fn mul(self, op: Float) -> Self::Output {
+ Self::Output::new_rgb(
+ self.c[0] * op,
+ self.c[1] * op,
+ self.c[2] * op,
+ )
+ }
+}
+
+impl std::ops::AddAssign<&Self> for Spectrum {
+ fn add_assign(&mut self, op: &Self) {
+ self.c[0] += op.c[0];
+ self.c[1] += op.c[1];
+ self.c[2] += op.c[2];
+ }
+}