remove final clamp! macro
This commit is contained in:
parent
33ccabce7b
commit
4d989b60b1
@ -132,30 +132,16 @@ impl Color {
|
||||
|
||||
/// Create a new `Color` with just RGBA values.
|
||||
/// Color representation is created automatically.
|
||||
pub fn from_rgba(red: Number, green: Number, blue: Number, alpha: Number) -> Self {
|
||||
macro_rules! clamp {
|
||||
($channel:ident) => {
|
||||
let $channel = if $channel > Number::from(255) {
|
||||
Number::from(255)
|
||||
} else if $channel.is_negative() {
|
||||
Number::zero()
|
||||
} else {
|
||||
$channel
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
clamp!(red);
|
||||
clamp!(green);
|
||||
clamp!(blue);
|
||||
|
||||
let alpha = if alpha > Number::one() {
|
||||
Number::one()
|
||||
} else if alpha.is_negative() {
|
||||
Number::zero()
|
||||
} else {
|
||||
alpha
|
||||
};
|
||||
pub fn from_rgba(
|
||||
mut red: Number,
|
||||
mut green: Number,
|
||||
mut blue: Number,
|
||||
mut alpha: Number,
|
||||
) -> Self {
|
||||
red = red.clamp(0, 255);
|
||||
green = green.clamp(0, 255);
|
||||
blue = blue.clamp(0, 255);
|
||||
alpha = alpha.clamp(0, 1);
|
||||
|
||||
let repr = repr(&red, &green, &blue, &alpha);
|
||||
Color::new_rgba(red, green, blue, alpha, repr)
|
||||
|
@ -58,12 +58,16 @@ impl Number {
|
||||
self.val.denom() != &BigInt::from(1)
|
||||
}
|
||||
|
||||
pub fn clamp<A: Into<Number>, B: Into<Number>>(self, min: A, max: B) -> Self {
|
||||
pub fn clamp<A: Into<Number> + Zero, B: Into<Number>>(self, min: A, max: B) -> Self {
|
||||
let max = max.into();
|
||||
if self > max {
|
||||
return max;
|
||||
}
|
||||
|
||||
if min.is_zero() && self.is_negative() {
|
||||
return Number::zero();
|
||||
}
|
||||
|
||||
let min = min.into();
|
||||
if self < min {
|
||||
return min;
|
||||
|
Loading…
x
Reference in New Issue
Block a user