Skip to content

Commit

Permalink
updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sidred committed Feb 8, 2016
1 parent 0b9f380 commit 91d7b79
Showing 1 changed file with 11 additions and 34 deletions.
45 changes: 11 additions & 34 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@ use num::Float;

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

///FromColor provides conversion between the colors. It requires from_xyz
///and derives conversion to other colors as a default from this.
///
///This is not optimal in all cases. For example Hsl -> Rgb using this method will
///result in Hsl -> Rgb -> Xyz -> Rgb. To avoid this the Rgb derivatives
///like Hsl and Hsv, convert through Rgb as default and Lab derivatives
///like Lch convert through Lab as default.
///FromColor provides conversion between the colors. It requires from_xyz and derives conversion
///to other colors as a default from this. These defaults must be overridden when direct
///conversion exists between colors. For example, Luma has direct conversion to Rgb.
///So from_rgb conversion for Luma and from_luma for Rgb is implemented directly.
pub trait FromColor<T>: Sized
where T: Float,
{
//To implement ColorConvert for a type, a few things must by kept in mind.
//
//First, derived colors like Hsl must override into_rgb and from_rgb and
//convert into_xyz and from_xyz via Rgb, as discussed above.
//First, derived colors like Hsl must override from_rgb and convert from_xyz via Rgb.
//
//Second, the from for the same color must override the default.
//For example, from_rgb and into_rgb for Rgb will convert via Xyz which
//needs to be overridden with *input_color and *self to avoid the unnecessary
//converison.
//Second, the from for the same color must override the default. For example,
//from_rgb for Rgb will convert via Xyz which needs to be overridden with self to
//avoid the unnecessary converison.
//
//Third, if a direct transform exists between the colors, then it should be
//overridden. For example, Luma has direct conversion to Rgb. So from_rgb conversion
//for Luma is implemented.
//for Luma and from_luma for Rgb is implemented directly.

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


///IntoColor provides conversion between the colors. It requires into into_xyz
///and derives conversion to other colors as a default from this.
///
///This is not optimal in all cases. For example Hsl -> Rgb using this method will
///result in Hsl -> Rgb -> Xyz -> Rgb. To avoid this the Rgb derivatives
///like Hsl and Hsv, convert through Rgb as default and Lab derivatives
///like Lch convert through Lab as default.
///and derives conversion to other colors as a default from this. These defaults
///must be overridden when direct conversion exists between colors.
pub trait IntoColor<T>: Sized
where T: Float,
{
//To implement ColorConvert for a type, a few things must by kept in mind.
//
//First, derived colors like Hsl must override into_rgb and from_rgb and
//convert into_xyz and from_xyz via Rgb, as discussed above.
//
//Second, the from and into for the same color must override the default.
//For example, from_rgb and into_rgb for Rgb will convert via Xyz which
//needs to be overridden with *input_color and *self to avoid the unnecessary
//converison.
//
//Third, if a direct transform exists between the colors, then it should be
//overridden in both the colors. For example, Luma has direct conversion to
//Rgb. So into_rgb and from_rgb conversion is implemented in Luma and into_luma
//and from_luma is overridden in Rgb to use the conversion from Luma.

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

0 comments on commit 91d7b79

Please sign in to comment.