This source file includes following definitions.
- greatestCommonDivisor
- lowestCommonMultiple
- usesDefaultInterpolationWith
- interpolateLists
- interpolateTo
- addWith
- equalTo
- trace
#include "config.h"
#include "core/animation/AnimatableRepeatable.h"
namespace {
size_t greatestCommonDivisor(size_t a, size_t b)
{
return b ? greatestCommonDivisor(b, a % b) : a;
}
size_t lowestCommonMultiple(size_t a, size_t b)
{
ASSERT(a && b);
return a / greatestCommonDivisor(a, b) * b;
}
}
namespace WebCore {
bool AnimatableRepeatable::usesDefaultInterpolationWith(const AnimatableValue* value) const
{
const WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >& fromValues = m_values;
const WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >& toValues = toAnimatableRepeatable(value)->m_values;
ASSERT(!fromValues.isEmpty() && !toValues.isEmpty());
size_t size = lowestCommonMultiple(fromValues.size(), toValues.size());
for (size_t i = 0; i < size; ++i) {
const AnimatableValue* from = fromValues[i % fromValues.size()].get();
const AnimatableValue* to = toValues[i % toValues.size()].get();
if (AnimatableValue::usesDefaultInterpolation(from, to))
return true;
}
return false;
}
bool AnimatableRepeatable::interpolateLists(const WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >& fromValues, const WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >& toValues, double fraction, WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >& interpolatedValues)
{
ASSERT(interpolatedValues.isEmpty());
ASSERT(!fromValues.isEmpty() && !toValues.isEmpty());
size_t size = lowestCommonMultiple(fromValues.size(), toValues.size());
for (size_t i = 0; i < size; ++i) {
const AnimatableValue* from = fromValues[i % fromValues.size()].get();
const AnimatableValue* to = toValues[i % toValues.size()].get();
if (AnimatableValue::usesDefaultInterpolation(from, to))
return false;
interpolatedValues.append(interpolate(from, to, fraction));
}
return true;
}
PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableRepeatable::interpolateTo(const AnimatableValue* value, double fraction) const
{
WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > interpolatedValues;
bool success = interpolateLists(m_values, toAnimatableRepeatable(value)->m_values, fraction, interpolatedValues);
if (success)
return create(interpolatedValues);
return defaultInterpolateTo(this, value, fraction);
}
PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableRepeatable::addWith(const AnimatableValue* value) const
{
const WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >& otherValues = toAnimatableRepeatable(value)->m_values;
ASSERT(!m_values.isEmpty() && !otherValues.isEmpty());
WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > addedValues(lowestCommonMultiple(m_values.size(), otherValues.size()));
for (size_t i = 0; i < addedValues.size(); ++i) {
const AnimatableValue* left = m_values[i % m_values.size()].get();
const AnimatableValue* right = otherValues[i % otherValues.size()].get();
addedValues[i] = add(left, right);
}
return create(addedValues);
}
bool AnimatableRepeatable::equalTo(const AnimatableValue* value) const
{
const WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> >& otherValues = toAnimatableRepeatable(value)->m_values;
if (m_values.size() != otherValues.size())
return false;
for (size_t i = 0; i < m_values.size(); ++i) {
if (!m_values[i]->equals(otherValues[i].get()))
return false;
}
return true;
}
void AnimatableRepeatable::trace(Visitor* visitor)
{
visitor->trace(m_values);
}
}