OLD | NEW |
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("The sequence must contain 6 elements for
a 2D matrix or 16 elements for a 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 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat32Array(DOMFloat32Array* float32A
rray, ExceptionState& exceptionState) |
19 { | 19 { |
20 if (sequence.size() == 6) { | 20 if (float32Array->length() != 6 && float32Array->length() != 16) { |
21 m_matrix = TransformationMatrix::create( | 21 exceptionState.throwTypeError("The sequence must contain 6 elements for
a 2D matrix or 16 elements a for 3D matrix."); |
22 sequence[0], sequence[1], sequence[2], sequence[3], | 22 return nullptr; |
23 sequence[4], sequence[5]); | |
24 m_is2D = true; | |
25 } else if (sequence.size() == 16) { | |
26 m_matrix = TransformationMatrix::create( | |
27 sequence[0], sequence[1], sequence[2], sequence[3], | |
28 sequence[4], sequence[5], sequence[6], sequence[7], | |
29 sequence[8], sequence[9], sequence[10], sequence[11], | |
30 sequence[12], sequence[13], sequence[14], sequence[15]); | |
31 m_is2D = false; | |
32 } else { | |
33 NOTREACHED(); | |
34 } | 23 } |
| 24 return new DOMMatrixReadOnly(float32Array->data(), float32Array->length()); |
| 25 } |
| 26 |
| 27 |
| 28 DOMMatrixReadOnly* DOMMatrixReadOnly::fromFloat64Array(DOMFloat64Array* float64A
rray, ExceptionState& exceptionState) |
| 29 { |
| 30 if (float64Array->length() != 6 && float64Array->length() != 16) { |
| 31 exceptionState.throwTypeError("The sequence must contain 6 elements for
a 2D matrix or 16 elements for a 3D matrix."); |
| 32 return nullptr; |
| 33 } |
| 34 return new DOMMatrixReadOnly(float64Array->data(), float64Array->length()); |
35 } | 35 } |
36 | 36 |
37 DOMMatrixReadOnly::~DOMMatrixReadOnly() | 37 DOMMatrixReadOnly::~DOMMatrixReadOnly() |
38 { | 38 { |
39 } | 39 } |
40 | 40 |
41 bool DOMMatrixReadOnly::is2D() const | 41 bool DOMMatrixReadOnly::is2D() const |
42 { | 42 { |
43 return m_is2D; | 43 return m_is2D; |
44 } | 44 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 << m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", " | 146 << m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", " |
147 << m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", " | 147 << m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", " |
148 << m41() << ", " << m42() << ", " << m43() << ", " << m44(); | 148 << m41() << ", " << m42() << ", " << m43() << ", " << m44(); |
149 } | 149 } |
150 stream << ")"; | 150 stream << ")"; |
151 | 151 |
152 return String(stream.str().c_str()); | 152 return String(stream.str().c_str()); |
153 } | 153 } |
154 | 154 |
155 } // namespace blink | 155 } // namespace blink |
OLD | NEW |