OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/animation/InterpolableValue.h" | 5 #include "core/animation/InterpolableValue.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 bool InterpolableNumber::equals(const InterpolableValue& other) const | 11 bool InterpolableNumber::equals(const InterpolableValue& other) const |
12 { | 12 { |
13 return m_value == toInterpolableNumber(other).m_value; | 13 return m_value == toInterpolableNumber(other).m_value; |
14 } | 14 } |
15 | 15 |
16 bool InterpolableList::equals(const InterpolableValue& other) const | 16 bool InterpolableList::equals(const InterpolableValue& other) const |
17 { | 17 { |
18 const InterpolableList& otherList = toInterpolableList(other); | 18 const InterpolableList& otherList = toInterpolableList(other); |
19 if (m_size != otherList.m_size) | 19 if (length() != otherList.length()) |
20 return false; | 20 return false; |
21 for (size_t i = 0; i < m_size; i++) { | 21 for (size_t i = 0; i < length(); i++) { |
22 if (!m_values[i]->equals(*otherList.m_values[i])) | 22 if (!m_values[i]->equals(*otherList.m_values[i])) |
23 return false; | 23 return false; |
24 } | 24 } |
25 return true; | 25 return true; |
26 } | 26 } |
27 | 27 |
28 void InterpolableNumber::interpolate(const InterpolableValue &to, const double p
rogress, InterpolableValue& result) const | 28 void InterpolableNumber::interpolate(const InterpolableValue &to, const double p
rogress, InterpolableValue& result) const |
29 { | 29 { |
30 const InterpolableNumber& toNumber = toInterpolableNumber(to); | 30 const InterpolableNumber& toNumber = toInterpolableNumber(to); |
31 InterpolableNumber& resultNumber = toInterpolableNumber(result); | 31 InterpolableNumber& resultNumber = toInterpolableNumber(result); |
(...skipping 15 matching lines...) Expand all Loading... |
47 resultBool.m_value = m_value; | 47 resultBool.m_value = m_value; |
48 else | 48 else |
49 resultBool.m_value = toBool.m_value; | 49 resultBool.m_value = toBool.m_value; |
50 } | 50 } |
51 | 51 |
52 void InterpolableList::interpolate(const InterpolableValue& to, const double pro
gress, InterpolableValue& result) const | 52 void InterpolableList::interpolate(const InterpolableValue& to, const double pro
gress, InterpolableValue& result) const |
53 { | 53 { |
54 const InterpolableList& toList = toInterpolableList(to); | 54 const InterpolableList& toList = toInterpolableList(to); |
55 InterpolableList& resultList = toInterpolableList(result); | 55 InterpolableList& resultList = toInterpolableList(result); |
56 | 56 |
57 DCHECK_EQ(toList.m_size, m_size); | 57 DCHECK_EQ(toList.length(), length()); |
58 DCHECK_EQ(resultList.m_size, m_size); | 58 DCHECK_EQ(resultList.length(), length()); |
59 | 59 |
60 for (size_t i = 0; i < m_size; i++) { | 60 for (size_t i = 0; i < length(); i++) { |
61 DCHECK(m_values[i]); | 61 DCHECK(m_values[i]); |
62 DCHECK(toList.m_values[i]); | 62 DCHECK(toList.m_values[i]); |
63 m_values[i]->interpolate(*(toList.m_values[i]), progress, *(resultList.m
_values[i])); | 63 m_values[i]->interpolate(*(toList.m_values[i]), progress, *(resultList.m
_values[i])); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 std::unique_ptr<InterpolableValue> InterpolableList::cloneAndZero() const | 67 std::unique_ptr<InterpolableValue> InterpolableList::cloneAndZero() const |
68 { | 68 { |
69 std::unique_ptr<InterpolableList> result = InterpolableList::create(m_size); | 69 std::unique_ptr<InterpolableList> result = InterpolableList::create(length()
); |
70 for (size_t i = 0; i < m_size; i++) | 70 for (size_t i = 0; i < length(); i++) |
71 result->set(i, m_values[i]->cloneAndZero()); | 71 result->set(i, m_values[i]->cloneAndZero()); |
72 return std::move(result); | 72 return std::move(result); |
73 } | 73 } |
74 | 74 |
75 void InterpolableNumber::scale(double scale) | 75 void InterpolableNumber::scale(double scale) |
76 { | 76 { |
77 m_value = m_value * scale; | 77 m_value = m_value * scale; |
78 } | 78 } |
79 | 79 |
80 void InterpolableList::scale(double scale) | 80 void InterpolableList::scale(double scale) |
81 { | 81 { |
82 for (size_t i = 0; i < m_size; i++) | 82 for (size_t i = 0; i < length(); i++) |
83 m_values[i]->scale(scale); | 83 m_values[i]->scale(scale); |
84 } | 84 } |
85 | 85 |
86 void InterpolableNumber::scaleAndAdd(double scale, const InterpolableValue& othe
r) | 86 void InterpolableNumber::scaleAndAdd(double scale, const InterpolableValue& othe
r) |
87 { | 87 { |
88 m_value = m_value * scale + toInterpolableNumber(other).m_value; | 88 m_value = m_value * scale + toInterpolableNumber(other).m_value; |
89 } | 89 } |
90 | 90 |
91 void InterpolableList::scaleAndAdd(double scale, const InterpolableValue& other) | 91 void InterpolableList::scaleAndAdd(double scale, const InterpolableValue& other) |
92 { | 92 { |
93 const InterpolableList& otherList = toInterpolableList(other); | 93 const InterpolableList& otherList = toInterpolableList(other); |
94 DCHECK_EQ(otherList.m_size, m_size); | 94 DCHECK_EQ(otherList.length(), length()); |
95 for (size_t i = 0; i < m_size; i++) | 95 for (size_t i = 0; i < length(); i++) |
96 m_values[i]->scaleAndAdd(scale, *otherList.m_values[i]); | 96 m_values[i]->scaleAndAdd(scale, *otherList.m_values[i]); |
97 } | 97 } |
98 | 98 |
99 void InterpolableAnimatableValue::interpolate(const InterpolableValue& to, const
double progress, InterpolableValue& result) const | 99 void InterpolableAnimatableValue::interpolate(const InterpolableValue& to, const
double progress, InterpolableValue& result) const |
100 { | 100 { |
101 const InterpolableAnimatableValue& toValue = toInterpolableAnimatableValue(t
o); | 101 const InterpolableAnimatableValue& toValue = toInterpolableAnimatableValue(t
o); |
102 InterpolableAnimatableValue& resultValue = toInterpolableAnimatableValue(res
ult); | 102 InterpolableAnimatableValue& resultValue = toInterpolableAnimatableValue(res
ult); |
103 if (progress == 0) | 103 if (progress == 0) |
104 resultValue.m_value = m_value; | 104 resultValue.m_value = m_value; |
105 if (progress == 1) | 105 if (progress == 1) |
106 resultValue.m_value = toValue.m_value; | 106 resultValue.m_value = toValue.m_value; |
107 resultValue.m_value = AnimatableValue::interpolate(m_value.get(), toValue.m_
value.get(), progress); | 107 resultValue.m_value = AnimatableValue::interpolate(m_value.get(), toValue.m_
value.get(), progress); |
108 } | 108 } |
109 | 109 |
110 } // namespace blink | 110 } // namespace blink |
OLD | NEW |