aboutsummaryrefslogtreecommitdiff
path: root/src/core/spectrum.rs
blob: 604c8c0252f18dfbe0a9769bb57a795612ee88bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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];
    }
}