Skip to content

Commit

Permalink
Implement compute_distance for Angle.
Browse files Browse the repository at this point in the history
When computing the distance between two filter functions, e.g.
HueRotate(0deg) and HueRotate(-360deg), we got an Err(()) and unwrap it
immediately in compute_filter_square_distance(), which causes a crash.
The root-cause is that we don't implement computed_distance of Angle, and we
assume we always get a valid result from compute_squared_distance() for
each filter function.
  • Loading branch information
BorisChiou committed Jul 27, 2017
1 parent b38d3f2 commit 20e3508
Showing 1 changed file with 7 additions and 0 deletions.
Expand Up @@ -925,6 +925,13 @@ impl Animatable for Angle {
}
}
}

#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
// Use the formula for calculating the distance between angles defined in SVG:
// https://www.w3.org/TR/SVG/animate.html#complexDistances
Ok((self.radians64() - other.radians64()).abs())
}
}

/// https://drafts.csswg.org/css-transitions/#animtype-percentage
Expand Down

0 comments on commit 20e3508

Please sign in to comment.