Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Unified Diff: Source/core/animation/AnimatableColor.cpp

Issue 186463002: Web Animations: define distance for AnimatableColor (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove blank line Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/animation/AnimatableColor.h ('k') | Source/core/animation/AnimatableColorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/animation/AnimatableColor.cpp
diff --git a/Source/core/animation/AnimatableColor.cpp b/Source/core/animation/AnimatableColor.cpp
index d501a81f4c10cae344c6f89226651ce60e835998..011e77e27b8da886219293f6d21e76843fd1624e 100644
--- a/Source/core/animation/AnimatableColor.cpp
+++ b/Source/core/animation/AnimatableColor.cpp
@@ -34,6 +34,15 @@
#include "platform/animation/AnimationUtilities.h"
#include "wtf/MathExtras.h"
+namespace {
+
+double square(double x)
+{
+ return x * x;
+}
+
+} // namespace
+
namespace WebCore {
AnimatableColorImpl::AnimatableColorImpl(float red, float green, float blue, float alpha)
@@ -83,6 +92,14 @@ bool AnimatableColorImpl::operator==(const AnimatableColorImpl& other) const
&& m_alpha == other.m_alpha;
}
+double AnimatableColorImpl::distanceTo(const AnimatableColorImpl& other) const
+{
+ return sqrt(square(m_red - other.m_red)
+ + square(m_green - other.m_green)
+ + square(m_blue - other.m_blue)
+ + square(m_alpha - other.m_alpha));
+}
+
PassRefPtr<AnimatableColor> AnimatableColor::create(const AnimatableColorImpl& color, const AnimatableColorImpl& visitedLinkColor)
{
return adoptRef(new AnimatableColor(color, visitedLinkColor));
@@ -108,4 +125,10 @@ bool AnimatableColor::equalTo(const AnimatableValue* value) const
return m_color == color->m_color && m_visitedLinkColor == color->m_visitedLinkColor;
}
+double AnimatableColor::distanceTo(const AnimatableValue* value) const
+{
+ const AnimatableColor* color = toAnimatableColor(value);
+ return m_color.distanceTo(color->m_color);
+}
+
} // namespace WebCore
« no previous file with comments | « Source/core/animation/AnimatableColor.h ('k') | Source/core/animation/AnimatableColorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698