diff --git a/rtchallenge/src/tuples.rs b/rtchallenge/src/tuples.rs index 681819f..7e6dcf0 100644 --- a/rtchallenge/src/tuples.rs +++ b/rtchallenge/src/tuples.rs @@ -158,17 +158,24 @@ pub fn cross(a: Tuple, b: Tuple) -> Tuple { ) } -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug)] pub struct Color { pub red: f32, pub green: f32, pub blue: f32, } impl Color { - pub fn new(red: f32, green: f32, blue: f32) -> Color { + pub const fn new(red: f32, green: f32, blue: f32) -> Color { Color { red, green, blue } } } +impl PartialEq for Color { + fn eq(&self, rhs: &Color) -> bool { + ((self.red - rhs.red).abs() < EPSILON) + && ((self.green - rhs.green).abs() < EPSILON) + && ((self.blue - rhs.blue).abs() < EPSILON) + } +} impl Add for Color { type Output = Self; fn add(self, other: Self) -> Self {