29
29
//!
30
30
//! ```rust
31
31
//! // An alias for Rgb<Srgb>, which is what most pictures store.
32
- //! use palette::{Srgb, Pixel };
32
+ //! use palette::{Pixel, Srgb };
33
33
//!
34
34
//! let orangeish = Srgb::new(1.0, 0.6, 0.0).into_linear();
35
35
//! let blueish = Srgb::new(0.0, 0.2, 1.0).into_linear();
36
36
//! let whateve_it_becomes = orangeish + blueish;
37
37
//!
38
38
//! // Encode the result back into sRGB and create a byte array
39
- //! let pixel: [u8;3] = Srgb::from_linear(whateve_it_becomes)
39
+ //! let pixel: [u8; 3] = Srgb::from_linear(whateve_it_becomes)
40
40
//! .into_format()
41
41
//! .into_raw();
42
42
//! ```
53
53
//! This approach comes with the extra benefit of allowing operations to
54
54
//! selectively affect the alpha component:
55
55
//!
56
- //! ```
56
+ //! ```rust
57
57
//! use palette::{LinSrgb, LinSrgba};
58
58
//!
59
59
//! let mut c1 = LinSrgba::new(1.0, 0.5, 0.5, 0.8);
63
63
//! c1.blue += 0.2; //The color components can easily be accessed
64
64
//! c1 = c1 * 0.5; //Scale both the color and the alpha
65
65
//! ```
66
+ //!
66
67
67
68
#![ doc( html_root_url = "https://docs.rs/palette/0.3.0/palette/" ) ]
68
69
#![ cfg_attr( feature = "strict" , deny( missing_docs) ) ]
@@ -583,18 +584,18 @@ pub trait Limited {
583
584
fn clamp_self ( & mut self ) ;
584
585
}
585
586
586
- ///A trait for linear color interpolation.
587
+ /// A trait for linear color interpolation.
587
588
///
588
- ///```
589
- ///use palette::{LinSrgb, Mix};
589
+ /// ```
590
+ /// use palette::{LinSrgb, Mix};
590
591
///
591
- ///let a = LinSrgb::new(0.0, 0.5, 1.0);
592
- ///let b = LinSrgb::new(1.0, 0.5, 0.0);
592
+ /// let a = LinSrgb::new(0.0, 0.5, 1.0);
593
+ /// let b = LinSrgb::new(1.0, 0.5, 0.0);
593
594
///
594
- ///assert_eq!(a.mix(&b, 0.0), a);
595
- ///assert_eq!(a.mix(&b, 0.5), LinSrgb::new(0.5, 0.5, 0.5));
596
- ///assert_eq!(a.mix(&b, 1.0), b);
597
- ///```
595
+ /// assert_eq!(a.mix(&b, 0.0), a);
596
+ /// assert_eq!(a.mix(&b, 0.5), LinSrgb::new(0.5, 0.5, 0.5));
597
+ /// assert_eq!(a.mix(&b, 1.0), b);
598
+ /// ```
598
599
pub trait Mix {
599
600
///The type of the mixing factor.
600
601
type Scalar : Float ;
@@ -607,16 +608,16 @@ pub trait Mix {
607
608
fn mix ( & self , other : & Self , factor : Self :: Scalar ) -> Self ;
608
609
}
609
610
610
- ///The `Shade` trait allows a color to be lightened or darkened.
611
+ /// The `Shade` trait allows a color to be lightened or darkened.
611
612
///
612
- ///```
613
- ///use palette::{LinSrgb, Shade};
613
+ /// ```
614
+ /// use palette::{LinSrgb, Shade};
614
615
///
615
- ///let a = LinSrgb::new(0.4, 0.4, 0.4);
616
- ///let b = LinSrgb::new(0.6, 0.6, 0.6);
616
+ /// let a = LinSrgb::new(0.4, 0.4, 0.4);
617
+ /// let b = LinSrgb::new(0.6, 0.6, 0.6);
617
618
///
618
- ///assert_eq!(a.lighten(0.1), b.darken(0.1));
619
- ///```
619
+ /// assert_eq!(a.lighten(0.1), b.darken(0.1));
620
+ /// ```
620
621
pub trait Shade : Sized {
621
622
///The type of the lighten/darken amount.
622
623
type Scalar : Float ;
@@ -630,21 +631,21 @@ pub trait Shade: Sized {
630
631
}
631
632
}
632
633
633
- ///A trait for colors where a hue may be calculated.
634
+ /// A trait for colors where a hue may be calculated.
634
635
///
635
- ///```
636
- ///use palette::{LinSrgb, GetHue };
636
+ /// ```
637
+ /// use palette::{GetHue, LinSrgb };
637
638
///
638
- ///let red = LinSrgb::new(1.0f32, 0.0, 0.0);
639
- ///let green = LinSrgb::new(0.0f32, 1.0, 0.0);
640
- ///let blue = LinSrgb::new(0.0f32, 0.0, 1.0);
641
- ///let gray = LinSrgb::new(0.5f32, 0.5, 0.5);
639
+ /// let red = LinSrgb::new(1.0f32, 0.0, 0.0);
640
+ /// let green = LinSrgb::new(0.0f32, 1.0, 0.0);
641
+ /// let blue = LinSrgb::new(0.0f32, 0.0, 1.0);
642
+ /// let gray = LinSrgb::new(0.5f32, 0.5, 0.5);
642
643
///
643
- ///assert_eq!(red.get_hue(), Some(0.0.into()));
644
- ///assert_eq!(green.get_hue(), Some(120.0.into()));
645
- ///assert_eq!(blue.get_hue(), Some(240.0.into()));
646
- ///assert_eq!(gray.get_hue(), None);
647
- ///```
644
+ /// assert_eq!(red.get_hue(), Some(0.0.into()));
645
+ /// assert_eq!(green.get_hue(), Some(120.0.into()));
646
+ /// assert_eq!(blue.get_hue(), Some(240.0.into()));
647
+ /// assert_eq!(gray.get_hue(), None);
648
+ /// ```
648
649
pub trait GetHue {
649
650
///The kind of hue unit this color space uses.
650
651
///
@@ -670,17 +671,17 @@ pub trait Hue: GetHue {
670
671
fn shift_hue < H : Into < Self :: Hue > > ( & self , amount : H ) -> Self ;
671
672
}
672
673
673
- ///A trait for colors where the saturation (or chroma) can be manipulated
674
- ///without conversion.
674
+ /// A trait for colors where the saturation (or chroma) can be manipulated
675
+ /// without conversion.
675
676
///
676
- ///```
677
- ///use palette::{Hsv, Saturate};
677
+ /// ```
678
+ /// use palette::{Hsv, Saturate};
678
679
///
679
- ///let a = Hsv::new(0.0, 0.25, 1.0);
680
- ///let b = Hsv::new(0.0, 1.0, 1.0);
680
+ /// let a = Hsv::new(0.0, 0.25, 1.0);
681
+ /// let b = Hsv::new(0.0, 1.0, 1.0);
681
682
///
682
- ///assert_eq!(a.saturate(1.0), b.desaturate(0.5));
683
- ///```
683
+ /// assert_eq!(a.saturate(1.0), b.desaturate(0.5));
684
+ /// ```
684
685
pub trait Saturate : Sized {
685
686
///The type of the (de)saturation factor.
686
687
type Scalar : Float ;
@@ -836,7 +837,8 @@ impl Component for u64 {
836
837
}
837
838
}
838
839
839
- ///A convenience function to convert a constant number to Float Type
840
+ /// A convenience function to convert a constant number to Float Type
841
+ #[ inline]
840
842
fn cast < T : NumCast , P : ToPrimitive > ( prim : P ) -> T {
841
843
NumCast :: from ( prim) . unwrap ( )
842
844
}
0 commit comments