OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "core/animation/AnimatableRepeatable.h" | |
33 | |
34 namespace WebCore { | |
35 | |
36 static size_t gcd(size_t a, size_t b) | |
Steve Block
2013/10/08 23:21:49
I think Blink style is to use size_t only for size
Steve Block
2013/10/08 23:27:23
I think we prefer anonymous namespaces to static
alancutter (OOO until 2018)
2013/10/09 07:20:55
Done.
Steve Block
2013/10/09 23:19:05
What about using int rather than size_t?
alancutter (OOO until 2018)
2013/10/10 00:58:38
Because these functions are used for vector sizes
| |
37 { | |
38 return b ? gcd(b, a % b) : a; | |
39 } | |
40 | |
41 static size_t lcm(size_t a, size_t b) | |
Steve Block
2013/10/08 23:21:49
Hmm, I've just implemented lowestCommonMultiple()
alancutter (OOO until 2018)
2013/10/09 07:20:55
Given that you intend to rebase ontop of this patc
Steve Block
2013/10/09 23:19:05
Agreed
| |
42 { | |
43 ASSERT(a && b); | |
44 return a / gcd(a, b) * b; | |
45 } | |
46 | |
47 PassRefPtr<AnimatableValue> AnimatableRepeatable::interpolateTo(const Animatable Value* value, double fraction) const | |
48 { | |
49 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable (value)->m_values; | |
50 Vector<RefPtr<AnimatableValue> > interpolatedValues(lcm(m_values.size(), oth erValues.size())); | |
Steve Block
2013/10/08 23:27:23
If one or other of the lists has zero entries, lcm
alancutter (OOO until 2018)
2013/10/09 07:20:55
Added support for 0 length AnimatableRepeatables.
| |
51 for (size_t i = 0; i < interpolatedValues.size(); ++i) { | |
52 const AnimatableValue* from = m_values[i % m_values.size()].get(); | |
53 const AnimatableValue* to = otherValues[i % otherValues.size()].get(); | |
54 if (!from->isSameType(to)) | |
dstockwell
2013/10/08 22:52:05
Needs a comment
Steve Block
2013/10/08 23:21:49
When could this happen? Should it be an assertion?
alancutter (OOO until 2018)
2013/10/09 07:20:55
This is most likely to happen when a keyword is us
alancutter (OOO until 2018)
2013/10/09 07:20:55
Added comment for method.
| |
55 return defaultInterpolateTo(this, value, fraction); | |
56 interpolatedValues[i] = interpolate(from, to, fraction); | |
57 } | |
58 return create(interpolatedValues); | |
59 } | |
60 | |
61 PassRefPtr<AnimatableValue> AnimatableRepeatable::addWith(const AnimatableValue* value) const | |
62 { | |
63 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable (value)->m_values; | |
64 Vector<RefPtr<AnimatableValue> > addedValues(lcm(m_values.size(), otherValue s.size())); | |
65 for (size_t i = 0; i < addedValues.size(); ++i) { | |
66 const AnimatableValue* left = m_values[i % m_values.size()].get(); | |
67 const AnimatableValue* right = otherValues[i % otherValues.size()].get() ; | |
68 if (!left->isSameType(right)) | |
69 return defaultAddWith(this, value); | |
70 addedValues[i] = add(left, right); | |
71 } | |
72 return create(addedValues); | |
73 } | |
74 | |
75 bool AnimatableRepeatable::equalTo(const AnimatableValue* value) const | |
76 { | |
77 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable (value)->m_values; | |
78 if (m_values.size() != otherValues.size()) | |
79 return false; | |
80 for (size_t i = 0; i < m_values.size(); ++i) { | |
81 if (!m_values[i]->equals(otherValues[i].get())) | |
82 return false; | |
83 } | |
84 return true; | |
Steve Block
2013/10/08 23:21:49
If we added operator==() to AnimatableValue(), we
alancutter (OOO until 2018)
2013/10/09 07:20:55
As discussed because it's a vector of RefPtrs we d
| |
85 } | |
86 | |
87 } // namespace WebCore | |
OLD | NEW |