p5 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/dist/accessibility/color_namer.js +5 -5
  2. package/dist/accessibility/describe.js +10 -0
  3. package/dist/accessibility/index.js +5 -5
  4. package/dist/accessibility/outputs.js +21 -0
  5. package/dist/app.js +5 -5
  6. package/dist/color/color_conversion.js +5 -5
  7. package/dist/color/creating_reading.js +1 -1
  8. package/dist/color/index.js +2 -2
  9. package/dist/color/p5.Color.js +1 -1
  10. package/dist/color/setting.js +2 -2
  11. package/dist/{constants-C-g_eAdC.js → constants-tYr0tCl8.js} +19 -3
  12. package/dist/core/constants.js +1 -1
  13. package/dist/core/environment.js +6 -5
  14. package/dist/core/friendly_errors/fes_core.js +1 -1
  15. package/dist/core/friendly_errors/index.js +1 -1
  16. package/dist/core/friendly_errors/param_validator.js +41 -75
  17. package/dist/core/friendly_errors/sketch_reader.js +5 -5
  18. package/dist/core/friendly_errors/sketch_verifier.js +1 -1
  19. package/dist/core/friendly_errors/validate_params.js +5 -5
  20. package/dist/core/helpers.js +1 -1
  21. package/dist/core/init.js +5 -5
  22. package/dist/core/legacy.js +5 -5
  23. package/dist/core/main.js +5 -5
  24. package/dist/core/p5.Graphics.js +4 -4
  25. package/dist/core/p5.Renderer.js +3 -3
  26. package/dist/core/p5.Renderer2D.js +5 -5
  27. package/dist/core/rendering.js +4 -4
  28. package/dist/{creating_reading-D4AAKRbx.js → creating_reading-Cr8L2Jnm.js} +2 -2
  29. package/dist/dom/dom.js +10 -10
  30. package/dist/dom/index.js +2 -2
  31. package/dist/dom/p5.Element.js +2 -2
  32. package/dist/dom/p5.MediaElement.js +2 -2
  33. package/dist/events/acceleration.js +24 -24
  34. package/dist/events/keyboard.js +1 -2
  35. package/dist/image/const.js +1 -1
  36. package/dist/image/filterRenderer2D.js +4 -4
  37. package/dist/image/image.js +4 -4
  38. package/dist/image/index.js +4 -4
  39. package/dist/image/loading_displaying.js +4 -4
  40. package/dist/image/p5.Image.js +3 -3
  41. package/dist/image/pixels.js +1 -0
  42. package/dist/io/files.js +4 -4
  43. package/dist/io/index.js +4 -4
  44. package/dist/io/p5.TableRow.js +2 -2
  45. package/dist/{main-s72KWcUy.js → main-CAxvgiOV.js} +12 -9
  46. package/dist/math/Matrices/Matrix.js +1 -1
  47. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  48. package/dist/math/index.js +1 -1
  49. package/dist/math/math.js +1 -1
  50. package/dist/math/p5.Matrix.js +1 -1
  51. package/dist/math/p5.Vector.js +1 -1
  52. package/dist/math/trigonometry.js +1 -1
  53. package/dist/{p5.Renderer-CwAYZOC2.js → p5.Renderer-Swjl9HQO.js} +5 -5
  54. package/dist/{rendering--aAe5aq3.js → rendering-B5TRR7aY.js} +101 -66
  55. package/dist/shape/2d_primitives.js +1 -1
  56. package/dist/shape/attributes.js +1 -1
  57. package/dist/shape/custom_shapes.js +2 -2
  58. package/dist/shape/index.js +2 -2
  59. package/dist/type/index.js +3 -3
  60. package/dist/type/p5.Font.js +3 -5
  61. package/dist/type/textCore.js +4 -4
  62. package/dist/webgl/3d_primitives.js +4 -4
  63. package/dist/webgl/GeometryBuilder.js +1 -1
  64. package/dist/webgl/ShapeBuilder.js +1 -1
  65. package/dist/webgl/index.js +4 -4
  66. package/dist/webgl/interaction.js +1 -1
  67. package/dist/webgl/light.js +4 -4
  68. package/dist/webgl/loading.js +4 -4
  69. package/dist/webgl/material.js +4 -4
  70. package/dist/webgl/p5.Camera.js +4 -4
  71. package/dist/webgl/p5.Framebuffer.js +4 -4
  72. package/dist/webgl/p5.Geometry.js +1 -1
  73. package/dist/webgl/p5.Quat.js +1 -1
  74. package/dist/webgl/p5.RendererGL.js +4 -4
  75. package/dist/webgl/p5.Shader.js +4 -4
  76. package/dist/webgl/p5.Texture.js +4 -4
  77. package/dist/webgl/text.js +32 -34
  78. package/lib/p5.esm.js +273 -225
  79. package/lib/p5.js +273 -225
  80. package/lib/p5.min.js +1 -1
  81. package/package.json +1 -2
  82. package/types/accessibility/color_namer.d.ts +8 -0
  83. package/types/accessibility/describe.d.ts +184 -0
  84. package/types/accessibility/gridOutput.d.ts +8 -0
  85. package/types/accessibility/outputs.d.ts +235 -0
  86. package/types/accessibility/textOutput.d.ts +8 -0
  87. package/types/color/color_conversion.d.ts +47 -0
  88. package/types/color/creating_reading.d.ts +1348 -0
  89. package/types/color/p5.Color.d.ts +1070 -0
  90. package/types/color/setting.d.ts +2085 -0
  91. package/types/core/constants.d.ts +341 -0
  92. package/types/core/environment.d.ts +668 -0
  93. package/types/core/friendly_errors/fes_core.d.ts +8 -0
  94. package/types/core/friendly_errors/file_errors.d.ts +8 -0
  95. package/types/core/friendly_errors/param_validator.d.ts +30 -0
  96. package/types/core/friendly_errors/sketch_reader.d.ts +8 -0
  97. package/types/core/friendly_errors/stacktrace.d.ts +11 -0
  98. package/types/core/friendly_errors/validate_params.d.ts +8 -0
  99. package/types/core/helpers.d.ts +8 -0
  100. package/types/core/legacy.d.ts +8 -0
  101. package/types/core/main.d.ts +5996 -0
  102. package/types/core/p5.Graphics.d.ts +484 -0
  103. package/types/core/p5.Renderer.d.ts +14 -0
  104. package/types/core/reference.d.ts +8 -0
  105. package/types/core/rendering.d.ts +481 -0
  106. package/types/core/structure.d.ts +492 -0
  107. package/types/core/transform.d.ts +1638 -0
  108. package/types/data/local_storage.d.ts +323 -0
  109. package/types/dom/dom.d.ts +1295 -0
  110. package/types/dom/p5.Element.d.ts +2011 -0
  111. package/types/dom/p5.File.d.ts +13 -0
  112. package/types/dom/p5.MediaElement.d.ts +1249 -0
  113. package/types/events/acceleration.d.ts +193 -0
  114. package/types/events/keyboard.d.ts +499 -0
  115. package/types/events/pointer.d.ts +782 -0
  116. package/types/global.d.ts +5542 -0
  117. package/types/image/filterRenderer2D.d.ts +54 -0
  118. package/types/image/image.d.ts +326 -0
  119. package/types/image/loading_displaying.d.ts +580 -0
  120. package/types/image/p5.Image.d.ts +5882 -0
  121. package/types/image/pixels.d.ts +832 -0
  122. package/types/io/files.d.ts +1447 -0
  123. package/types/io/p5.Table.d.ts +1247 -0
  124. package/types/io/p5.TableRow.d.ts +343 -0
  125. package/types/io/p5.XML.d.ts +1188 -0
  126. package/types/math/Matrices/Matrix.d.ts +1029 -0
  127. package/types/math/Matrices/MatrixNumjs.d.ts +8 -0
  128. package/types/math/calculation.d.ts +923 -0
  129. package/types/math/math.d.ts +90 -0
  130. package/types/math/noise.d.ts +311 -0
  131. package/types/math/p5.Matrix.d.ts +8 -0
  132. package/types/math/p5.Vector.d.ts +3416 -0
  133. package/types/math/random.d.ts +267 -0
  134. package/types/math/trigonometry.d.ts +663 -0
  135. package/types/p5.d.ts +6663 -0
  136. package/types/shape/2d_primitives.d.ts +1033 -0
  137. package/types/shape/attributes.d.ts +466 -0
  138. package/types/shape/curves.d.ts +740 -0
  139. package/types/shape/custom_shapes.d.ts +888 -0
  140. package/types/shape/vertex.d.ts +1141 -0
  141. package/types/type/p5.Font.d.ts +575 -0
  142. package/types/type/textCore.d.ts +1198 -0
  143. package/types/utilities/conversion.d.ts +894 -0
  144. package/types/utilities/time_date.d.ts +295 -0
  145. package/types/utilities/utility_functions.d.ts +587 -0
  146. package/types/webgl/3d_primitives.d.ts +1432 -0
  147. package/types/webgl/ShaderGenerator.d.ts +8 -0
  148. package/types/webgl/interaction.d.ts +371 -0
  149. package/types/webgl/light.d.ts +1184 -0
  150. package/types/webgl/loading.d.ts +481 -0
  151. package/types/webgl/material.d.ts +2656 -0
  152. package/types/webgl/p5.Camera.d.ts +3023 -0
  153. package/types/webgl/p5.DataArray.d.ts +61 -0
  154. package/types/webgl/p5.Framebuffer.d.ts +760 -0
  155. package/types/webgl/p5.Geometry.d.ts +1191 -0
  156. package/types/webgl/p5.Quat.d.ts +45 -0
  157. package/types/webgl/p5.RendererGL.d.ts +234 -0
  158. package/types/webgl/p5.Shader.d.ts +660 -0
  159. package/types/webgl/p5.Texture.d.ts +61 -0
  160. package/types/webgl/text.d.ts +74 -0
@@ -0,0 +1,1029 @@
1
+ // This file is auto-generated from JSDoc documentation
2
+
3
+ import p5 from 'p5';
4
+ import { Vector } from '../math/p5.Vector';
5
+
6
+ declare module 'p5' {
7
+ /**
8
+ * Adds the corresponding elements of the given matrix to this matrix, if the dimentions are the same.
9
+ *
10
+ * @param The matrix to add to this matrix. It must have the same dimensions as this matrix.
11
+ * @returns The resulting matrix after addition.
12
+ * @throws If the matrices do not have the same dimensions.
13
+ * @example const matrix1 = new p5.Matrix([1, 2, 3]);
14
+ * const matrix2 = new p5.Matrix([4, 5, 6]);
15
+ * matrix1.add(matrix2); // matrix1 is now [5, 7, 9]
16
+ *
17
+ * // p5.js script example
18
+ * <div class="norender"><code>
19
+ * function setup() {
20
+ *
21
+ * const matrix1 = new p5.Matrix([1, 2, 3, 4]);
22
+ * const matrix2 = new p5.Matrix([5, 6, 7, 8]);
23
+ * matrix1.add(matrix2);
24
+ * console.log(matrix1.matrix); // Output: [6, 8, 10, 12]
25
+ * }
26
+ * </code></div>
27
+ */
28
+ function add(matrix: Matrix): Matrix;
29
+
30
+ /**
31
+ * Sets the value of a specific element in the matrix in column-major order.A matrix is stored in column-major order, meaning elements are arranged column by column.
32
+ * This function allows you to update or change the value of a specific element
33
+ * in the matrix by specifying its index in the column-major order and the new value.Parameters:Example:
34
+ * If you have the following 3x3 matrix stored in column-major order:`[
35
+ * 1, 4, 7, // Column 1
36
+ * 2, 5, 8, // Column 2
37
+ * 3, 6, 9 // Column 3
38
+ * ]`Calling `setElement(4, 10)` will update the element at index 4
39
+ * (which corresponds to row 2, column 2 in row-major order) to `10`.
40
+ * The updated matrix will look like this:`[
41
+ * 1, 4, 7,
42
+ * 2, 10, 8,
43
+ * 3, 6, 9
44
+ * ]`This function is useful for modifying specific parts of the matrix without
45
+ * having to recreate the entire structure.
46
+ *
47
+ * @param The position in the matrix where the value should be set.
48
+ * Must be a non-negative integer less than the length of the matrix.
49
+ * @param The new value to be assigned to the specified position in the matrix.
50
+ * @returns The current instance of the Matrix, allowing for method chaining.
51
+ * @example // Assuming matrix is an instance of Matrix with initial values [1, 2, 3, 4] matrix.setElement(2, 99);
52
+ * // Now the matrix values are [1, 2, 99, 4]
53
+ *
54
+ * // p5.js script example
55
+ * <div class="norender"><code>
56
+ * function setup() {
57
+ *
58
+ * const matrix = new p5.Matrix([1, 2, 3, 4]);
59
+ * matrix.setElement(2, 99);
60
+ * console.log(matrix.matrix); // Output: [1, 2, 99, 4]
61
+ * }
62
+ * </code></div>
63
+ */
64
+ function setElement(index: number, value: number): Matrix;
65
+
66
+ /**
67
+ * Resets the current matrix to an identity matrix.This method replaces the current matrix with an identity matrix of the same dimensions.
68
+ * An identity matrix is a square matrix with ones on the main diagonal and zeros elsewhere.
69
+ * This is useful for resetting transformations or starting fresh with a clean matrix.
70
+ *
71
+ * @returns The current instance of the Matrix class, allowing for method chaining.
72
+ * @example // Resetting a 4x4 matrix to an identity matrix
73
+ * const matrix = new p5.Matrix(4);
74
+ * matrix.scale(2, 2, 2); // Apply some transformations
75
+ * console.log(matrix.matrix); // Output: Transformed matrix
76
+ * matrix.reset(); // Reset to identity matrix
77
+ * console.log(matrix.matrix); // Output: Identity matrix
78
+ *
79
+ * // p5.js script example
80
+ * <div class="norender"><code>
81
+ * function setup() {
82
+ *
83
+ * const matrix = new p5.Matrix(4);
84
+ * matrix.scale(2, 2, 2); // Apply scaling transformation
85
+ * console.log("Before reset:", matrix.matrix);
86
+ * matrix.reset(); // Reset to identity matrix
87
+ * console.log("After reset:", matrix.matrix);
88
+ * }
89
+ * </code></div>
90
+ */
91
+ function reset(): Matrix;
92
+
93
+ /**
94
+ * Replace the entire contents of a NxN matrix.This method allows you to replace the values of the current matrix with
95
+ * those from another matrix, an array, or individual arguments. The input
96
+ * can be a `Matrix` instance, an array of numbers, or individual numbers
97
+ * that match the dimensions of the current matrix. The values are copied
98
+ * without referencing the source object, ensuring that the original input
99
+ * remains unchanged.If the input dimensions do not match the current matrix, an error will
100
+ * be thrown to ensure consistency.
101
+ *
102
+ * @param The input matrix, array,
103
+ * or individual numbers to replace the current matrix values.
104
+ * @returns The current instance of the Matrix class, allowing for
105
+ * method chaining.
106
+ * @example // Replacing the contents of a matrix with another matrix
107
+ * const matrix1 = new p5.Matrix([1, 2, 3, 4]);
108
+ * const matrix2 = new p5.Matrix([5, 6, 7, 8]);
109
+ * matrix1.set(matrix2);
110
+ * console.log(matrix1.matrix); // Output: [5, 6, 7, 8]
111
+ *
112
+ * // Replacing the contents of a matrix with an array
113
+ * const matrix = new p5.Matrix([1, 2, 3, 4]);
114
+ * matrix.set([9, 10, 11, 12]);
115
+ * console.log(matrix.matrix); // Output: [9, 10, 11, 12]
116
+ *
117
+ * // Replacing the contents of a matrix with individual numbers
118
+ * const matrix = new p5.Matrix(4); // Creates a 4x4 identity matrix
119
+ * matrix.set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
120
+ * console.log(matrix.matrix); // Output: [1, 2, 3, ..., 16]
121
+ *
122
+ * // p5.js script example
123
+ * <div class="norender"><code>
124
+ * function setup() {
125
+ *
126
+ * const matrix = new p5.Matrix([1, 2, 3, 4]);
127
+ * console.log("Before set:", matrix.matrix);
128
+ * matrix.set([5, 6, 7, 8]);
129
+ * console.log("After set:", matrix.matrix); // Output: [5, 6, 7, 8]
130
+ * }
131
+ * </code></div>
132
+ */
133
+ function set(inMatrix?: Matrix | Float32Array | number[]): Matrix;
134
+
135
+ /**
136
+ * Gets a copy of the matrix, returns a p5.Matrix object.This method creates a new instance of the `Matrix` class and copies the
137
+ * current matrix values into it. The returned matrix is independent of the
138
+ * original, meaning changes to the copy will not affect the original matrix.This is useful when you need to preserve the current state of a matrix
139
+ * while performing operations on a duplicate.
140
+ *
141
+ * @return A new instance of the `Matrix` class containing the
142
+ * same values as the original matrix.
143
+ * @example // p5.js script example
144
+ * <div class="norender"><code>
145
+ * function setup() {
146
+ *
147
+ * const originalMatrix = new p5.Matrix([1, 2, 3, 4]);
148
+ * const copiedMatrix = originalMatrix.get();
149
+ * console.log("Original Matrix:", originalMatrix.matrix); // Output: [1, 2, 3, 4]
150
+ * console.log("Copied Matrix:", copiedMatrix.matrix); // Output: [1, 2, 3, 4]
151
+ *
152
+ * // Modify the copied matrix
153
+ * copiedMatrix.setElement(2, 99);
154
+ * console.log("Modified Copied Matrix:", copiedMatrix.matrix); // Output: [1, 2, 99, 4]
155
+ * console.log("Original Matrix remains unchanged:", originalMatrix.matrix); // Output: [1, 2, 3, 4]
156
+ * }
157
+ * </code></div>
158
+ */
159
+ function get(): p5.Matrix;
160
+
161
+ /**
162
+ * Return a copy of this matrix.
163
+ * If this matrix is 4x4, a 4x4 matrix with exactly the same entries will be
164
+ * generated. The same is true if this matrix is 3x3 or any NxN matrix.This method is useful when you need to preserve the current state of a matrix
165
+ * while performing operations on a duplicate. The returned matrix is independent
166
+ * of the original, meaning changes to the copy will not affect the original matrix.
167
+ *
168
+ * @return The result matrix.
169
+ * @example // p5.js script example
170
+ * <div class="norender"><code>
171
+ * function setup() {
172
+ *
173
+ * const originalMatrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
174
+ * const copiedMatrix = originalMatrix.copy();
175
+ * console.log("Original Matrix:", originalMatrix.matrix);
176
+ * console.log("Copied Matrix:", copiedMatrix.matrix);
177
+ *
178
+ * // Modify the copied matrix
179
+ * copiedMatrix.setElement(4, 99);
180
+ * console.log("Modified Copied Matrix:", copiedMatrix.matrix);
181
+ * console.log("Original Matrix remains unchanged:", originalMatrix.matrix);
182
+ * }
183
+ * </code></div>
184
+ */
185
+ function copy(): p5.Matrix;
186
+
187
+ /**
188
+ * Creates a copy of the current matrix instance.
189
+ * This method is useful when you need a duplicate of the matrix
190
+ * without modifying the original one.
191
+ *
192
+ * @returns A new matrix instance that is a copy of the current matrix.
193
+ * @example // p5.js script example
194
+ * <div class="norender"><code>
195
+ * function setup() {
196
+ *
197
+ * const originalMatrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
198
+ * const clonedMatrix = originalMatrix.clone();
199
+ * console.log("Original Matrix:", originalMatrix.matrix);
200
+ * console.log("Cloned Matrix:", clonedMatrix.matrix);
201
+ *
202
+ * // Modify the cloned matrix
203
+ * clonedMatrix.setElement(4, 99);
204
+ * console.log("Modified Cloned Matrix:", clonedMatrix.matrix);
205
+ * console.log("Original Matrix remains unchanged:", originalMatrix.matrix);
206
+ * }
207
+ * </code></div>
208
+ */
209
+ function clone(): Matrix;
210
+
211
+ /**
212
+ * Returns the diagonal elements of the matrix in the form of an array.
213
+ * A NxN matrix will return an array of length N.This method extracts the diagonal elements of the matrix, which are the
214
+ * elements where the row index equals the column index. For example, in a
215
+ * 3x3 matrix:`[
216
+ * 1, 2, 3,
217
+ * 4, 5, 6,
218
+ * 7, 8, 9
219
+ * ]`The diagonal elements are [1, 5, 9].This is useful for operations that require the main diagonal of a matrix,
220
+ * such as calculating the trace of a matrix or verifying if a matrix is diagonal.
221
+ *
222
+ * @return An array obtained by arranging the diagonal elements
223
+ * of the matrix in ascending order of index.
224
+ * @example // Extracting the diagonal elements of a matrix
225
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
226
+ * const diagonal = matrix.diagonal(); // [1, 5, 9]
227
+ *
228
+ * // p5.js script example
229
+ * <div class="norender"><code>
230
+ * function setup() {
231
+ *
232
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
233
+ * const diagonal = matrix.diagonal();
234
+ * console.log("Diagonal elements:", diagonal); // Output: [1, 5, 9]
235
+ * }
236
+ * </code></div>
237
+ */
238
+ function diagonal(): number[];
239
+
240
+ /**
241
+ * This function is only for 3x3 matrices A function that returns a row vector of a NxN matrix.This method extracts a specific row from the matrix and returns it as a `p5.Vector`.
242
+ * The row is determined by the `columnIndex` parameter, which specifies the column
243
+ * index of the matrix. This is useful for operations that require working with
244
+ * individual rows of a matrix, such as row transformations or dot products.
245
+ *
246
+ * @param The index of the column to extract as a row vector.
247
+ * Must be a non-negative integer less than the matrix dimension.
248
+ * @return A `p5.Vector` representing the extracted row of the matrix.
249
+ * @example // Extracting a row vector from a 3x3 matrix
250
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
251
+ * const rowVector = matrix.row(1); // Returns a vector [2, 5, 8]
252
+ *
253
+ * // p5.js script example
254
+ * <div class="norender"><code>
255
+ * function setup() {
256
+ *
257
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
258
+ * const rowVector = matrix.row(1); // Extract the second row (index 1)
259
+ * console.log("Row Vector:", rowVector.toString()); // Output: Row Vector: [2, 5, 8]
260
+ * }
261
+ * </code></div>
262
+ */
263
+ function row(columnIndex: number): p5.Vector;
264
+
265
+ /**
266
+ * A function that returns a column vector of a NxN matrix.This method extracts a specific column from the matrix and returns it as a `p5.Vector`.
267
+ * The column is determined by the `rowIndex` parameter, which specifies the row index
268
+ * of the matrix. This is useful for operations that require working with individual
269
+ * columns of a matrix, such as column transformations or dot products.
270
+ *
271
+ * @param The index of the row to extract as a column vector.
272
+ * Must be a non-negative integer less than the matrix dimension.
273
+ * @return A `p5.Vector` representing the extracted column of the matrix.
274
+ * @example // Extracting a column vector from a 3x3 matrix
275
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
276
+ * const columnVector = matrix.column(1); // Returns a vector [4, 5, 6]
277
+ *
278
+ * // p5.js script example
279
+ * <div class="norender"><code>
280
+ * function setup() {
281
+ *
282
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
283
+ * const columnVector = matrix.column(1); // Extract the second column (index 1)
284
+ * console.log("Column Vector:", columnVector.toString()); // Output: Column Vector: [4, 5, 6]
285
+ * }
286
+ * </code></div>
287
+ */
288
+ function column(rowIndex: number): p5.Vector;
289
+
290
+ /**
291
+ * Transposes the given matrix `a` based on the square dimension of the matrix.This method rearranges the elements of the matrix such that the rows become columns
292
+ * and the columns become rows. It handles matrices of different dimensions (4x4, 3x3, NxN)
293
+ * by delegating to specific transpose methods for each case.If no argument is provided, the method transposes the current matrix instance.
294
+ * If an argument is provided, it transposes the given matrix `a` and updates the current matrix.
295
+ *
296
+ * @param The matrix to be transposed. It should be a 2D array where each sub-array represents a row.
297
+ * If omitted, the current matrix instance is transposed.
298
+ * @returns The current instance of the Matrix class, allowing for method chaining.
299
+ * @example // Transposing a 3x3 matrix
300
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
301
+ * matrix.transpose();
302
+ * console.log(matrix.matrix); // Output: [1, 4, 7, 2, 5, 8, 3, 6, 9]
303
+ *
304
+ * // Transposing a 4x4 matrix
305
+ * const matrix4x4 = new p5.Matrix(4);
306
+ * matrix4x4.transpose();
307
+ * console.log(matrix4x4.matrix); // Output: Transposed 4x4 identity matrix
308
+ *
309
+ * // p5.js script example
310
+ * <div class="norender"><code>
311
+ * function setup() {
312
+ *
313
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
314
+ * console.log("Before transpose:", matrix.matrix);
315
+ * matrix.transpose();
316
+ * console.log("After transpose:", matrix.matrix); // Output: [1, 4, 7, 2, 5, 8, 3, 6, 9]
317
+ * }
318
+ * </code></div>
319
+ */
320
+ function transpose(a?: Array): Matrix;
321
+
322
+ /**
323
+ * Multiplies the current matrix with another matrix or matrix-like array.This method supports several types of input:If the input is the same as the current matrix, a copy is made to avoid modifying the original matrix.The method determines the appropriate multiplication strategy based on the dimensions of the current matrix
324
+ * and the input matrix. It supports 3x3, 4x4, and NxN matrices.
325
+ *
326
+ * @param The matrix or matrix-like array to multiply with.
327
+ * @returns The resulting matrix after multiplication, or undefined if the input is invalid.
328
+ * @example // Multiplying two 3x3 matrices
329
+ * const matrix1 = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
330
+ * const matrix2 = new p5.Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1]);
331
+ * matrix1.mult(matrix2);
332
+ * console.log(matrix1.matrix); // Output: [30, 24, 18, 84, 69, 54, 138, 114, 90]
333
+ *
334
+ * // Multiplying a 4x4 matrix with another 4x4 matrix
335
+ * const matrix4x4_1 = new p5.Matrix(4); // Identity matrix
336
+ * const matrix4x4_2 = new p5.Matrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1]);
337
+ * matrix4x4_1.mult(matrix4x4_2);
338
+ * console.log(matrix4x4_1.matrix); // Output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1]
339
+ *
340
+ * // p5.js script example
341
+ * <div class="norender"><code>
342
+ * function setup() {
343
+ *
344
+ * const matrix1 = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
345
+ * const matrix2 = new p5.Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1]);
346
+ * console.log("Before multiplication:", matrix1.matrix);
347
+ * matrix1.mult(matrix2);
348
+ * console.log("After multiplication:", matrix1.matrix); // Output: [30, 24, 18, 84, 69, 54, 138, 114, 90]
349
+ * }
350
+ * </code></div>
351
+ */
352
+ function mult(multMatrix: any): Matrix | any;
353
+
354
+ /**
355
+ * Takes a vector and returns the vector resulting from multiplying to that vector by this matrix from left. This function is only for 3x3 matrices.This method applies the current 3x3 matrix to a given vector, effectively
356
+ * transforming the vector using the matrix. The resulting vector is returned
357
+ * as a new vector or stored in the provided target vector.
358
+ *
359
+ * @param The vector to which this matrix applies.
360
+ * @param The vector to receive the result. If not provided,
361
+ * a copy of the input vector will be created and returned.
362
+ * @return The transformed vector after applying the matrix.
363
+ * @example // Multiplying a 3x3 matrix with a vector
364
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
365
+ * const vector = new p5.Vector(1, 2, 3);
366
+ * const result = matrix.multiplyVec(vector);
367
+ * console.log(result.toString()); // Output: Transformed vector
368
+ *
369
+ * // p5.js script example
370
+ * <div class="norender"><code>
371
+ * function setup() {
372
+ *
373
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
374
+ * const vector = new p5.Vector(1, 2, 3);
375
+ * const result = matrix.multiplyVec(vector);
376
+ * console.log("Original Vector:", vector.toString()); // Output : Original Vector: [1, 2, 3]
377
+ * console.log("Transformed Vector:", result.toString()); // Output : Transformed Vector: [30, 36, 42]
378
+ * }
379
+ * </code></div>
380
+ */
381
+ function multiplyVec(multVector: p5.Vector, target?: p5.Vector): p5.Vector;
382
+
383
+ /**
384
+ * Inverts a given matrix.This method inverts a matrix based on its dimensions. Currently, it supports
385
+ * 3x3 and 4x4 matrices. If the matrix dimension is greater than 4, an error is thrown.For 4x4 matrices, it uses a specialized algorithm to compute the inverse.
386
+ * For 3x3 matrices, it uses a different algorithm optimized for smaller matrices.If the matrix is singular (non-invertible), the method will return `null`.
387
+ *
388
+ * @param The matrix to be inverted. It should be a 2D array representing the matrix.
389
+ * @returns The inverted matrix, or `null` if the matrix is singular.
390
+ * @throws Throws an error if the matrix dimension is greater than 4.
391
+ * @example // Inverting a 3x3 matrix
392
+ * const matrix = new p5.Matrix([1, 2, 3, 0, 1, 4, 5, 6, 0]);
393
+ * const invertedMatrix = matrix.invert();
394
+ * console.log(invertedMatrix.matrix); // Output: Inverted 3x3 matrix
395
+ *
396
+ * // Inverting a 4x4 matrix
397
+ * const matrix4x4 = new p5.Matrix(4); // Identity matrix
398
+ * matrix4x4.scale(2, 2, 2);
399
+ * const invertedMatrix4x4 = matrix4x4.invert();
400
+ * console.log(invertedMatrix4x4.matrix); // Output: Inverted 4x4 matrix
401
+ *
402
+ * // p5.js script example
403
+ * <div class="norender"><code>
404
+ * function setup() {
405
+ *
406
+ * const matrix = new p5.Matrix([1, 2, 3, 0, 1, 4, 5, 6, 0]);
407
+ * console.log("Original Matrix:", matrix.matrix);
408
+ * const invertedMatrix = matrix.invert();
409
+ * if (invertedMatrix) {
410
+ * console.log("Inverted Matrix:", invertedMatrix.matrix);
411
+ * } else {
412
+ * console.log("Matrix is singular and cannot be inverted.");
413
+ * }
414
+ * }
415
+ * </code></div>
416
+ */
417
+ function invert(a: Array): Array | any;
418
+
419
+ /**
420
+ * Creates a 3x3 matrix whose entries are the top left 3x3 part and returns it. This function is only for 4x4 matrices.This method extracts the top-left 3x3 portion of a 4x4 matrix and creates a new
421
+ * 3x3 matrix from it. This is particularly useful in 3D graphics for operations
422
+ * that require only the rotational or scaling components of a transformation matrix.If the current matrix is not 4x4, an error is thrown to ensure the method is used
423
+ * correctly. The resulting 3x3 matrix is independent of the original matrix, meaning
424
+ * changes to the new matrix will not affect the original.
425
+ *
426
+ * @return A new 3x3 matrix containing the top-left portion of the original 4x4 matrix.
427
+ * @throws If the current matrix is not 4x4.
428
+ * @example // Extracting a 3x3 submatrix from a 4x4 matrix
429
+ * const matrix4x4 = new p5.Matrix(4); // Creates a 4x4 identity matrix
430
+ * matrix4x4.scale(2, 2, 2); // Apply scaling transformation
431
+ * const subMatrix3x3 = matrix4x4.createSubMatrix3x3();
432
+ * console.log("Original 4x4 Matrix:", matrix4x4.matrix);
433
+ * console.log("Extracted 3x3 Submatrix:", subMatrix3x3.matrix);
434
+ *
435
+ * // p5.js script example
436
+ * <div class="norender"><code>
437
+ * function setup() {
438
+ *
439
+ * const matrix4x4 = new p5.Matrix(4); // Creates a 4x4 identity matrix
440
+ * matrix4x4.scale(2, 2, 2); // Apply scaling transformation
441
+ * console.log("Original 4x4 Matrix:", matrix4x4.matrix);
442
+ *
443
+ * const subMatrix3x3 = matrix4x4.createSubMatrix3x3();
444
+ * console.log("Extracted 3x3 Submatrix:", subMatrix3x3.matrix);
445
+ * }
446
+ * </code></div>
447
+ */
448
+ function createSubMatrix3x3(): p5.Matrix;
449
+
450
+ /**
451
+ * Converts a 4×4 matrix to its 3×3 inverse transpose transform.
452
+ * This is commonly used in MVMatrix to NMatrix conversions, particularly
453
+ * in 3D graphics for transforming normal vectors.This method extracts the top-left 3×3 portion of a 4×4 matrix, inverts it,
454
+ * and then transposes the result. If the matrix is singular (non-invertible),
455
+ * the resulting matrix will be zeroed out.
456
+ *
457
+ * @param The 4×4 matrix to be converted.
458
+ * @returns The current instance of the Matrix class, allowing for method chaining.
459
+ * @throws If the current matrix is not 3×3.
460
+ * @example // Converting a 4×4 matrix to its 3×3 inverse transpose
461
+ * const mat4 = new p5.Matrix(4); // Create a 4×4 identity matrix
462
+ * mat4.scale(2, 2, 2); // Apply scaling transformation
463
+ * const mat3 = new p5.Matrix(3); // Create a 3×3 matrix
464
+ * mat3.inverseTranspose4x4(mat4);
465
+ * console.log("Converted 3×3 Matrix:", mat3.matrix);
466
+ *
467
+ * // p5.js script example
468
+ * <div class="norender"><code>
469
+ * function setup() {
470
+ *
471
+ * const mat4 = new p5.Matrix(4); // Create a 4×4 identity matrix
472
+ * mat4.scale(2, 2, 2); // Apply scaling transformation
473
+ * console.log("Original 4×4 Matrix:", mat4.matrix);
474
+ *
475
+ * const mat3 = new p5.Matrix(3); // Create a 3×3 matrix
476
+ * mat3.inverseTranspose4x4(mat4);
477
+ * console.log("Converted 3×3 Matrix:", mat3.matrix);
478
+ * }
479
+ * </code></div>
480
+ */
481
+ function inverseTranspose4x4(mat4: p5.Matrix): Matrix;
482
+
483
+ /**
484
+ * Applies a transformation matrix to the current matrix.This method multiplies the current matrix by another matrix, which can be provided
485
+ * in several forms: another Matrix instance, an array representing a matrix, or as
486
+ * individual arguments representing the elements of a 4x4 matrix.This operation is useful for combining transformations such as translation, rotation,
487
+ * scaling, and perspective projection into a single matrix. By applying a transformation
488
+ * matrix, you can modify the current matrix to represent a new transformation.
489
+ *
490
+ * @param The matrix to multiply with. This can be:
491
+ * - An instance of the Matrix class.
492
+ * - An array of 16 numbers representing a 4x4 matrix.
493
+ * - 16 individual numbers representing the elements of a 4x4 matrix.
494
+ * @returns The current matrix after applying the transformation.
495
+ * @example <div class="norender"><code>
496
+ * function setup() {
497
+ *
498
+ * // Assuming `matrix` is an instance of Matrix
499
+ * const anotherMatrix = new p5.Matrix(4);
500
+ * const anotherMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
501
+ * matrix.apply(anotherMatrix);
502
+ *
503
+ * // Applying a transformation using an array
504
+ * const matrixArray = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
505
+ * matrix.apply(matrixArray);
506
+ *
507
+ * // Applying a transformation using individual arguments
508
+ * matrix.apply(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
509
+ *
510
+ * // Create a 4x4 identity matrix
511
+ * const matrix = new p5.Matrix(4);
512
+ * console.log("Original Matrix:", matrix.matrix);
513
+ *
514
+ * // Create a scaling transformation matrix
515
+ * const scalingMatrix = new p5.Matrix([2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1]);
516
+ *
517
+ * // Apply the scaling transformation
518
+ * matrix.apply(scalingMatrix);
519
+ * console.log("After Scaling Transformation:", matrix.matrix);
520
+ *
521
+ * // Apply a translation transformation using an array
522
+ * const translationMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5, 5, 5, 1];
523
+ * matrix.apply(translationMatrix);
524
+ * console.log("After Translation Transformation:", matrix.matrix);
525
+ * }
526
+ * </code></div>
527
+ */
528
+ function apply(multMatrix: Matrix | Array | number): Matrix;
529
+
530
+ /**
531
+ * Scales a p5.Matrix by scalars or a vector.This method applies a scaling transformation to the current matrix.
532
+ * Scaling is a transformation that enlarges or shrinks objects by a scale factor
533
+ * along the x, y, and z axes. The scale factors can be provided as individual
534
+ * numbers, an array, or a `p5.Vector`.If a `p5.Vector` or an array is provided, the x, y, and z components are extracted
535
+ * from it. If the z component is not provided, it defaults to 1 (no scaling along the z-axis).
536
+ *
537
+ * @param The vector or scalars to scale by.
538
+ * Can be a `p5.Vector`, an array, or individual numbers.
539
+ * @returns The current instance of the Matrix class, allowing for method chaining.
540
+ * @example // Scaling a matrix by individual scalars
541
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
542
+ * matrix.scale(2, 3, 4); // Scale by 2 along x, 3 along y, and 4 along z
543
+ * console.log(matrix.matrix);
544
+ *
545
+ * // Scaling a matrix by a p5.Vector
546
+ * const scaleVector = new p5.Vector(2, 3, 4);
547
+ * matrix.scale(scaleVector);
548
+ * console.log(matrix.matrix);
549
+ *
550
+ * // Scaling a matrix by an array
551
+ * const scaleArray = [2, 3, 4];
552
+ * matrix.scale(scaleArray);
553
+ * console.log(matrix.matrix);
554
+ *
555
+ * // p5.js script example
556
+ * <div class="norender"><code>
557
+ * function setup() {
558
+ *
559
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
560
+ * console.log("Original Matrix:", matrix.matrix);
561
+ *
562
+ * // Scale the matrix by individual scalars
563
+ * matrix.scale(2, 3, 4);
564
+ * console.log("Scaled Matrix (2, 3, 4):", matrix.matrix);
565
+ *
566
+ * // Scale the matrix by a p5.Vector
567
+ * const scaleVector = new p5.Vector(1.5, 2.5, 3.5);
568
+ * matrix.scale(scaleVector);
569
+ * console.log("Scaled Matrix (Vector):", matrix.matrix);
570
+ *
571
+ * // Scale the matrix by an array
572
+ * const scaleArray = [0.5, 0.5, 0.5];
573
+ * matrix.scale(scaleArray);
574
+ * console.log("Scaled Matrix (Array):", matrix.matrix);
575
+ * }
576
+ * </code></div>
577
+ */
578
+ function scale(x: any, y: any, z: any, s: p5.Vector | Float32Array | number[]): Matrix;
579
+
580
+ /**
581
+ * Rotate the Matrix around a specified axis by a given angle.This method applies a rotation transformation to the matrix, modifying its orientation
582
+ * in 3D space. The rotation is performed around the provided axis, which can be defined
583
+ * as a `p5.Vector` or an array of numbers representing the x, y, and z components of the axis.
584
+ * Rotate our Matrix around an axis by the given angle.
585
+ *
586
+ * @param The angle of rotation in radians.
587
+ * Angles in radians are a measure of rotation, where 2π radians
588
+ * represent a full circle (360 degrees). For example:
589
+ * - π/2 radians = 90 degrees (quarter turn)
590
+ * - π radians = 180 degrees (half turn)
591
+ * - 2π radians = 360 degrees (full turn)
592
+ * Use `Math.PI` for π or `p5`'s `PI` constant if using p5.js.
593
+ * @param The axis or axes to rotate around.
594
+ * This defines the direction of the rotation.
595
+ * - If using a `p5.Vector`, it should represent
596
+ * the x, y, and z components of the axis.
597
+ * - If using an array, it should be in the form
598
+ * [x, y, z], where x, y, and z are numbers.
599
+ * For example:
600
+ * - [1, 0, 0] rotates around the x-axis.
601
+ * - [0, 1, 0] rotates around the y-axis.
602
+ * - [0, 0, 1] rotates around the z-axis. *
603
+ * @chainable inspired by Toji's gl-matrix lib, mat4 rotation
604
+ * @example // p5.js script example
605
+ * <div class="norender"><code>
606
+ * function setup() {
607
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
608
+ * console.log("Original Matrix:", matrix.matrix.slice().toString()); // [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
609
+ *
610
+ * // Translate the matrix by a 3D vector
611
+ * matrix.rotate4x4(Math.PI, [1,0,0]);
612
+ * console.log("After rotation of PI degrees on vector [1,0,0]:", matrix.matrix.slice().toString()); // [1,0,0,0,0,-1,1.2246468525851679e-16,0,0,-1.2246468525851679e-16,-1,0,0,0,0,1]
613
+ * }
614
+ * </code></div>
615
+ */
616
+ function rotate4x4(a: number, x: any, y: any, z: any, axis: p5.Vector | number[]): void;
617
+
618
+ /**
619
+ * Translates the current matrix by a given vector.This method applies a translation transformation to the current matrix.
620
+ * Translation moves the matrix by a specified amount along the x, y, and z axes.
621
+ * The input vector can be a 2D or 3D vector. If the z-component is not provided,
622
+ * it defaults to 0, meaning no translation along the z-axis.
623
+ *
624
+ * @param A vector representing the translation. It should be an array
625
+ * with two or three elements: [x, y, z]. The z-component is optional.
626
+ * @returns The current instance of the Matrix class, allowing for method chaining.
627
+ * @example // Translating a matrix by a 3D vector
628
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
629
+ * matrix.translate([10, 20, 30]); // Translate by 10 units along x, 20 along y, and 30 along z
630
+ * console.log(matrix.matrix);
631
+ *
632
+ * // Translating a matrix by a 2D vector
633
+ * matrix.translate([5, 15]); // Translate by 5 units along x and 15 along y
634
+ * console.log(matrix.matrix);
635
+ *
636
+ * // p5.js script example
637
+ * <div class="norender"><code>
638
+ * function setup() {
639
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
640
+ * console.log("Original Matrix:", matrix.matrix.slice().toString()); // [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
641
+ *
642
+ * // Translate the matrix by a 3D vector
643
+ * matrix.translate([10, 20, 30]);
644
+ * console.log("After 3D Translation (10, 20, 30):", matrix.matrix.slice().toString()); // [1,0,0,0,0,1,0,0,0,0,1,0,10,20,30,1]
645
+ *
646
+ * // Translate the matrix by a 2D vector
647
+ * matrix.translate([5, 15]);
648
+ * console.log("After 2D Translation (5, 15):", matrix.matrix.slice().toString()); // [1,0,0,0,0,1,0,0,0,0,1,0,15,35,30,1]
649
+ * }
650
+ * </code></div>
651
+ */
652
+ function translate(v: number[]): Matrix;
653
+
654
+ /**
655
+ * Rotates the matrix around the X-axis by a given angle.This method modifies the current matrix to apply a rotation transformation
656
+ * around the X-axis. The rotation angle is specified in radians.Rotating around the X-axis means that the Y and Z coordinates of the matrix
657
+ * are transformed while the X coordinates remain unchanged. This is commonly
658
+ * used in 3D graphics to create animations or transformations along the X-axis.
659
+ *
660
+ * @param The angle in radians to rotate the matrix by.
661
+ * @example // Rotating a matrix around the X-axis
662
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
663
+ * matrix.rotateX(Math.PI / 4); // Rotate 45 degrees around the X-axis
664
+ * console.log(matrix.matrix);
665
+ *
666
+ * // p5.js script example
667
+ * <div class="norender"><code>
668
+ * function setup() {
669
+ *
670
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
671
+ * console.log("Original Matrix:", matrix.matrix);
672
+ *
673
+ * // Rotate the matrix 45 degrees (PI/4 radians) around the X-axis
674
+ * matrix.rotateX(Math.PI / 4);
675
+ * console.log("After Rotation (X-axis, 45 degrees):", matrix.matrix);
676
+ * }
677
+ * </code></div>
678
+ */
679
+ function rotateX(a: number): void;
680
+
681
+ /**
682
+ * Rotates the matrix around the Y-axis by a given angle.This method modifies the current matrix to apply a rotation transformation
683
+ * around the Y-axis. The rotation is performed in 3D space, and the angle
684
+ * is specified in radians. Rotating around the Y-axis means that the X and Z
685
+ * coordinates of the matrix are transformed while the Y coordinates remain
686
+ * unchanged. This is commonly used in 3D graphics to create animations or
687
+ * transformations along the Y-axis.
688
+ *
689
+ * @param The angle in radians to rotate the matrix by. Positive
690
+ * values rotate the matrix counterclockwise, and negative values rotate it
691
+ * clockwise.
692
+ * @example // Rotating a matrix around the Y-axis
693
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
694
+ * matrix.rotateY(Math.PI / 4); // Rotate 45 degrees around the Y-axis
695
+ * console.log(matrix.matrix);
696
+ *
697
+ * // p5.js script example
698
+ * <div class="norender"><code>
699
+ * function setup() {
700
+ *
701
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
702
+ * console.log("Original Matrix:", matrix.matrix);
703
+ *
704
+ * // Rotate the matrix 45 degrees (PI/4 radians) around the Y-axis
705
+ * matrix.rotateY(Math.PI / 4);
706
+ * console.log("After Rotation (Y-axis, 45 degrees):", matrix.matrix);
707
+ * }
708
+ * </code></div>
709
+ */
710
+ function rotateY(a: number): void;
711
+
712
+ /**
713
+ * Rotates the matrix around the Z-axis by a given angle.This method modifies the current matrix to apply a rotation transformation
714
+ * around the Z-axis. The rotation is performed in a 4x4 matrix context, which
715
+ * is commonly used in 3D graphics to handle transformations. Rotating around
716
+ * the Z-axis means that the X and Y coordinates of the matrix are transformed
717
+ * while the Z coordinates remain unchanged.
718
+ *
719
+ * @param The angle in radians to rotate the matrix by. Positive
720
+ * values rotate the matrix counterclockwise, and negative values rotate it
721
+ * clockwise.
722
+ * @returns The current instance of the Matrix class, allowing for
723
+ * method chaining.
724
+ * @example // Rotating a matrix around the Z-axis
725
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
726
+ * matrix.rotateZ(Math.PI / 4); // Rotate 45 degrees around the Z-axis
727
+ * console.log(matrix.matrix);
728
+ *
729
+ * // p5.js script example
730
+ * <div class="norender"><code>
731
+ * function setup() {
732
+ *
733
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
734
+ * console.log("Original Matrix:", matrix.matrix);
735
+ *
736
+ * // Rotate the matrix 45 degrees (PI/4 radians) around the Z-axis
737
+ * matrix.rotateZ(Math.PI / 4);
738
+ * console.log("After Rotation (Z-axis, 45 degrees):", matrix.matrix);
739
+ * }
740
+ * </code></div>
741
+ */
742
+ function rotateZ(a: number): Matrix;
743
+
744
+ /**
745
+ * Sets the perspective projection matrix.This method modifies the current matrix to represent a perspective projection.
746
+ * Perspective projection is commonly used in 3D graphics to simulate the effect
747
+ * of objects appearing smaller as they move further away from the camera.The perspective matrix is defined by the field of view (fovy), aspect ratio,
748
+ * and the near and far clipping planes. The near and far clipping planes define
749
+ * the range of depth that will be rendered, with anything outside this range
750
+ * being clipped.
751
+ *
752
+ * @param The field of view in the y direction, in radians.
753
+ * @param The aspect ratio of the viewport (width / height).
754
+ * @param The distance to the near clipping plane. Must be greater than 0.
755
+ * @param The distance to the far clipping plane. Must be greater than the near value.
756
+ * @returns The current instance of the Matrix class, allowing for method chaining.
757
+ * @example // Setting a perspective projection matrix
758
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
759
+ * matrix.perspective(Math.PI / 4, 1.5, 0.1, 100); // Set perspective projection
760
+ * console.log(matrix.matrix);
761
+ *
762
+ * // p5.js script example
763
+ * <div class="norender"><code>
764
+ * function setup() {
765
+ *
766
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
767
+ * console.log("Original Matrix:", matrix.matrix);
768
+ *
769
+ * // Set a perspective projection with a 45-degree field of view,
770
+ * // an aspect ratio of 1.5, and near/far clipping planes at 0.1 and 100.
771
+ * matrix.perspective(Math.PI / 4, 1.5, 0.1, 100);
772
+ * console.log("Perspective Matrix:", matrix.matrix);
773
+ * }
774
+ * </code></div>
775
+ */
776
+ function perspective(fovy: number, aspect: number, near: number, far: number): Matrix;
777
+
778
+ /**
779
+ * Sets this matrix to an orthographic projection matrix.An orthographic projection matrix is used to create a 2D rendering
780
+ * of a 3D scene by projecting points onto a plane without perspective
781
+ * distortion. This method modifies the current matrix to represent
782
+ * the orthographic projection defined by the given parameters.
783
+ *
784
+ * @param The coordinate for the left vertical clipping plane.
785
+ * @param The coordinate for the right vertical clipping plane.
786
+ * @param The coordinate for the bottom horizontal clipping plane.
787
+ * @param The coordinate for the top horizontal clipping plane.
788
+ * @param The distance to the near depth clipping plane. Must be positive.
789
+ * @param The distance to the far depth clipping plane. Must be positive.
790
+ * @returns The current matrix instance, updated with the orthographic projection.
791
+ * @example <div class="norender"><code>
792
+ * // Example using p5.js to demonstrate orthographic projection
793
+ * function setup() {
794
+ * let orthoMatrix = new p5.Matrix(4);
795
+ * console.log(orthoMatrix.matrix.toString()) // Output: 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1
796
+ * orthoMatrix.ortho(-200, 200, -200, 200, 0.1, 1000);
797
+ * console.log(orthoMatrix.matrix.toString()) // Output: [24 0.004999999888241291,0,0,0,0,0.004999999888241291,0,0,0,0,-0.0020002000965178013,0,0,0,-1.0002000331878662,1]
798
+ * applyMatrix(
799
+ * orthoMatrix.mat4[0], orthoMatrix.mat4[1], orthoMatrix.mat4[2], orthoMatrix.mat4[3],
800
+ * orthoMatrix.mat4[4], orthoMatrix.mat4[5], orthoMatrix.mat4[6], orthoMatrix.mat4[7],
801
+ * orthoMatrix.mat4[8], orthoMatrix.mat4[9], orthoMatrix.mat4[10], orthoMatrix.mat4[11],
802
+ * orthoMatrix.mat4[12], orthoMatrix.mat4[13], orthoMatrix.mat4[14], orthoMatrix.mat4[15]
803
+ * );
804
+ * console.log(orthoMatrix.matrix.toString()) // Output: [31 0.004999999888241291,0,0,0,0,0.004999999888241291,0,0,0,0,-0.0020002000965178013,0,0,0,-1.0002000331878662,1]
805
+ * }
806
+ * </code></div>
807
+ */
808
+ function ortho(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix;
809
+
810
+ /**
811
+ * Applies a matrix to a vector with x, y, z, w components and returns the result as an array.This method multiplies the current matrix by a 4D vector (x, y, z, w) and computes the resulting vector.
812
+ * It is commonly used in 3D graphics for transformations such as translation, rotation, scaling, and perspective projection.The resulting vector is returned as an array of four numbers, representing the transformed x, y, z, and w components.
813
+ *
814
+ * @param The x component of the vector.
815
+ * @param The y component of the vector.
816
+ * @param The z component of the vector.
817
+ * @param The w component of the vector.
818
+ * @returns An array containing the transformed [x, y, z, w] components.
819
+ * @example // Applying a matrix to a 4D vector
820
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
821
+ * const result = matrix.multiplyVec4(1, 2, 3, 1); // Transform the vector [1, 2, 3, 1]
822
+ * console.log(result); // Output: [1, 2, 3, 1] (unchanged for identity matrix)
823
+ *
824
+ * // p5.js script example
825
+ * <div class="norender"><code>
826
+ * function setup() {
827
+ *
828
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
829
+ * console.log("Original Matrix:", matrix.matrix);
830
+ *
831
+ * // Apply the matrix to a 4D vector
832
+ * const result = matrix.multiplyVec4(1, 2, 3, 1);
833
+ * console.log("Transformed Vector:", result); // Output: [1, 2, 3, 1]
834
+ *
835
+ * // Modify the matrix (e.g., apply a translation)
836
+ * matrix.translate([5, 5, 5]);
837
+ * console.log("Modified Matrix:", matrix.matrix);
838
+ *
839
+ * // Apply the modified matrix to the same vector
840
+ * const transformedResult = matrix.multiplyVec4(1, 2, 3, 1);
841
+ * console.log("Transformed Vector after Translation:", transformedResult); // Output: [6, 7, 8, 1]
842
+ * }
843
+ * </code></div>
844
+ */
845
+ function multiplyVec4(x: number, y: number, z: number, w: number): number[];
846
+
847
+ /**
848
+ * Applies a matrix to a vector. The fourth component is set to 1.
849
+ * Returns a vector consisting of the first
850
+ * through third components of the result.This method multiplies the current matrix by a 4D vector (x, y, z, 1),
851
+ * effectively transforming the vector using the matrix. The resulting
852
+ * vector is returned as a new `p5.Vector` instance.This is useful for applying transformations such as translation,
853
+ * rotation, scaling, or perspective projection to a point in 3D space.
854
+ *
855
+ * @param The input vector to transform. It should
856
+ * have x, y, and z components.
857
+ * @return A new `p5.Vector` instance representing the transformed point.
858
+ * @example // Applying a matrix to a 3D point
859
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
860
+ * const point = new p5.Vector(1, 2, 3); // Define a 3D point
861
+ * const transformedPoint = matrix.multiplyPoint(point);
862
+ * console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
863
+ *
864
+ * // p5.js script example
865
+ * <div class="norender"><code>
866
+ * function setup() {
867
+ *
868
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
869
+ * console.log("Original Matrix:", matrix.matrix);
870
+ *
871
+ * // Define a 3D point
872
+ * const point = new p5.Vector(1, 2, 3);
873
+ * console.log("Original Point:", point.toString());
874
+ *
875
+ * // Apply the matrix to the point
876
+ * const transformedPoint = matrix.multiplyPoint(point);
877
+ * console.log("Transformed Point:", transformedPoint.toString());
878
+ *
879
+ * // Modify the matrix (e.g., apply a translation)
880
+ * matrix.translate([5, 5, 5]);
881
+ * console.log("Modified Matrix:", matrix.matrix);
882
+ *
883
+ * // Apply the modified matrix to the same point
884
+ * const translatedPoint = matrix.multiplyPoint(point);
885
+ * console.log("Translated Point:", translatedPoint.toString()); // Output: [6, 7, 8]
886
+ * }
887
+ * </code></div>
888
+ */
889
+ function multiplyPoint(vector: p5.Vector): p5.Vector;
890
+
891
+ /**
892
+ * Applies a matrix to a vector.
893
+ * The fourth component is set to 1.
894
+ * Returns the result of dividing the 1st to 3rd components
895
+ * of the result by the 4th component as a vector.This method multiplies the current matrix by a 4D vector (x, y, z, 1),
896
+ * effectively transforming the vector using the matrix. The resulting
897
+ * vector is normalized by dividing its x, y, and z components by the w component.
898
+ * This is useful for applying transformations such as perspective projection
899
+ * to a point in 3D space.
900
+ *
901
+ * @param The input vector to transform. It should
902
+ * have x, y, and z components.
903
+ * @return A new `p5.Vector` instance representing the transformed and normalized point.
904
+ * @example // Applying a matrix to a 3D point and normalizing it
905
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
906
+ * const point = new p5.Vector(1, 2, 3); // Define a 3D point
907
+ * const transformedPoint = matrix.multiplyAndNormalizePoint(point);
908
+ * console.log(transformedPoint.toString()); // Output: [1, 2, 3] (unchanged for identity matrix)
909
+ *
910
+ * // p5.js script example
911
+ * <div class="norender"><code>
912
+ * function setup() {
913
+ *
914
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
915
+ * console.log("Original Matrix:", matrix.matrix);
916
+ *
917
+ * // Define a 3D point
918
+ * const point = new p5.Vector(1, 2, 3);
919
+ * console.log("Original Point:", point.toString());
920
+ *
921
+ * // Apply the matrix to the point and normalize it
922
+ * const transformedPoint = matrix.multiplyAndNormalizePoint(point);
923
+ * console.log("Transformed and Normalized Point:", transformedPoint.toString());
924
+ *
925
+ * // Modify the matrix (e.g., apply a perspective transformation)
926
+ * matrix.perspective(Math.PI / 4, 1.5, 0.1, 100);
927
+ * console.log("Modified Matrix (Perspective):", matrix.matrix);
928
+ *
929
+ * // Apply the modified matrix to the same point
930
+ * const perspectivePoint = matrix.multiplyAndNormalizePoint(point);
931
+ * console.log("Point after Perspective Transformation:", perspectivePoint.toString());
932
+ * }
933
+ * </code></div>
934
+ */
935
+ function multiplyAndNormalizePoint(vector: p5.Vector): p5.Vector;
936
+
937
+ /**
938
+ * Applies a matrix to a vector.
939
+ * The fourth component is set to 0.
940
+ * Returns a vector consisting of the first
941
+ * through third components of the result.This method multiplies the current matrix by a 4D vector (x, y, z, 0),
942
+ * effectively transforming the direction vector using the matrix. The resulting
943
+ * vector is returned as a new `p5.Vector` instance. This is particularly useful
944
+ * for transforming direction vectors (e.g., normals) without applying translation.
945
+ *
946
+ * @param The input vector to transform. It should
947
+ * have x, y, and z components.
948
+ * @return A new `p5.Vector` instance representing the transformed direction.
949
+ * @example // Applying a matrix to a direction vector
950
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
951
+ * const direction = new p5.Vector(1, 0, 0); // Define a direction vector
952
+ * const transformedDirection = matrix.multiplyDirection(direction);
953
+ * console.log(transformedDirection.toString()); // Output: [1, 0, 0] (unchanged for identity matrix)
954
+ *
955
+ * // p5.js script example
956
+ * <div class="norender"><code>
957
+ * function setup() {
958
+ *
959
+ * const matrix = new p5.Matrix(4); // Create a 4x4 identity matrix
960
+ * console.log("Original Matrix:", matrix.matrix);
961
+ *
962
+ * // Define a direction vector
963
+ * const direction = new p5.Vector(1, 0, 0);
964
+ * console.log("Original Direction:", direction.toString());
965
+ *
966
+ * // Apply the matrix to the direction vector
967
+ * const transformedDirection = matrix.multiplyDirection(direction);
968
+ * console.log("Transformed Direction:", transformedDirection.toString());
969
+ *
970
+ * // Modify the matrix (e.g., apply a rotation)
971
+ * matrix.rotateY(Math.PI / 4); // Rotate 45 degrees around the Y-axis
972
+ * console.log("Modified Matrix (Rotation):", matrix.matrix);
973
+ *
974
+ * // Apply the modified matrix to the same direction vector
975
+ * const rotatedDirection = matrix.multiplyDirection(direction);
976
+ * console.log("Rotated Direction:", rotatedDirection.toString()); // Output: Rotated vector
977
+ * }
978
+ * </code></div>
979
+ */
980
+ function multiplyDirection(vector: p5.Vector): p5.Vector;
981
+
982
+ /**
983
+ * Takes a vector and returns the vector resulting from multiplying. This function is only for 3x3 matrices.
984
+ * that vector by this matrix from the left.This method applies the current 3x3 matrix to a given vector, effectively
985
+ * transforming the vector using the matrix. The resulting vector is returned
986
+ * as a new vector or stored in the provided target vector.This is useful for operations such as transforming points or directions
987
+ * in 2D or 3D space using a 3x3 transformation matrix.
988
+ *
989
+ * @param The vector to which this matrix applies.
990
+ * @param The vector to receive the result. If not provided,
991
+ * a copy of the input vector will be created and returned.
992
+ * @return The transformed vector after applying the matrix.
993
+ * @example // Multiplying a 3x3 matrix with a vector
994
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
995
+ * const vector = new p5.Vector(1, 2, 3);
996
+ * const result = matrix.multiplyVec3(vector);
997
+ * console.log(result.toString()); // Output: Transformed vector
998
+ *
999
+ * // p5.js script example
1000
+ * <div class="norender"><code>
1001
+ * function setup() {
1002
+ *
1003
+ * // Create a 3x3 matrix
1004
+ * const matrix = new p5.Matrix([1, 2, 3, 4, 5, 6, 7, 8, 9]);
1005
+ * console.log("Original Matrix:", matrix.matrix);
1006
+ *
1007
+ * // Define a vector
1008
+ * const vector = new p5.Vector(1, 2, 3);
1009
+ * console.log("Original Vector:", vector.toString()); // Output: [1, 2, 3]
1010
+ *
1011
+ * // Apply the matrix to the vector
1012
+ * const transformedVector = matrix.multiplyVec3(vector);
1013
+ * console.log("Transformed Vector:", transformedVector.toString()); // Output: [30, 36, 42]
1014
+ *
1015
+ * // Modify the matrix (e.g., apply a scaling transformation)
1016
+ * matrix.scale(2, 2, 2);
1017
+ * console.log("Modified Matrix (Scaling):", matrix.matrix); // Output: [2, 4, 6, 8, 10, 12, 14, 16, 18]
1018
+ *
1019
+ * // Apply the modified matrix to the same vector
1020
+ * const scaledVector = matrix.multiplyVec3(vector);
1021
+ * console.log("Scaled Vector:", scaledVector.toString()); // Output: [60, 72, 84]
1022
+ * }
1023
+ * </code></div>
1024
+ */
1025
+ function multiplyVec3(multVector: p5.Vector, target?: p5.Vector): p5.Vector;
1026
+
1027
+ }
1028
+
1029
+ export default function Matrix(p5: any, fn: any): void;