-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New pages: DOMMatrix multiply(), multiplySelf(), and preMultiplySelf() (
#37185) * New files: DOMMatrix.multiply() * typo * typo * forgot to save * new page: premultiplyself() * change examples * return values * return * Update index.md * Apply suggestions from code review Co-authored-by: wbamberg <[email protected]> * edits per review * Update files/en-us/web/api/dommatrix/multiplyself/index.md --------- Co-authored-by: wbamberg <[email protected]>
- Loading branch information
Showing
5 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: "DOMMatrix: multiplySelf() method" | ||
short-title: multiplySelf() | ||
slug: Web/API/DOMMatrix/multiplySelf | ||
page-type: web-api-instance-method | ||
browser-compat: api.DOMMatrix.multiplySelf | ||
--- | ||
|
||
{{APIRef("Geometry Interfaces")}}{{AvailableInWorkers}} | ||
|
||
The **`multiplySelf()`** method of the {{domxref("DOMMatrix")}} interface multiplies a matrix by the `otherMatrix` parameter, computing the dot product of the original matrix and the specified matrix: `A⋅B`. If no matrix is specified as the multiplier, the matrix is multiplied by a matrix in which every element is `0` _except_ the bottom-right corner and the element immediately above and to its left: `m33` and `m34`. These have the default value of `1`. | ||
|
||
To multiply a matrix without mutating it, see {{domxref("DOMMatrixReadOnly.multiply()")}}. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
DOMMatrix.multiplySelf() | ||
DOMMatrix.multiplySelf(otherMatrix) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `otherMatrix` {{optional_inline}} | ||
- : The [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix) multiplier. | ||
|
||
### Return value | ||
|
||
Returns itself; the [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix) updated to the results of the applied multiplications. | ||
|
||
## Examples | ||
|
||
```js | ||
const matrix = new DOMMatrix().rotate(30); | ||
|
||
console.log(matrix.toString()); | ||
// output: matrix(0.866, 0.5, -0.5, 0.866, 0, 0) | ||
|
||
matrix.multiplySelf(matrix); | ||
|
||
console.log(matrix.toString()); | ||
// output: matrix(0.5, 0.866, -0.866, 0.5, 0, 0) (a 60deg rotation) | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("DOMMatrixReadOnly.multiply()")}} | ||
- {{domxref("DOMMatrix.preMultiplySelf()")}} | ||
- CSS {{CSSxRef("transform-function/matrix", "matrix()")}} function | ||
- CSS {{CSSxRef("transform-function/matrix3d", "matrix3d()")}} function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
title: "DOMMatrix: preMultiplySelf() method" | ||
short-title: preMultiplySelf() | ||
slug: Web/API/DOMMatrix/preMultiplySelf | ||
page-type: web-api-instance-method | ||
browser-compat: api.DOMMatrix.preMultiplySelf | ||
--- | ||
|
||
{{APIRef("Geometry Interfaces")}}{{AvailableInWorkers}} | ||
|
||
The **`preMultiplySelf()`** method of the {{domxref("DOMMatrix")}} interface modifies the matrix by pre-multiplying it with the specified `DOMMatrix`. This is equivalent to the dot product `B⋅A`, where matrix `A` is the source matrix and `B` is the matrix given as an input to the method. If no matrix is specified as the multiplier, the matrix is multiplied by a matrix in which every element is `0` _except_ the bottom-right corner and the element immediately above and to its left: `m33` and `m34`. These have the default value of `1`. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
DOMMatrix.preMultiplySelf() | ||
DOMMatrix.preMultiplySelf(otherMatrix) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `otherMatrix` {{optional_inline}} | ||
- : The [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix) multiplier. | ||
|
||
### Return value | ||
|
||
Returns itself; a [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix) updated to results of the applied multiplications. | ||
|
||
## Examples | ||
|
||
```js | ||
const matrix = new DOMMatrix().translate(3, 22); | ||
const otherMatrix = new DOMMatrix().translateSelf(15, 45); | ||
|
||
console.log(matrix.toString()); // output: matrix(1, 0, 0, 1, 3, 22) | ||
console.log(otherMatrix.toString()); // output: matrix(1, 0, 0, 1, 15, 45) | ||
|
||
matrix.preMultiplySelf(otherMatrix); | ||
|
||
console.log(matrix.toString()); // output: matrix(1, 0, 0, 1, 18, 67) | ||
console.log(otherMatrix.toString()); // output: matrix(1, 0, 0, 1, 15, 45) | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("DOMMatrix.multiplySelf()")}} | ||
- {{domxref("DOMMatrixReadOnly.multiply()")}} | ||
- CSS {{CSSxRef("transform-function/matrix", "matrix()")}} function | ||
- CSS {{CSSxRef("transform-function/matrix3d", "matrix3d()")}} function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
title: "DOMMatrixReadOnly: multiply() method" | ||
short-title: multiply() | ||
slug: Web/API/DOMMatrixReadOnly/multiply | ||
page-type: web-api-instance-method | ||
browser-compat: api.DOMMatrixReadOnly.multiply | ||
--- | ||
|
||
{{APIRef("Geometry Interfaces")}}{{AvailableInWorkers}} | ||
|
||
The **`multiply()`** method of the {{domxref("DOMMatrixReadOnly")}} interface creates and returns a new matrix which is the dot product of the matrix and the `otherMatrix` parameter. If `otherMatrix` is omitted, the matrix is multiplied by a matrix in which every element is `0` _except_ the bottom-right corner and the element immediately above and to its left: `m33` and `m34`. These have the default value of `1`. The original matrix is not modified. | ||
|
||
To mutate the matrix as you multiply it, see {{domxref("DOMMatrix.multiplySelf()")}}. | ||
|
||
## Syntax | ||
|
||
```js-nolint | ||
DOMMatrixReadOnly.multiply() | ||
DOMMatrixReadOnly.multiply(otherMatrix) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `otherMatrix` {{optional_inline}} | ||
- : The [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix) multiplier. | ||
|
||
### Return value | ||
|
||
A {{domxref("DOMMatrix")}}. | ||
|
||
## Examples | ||
|
||
```js | ||
const matrix = new DOMMatrixReadOnly().translate(13, 21); | ||
const multipliedMatrix = matrix.multiply(matrix); | ||
console.log(matrix.toString()); // output: matrix(1, 0, 0, 1, 13, 21) | ||
console.log(multipliedMatrix.toString()); // output: matrix(1, 0, 0, 1, 26, 42) | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("DOMMatrix.multiplySelf()")}} | ||
- {{domxref("DOMMatrixReadOnly.preMultiply()")}} | ||
- CSS {{CSSxRef("transform-function/matrix", "matrix()")}} function | ||
- CSS {{CSSxRef("transform-function/matrix3d", "matrix3d()")}} function |