|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# toRotl90 |
| 22 | + |
| 23 | +> Return a new ndarray where a matrix (or a stack of matrices) is rotated 90 degrees counterclockwise. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var toRotl90 = require( '@stdlib/ndarray/base/to-rotl90' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### toRotl90( x, k ) |
| 44 | + |
| 45 | +Returns a new ndarray where a matrix (or a stack of matrices) is rotated 90 degrees counterclockwise. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var array = require( '@stdlib/ndarray/array' ); |
| 49 | + |
| 50 | +var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); |
| 51 | +// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ] |
| 52 | + |
| 53 | +var y = toRotl90( x, 1 ); |
| 54 | +// returns <ndarray>[ [ 2, 4 ], [ 1, 3 ] ] |
| 55 | +``` |
| 56 | + |
| 57 | +The function accepts the following arguments: |
| 58 | + |
| 59 | +- **x**: input ndarray. |
| 60 | +- **k**: number of times to rotate by 90 degrees. Positive values rotate counterclockwise. Negative values rotate clockwise. |
| 61 | + |
| 62 | +</section> |
| 63 | + |
| 64 | +<!-- /.usage --> |
| 65 | + |
| 66 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 67 | + |
| 68 | +<section class="notes"> |
| 69 | + |
| 70 | +## Notes |
| 71 | + |
| 72 | +- If `k > 0`, the function rotates the matrix counterclockwise. |
| 73 | +- If `k < 0`, the function rotates the matrix clockwise. |
| 74 | +- If provided an ndarray with fewer than two dimensions, the function does not perform a rotation and simply returns a copy of the input ndarray. |
| 75 | + |
| 76 | +</section> |
| 77 | + |
| 78 | +<!-- /.notes --> |
| 79 | + |
| 80 | +<!-- Package usage examples. --> |
| 81 | + |
| 82 | +<section class="examples"> |
| 83 | + |
| 84 | +## Examples |
| 85 | + |
| 86 | +<!-- eslint no-undef: "error" --> |
| 87 | + |
| 88 | +```javascript |
| 89 | +var array = require( '@stdlib/ndarray/array' ); |
| 90 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 91 | +var toRotl90 = require( '@stdlib/ndarray/base/to-rotl90' ); |
| 92 | + |
| 93 | +// Create a 2x3 matrix: |
| 94 | +var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); |
| 95 | + |
| 96 | +// Rotate 90 degrees counterclockwise: |
| 97 | +var y = toRotl90( x, 1 ); |
| 98 | +var arr = ndarray2array( y ); |
| 99 | +// returns [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] |
| 100 | + |
| 101 | +// Rotate 180 degrees: |
| 102 | +y = toRotl90( x, 2 ); |
| 103 | +arr = ndarray2array( y ); |
| 104 | +// returns [ [ 6, 5, 4 ], [ 3, 2, 1 ] ] |
| 105 | + |
| 106 | +// Rotate 270 degrees counterclockwise (equivalent to 90 degrees clockwise): |
| 107 | +y = toRotl90( x, 3 ); |
| 108 | +arr = ndarray2array( y ); |
| 109 | +// returns [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] |
| 110 | + |
| 111 | +// Rotate 360 degrees (equivalent to no rotation): |
| 112 | +y = toRotl90( x, 4 ); |
| 113 | +arr = ndarray2array( y ); |
| 114 | +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] |
| 115 | + |
| 116 | +// Rotate 90 degrees clockwise (equivalent to k=3): |
| 117 | +y = toRotl90( x, -1 ); |
| 118 | +arr = ndarray2array( y ); |
| 119 | +// returns [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] |
| 120 | +``` |
| 121 | + |
| 122 | +</section> |
| 123 | + |
| 124 | +<!-- /.examples --> |
| 125 | + |
| 126 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 127 | + |
| 128 | +<section class="references"> |
| 129 | + |
| 130 | +</section> |
| 131 | + |
| 132 | +<!-- /.references --> |
| 133 | + |
| 134 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 135 | + |
| 136 | +<section class="related"> |
| 137 | + |
| 138 | +</section> |
| 139 | + |
| 140 | +<!-- /.related --> |
| 141 | + |
| 142 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 143 | + |
| 144 | +<section class="links"> |
| 145 | + |
| 146 | +<!-- <related-links> --> |
| 147 | + |
| 148 | +<!-- </related-links> --> |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.links --> |
0 commit comments