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

Side by Side Diff: Source/platform/transforms/RotateTransformOperation.cpp

Issue 1027513003: Avoid uninitialized memory when decomposing a matrix fails. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 toT.rotate3d((toOp ? toOp->m_x : 0), 120 toT.rotate3d((toOp ? toOp->m_x : 0),
121 (toOp ? toOp->m_y : 0), 121 (toOp ? toOp->m_y : 0),
122 (toOp ? toOp->m_z : 1), 122 (toOp ? toOp->m_z : 1),
123 (toOp ? toOp->m_angle : 0)); 123 (toOp ? toOp->m_angle : 0));
124 124
125 // Blend them 125 // Blend them
126 toT.blend(fromT, progress); 126 toT.blend(fromT, progress);
127 127
128 // Extract the result as a quaternion 128 // Extract the result as a quaternion
129 TransformationMatrix::DecomposedType decomp; 129 TransformationMatrix::DecomposedType decomp;
130 toT.decompose(decomp); 130 if (!toT.decompose(decomp)) {
131 // If we can't decompose, bail out of interpolation.
132 const RotateTransformOperation* usedOperation = progress > 0.5 ? this : fromOp;
133 return RotateTransformOperation::create(usedOperation->x(), usedOperatio n->y(), usedOperation->z(), usedOperation->angle(), Rotate3D);
134 }
131 135
132 // Convert that to Axis/Angle form 136 // Convert that to Axis/Angle form
133 double x = -decomp.quaternionX; 137 double x = -decomp.quaternionX;
134 double y = -decomp.quaternionY; 138 double y = -decomp.quaternionY;
135 double z = -decomp.quaternionZ; 139 double z = -decomp.quaternionZ;
136 double length = std::sqrt(x * x + y * y + z * z); 140 double length = std::sqrt(x * x + y * y + z * z);
137 double angle = 0; 141 double angle = 0;
138 142
139 if (length > 0.00001) { 143 if (length > 0.00001) {
140 x /= length; 144 x /= length;
141 y /= length; 145 y /= length;
142 z /= length; 146 z /= length;
143 angle = rad2deg(std::acos(decomp.quaternionW) * 2); 147 angle = rad2deg(std::acos(decomp.quaternionW) * 2);
144 } else { 148 } else {
145 x = 0; 149 x = 0;
146 y = 0; 150 y = 0;
147 z = 1; 151 z = 1;
148 } 152 }
149 return RotateTransformOperation::create(x, y, z, angle, Rotate3D); 153 return RotateTransformOperation::create(x, y, z, angle, Rotate3D);
150 } 154 }
151 155
152 bool RotateTransformOperation::canBlendWith(const TransformOperation& other) con st 156 bool RotateTransformOperation::canBlendWith(const TransformOperation& other) con st
153 { 157 {
154 return other.isSameType(*this); 158 return other.isSameType(*this);
155 } 159 }
156 160
157 } // namespace blink 161 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/transforms/PerspectiveTransformOperation.cpp ('k') | Source/platform/transforms/TransformationMatrix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698