DOMMatrixReadOnly: fromFloat64Array() statische Methode
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Juli 2020.
Hinweis: Diese Funktion ist in Web Workers verfügbar.
Die fromFloat64Array() statische Methode der DOMMatrixReadOnly-Schnittstelle erstellt ein neues DOMMatrixReadOnly-Objekt aus einem Array mit Gleitkommazahlen mit doppelter Genauigkeit (64-Bit).
Hat das Array 6 Werte, handelt es sich um eine 2D-Matrix; hat das Array 16 Werte, handelt es sich um eine 3D-Matrix. Andernfalls wird eine TypeError-Ausnahme ausgelöst.
Syntax
DOMMatrixReadOnly.fromFloat64Array(array)
Parameter
array-
Ein
Float64Arraymit 6 oder 16 Elementen in spaltenmajorer Reihenfolge.
Rückgabewert
Ein DOMMatrixReadOnly-Objekt.
Ausnahmen
TypeError-
Wird ausgelöst, wenn die Länge des Parameters
arraynicht 6 oder 16 ist.
Beispiele
>Erstellen einer 2D-Matrix aus einem Float64Array
Dieses Beispiel erstellt eine 2D-Matrix aus einem Float64Array mit 6 Elementen.
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
Erstellen einer 3D-Matrix aus einem Float64Array
Dieses Beispiel erstellt eine 3D-Matrix aus einem Float64Array mit 16 Elementen.
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
Spezifikationen
| Specification |
|---|
| Geometry Interfaces Module Level 1> # dom-dommatrixreadonly-fromfloat64array> |
Browser-Kompatibilität
Loading…