Avoid unwrap in LengthOrPercentageOrAuto::compute_squared_distance

This commit is contained in:
Anthony Ramine 2017-05-18 19:10:15 +02:00
parent 864f5509d8
commit bcf1a6c5e5

View file

@ -1185,12 +1185,12 @@ impl Animatable for LengthOrPercentageOrAuto {
(this, other) => {
let this: Option<CalcLengthOrPercentage> = From::from(this);
let other: Option<CalcLengthOrPercentage> = From::from(other);
if this.is_none() || other.is_none() {
Err(())
} else {
let length_diff = (this.unwrap().length().0 - other.unwrap().length().0) as f64;
let percentage_diff = (this.unwrap().percentage() - other.unwrap().percentage()) as f64;
if let (Some(this), Some(other)) = (this, other) {
let length_diff = (this.length().0 - other.length().0) as f64;
let percentage_diff = (this.percentage() - other.percentage()) as f64;
Ok(length_diff * length_diff + percentage_diff * percentage_diff)
} else {
Err(())
}
}
}