Skip to content

Commit fe3c377

Browse files
authored
Merge pull request #411 from antogilbert/rgbafrom
Implement From for RGBColor and RGBAColor
2 parents 30fe77a + c9995cc commit fe3c377

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

plotters/src/style/color.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ impl Color for RGBAColor {
7676
}
7777
}
7878

79+
impl From<RGBColor> for RGBAColor {
80+
fn from(rgb: RGBColor) -> Self {
81+
Self(rgb.0, rgb.1, rgb.2, 1.0)
82+
}
83+
}
84+
7985
/// A color in the given palette
8086
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
8187
pub struct PaletteColor<P: Palette>(usize, PhantomData<P>);

plotters/src/test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ fn regression_test_issue_267() {
1212
.draw_line(p1, p2, &RGBColor(0, 0, 0).stroke_width(0))
1313
.unwrap();
1414
}
15+
16+
#[test]
17+
fn from_trait_impl_rgba_color() {
18+
let rgb = RGBColor(1, 2, 3);
19+
let c = RGBAColor::from(rgb);
20+
21+
assert_eq!(c.rgb(), rgb.rgb());
22+
}

0 commit comments

Comments
 (0)