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

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

Issue 2309013002: [GeometryInterface] Add fromFloat32Array & fromFloat64Array function (Closed)
Patch Set: Implement fromFloat32Array & fromFloat64Array function in DOMMatrix & DOMMatrixReadOnly. Created 4 years, 3 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 6
7 namespace blink { 7 namespace blink {
8 8
9 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, ExceptionS tate& exceptionState) 9 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, ExceptionS tate& exceptionState)
10 { 10 {
11 if (sequence.size() != 6 && sequence.size() != 16) { 11 if (sequence.size() != 6 && sequence.size() != 16) {
12 exceptionState.throwTypeError("An invalid number sequence is specified. The sequence must contain 6 elements for 2D matrix and 16 elements for 3D matrix ."); 12 exceptionState.throwTypeError("An invalid number sequence is specified. The sequence must contain 6 elements for 2D matrix and 16 elements for 3D matrix .");
13 return nullptr; 13 return nullptr;
14 } 14 }
15 return new DOMMatrixReadOnly(sequence); 15 return new DOMMatrixReadOnly(sequence, sequence.size());
16 } 16 }
17 17
18 DOMMatrixReadOnly::DOMMatrixReadOnly(Vector<double> sequence) 18 template <typename T>
19 DOMMatrixReadOnly::DOMMatrixReadOnly(T sequence, int size)
19 { 20 {
20 if (sequence.size() == 6) { 21 if (size == 6) {
21 m_matrix = TransformationMatrix::create( 22 m_matrix = TransformationMatrix::create(
22 sequence[0], sequence[1], sequence[2], sequence[3], 23 sequence[0], sequence[1], sequence[2], sequence[3],
23 sequence[4], sequence[5]); 24 sequence[4], sequence[5]);
24 m_is2D = true; 25 m_is2D = true;
25 } else if (sequence.size() == 16) { 26 } else if (size == 16) {
26 m_matrix = TransformationMatrix::create( 27 m_matrix = TransformationMatrix::create(
27 sequence[0], sequence[1], sequence[2], sequence[3], 28 sequence[0], sequence[1], sequence[2], sequence[3],
28 sequence[4], sequence[5], sequence[6], sequence[7], 29 sequence[4], sequence[5], sequence[6], sequence[7],
29 sequence[8], sequence[9], sequence[10], sequence[11], 30 sequence[8], sequence[9], sequence[10], sequence[11],
30 sequence[12], sequence[13], sequence[14], sequence[15]); 31 sequence[12], sequence[13], sequence[14], sequence[15]);
31 m_is2D = false; 32 m_is2D = false;
32 } else { 33 } else {
33 NOTREACHED(); 34 NOTREACHED();
34 } 35 }
35 } 36 }
36 37
38 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat32Array(DOMFloat32Array* float32A rray, ExceptionState& exceptionState)
39 {
40 if (float32Array->length() != 6 && float32Array->length() != 16) {
41 exceptionState.throwTypeError("An invalid number sequence is specified. The sequence must contain 6 elements for 2D matrix and 16 elements for 3D matrix .");
dominicc (has gone to gerrit) 2016/09/06 17:07:22 and 16 elements -> or 16 elements Saying 'and' he
Hwanseung Lee 2016/09/07 14:21:47 Done.
42 return nullptr;
43 }
44 return new DOMMatrixReadOnly(float32Array->data(), float32Array->length());
45 }
46
47
48 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat64Array(DOMFloat64Array* float64A rray, ExceptionState& exceptionState)
49 {
50 if (float64Array->length() != 6 && float64Array->length() != 16) {
51 exceptionState.throwTypeError("An invalid number sequence is specified. The sequence must contain 6 elements for 2D matrix and 16 elements for 3D matrix .");
52 return nullptr;
53 }
54 return new DOMMatrixReadOnly(float64Array->data(), float64Array->length());
55 }
56
37 DOMMatrixReadOnly::~DOMMatrixReadOnly() 57 DOMMatrixReadOnly::~DOMMatrixReadOnly()
38 { 58 {
39 } 59 }
40 60
41 bool DOMMatrixReadOnly::is2D() const 61 bool DOMMatrixReadOnly::is2D() const
42 { 62 {
43 return m_is2D; 63 return m_is2D;
44 } 64 }
45 65
46 bool DOMMatrixReadOnly::isIdentity() const 66 bool DOMMatrixReadOnly::isIdentity() const
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 << m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", " 166 << m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", "
147 << m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", " 167 << m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", "
148 << m41() << ", " << m42() << ", " << m43() << ", " << m44(); 168 << m41() << ", " << m42() << ", " << m43() << ", " << m44();
149 } 169 }
150 stream << ")"; 170 stream << ")";
151 171
152 return String(stream.str().c_str()); 172 return String(stream.str().c_str());
153 } 173 }
154 174
155 } // namespace blink 175 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698