DOMMatrixReadOnly: fromFloat64Array() static method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
Note: This feature is available in Web Workers.
Phương thức tĩnh fromFloat64Array() của giao diện DOMMatrixReadOnly tạo một đối tượng DOMMatrixReadOnly mới từ một mảng các giá trị số thực dấu phẩy động độ chính xác kép (64-bit).
Nếu mảng có 6 giá trị, kết quả là ma trận 2D; nếu mảng có 16 giá trị, kết quả là ma trận 3D. Ngược lại, ngoại lệ TypeError sẽ được ném ra.
Cú pháp
DOMMatrixReadOnly.fromFloat64Array(array)
Tham số
array-
Một
Float64Arrayvới 6 hoặc 16 phần tử theo thứ tự cột chính.
Giá trị trả về
Một đối tượng DOMMatrixReadOnly.
Ngoại lệ
TypeError-
Được ném ra nếu độ dài của tham số
arraykhông phải là 6 hoặc 16.
Ví dụ
>Tạo ma trận 2D từ Float64Array
Ví dụ này tạo một ma trận 2D từ Float64Array có 6 phần tử.
const float64Array = new Float64Array([1, 0, 0, 1, 10, 20]);
const matrix2D = DOMMatrixReadOnly.fromFloat64Array(float64Array);
console.log(matrix2D.toString());
// Output: matrix(1, 0, 0, 1, 10, 20)
console.log(matrix2D.is2D);
// Output: true
console.log(matrix2D.e, matrix2D.f);
// Output: 10 20
Tạo ma trận 3D từ Float64Array
Ví dụ này tạo một ma trận 3D từ Float64Array có 16 phần tử.
const float64Array = new Float64Array([
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 20, 30, 1,
]);
const matrix3D = DOMMatrixReadOnly.fromFloat64Array(float64Array);
console.log(matrix3D.is2D);
// Output: false
console.log(matrix3D.m41, matrix3D.m42, matrix3D.m43);
// Output: 10 20 30
Thông số kỹ thuật
| Specification |
|---|
| Geometry Interfaces Module Level 1> # dom-dommatrixreadonly-fromfloat64array> |