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

Side by Side Diff: third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp

Issue 2423753002: [GeometryInterface] add transformPoint(point) function. (Closed)
Patch Set: [GeometryInterface] add transformPoint(point) method. Created 4 years, 2 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
OLDNEW
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/dom/DOMMatrix.h" 5 #include "core/dom/DOMMatrix.h"
6 #include "core/dom/DOMMatrixInit.h" 6 #include "core/dom/DOMMatrixInit.h"
7 #include "core/dom/DOMPoint.h"
8 #include "core/dom/DOMPointInit.h"
7 9
8 namespace blink { 10 namespace blink {
9 namespace { 11 namespace {
10 12
11 void setDictionaryMembers(DOMMatrixInit& other) { 13 void setDictionaryMembers(DOMMatrixInit& other) {
12 if (!other.hasM11()) 14 if (!other.hasM11())
13 other.setM11(other.hasA() ? other.a() : 1); 15 other.setM11(other.hasA() ? other.a() : 1);
14 16
15 if (!other.hasM12()) 17 if (!other.hasM12())
16 other.setM12(other.hasB() ? other.b() : 0); 18 other.setM12(other.hasB() ? other.b() : 0);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 flipY->setM22(-this->m22()); 205 flipY->setM22(-this->m22());
204 flipY->setM23(-this->m23()); 206 flipY->setM23(-this->m23());
205 flipY->setM24(-this->m24()); 207 flipY->setM24(-this->m24());
206 return flipY; 208 return flipY;
207 } 209 }
208 210
209 DOMMatrix* DOMMatrixReadOnly::inverse() { 211 DOMMatrix* DOMMatrixReadOnly::inverse() {
210 return DOMMatrix::create(this)->invertSelf(); 212 return DOMMatrix::create(this)->invertSelf();
211 } 213 }
212 214
215 DOMPoint* DOMMatrixReadOnly::transformPoint(const DOMPointInit& point) {
216 if (is2D() && point.z() == 0 && point.w() == 1) {
217 double x = point.x() * m11() + point.y() * m12() + m41();
218 double y = point.x() * m12() + point.y() * m22() + m42();
219 return DOMPoint::create(x, y, 0, 1);
220 }
221
222 double x = point.x() * m11() + point.y() * m21() + point.z() * m31() +
223 point.w() * m41();
224 double y = point.x() * m12() + point.y() * m22() + point.z() * m32() +
225 point.w() * m42();
226 double z = point.x() * m13() + point.y() * m23() + point.z() * m33() +
227 point.w() * m43();
228 double w = point.x() * m14() + point.y() * m24() + point.z() * m34() +
229 point.w() * m44();
230 return DOMPoint::create(x, y, z, w);
231 }
232
213 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const { 233 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const {
214 float array[] = { 234 float array[] = {
215 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()), 235 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()),
216 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()), 236 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()),
217 static_cast<float>(m_matrix->m21()), static_cast<float>(m_matrix->m22()), 237 static_cast<float>(m_matrix->m21()), static_cast<float>(m_matrix->m22()),
218 static_cast<float>(m_matrix->m23()), static_cast<float>(m_matrix->m24()), 238 static_cast<float>(m_matrix->m23()), static_cast<float>(m_matrix->m24()),
219 static_cast<float>(m_matrix->m31()), static_cast<float>(m_matrix->m32()), 239 static_cast<float>(m_matrix->m31()), static_cast<float>(m_matrix->m32()),
220 static_cast<float>(m_matrix->m33()), static_cast<float>(m_matrix->m34()), 240 static_cast<float>(m_matrix->m33()), static_cast<float>(m_matrix->m34()),
221 static_cast<float>(m_matrix->m41()), static_cast<float>(m_matrix->m42()), 241 static_cast<float>(m_matrix->m41()), static_cast<float>(m_matrix->m42()),
222 static_cast<float>(m_matrix->m43()), static_cast<float>(m_matrix->m44())}; 242 static_cast<float>(m_matrix->m43()), static_cast<float>(m_matrix->m44())};
(...skipping 22 matching lines...) Expand all
245 << m24() << ", " << m31() << ", " << m32() << ", " << m33() << ", " 265 << m24() << ", " << m31() << ", " << m32() << ", " << m33() << ", "
246 << m34() << ", " << m41() << ", " << m42() << ", " << m43() << ", " 266 << m34() << ", " << m41() << ", " << m42() << ", " << m43() << ", "
247 << m44(); 267 << m44();
248 } 268 }
249 stream << ")"; 269 stream << ")";
250 270
251 return String(stream.str().c_str()); 271 return String(stream.str().c_str());
252 } 272 }
253 273
254 } // namespace blink 274 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698