diff --git a/Cargo.toml b/Cargo.toml index 5e992e4..d6cdfa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ clippy.cargo = { level = "warn", priority = -1 } ## Explicit per-crate exceptions, should be manually checked occasionally. # There are lots of conversion to u8 color field, which in degenerate cases might not work # properly, but generally are fine. -# E.g. `with_alpha_factor` sets the alpha to `0` for a negative provided `alpha` +# E.g. `multiply_alpha` sets the alpha to `0` for a negative provided `alpha` # clippy.cast_possible_truncation = "warn" # Most enums are correctly exhaustive, as this is a vocabulary crate. # clippy.exhaustive_enums = "warn" diff --git a/src/brush.rs b/src/brush.rs index 6e2273e..7528551 100644 --- a/src/brush.rs +++ b/src/brush.rs @@ -45,20 +45,20 @@ impl Brush { /// Returns the brush with the alpha component multiplied by the specified /// factor. #[must_use] - pub fn with_alpha_factor(self, alpha: f32) -> Self { + pub fn multiply_alpha(self, alpha: f32) -> Self { if alpha == 1.0 { self } else { match self { - Self::Solid(color) => color.with_alpha_factor(alpha).into(), + Self::Solid(color) => color.multiply_alpha(alpha).into(), Self::Gradient(mut gradient) => { gradient .stops .iter_mut() - .for_each(|stop| *stop = stop.with_alpha_factor(alpha)); + .for_each(|stop| *stop = stop.multiply_alpha(alpha)); gradient.into() } - Self::Image(image) => image.with_alpha_factor(alpha).into(), + Self::Image(image) => image.multiply_alpha(alpha).into(), } } } diff --git a/src/color.rs b/src/color.rs index 09d6121..8b44e74 100644 --- a/src/color.rs +++ b/src/color.rs @@ -142,7 +142,17 @@ impl Color { /// Returns the color with the alpha component multiplied by the specified /// factor. #[must_use] + #[deprecated( + since = "0.2.0", + note = "This method has been renamed to `multiply_alpha`." + )] pub fn with_alpha_factor(self, alpha: f32) -> Self { + self.multiply_alpha(alpha) + } + /// Returns the color with the alpha component multiplied by the specified + /// factor. + #[must_use] + pub fn multiply_alpha(self, alpha: f32) -> Self { let mut result = self; result.a = ((result.a as f32) * alpha).round() as u8; result diff --git a/src/gradient.rs b/src/gradient.rs index a839f09..d8b49fc 100644 --- a/src/gradient.rs +++ b/src/gradient.rs @@ -38,10 +38,21 @@ impl ColorStop { /// Returns the color stop with the alpha component multiplied by the specified /// factor. #[must_use] + #[deprecated( + since = "0.2.0", + note = "This method has been renamed to `multiply_alpha`." + )] pub fn with_alpha_factor(self, alpha: f32) -> Self { + self.multiply_alpha(alpha) + } + + /// Returns the color stop with the alpha component multiplied by the specified + /// factor. + #[must_use] + pub fn multiply_alpha(self, alpha: f32) -> Self { Self { offset: self.offset, - color: self.color.with_alpha_factor(alpha), + color: self.color.multiply_alpha(alpha), } } } diff --git a/src/image.rs b/src/image.rs index 51468c1..c0b84ac 100644 --- a/src/image.rs +++ b/src/image.rs @@ -73,7 +73,7 @@ impl Image { /// Builder method for setting the image alpha. #[must_use] - pub fn with_alpha_factor(mut self, alpha: f32) -> Self { + pub fn multiply_alpha(mut self, alpha: f32) -> Self { self.alpha = ((self.alpha as f32) * alpha).round() as u8; self }