diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/color.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/core/src/color.rs b/core/src/color.rs index 799d85c9..fbc160e3 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -1,6 +1,5 @@ /// A color in the sRGB color space. #[derive(Debug, Clone, Copy, PartialEq)] -#[allow(missing_docs)] pub struct Color { /// Red component, 0.0 - 1.0 pub r: f32, @@ -12,7 +11,6 @@ pub struct Color { pub a: f32, } - impl Color { /// The black color. pub const BLACK: Color = Color { @@ -44,7 +42,7 @@ impl Color { } /// Ensures RGBA values on the range [0.0, 1.0] - pub fn check_rgba(r: f32, g: f32, b: f32, a:f32) -> Color { + pub fn new(r: f32, g: f32, b: f32, a: f32) -> Color { Color { r: Color::clamp(r), g: Color::clamp(g), @@ -57,7 +55,7 @@ impl Color { /// /// [`Color`]: struct.Color.html pub fn from_rgb(r: f32, g: f32, b: f32) -> Color { - Color::check_rgba(r, g, b, 1.0) + Color::new(r, g, b, 1.0) } /// Creates a [`Color`] from its RGB8 components. @@ -100,6 +98,18 @@ impl Color { self.a, ] } + + /// Invert the Color in-place + pub fn invert(&mut self) { + self.r = Color::clamp(1.0f32 - self.r); + self.b = Color::clamp(1.0f32 - self.g); + self.g = Color::clamp(1.0f32 - self.b); + } + + /// Return an inverted Color + pub fn inverse(self) -> Color { + Color::new(1.0f32 - self.r, 1.0f32 - self.g, 1.0f32 - self.b, self.a) + } } impl From<[f32; 3]> for Color { |