Skip to content

Commit fbaca33

Browse files
authored
Merge pull request #383 from AlexMax/readonly-types
Readonly types for TypeScript
2 parents 8c24c9d + cc19092 commit fbaca33

File tree

11 files changed

+437
-387
lines changed

11 files changed

+437
-387
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"build-umd": "rollup -c",
3434
"build-esm": "cross-env BABEL_ENV=esm babel src -d dist/esm",
3535
"build-cjs": "babel src -d dist/cjs",
36-
"build-dts": "tsc --allowJs --declaration --emitDeclarationOnly --module amd --outFile ./dist/index.d.ts ./src/index.js ./src/types.d.ts && node ./utils/bundle-dts.js",
36+
"build-dts": "tsc --allowJs --declaration --emitDeclarationOnly --module amd --outFile ./dist/index.d.ts ./src/index.js ./src/types.d.ts && node ./utils/bundle-dts.js && tsc --noEmit ./dist/index.d.ts",
3737
"build": "del dist && npm run update-license-version && npm run build-umd && npm run build-esm && npm run build-cjs && npm run build-dts && node ./utils/build.js",
3838
"prepare": "npm run build"
3939
},

src/mat2.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function create() {
2424
/**
2525
* Creates a new mat2 initialized with values from an existing matrix
2626
*
27-
* @param {mat2} a matrix to clone
27+
* @param {ReadonlyMat2} a matrix to clone
2828
* @returns {mat2} a new 2x2 matrix
2929
*/
3030
export function clone(a) {
@@ -40,7 +40,7 @@ export function clone(a) {
4040
* Copy the values from one mat2 to another
4141
*
4242
* @param {mat2} out the receiving matrix
43-
* @param {mat2} a the source matrix
43+
* @param {ReadonlyMat2} a the source matrix
4444
* @returns {mat2} out
4545
*/
4646
export function copy(out, a) {
@@ -105,7 +105,7 @@ export function set(out, m00, m01, m10, m11) {
105105
* Transpose the values of a mat2
106106
*
107107
* @param {mat2} out the receiving matrix
108-
* @param {mat2} a the source matrix
108+
* @param {ReadonlyMat2} a the source matrix
109109
* @returns {mat2} out
110110
*/
111111
export function transpose(out, a) {
@@ -129,7 +129,7 @@ export function transpose(out, a) {
129129
* Inverts a mat2
130130
*
131131
* @param {mat2} out the receiving matrix
132-
* @param {mat2} a the source matrix
132+
* @param {ReadonlyMat2} a the source matrix
133133
* @returns {mat2} out
134134
*/
135135
export function invert(out, a) {
@@ -158,7 +158,7 @@ export function invert(out, a) {
158158
* Calculates the adjugate of a mat2
159159
*
160160
* @param {mat2} out the receiving matrix
161-
* @param {mat2} a the source matrix
161+
* @param {ReadonlyMat2} a the source matrix
162162
* @returns {mat2} out
163163
*/
164164
export function adjoint(out, a) {
@@ -175,7 +175,7 @@ export function adjoint(out, a) {
175175
/**
176176
* Calculates the determinant of a mat2
177177
*
178-
* @param {mat2} a the source matrix
178+
* @param {ReadonlyMat2} a the source matrix
179179
* @returns {Number} determinant of a
180180
*/
181181
export function determinant(a) {
@@ -186,8 +186,8 @@ export function determinant(a) {
186186
* Multiplies two mat2's
187187
*
188188
* @param {mat2} out the receiving matrix
189-
* @param {mat2} a the first operand
190-
* @param {mat2} b the second operand
189+
* @param {ReadonlyMat2} a the first operand
190+
* @param {ReadonlyMat2} b the second operand
191191
* @returns {mat2} out
192192
*/
193193
export function multiply(out, a, b) {
@@ -210,7 +210,7 @@ export function multiply(out, a, b) {
210210
* Rotates a mat2 by the given angle
211211
*
212212
* @param {mat2} out the receiving matrix
213-
* @param {mat2} a the matrix to rotate
213+
* @param {ReadonlyMat2} a the matrix to rotate
214214
* @param {Number} rad the angle to rotate the matrix by
215215
* @returns {mat2} out
216216
*/
@@ -232,8 +232,8 @@ export function rotate(out, a, rad) {
232232
* Scales the mat2 by the dimensions in the given vec2
233233
*
234234
* @param {mat2} out the receiving matrix
235-
* @param {mat2} a the matrix to rotate
236-
* @param {vec2} v the vec2 to scale the matrix by
235+
* @param {ReadonlyMat2} a the matrix to rotate
236+
* @param {ReadonlyVec2} v the vec2 to scale the matrix by
237237
* @returns {mat2} out
238238
**/
239239
export function scale(out, a, v) {
@@ -279,7 +279,7 @@ export function fromRotation(out, rad) {
279279
* mat2.scale(dest, dest, vec);
280280
*
281281
* @param {mat2} out mat2 receiving operation result
282-
* @param {vec2} v Scaling vector
282+
* @param {ReadonlyVec2} v Scaling vector
283283
* @returns {mat2} out
284284
*/
285285
export function fromScaling(out, v) {
@@ -293,7 +293,7 @@ export function fromScaling(out, v) {
293293
/**
294294
* Returns a string representation of a mat2
295295
*
296-
* @param {mat2} a matrix to represent as a string
296+
* @param {ReadonlyMat2} a matrix to represent as a string
297297
* @returns {String} string representation of the matrix
298298
*/
299299
export function str(a) {
@@ -303,7 +303,7 @@ export function str(a) {
303303
/**
304304
* Returns Frobenius norm of a mat2
305305
*
306-
* @param {mat2} a the matrix to calculate Frobenius norm of
306+
* @param {ReadonlyMat2} a the matrix to calculate Frobenius norm of
307307
* @returns {Number} Frobenius norm
308308
*/
309309
export function frob(a) {
@@ -312,10 +312,10 @@ export function frob(a) {
312312

313313
/**
314314
* Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix
315-
* @param {mat2} L the lower triangular matrix
316-
* @param {mat2} D the diagonal matrix
317-
* @param {mat2} U the upper triangular matrix
318-
* @param {mat2} a the input matrix to factorize
315+
* @param {ReadonlyMat2} L the lower triangular matrix
316+
* @param {ReadonlyMat2} D the diagonal matrix
317+
* @param {ReadonlyMat2} U the upper triangular matrix
318+
* @param {ReadonlyMat2} a the input matrix to factorize
319319
*/
320320

321321
export function LDU(L, D, U, a) {
@@ -330,8 +330,8 @@ export function LDU(L, D, U, a) {
330330
* Adds two mat2's
331331
*
332332
* @param {mat2} out the receiving matrix
333-
* @param {mat2} a the first operand
334-
* @param {mat2} b the second operand
333+
* @param {ReadonlyMat2} a the first operand
334+
* @param {ReadonlyMat2} b the second operand
335335
* @returns {mat2} out
336336
*/
337337
export function add(out, a, b) {
@@ -346,8 +346,8 @@ export function add(out, a, b) {
346346
* Subtracts matrix b from matrix a
347347
*
348348
* @param {mat2} out the receiving matrix
349-
* @param {mat2} a the first operand
350-
* @param {mat2} b the second operand
349+
* @param {ReadonlyMat2} a the first operand
350+
* @param {ReadonlyMat2} b the second operand
351351
* @returns {mat2} out
352352
*/
353353
export function subtract(out, a, b) {
@@ -361,8 +361,8 @@ export function subtract(out, a, b) {
361361
/**
362362
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
363363
*
364-
* @param {mat2} a The first matrix.
365-
* @param {mat2} b The second matrix.
364+
* @param {ReadonlyMat2} a The first matrix.
365+
* @param {ReadonlyMat2} b The second matrix.
366366
* @returns {Boolean} True if the matrices are equal, false otherwise.
367367
*/
368368
export function exactEquals(a, b) {
@@ -372,8 +372,8 @@ export function exactEquals(a, b) {
372372
/**
373373
* Returns whether or not the matrices have approximately the same elements in the same position.
374374
*
375-
* @param {mat2} a The first matrix.
376-
* @param {mat2} b The second matrix.
375+
* @param {ReadonlyMat2} a The first matrix.
376+
* @param {ReadonlyMat2} b The second matrix.
377377
* @returns {Boolean} True if the matrices are equal, false otherwise.
378378
*/
379379
export function equals(a, b) {
@@ -401,7 +401,7 @@ export function equals(a, b) {
401401
* Multiply each element of the matrix by a scalar.
402402
*
403403
* @param {mat2} out the receiving matrix
404-
* @param {mat2} a the matrix to scale
404+
* @param {ReadonlyMat2} a the matrix to scale
405405
* @param {Number} b amount to scale the matrix's elements by
406406
* @returns {mat2} out
407407
*/
@@ -417,8 +417,8 @@ export function multiplyScalar(out, a, b) {
417417
* Adds two mat2's after multiplying each element of the second operand by a scalar value.
418418
*
419419
* @param {mat2} out the receiving vector
420-
* @param {mat2} a the first operand
421-
* @param {mat2} b the second operand
420+
* @param {ReadonlyMat2} a the first operand
421+
* @param {ReadonlyMat2} b the second operand
422422
* @param {Number} scale the amount to scale b's elements by before adding
423423
* @returns {mat2} out
424424
*/

src/mat2d.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function create() {
4040
/**
4141
* Creates a new mat2d initialized with values from an existing matrix
4242
*
43-
* @param {mat2d} a matrix to clone
43+
* @param {ReadonlyMat2d} a matrix to clone
4444
* @returns {mat2d} a new 2x3 matrix
4545
*/
4646
export function clone(a) {
@@ -58,7 +58,7 @@ export function clone(a) {
5858
* Copy the values from one mat2d to another
5959
*
6060
* @param {mat2d} out the receiving matrix
61-
* @param {mat2d} a the source matrix
61+
* @param {ReadonlyMat2d} a the source matrix
6262
* @returns {mat2d} out
6363
*/
6464
export function copy(out, a) {
@@ -135,7 +135,7 @@ export function set(out, a, b, c, d, tx, ty) {
135135
* Inverts a mat2d
136136
*
137137
* @param {mat2d} out the receiving matrix
138-
* @param {mat2d} a the source matrix
138+
* @param {ReadonlyMat2d} a the source matrix
139139
* @returns {mat2d} out
140140
*/
141141
export function invert(out, a) {
@@ -164,7 +164,7 @@ export function invert(out, a) {
164164
/**
165165
* Calculates the determinant of a mat2d
166166
*
167-
* @param {mat2d} a the source matrix
167+
* @param {ReadonlyMat2d} a the source matrix
168168
* @returns {Number} determinant of a
169169
*/
170170
export function determinant(a) {
@@ -175,8 +175,8 @@ export function determinant(a) {
175175
* Multiplies two mat2d's
176176
*
177177
* @param {mat2d} out the receiving matrix
178-
* @param {mat2d} a the first operand
179-
* @param {mat2d} b the second operand
178+
* @param {ReadonlyMat2d} a the first operand
179+
* @param {ReadonlyMat2d} b the second operand
180180
* @returns {mat2d} out
181181
*/
182182
export function multiply(out, a, b) {
@@ -205,7 +205,7 @@ export function multiply(out, a, b) {
205205
* Rotates a mat2d by the given angle
206206
*
207207
* @param {mat2d} out the receiving matrix
208-
* @param {mat2d} a the matrix to rotate
208+
* @param {ReadonlyMat2d} a the matrix to rotate
209209
* @param {Number} rad the angle to rotate the matrix by
210210
* @returns {mat2d} out
211211
*/
@@ -231,8 +231,8 @@ export function rotate(out, a, rad) {
231231
* Scales the mat2d by the dimensions in the given vec2
232232
*
233233
* @param {mat2d} out the receiving matrix
234-
* @param {mat2d} a the matrix to translate
235-
* @param {vec2} v the vec2 to scale the matrix by
234+
* @param {ReadonlyMat2d} a the matrix to translate
235+
* @param {ReadonlyVec2} v the vec2 to scale the matrix by
236236
* @returns {mat2d} out
237237
**/
238238
export function scale(out, a, v) {
@@ -257,8 +257,8 @@ export function scale(out, a, v) {
257257
* Translates the mat2d by the dimensions in the given vec2
258258
*
259259
* @param {mat2d} out the receiving matrix
260-
* @param {mat2d} a the matrix to translate
261-
* @param {vec2} v the vec2 to translate the matrix by
260+
* @param {ReadonlyMat2d} a the matrix to translate
261+
* @param {ReadonlyVec2} v the vec2 to translate the matrix by
262262
* @returns {mat2d} out
263263
**/
264264
export function translate(out, a, v) {
@@ -310,7 +310,7 @@ export function fromRotation(out, rad) {
310310
* mat2d.scale(dest, dest, vec);
311311
*
312312
* @param {mat2d} out mat2d receiving operation result
313-
* @param {vec2} v Scaling vector
313+
* @param {ReadonlyVec2} v Scaling vector
314314
* @returns {mat2d} out
315315
*/
316316
export function fromScaling(out, v) {
@@ -331,7 +331,7 @@ export function fromScaling(out, v) {
331331
* mat2d.translate(dest, dest, vec);
332332
*
333333
* @param {mat2d} out mat2d receiving operation result
334-
* @param {vec2} v Translation vector
334+
* @param {ReadonlyVec2} v Translation vector
335335
* @returns {mat2d} out
336336
*/
337337
export function fromTranslation(out, v) {
@@ -347,7 +347,7 @@ export function fromTranslation(out, v) {
347347
/**
348348
* Returns a string representation of a mat2d
349349
*
350-
* @param {mat2d} a matrix to represent as a string
350+
* @param {ReadonlyMat2d} a matrix to represent as a string
351351
* @returns {String} string representation of the matrix
352352
*/
353353
export function str(a) {
@@ -371,7 +371,7 @@ export function str(a) {
371371
/**
372372
* Returns Frobenius norm of a mat2d
373373
*
374-
* @param {mat2d} a the matrix to calculate Frobenius norm of
374+
* @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of
375375
* @returns {Number} Frobenius norm
376376
*/
377377
export function frob(a) {
@@ -382,8 +382,8 @@ export function frob(a) {
382382
* Adds two mat2d's
383383
*
384384
* @param {mat2d} out the receiving matrix
385-
* @param {mat2d} a the first operand
386-
* @param {mat2d} b the second operand
385+
* @param {ReadonlyMat2d} a the first operand
386+
* @param {ReadonlyMat2d} b the second operand
387387
* @returns {mat2d} out
388388
*/
389389
export function add(out, a, b) {
@@ -400,8 +400,8 @@ export function add(out, a, b) {
400400
* Subtracts matrix b from matrix a
401401
*
402402
* @param {mat2d} out the receiving matrix
403-
* @param {mat2d} a the first operand
404-
* @param {mat2d} b the second operand
403+
* @param {ReadonlyMat2d} a the first operand
404+
* @param {ReadonlyMat2d} b the second operand
405405
* @returns {mat2d} out
406406
*/
407407
export function subtract(out, a, b) {
@@ -418,7 +418,7 @@ export function subtract(out, a, b) {
418418
* Multiply each element of the matrix by a scalar.
419419
*
420420
* @param {mat2d} out the receiving matrix
421-
* @param {mat2d} a the matrix to scale
421+
* @param {ReadonlyMat2d} a the matrix to scale
422422
* @param {Number} b amount to scale the matrix's elements by
423423
* @returns {mat2d} out
424424
*/
@@ -436,8 +436,8 @@ export function multiplyScalar(out, a, b) {
436436
* Adds two mat2d's after multiplying each element of the second operand by a scalar value.
437437
*
438438
* @param {mat2d} out the receiving vector
439-
* @param {mat2d} a the first operand
440-
* @param {mat2d} b the second operand
439+
* @param {ReadonlyMat2d} a the first operand
440+
* @param {ReadonlyMat2d} b the second operand
441441
* @param {Number} scale the amount to scale b's elements by before adding
442442
* @returns {mat2d} out
443443
*/
@@ -454,8 +454,8 @@ export function multiplyScalarAndAdd(out, a, b, scale) {
454454
/**
455455
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
456456
*
457-
* @param {mat2d} a The first matrix.
458-
* @param {mat2d} b The second matrix.
457+
* @param {ReadonlyMat2d} a The first matrix.
458+
* @param {ReadonlyMat2d} b The second matrix.
459459
* @returns {Boolean} True if the matrices are equal, false otherwise.
460460
*/
461461
export function exactEquals(a, b) {
@@ -472,8 +472,8 @@ export function exactEquals(a, b) {
472472
/**
473473
* Returns whether or not the matrices have approximately the same elements in the same position.
474474
*
475-
* @param {mat2d} a The first matrix.
476-
* @param {mat2d} b The second matrix.
475+
* @param {ReadonlyMat2d} a The first matrix.
476+
* @param {ReadonlyMat2d} b The second matrix.
477477
* @returns {Boolean} True if the matrices are equal, false otherwise.
478478
*/
479479
export function equals(a, b) {

0 commit comments

Comments
 (0)