pub trait HasAlpha {
type Component;
#[must_use]
fn new_alpha(value: Self::Component) -> Self
where
Self: Sized + Default,
{
let mut color = Self::default();
color.set_alpha(value);
color
}
#[must_use]
fn alpha(&self) -> Self::Component;
fn set_alpha(&mut self, value: Self::Component);
#[must_use]
fn with_alpha(self, value: Self::Component) -> Self
where
Self: Sized,
{
let mut color = self;
color.set_alpha(value);
color
}
}
#[cfg(test)]
#[allow(clippy::float_cmp)]
mod tests {
use crate::gray::GrayAlpha8;
use super::*;
#[test]
fn with_alpha_grayalpha8_new_alpha() {
assert_eq!(GrayAlpha8::new_alpha(128), GrayAlpha8::new(0, 128));
}
#[test]
fn with_alpha_grayalpha8_get_alpha() {
assert_eq!(GrayAlpha8::new(128, 255).alpha(), 255);
}
#[test]
fn with_alpha_grayalpha8_set_alpha() {
let mut color = GrayAlpha8::new(128, 255);
color.set_alpha(64);
assert_eq!(color, GrayAlpha8::new(128, 64));
}
#[test]
fn with_alpha_grayalpha8_with_alpha() {
let color = GrayAlpha8::new(128, 255);
let new_color = color.with_alpha(64);
assert_eq!(new_color, GrayAlpha8::new(128, 64));
}
}