Chromium Code Reviews| Index: Source/platform/transforms/RotateTransformOperation.cpp |
| diff --git a/Source/platform/transforms/RotateTransformOperation.cpp b/Source/platform/transforms/RotateTransformOperation.cpp |
| index 94ab0d431f5be5ec2bcb002444378bc5d9ad49c0..9c9d95d883392b72327b18697206cb58c20ca201 100644 |
| --- a/Source/platform/transforms/RotateTransformOperation.cpp |
| +++ b/Source/platform/transforms/RotateTransformOperation.cpp |
| @@ -30,6 +30,63 @@ using namespace std; |
| namespace WebCore { |
| +const double kAngleEpsilon = 1e-4; |
| + |
| +static bool isZeroAxis(const RotateTransformOperation& from) |
|
Ian Vollick
2014/06/16 15:23:37
Please expose this rather than duplicating in Tran
awoloszyn
2014/06/17 14:26:01
Done.
|
| +{ |
| + double length = from.x() * from.x() + from.y() * from.y() + from.z() * from.z(); |
|
Ian Vollick
2014/06/16 15:23:37
If you add a FloatPoint3D RotationTransformOperati
awoloszyn
2014/06/17 14:26:00
Done.
|
| + return(length < kAngleEpsilon); |
| +} |
| + |
| +static bool shareSameAxis(const RotateTransformOperation* from, const RotateTransformOperation* to, double& x, double& y, double& z, double& fromAngle, double& toAngle) |
|
Ian Vollick
2014/06/16 15:23:37
Please expose this, too.
awoloszyn
2014/06/17 14:26:00
Done.
|
| +{ |
| + x = 0; |
| + y = 0; |
| + z = 1; |
| + fromAngle = 0; |
| + toAngle = 0; |
| + |
| + if (!from && !to) |
| + return true; |
| + |
| + bool fromZero = !from || isZeroAxis(*from); |
| + bool toZero = !to || isZeroAxis(*to); |
| + |
| + if (fromZero && toZero) |
| + return true; |
| + |
| + if (fromZero) { |
| + x = to->x(); |
| + y = to->y(); |
| + z = to->z(); |
| + toAngle = to->angle(); |
| + return true; |
| + } |
| + |
| + if (toZero) { |
| + x = from->x(); |
| + y = from->y(); |
| + z = from->z(); |
| + fromAngle = from->angle(); |
| + return true; |
| + } |
| + |
| + double fromSquared = from->x() * from->x() + from->y() * from->y() + from->z() * from->z(); |
| + double toSquared = to->x() * to->x() + to->y() * to->y() + to->z() * to->z(); |
| + |
| + double dot = from->x() * to->x() + from->y() * to->y() + from->z() * to->z(); |
| + double error = std::abs(1 - (dot * dot) / (fromSquared * toSquared)); |
| + |
| + if (error > kAngleEpsilon) |
| + return false; |
| + x = from->x(); |
| + y = from->y(); |
| + z = from->z(); |
| + 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,14 @@ PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp |
| fromOp ? fromOp->m_z : m_z, |
| WebCore::blend(fromAngle, m_angle, progress), m_type); |
| } |
| + double axisX; |
| + double axisY; |
| + double axisZ; |
| + double fromAngle; |
| + double toAngle; |
| + if (shareSameAxis(fromOp, this, axisX, axisY, axisZ, fromAngle, toAngle)) { |
| + return RotateTransformOperation::create(axisX, axisY, axisZ, WebCore::blend(fromAngle, toAngle, progress), m_type); |
| + } |
| const RotateTransformOperation* toOp = this; |
| @@ -93,4 +158,9 @@ PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp |
| return RotateTransformOperation::create(x, y, z, angle, Rotate3D); |
| } |
| +bool RotateTransformOperation::isCompatibleType(const TransformOperation& other) const |
| +{ |
| + return(other.isSameType(*this)); |
| +} |
| + |
| } // namespace WebCore |