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.
|
/// Create a new `Color` with just RGBA values.
|
||||||
/// Color representation is created automatically.
|
/// Color representation is created automatically.
|
||||||
pub fn from_rgba(red: Number, green: Number, blue: Number, alpha: Number) -> Self {
|
pub fn from_rgba(
|
||||||
macro_rules! clamp {
|
mut red: Number,
|
||||||
($channel:ident) => {
|
mut green: Number,
|
||||||
let $channel = if $channel > Number::from(255) {
|
mut blue: Number,
|
||||||
Number::from(255)
|
mut alpha: Number,
|
||||||
} else if $channel.is_negative() {
|
) -> Self {
|
||||||
Number::zero()
|
red = red.clamp(0, 255);
|
||||||
} else {
|
green = green.clamp(0, 255);
|
||||||
$channel
|
blue = blue.clamp(0, 255);
|
||||||
};
|
alpha = alpha.clamp(0, 1);
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
clamp!(red);
|
|
||||||
clamp!(green);
|
|
||||||
clamp!(blue);
|
|
||||||
|
|
||||||
let alpha = if alpha > Number::one() {
|
|
||||||
Number::one()
|
|
||||||
} else if alpha.is_negative() {
|
|
||||||
Number::zero()
|
|
||||||
} else {
|
|
||||||
alpha
|
|
||||||
};
|
|
||||||
|
|
||||||
let repr = repr(&red, &green, &blue, &alpha);
|
let repr = repr(&red, &green, &blue, &alpha);
|
||||||
Color::new_rgba(red, green, blue, alpha, repr)
|
Color::new_rgba(red, green, blue, alpha, repr)
|
||||||
|
@ -58,12 +58,16 @@ impl Number {
|
|||||||
self.val.denom() != &BigInt::from(1)
|
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();
|
let max = max.into();
|
||||||
if self > max {
|
if self > max {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if min.is_zero() && self.is_negative() {
|
||||||
|
return Number::zero();
|
||||||
|
}
|
||||||
|
|
||||||
let min = min.into();
|
let min = min.into();
|
||||||
if self < min {
|
if self < min {
|
||||||
return min;
|
return min;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user