mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
ComputedDistance for IntermediateRGBA.
This commit is contained in:
parent
d70e4aa229
commit
8de605f0dd
1 changed files with 25 additions and 0 deletions
|
@ -2325,6 +2325,31 @@ impl ComputeDistance for CSSParserColor {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for IntermediateRGBA {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sq| sq.sqrt())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
let start = [ self.alpha,
|
||||
self.red * self.alpha,
|
||||
self.green * self.alpha,
|
||||
self.blue * self.alpha ];
|
||||
let end = [ other.alpha,
|
||||
other.red * other.alpha,
|
||||
other.green * other.alpha,
|
||||
other.blue * other.alpha ];
|
||||
let diff = start.iter().zip(&end)
|
||||
.fold(0.0f64, |n, (&a, &b)| {
|
||||
let diff = (a - b) as f64;
|
||||
n + diff * diff
|
||||
});
|
||||
Ok(diff)
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for CalcLengthOrPercentage {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue