patterns: make From for Pattern a little generic.

This commit is contained in:
Bill Thiede 2021-07-25 13:35:14 -07:00
parent b9f2c3f0ec
commit 2e4e8b3dcd

View File

@ -2,7 +2,7 @@ use crate::{
matrices::Matrix4x4,
shapes::Shape,
tuples::{Color, Tuple},
Float, WHITE,
WHITE,
};
#[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]
impl From<[Float; 3]> for Pattern {
fn from(rgb: [Float; 3]) -> Self {
impl<C> From<C> for Pattern
where
C: Into<Color>,
{
fn from(c: C) -> Self {
Pattern {
color: ColorMapper::Constant(rgb.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),
color: ColorMapper::Constant(c.into()),
..Pattern::default()
}
}