tuples: implement EPSILON aware PartialEq for Color.
Mark Color::new const so it can be used in const expressions (like predefining colors).
This commit is contained in:
parent
1cbfbc8641
commit
385ed70d88
@ -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 struct Color {
|
||||||
pub red: f32,
|
pub red: f32,
|
||||||
pub green: f32,
|
pub green: f32,
|
||||||
pub blue: f32,
|
pub blue: f32,
|
||||||
}
|
}
|
||||||
impl Color {
|
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 }
|
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 {
|
impl Add for Color {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
fn add(self, other: Self) -> Self {
|
fn add(self, other: Self) -> Self {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user