mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Handle zero-length lists in add_weighted
This commit is contained in:
parent
296a215e54
commit
59a3142200
1 changed files with 8 additions and 0 deletions
|
@ -828,6 +828,10 @@ macro_rules! repeated_vec_impl {
|
||||||
$(impl<T: RepeatableListAnimatable> Animatable for $ty {
|
$(impl<T: RepeatableListAnimatable> Animatable for $ty {
|
||||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
|
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
|
||||||
-> Result<Self, ()> {
|
-> Result<Self, ()> {
|
||||||
|
// If the length of either list is zero, the least common multiple is undefined.
|
||||||
|
if cmp::min(self.len(), other.len()) < 1 {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
use num_integer::lcm;
|
use num_integer::lcm;
|
||||||
let len = lcm(self.len(), other.len());
|
let len = lcm(self.len(), other.len());
|
||||||
self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
|
self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
|
||||||
|
@ -842,6 +846,10 @@ macro_rules! repeated_vec_impl {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
|
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||||
|
// If the length of either list is zero, the least common multiple is undefined.
|
||||||
|
if cmp::min(self.len(), other.len()) < 1 {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
use num_integer::lcm;
|
use num_integer::lcm;
|
||||||
let len = lcm(self.len(), other.len());
|
let len = lcm(self.len(), other.len());
|
||||||
self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
|
self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue