patterns: make From for Pattern a little generic.
This commit is contained in:
parent
b9f2c3f0ec
commit
2e4e8b3dcd
@ -2,7 +2,7 @@ use crate::{
|
|||||||
matrices::Matrix4x4,
|
matrices::Matrix4x4,
|
||||||
shapes::Shape,
|
shapes::Shape,
|
||||||
tuples::{Color, Tuple},
|
tuples::{Color, Tuple},
|
||||||
Float, WHITE,
|
WHITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@ -34,19 +34,13 @@ impl Default for Pattern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a [Pattern] with a color type of [ColorMapper::Constant] from the given [Color]
|
/// Creates a [Pattern] with a color type of [ColorMapper::Constant] from the given [Color]
|
||||||
impl From<[Float; 3]> for Pattern {
|
impl<C> From<C> for Pattern
|
||||||
fn from(rgb: [Float; 3]) -> Self {
|
where
|
||||||
|
C: Into<Color>,
|
||||||
|
{
|
||||||
|
fn from(c: C) -> Self {
|
||||||
Pattern {
|
Pattern {
|
||||||
color: ColorMapper::Constant(rgb.into()),
|
color: ColorMapper::Constant(c.into()),
|
||||||
..Pattern::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Creates a [Pattern] with a color type of [ColorMapper::Constant] from the given [Color]
|
|
||||||
impl From<Color> for Pattern {
|
|
||||||
fn from(c: Color) -> Self {
|
|
||||||
Pattern {
|
|
||||||
color: ColorMapper::Constant(c),
|
|
||||||
..Pattern::default()
|
..Pattern::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user