Skip to content

Commit 91d7b79

Browse files
committed
updated comments
1 parent 0b9f380 commit 91d7b79

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

src/convert.rs

+11-34
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,24 @@ use num::Float;
22

33
use {Alpha, Rgb, Luma, Xyz, Yxy, Lab, Lch, Hsv, Hsl, Color};
44

5-
///FromColor provides conversion between the colors. It requires from_xyz
6-
///and derives conversion to other colors as a default from this.
7-
///
8-
///This is not optimal in all cases. For example Hsl -> Rgb using this method will
9-
///result in Hsl -> Rgb -> Xyz -> Rgb. To avoid this the Rgb derivatives
10-
///like Hsl and Hsv, convert through Rgb as default and Lab derivatives
11-
///like Lch convert through Lab as default.
5+
///FromColor provides conversion between the colors. It requires from_xyz and derives conversion
6+
///to other colors as a default from this. These defaults must be overridden when direct
7+
///conversion exists between colors. For example, Luma has direct conversion to Rgb.
8+
///So from_rgb conversion for Luma and from_luma for Rgb is implemented directly.
129
pub trait FromColor<T>: Sized
1310
where T: Float,
1411
{
1512
//To implement ColorConvert for a type, a few things must by kept in mind.
1613
//
17-
//First, derived colors like Hsl must override into_rgb and from_rgb and
18-
//convert into_xyz and from_xyz via Rgb, as discussed above.
14+
//First, derived colors like Hsl must override from_rgb and convert from_xyz via Rgb.
1915
//
20-
//Second, the from for the same color must override the default.
21-
//For example, from_rgb and into_rgb for Rgb will convert via Xyz which
22-
//needs to be overridden with *input_color and *self to avoid the unnecessary
23-
//converison.
16+
//Second, the from for the same color must override the default. For example,
17+
//from_rgb for Rgb will convert via Xyz which needs to be overridden with self to
18+
//avoid the unnecessary converison.
2419
//
2520
//Third, if a direct transform exists between the colors, then it should be
2621
//overridden. For example, Luma has direct conversion to Rgb. So from_rgb conversion
27-
//for Luma is implemented.
22+
//for Luma and from_luma for Rgb is implemented directly.
2823

2924
///Convert from XYZ color space
3025
fn from_xyz(Xyz<T>) -> Self;
@@ -68,29 +63,11 @@ pub trait FromColor<T>: Sized
6863

6964

7065
///IntoColor provides conversion between the colors. It requires into into_xyz
71-
///and derives conversion to other colors as a default from this.
72-
///
73-
///This is not optimal in all cases. For example Hsl -> Rgb using this method will
74-
///result in Hsl -> Rgb -> Xyz -> Rgb. To avoid this the Rgb derivatives
75-
///like Hsl and Hsv, convert through Rgb as default and Lab derivatives
76-
///like Lch convert through Lab as default.
66+
///and derives conversion to other colors as a default from this. These defaults
67+
///must be overridden when direct conversion exists between colors.
7768
pub trait IntoColor<T>: Sized
7869
where T: Float,
7970
{
80-
//To implement ColorConvert for a type, a few things must by kept in mind.
81-
//
82-
//First, derived colors like Hsl must override into_rgb and from_rgb and
83-
//convert into_xyz and from_xyz via Rgb, as discussed above.
84-
//
85-
//Second, the from and into for the same color must override the default.
86-
//For example, from_rgb and into_rgb for Rgb will convert via Xyz which
87-
//needs to be overridden with *input_color and *self to avoid the unnecessary
88-
//converison.
89-
//
90-
//Third, if a direct transform exists between the colors, then it should be
91-
//overridden in both the colors. For example, Luma has direct conversion to
92-
//Rgb. So into_rgb and from_rgb conversion is implemented in Luma and into_luma
93-
//and from_luma is overridden in Rgb to use the conversion from Luma.
9471

9572
///Convert into XYZ space
9673
fn into_xyz(self) -> Xyz<T>;

0 commit comments

Comments
 (0)