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

Unified Diff: Source/platform/transforms/RotateTransformOperation.cpp

Issue 328333003: Adding Blink-side 3d Box and Bounds calculations to TransformOperations (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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
Index: Source/platform/transforms/RotateTransformOperation.cpp
diff --git a/Source/platform/transforms/RotateTransformOperation.cpp b/Source/platform/transforms/RotateTransformOperation.cpp
index 94ab0d431f5be5ec2bcb002444378bc5d9ad49c0..2cbf540d7e65ab4c326336a08dccbd99ca0d357d 100644
--- a/Source/platform/transforms/RotateTransformOperation.cpp
+++ b/Source/platform/transforms/RotateTransformOperation.cpp
@@ -23,6 +23,7 @@
#include "platform/transforms/RotateTransformOperation.h"
#include "platform/animation/AnimationUtilities.h"
+#include "platform/geometry/FloatPoint3D.h"
#include "wtf/MathExtras.h"
#include <algorithm>
@@ -30,6 +31,62 @@ using namespace std;
namespace WebCore {
+static const double kAngleEpsilon = 1e-4;
Ian Vollick 2014/06/17 15:54:55 s/kAngleEpsilon/angleEpsilon/
awoloszyn 2014/06/17 20:06:02 Done.
+
+bool RotateTransformOperation::hasZeroAxis() const
+{
+ return(axis().lengthSquared() < kAngleEpsilon);
+}
+
+FloatPoint3D RotateTransformOperation::axis() const
+{
+ return(FloatPoint3D(x(), y(), z()));
Ian Vollick 2014/06/17 15:54:55 No braces around the return value, pls. Here and a
awoloszyn 2014/06/17 20:06:02 Done.
+}
+
+bool RotateTransformOperation::shareSameAxis(const RotateTransformOperation* from, const RotateTransformOperation* to, FloatPoint3D* axis, double* fromAngle, double* toAngle)
+{
+ *axis = FloatPoint3D(0, 0, 1);
+ *fromAngle = 0;
+ *toAngle = 0;
+
+ if (!from && !to)
+ return true;
+
+ bool fromZero = !from || from->hasZeroAxis();
+ bool toZero = !to || to->hasZeroAxis();
+
+ if (fromZero && toZero)
+ return true;
+
+ if (fromZero) {
+ *axis = to->axis();
+ *toAngle = to->angle();
+ return true;
+ }
+
+ if (toZero) {
+ *axis = from->axis();
+ *fromAngle = from->angle();
+ return true;
+ }
+
+ FloatPoint3D fromAxis = from->axis();
+ FloatPoint3D toAxis = to->axis();
+
+ double fromSquared = fromAxis.lengthSquared();
+ double toSquared = toAxis.lengthSquared();
+
+ double dot = fromAxis.dot(toAxis);
+ double error = std::abs(1 - (dot * dot) / (fromSquared * toSquared));
+
+ if (error > kAngleEpsilon)
+ return false;
+ *axis = from->axis();
+ *fromAngle = from->angle();
+ *toAngle = to->angle();
+ return true;
+}
+
PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
@@ -50,6 +107,12 @@ PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp
fromOp ? fromOp->m_z : m_z,
WebCore::blend(fromAngle, m_angle, progress), m_type);
}
+ double fromAngle;
+ double toAngle;
+ FloatPoint3D axis;
+
+ if (shareSameAxis(fromOp, this, &axis, &fromAngle, &toAngle))
+ return RotateTransformOperation::create(axis.x(), axis.y(), axis.z(), WebCore::blend(fromAngle, toAngle, progress), m_type);
const RotateTransformOperation* toOp = this;
@@ -93,4 +156,9 @@ PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp
return RotateTransformOperation::create(x, y, z, angle, Rotate3D);
}
+bool RotateTransformOperation::canInterpolateWith(const TransformOperation& other) const
+{
+ return(other.isSameType(*this));
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698