@defold-typescript/types 0.5.4 → 0.5.5

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.
@@ -13,16 +13,16 @@ declare global {
13
13
  * @param max - Max value(s) border
14
14
  * @returns Clamped value or vector
15
15
  * @example
16
- * ```lua
17
- * local value1 = 56
18
- * print(vmath.clamp(value1, 89, 134)) -> 89
19
- * local v2 = vmath.vector3(190, 190, -10)
20
- * print(vmath.clamp(v2, -50, 150)) -> vmath.vector3(150, 150, -10)
21
- * local v3 = vmath.vector4(30, -30, 45, 1)
22
- * print(vmath.clamp(v3, 0, 20)) -> vmath.vector4(20, 0, 20, 1)
16
+ * ```ts
17
+ * const value1 = 56;
18
+ * print(vmath.clamp(value1, 89, 134)); // => 89
19
+ * const v2 = vmath.vector3(190, 190, -10);
20
+ * print(vmath.clamp(v2, -50, 150)); // => vmath.vector3(150, 150, -10)
21
+ * const v3 = vmath.vector4(30, -30, 45, 1);
22
+ * print(vmath.clamp(v3, 0, 20)); // => vmath.vector4(20, 0, 20, 1)
23
23
  *
24
- * local min_v = vmath.vector4(0, -10, -10, 1)
25
- * print(vmath.clamp(v3, min_v, 20)) -> vmath.vector4(20, -10, 20, 1)
24
+ * const min_v = vmath.vector4(0, -10, -10, 1);
25
+ * print(vmath.clamp(v3, min_v, 20)); // => vmath.vector4(20, -10, 20, 1)
26
26
  * ```
27
27
  */
28
28
  function clamp(value: number | Vector3 | Vector4, min: number | Vector3 | Vector4, max: number | Vector3 | Vector4): number | Vector3 | Vector4;
@@ -35,9 +35,9 @@ declare global {
35
35
  * @param q1 - quaternion of which to calculate the conjugate
36
36
  * @returns the conjugate
37
37
  * @example
38
- * ```lua
39
- * local quat = vmath.quat(1, 2, 3, 4)
40
- * print(vmath.conj(quat)) --> vmath.quat(-1, -2, -3, 4)
38
+ * ```ts
39
+ * const quat = vmath.quat(1, 2, 3, 4);
40
+ * print(vmath.conj(quat)); // => vmath.quat(-1, -2, -3, 4)
41
41
  * ```
42
42
  */
43
43
  function conj(q1: Quaternion): Quaternion;
@@ -53,12 +53,12 @@ declare global {
53
53
  * @param v2 - second vector
54
54
  * @returns a new vector representing the cross product
55
55
  * @example
56
- * ```lua
57
- * local vec1 = vmath.vector3(1, 0, 0)
58
- * local vec2 = vmath.vector3(0, 1, 0)
59
- * print(vmath.cross(vec1, vec2)) --> vmath.vector3(0, 0, 1)
60
- * local vec3 = vmath.vector3(-1, 0, 0)
61
- * print(vmath.cross(vec1, vec3)) --> vmath.vector3(0, -0, 0)
56
+ * ```ts
57
+ * const vec1 = vmath.vector3(1, 0, 0);
58
+ * const vec2 = vmath.vector3(0, 1, 0);
59
+ * print(vmath.cross(vec1, vec2)); // => vmath.vector3(0, 0, 1)
60
+ * const vec3 = vmath.vector3(-1, 0, 0);
61
+ * print(vmath.cross(vec1, vec3)); // => vmath.vector3(0, -0, 0)
62
62
  * ```
63
63
  */
64
64
  function cross(v1: Vector3, v2: Vector3): Vector3;
@@ -74,11 +74,11 @@ declare global {
74
74
  * @param v2 - second vector
75
75
  * @returns dot product
76
76
  * @example
77
- * ```lua
78
- * if vmath.dot(vector1, vector2) == 0 then
79
- * -- The two vectors are perpendicular (at right-angles to each other)
80
- * ...
81
- * end
77
+ * ```ts
78
+ * if (vmath.dot(vector1, vector2) === 0) {
79
+ * // The two vectors are perpendicular (at right-angles to each other)
80
+ * // ...
81
+ * }
82
82
  * ```
83
83
  */
84
84
  function dot(v1: Vector3 | Vector4, v2: Vector3 | Vector4): number;
@@ -92,12 +92,12 @@ declare global {
92
92
  * @param z - rotation around z-axis in degrees
93
93
  * @returns quaternion describing an equivalent rotation (231 (YZX) rotation sequence)
94
94
  * @example
95
- * ```lua
96
- * local q = vmath.euler_to_quat(0, 45, 90)
97
- * print(q) --> vmath.quat(0.27059805393219, 0.27059805393219, 0.65328145027161, 0.65328145027161)
95
+ * ```ts
96
+ * const q = vmath.euler_to_quat(0, 45, 90);
97
+ * print(q); // => vmath.quat(0.27059805393219, 0.27059805393219, 0.65328145027161, 0.65328145027161)
98
98
  *
99
- * local v = vmath.vector3(0, 0, 90)
100
- * print(vmath.euler_to_quat(v)) --> vmath.quat(0, 0, 0.70710676908493, 0.70710676908493)
99
+ * const v = vmath.vector3(0, 0, 90);
100
+ * print(vmath.euler_to_quat(v)); // => vmath.quat(0, 0, 0.70710676908493, 0.70710676908493)
101
101
  * ```
102
102
  */
103
103
  function euler_to_quat(x: number | Vector3, y: number, z: number): Quaternion;
@@ -111,11 +111,11 @@ declare global {
111
111
  * @param m1 - matrix to invert
112
112
  * @returns inverse of the supplied matrix
113
113
  * @example
114
- * ```lua
115
- * local mat1 = vmath.matrix4_rotation_z(3.141592653)
116
- * local mat2 = vmath.inv(mat1)
117
- * -- M * inv(M) = identity matrix
118
- * print(mat1 * mat2) --> vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
114
+ * ```ts
115
+ * const mat1 = vmath.matrix4_rotation_z(3.141592653);
116
+ * const mat2 = vmath.inv(mat1);
117
+ * // M * inv(M) = identity matrix
118
+ * print(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
119
119
  * ```
120
120
  */
121
121
  function inv(m1: Matrix4): Matrix4;
@@ -128,14 +128,14 @@ declare global {
128
128
  * @param v - value of which to calculate the length
129
129
  * @returns length
130
130
  * @example
131
- * ```lua
132
- * if vmath.length(self.velocity) < max_velocity then
133
- * -- The speed (velocity vector) is below max.
131
+ * ```ts
132
+ * if (vmath.length(self.velocity) < max_velocity) {
133
+ * // The speed (velocity vector) is below max.
134
134
  *
135
- * -- TODO: max_velocity can be expressed as squared
136
- * -- so we can compare with length_sqr() instead.
137
- * ...
138
- * end
135
+ * // TODO: max_velocity can be expressed as squared
136
+ * // so we can compare with length_sqr() instead.
137
+ * // ...
138
+ * }
139
139
  * ```
140
140
  */
141
141
  function length(v: Vector3 | Vector4 | Quaternion): number;
@@ -145,11 +145,11 @@ declare global {
145
145
  * @param v - value of which to calculate the squared length
146
146
  * @returns squared length
147
147
  * @example
148
- * ```lua
149
- * if vmath.length_sqr(vector1) < vmath.length_sqr(vector2) then
150
- * -- Vector 1 has less magnitude than vector 2
151
- * ...
152
- * end
148
+ * ```ts
149
+ * if (vmath.length_sqr(vector1) < vmath.length_sqr(vector2)) {
150
+ * // Vector 1 has less magnitude than vector 2
151
+ * // ...
152
+ * }
153
153
  * ```
154
154
  */
155
155
  function length_sqr(v: Vector3 | Vector4 | Quaternion): number;
@@ -165,20 +165,22 @@ declare global {
165
165
  * @param v2 - vector to lerp to
166
166
  * @returns the lerped vector
167
167
  * @example
168
- * ```lua
169
- * function init(self)
170
- * self.t = 0
171
- * end
168
+ * ```ts
169
+ * export default defineScript({
170
+ * init() {
171
+ * return { t: 0 };
172
+ * },
172
173
  *
173
- * function update(self, dt)
174
- * self.t = self.t + dt
175
- * if self.t <= 1 then
176
- * local startpos = vmath.vector3(0, 600, 0)
177
- * local endpos = vmath.vector3(600, 0, 0)
178
- * local pos = vmath.lerp(self.t, startpos, endpos)
179
- * go.set_position(pos, "go")
180
- * end
181
- * end
174
+ * update(self, dt) {
175
+ * self.t = self.t + dt;
176
+ * if (self.t <= 1) {
177
+ * const startpos = vmath.vector3(0, 600, 0);
178
+ * const endpos = vmath.vector3(600, 0, 0);
179
+ * const pos = vmath.lerp(self.t, startpos, endpos);
180
+ * go.set_position(pos, "go");
181
+ * }
182
+ * },
183
+ * });
182
184
  * ```
183
185
  */
184
186
  function lerp(t: number, v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
@@ -244,13 +246,13 @@ declare global {
244
246
  *
245
247
  * @returns identity matrix
246
248
  * @example
247
- * ```lua
248
- * local mat = vmath.matrix4()
249
- * print(mat) --> vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
250
- * -- get column 0:
251
- * print(mat.c0) --> vmath.vector4(1, 0, 0, 0)
252
- * -- get the value in row 3 and column 2:
253
- * print(mat.m32) --> 0
249
+ * ```ts
250
+ * const mat = vmath.matrix4();
251
+ * print(mat); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
252
+ * // get column 0:
253
+ * print(mat.c0); // => vmath.vector4(1, 0, 0, 0)
254
+ * // get the value in row 3 and column 2:
255
+ * print(mat.m32); // => 0
254
256
  * ```
255
257
  */
256
258
  function matrix4(): Matrix4;
@@ -279,11 +281,11 @@ declare global {
279
281
  * @param angle - angle in radians
280
282
  * @returns matrix represented by axis and angle
281
283
  * @example
282
- * ```lua
283
- * local vec = vmath.vector4(1, 1, 0, 0)
284
- * local axis = vmath.vector3(0, 0, 1) -- z-axis
285
- * local mat = vmath.matrix4_axis_angle(axis, 3.141592653)
286
- * print(mat * vec) --> vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
284
+ * ```ts
285
+ * const vec = vmath.vector4(1, 1, 0, 0);
286
+ * const axis = vmath.vector3(0, 0, 1); // z-axis
287
+ * const mat = vmath.matrix4_axis_angle(axis, 3.141592653);
288
+ * print(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
287
289
  * ```
288
290
  */
289
291
  function matrix4_axis_angle(v: Vector3, angle: number): Matrix4;
@@ -296,12 +298,12 @@ declare global {
296
298
  * @param scale - scale
297
299
  * @returns new matrix4
298
300
  * @example
299
- * ```lua
300
- * local translation = vmath.vector3(103, -95, 14)
301
- * local quat = vmath.quat(1, 2, 3, 4)
302
- * local scale = vmath.vector3(1, 0.5, 0.5)
303
- * local result = vmath.matrix4_compose(translation, quat, scale)
304
- * print(result) --> vmath.matrix4(-25, -10, 11, 103, 28, -9.5, 2, -95, -10, 10, -4.5, 14, 0, 0, 0, 1)
301
+ * ```ts
302
+ * const translation = vmath.vector3(103, -95, 14);
303
+ * const quat = vmath.quat(1, 2, 3, 4);
304
+ * const scale = vmath.vector3(1, 0.5, 0.5);
305
+ * const result = vmath.matrix4_compose(translation, quat, scale);
306
+ * print(result); // => vmath.matrix4(-25, -10, 11, 103, 28, -9.5, 2, -95, -10, 10, -4.5, 14, 0, 0, 0, 1)
305
307
  * ```
306
308
  */
307
309
  function matrix4_compose(translation: Vector3 | Vector4, rotation: Quaternion, scale: Vector3): Matrix4;
@@ -319,11 +321,11 @@ declare global {
319
321
  * @param far - coordinate for far clipping plane
320
322
  * @returns matrix representing the frustum
321
323
  * @example
322
- * ```lua
323
- * -- Construct a projection frustum with a vertical and horizontal
324
- * -- FOV of 45 degrees. Useful for rendering a square view.
325
- * local proj = vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000)
326
- * render.set_projection(proj)
324
+ * ```ts
325
+ * // Construct a projection frustum with a vertical and horizontal FOV of
326
+ * // 45 degrees. Useful for rendering a square view.
327
+ * const proj = vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000);
328
+ * render.set_projection(proj);
327
329
  * ```
328
330
  */
329
331
  function matrix4_frustum(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4;
@@ -337,16 +339,15 @@ declare global {
337
339
  * @param up - up vector
338
340
  * @returns look-at matrix
339
341
  * @example
340
- * ```lua
341
- * -- Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV
342
- * -- Aspect ratio 4:3
343
- * local eye = vmath.vector3(0, 0, 100)
344
- * local look_at = vmath.vector3(0, 0, 0)
345
- * local up = vmath.vector3(0, 1, 0)
346
- * local view = vmath.matrix4_look_at(eye, look_at, up)
347
- * render.set_view(view)
348
- * local proj = vmath.matrix4_perspective(3.141592/2, 4/3, 1, 1000)
349
- * render.set_projection(proj)
342
+ * ```ts
343
+ * // Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.
344
+ * const eye = vmath.vector3(0, 0, 100);
345
+ * const look_at = vmath.vector3(0, 0, 0);
346
+ * const up = vmath.vector3(0, 1, 0);
347
+ * const view = vmath.matrix4_look_at(eye, look_at, up);
348
+ * render.set_view(view);
349
+ * const proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);
350
+ * render.set_projection(proj);
350
351
  * ```
351
352
  */
352
353
  function matrix4_look_at(eye: Vector3, look_at: Vector3, up: Vector3): Matrix4;
@@ -362,13 +363,13 @@ declare global {
362
363
  * @param far - coordinate for far clipping plane
363
364
  * @returns orthographic projection matrix
364
365
  * @example
365
- * ```lua
366
- * -- Set up an orthographic projection based on the width and height
367
- * -- of the game window.
368
- * local w = render.get_width()
369
- * local h = render.get_height()
370
- * local proj = vmath.matrix4_orthographic(- w / 2, w / 2, -h / 2, h / 2, -1000, 1000)
371
- * render.set_projection(proj)
366
+ * ```ts
367
+ * // Set up an orthographic projection based on the width and height of the
368
+ * // game window.
369
+ * const w = render.get_width();
370
+ * const h = render.get_height();
371
+ * const proj = vmath.matrix4_orthographic(-w / 2, w / 2, -h / 2, h / 2, -1000, 1000);
372
+ * render.set_projection(proj);
372
373
  * ```
373
374
  */
374
375
  function matrix4_orthographic(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4;
@@ -382,16 +383,15 @@ declare global {
382
383
  * @param far - coordinate for far clipping plane
383
384
  * @returns perspective projection matrix
384
385
  * @example
385
- * ```lua
386
- * -- Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV
387
- * -- Aspect ratio 4:3
388
- * local eye = vmath.vector3(0, 0, 100)
389
- * local look_at = vmath.vector3(0, 0, 0)
390
- * local up = vmath.vector3(0, 1, 0)
391
- * local view = vmath.matrix4_look_at(eye, look_at, up)
392
- * render.set_view(view)
393
- * local proj = vmath.matrix4_perspective(3.141592/2, 4/3, 1, 1000)
394
- * render.set_projection(proj)
386
+ * ```ts
387
+ * // Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.
388
+ * const eye = vmath.vector3(0, 0, 100);
389
+ * const look_at = vmath.vector3(0, 0, 0);
390
+ * const up = vmath.vector3(0, 1, 0);
391
+ * const view = vmath.matrix4_look_at(eye, look_at, up);
392
+ * render.set_view(view);
393
+ * const proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);
394
+ * render.set_projection(proj);
395
395
  * ```
396
396
  */
397
397
  function matrix4_perspective(fov: number, aspect: number, near: number, far: number): Matrix4;
@@ -401,11 +401,11 @@ declare global {
401
401
  * @param q - quaternion to create matrix from
402
402
  * @returns matrix represented by quaternion
403
403
  * @example
404
- * ```lua
405
- * local vec = vmath.vector4(1, 1, 0, 0)
406
- * local quat = vmath.quat_rotation_z(3.141592653)
407
- * local mat = vmath.matrix4_quat(quat)
408
- * print(mat * vec) --> vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000)
404
+ * ```ts
405
+ * const vec = vmath.vector4(1, 1, 0, 0);
406
+ * const quat = vmath.quat_rotation_z(3.141592653);
407
+ * const mat = vmath.matrix4_quat(quat);
408
+ * print(mat.mul(vec)); // => vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000)
409
409
  * ```
410
410
  */
411
411
  function matrix4_quat(q: Quaternion): Matrix4;
@@ -416,10 +416,10 @@ declare global {
416
416
  * @param angle - angle in radians around x-axis
417
417
  * @returns matrix from rotation around x-axis
418
418
  * @example
419
- * ```lua
420
- * local vec = vmath.vector4(1, 1, 0, 0)
421
- * local mat = vmath.matrix4_rotation_x(3.141592653)
422
- * print(mat * vec) --> vmath.vector4(1, -1, -8.7422776573476e-08, 0)
419
+ * ```ts
420
+ * const vec = vmath.vector4(1, 1, 0, 0);
421
+ * const mat = vmath.matrix4_rotation_x(3.141592653);
422
+ * print(mat.mul(vec)); // => vmath.vector4(1, -1, -8.7422776573476e-08, 0)
423
423
  * ```
424
424
  */
425
425
  function matrix4_rotation_x(angle: number): Matrix4;
@@ -430,10 +430,10 @@ declare global {
430
430
  * @param angle - angle in radians around y-axis
431
431
  * @returns matrix from rotation around y-axis
432
432
  * @example
433
- * ```lua
434
- * local vec = vmath.vector4(1, 1, 0, 0)
435
- * local mat = vmath.matrix4_rotation_y(3.141592653)
436
- * print(mat * vec) --> vmath.vector4(-1, 1, 8.7422776573476e-08, 0)
433
+ * ```ts
434
+ * const vec = vmath.vector4(1, 1, 0, 0);
435
+ * const mat = vmath.matrix4_rotation_y(3.141592653);
436
+ * print(mat.mul(vec)); // => vmath.vector4(-1, 1, 8.7422776573476e-08, 0)
437
437
  * ```
438
438
  */
439
439
  function matrix4_rotation_y(angle: number): Matrix4;
@@ -444,10 +444,10 @@ declare global {
444
444
  * @param angle - angle in radians around z-axis
445
445
  * @returns matrix from rotation around z-axis
446
446
  * @example
447
- * ```lua
448
- * local vec = vmath.vector4(1, 1, 0, 0)
449
- * local mat = vmath.matrix4_rotation_z(3.141592653)
450
- * print(mat * vec) --> vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
447
+ * ```ts
448
+ * const vec = vmath.vector4(1, 1, 0, 0);
449
+ * const mat = vmath.matrix4_rotation_z(3.141592653);
450
+ * print(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
451
451
  * ```
452
452
  */
453
453
  function matrix4_rotation_z(angle: number): Matrix4;
@@ -457,10 +457,10 @@ declare global {
457
457
  * @param scale - scale
458
458
  * @returns new matrix4
459
459
  * @example
460
- * ```lua
461
- * local scale = vmath.vector3(1, 0.5, 0.5)
462
- * local result = vmath.matrix4_scale(scale)
463
- * print(result) --> vmath.matrix4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)
460
+ * ```ts
461
+ * const scale = vmath.vector3(1, 0.5, 0.5);
462
+ * const result = vmath.matrix4_scale(scale);
463
+ * print(result); // => vmath.matrix4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)
464
464
  * ```
465
465
  */
466
466
  function matrix4_scale(scale: Vector3): Matrix4;
@@ -497,11 +497,11 @@ declare global {
497
497
  * @param position - position vector to create matrix from
498
498
  * @returns matrix from the supplied position vector
499
499
  * @example
500
- * ```lua
501
- * -- Set camera view from custom view and translation matrices
502
- * local mat_trans = vmath.matrix4_translation(vmath.vector3(0, 10, 100))
503
- * local mat_view = vmath.matrix4_rotation_y(-3.141592/4)
504
- * render.set_view(mat_view * mat_trans)
500
+ * ```ts
501
+ * // Set camera view from custom view and translation matrices.
502
+ * const mat_trans = vmath.matrix4_translation(vmath.vector3(0, 10, 100));
503
+ * const mat_view = vmath.matrix4_rotation_y(-3.141592 / 4);
504
+ * render.set_view(mat_view.mul(mat_trans));
505
505
  * ```
506
506
  */
507
507
  function matrix4_translation(position: Vector3 | Vector4): Matrix4;
@@ -514,8 +514,8 @@ declare global {
514
514
  * @param v2 - second vector
515
515
  * @returns multiplied vector
516
516
  * @example
517
- * ```lua
518
- * local blend_color = vmath.mul_per_elem(color1, color2)
517
+ * ```ts
518
+ * const blend_color = vmath.mul_per_elem(color1, color2);
519
519
  * ```
520
520
  */
521
521
  function mul_per_elem(v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
@@ -528,11 +528,11 @@ declare global {
528
528
  * @param v1 - vector to normalize
529
529
  * @returns new normalized vector
530
530
  * @example
531
- * ```lua
532
- * local vec = vmath.vector3(1, 2, 3)
533
- * local norm_vec = vmath.normalize(vec)
534
- * print(norm_vec) --> vmath.vector3(0.26726123690605, 0.5345224738121, 0.80178368091583)
535
- * print(vmath.length(norm_vec)) --> 0.99999994039536
531
+ * ```ts
532
+ * const vec = vmath.vector3(1, 2, 3);
533
+ * const norm_vec = vmath.normalize(vec);
534
+ * print(norm_vec); // => vmath.vector3(0.26726123690605, 0.5345224738121, 0.80178368091583)
535
+ * print(vmath.length(norm_vec)); // => 0.99999994039536
536
536
  * ```
537
537
  */
538
538
  function normalize(v1: Vector3 | Vector4 | Quaternion): Vector3 | Vector4 | Quaternion;
@@ -546,11 +546,11 @@ declare global {
546
546
  * @param m1 - ortho-normalized matrix to invert
547
547
  * @returns inverse of the supplied matrix
548
548
  * @example
549
- * ```lua
550
- * local mat1 = vmath.matrix4_rotation_z(3.141592653)
551
- * local mat2 = vmath.ortho_inv(mat1)
552
- * -- M * inv(M) = identity matrix
553
- * print(mat1 * mat2) --> vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
549
+ * ```ts
550
+ * const mat1 = vmath.matrix4_rotation_z(3.141592653);
551
+ * const mat2 = vmath.ortho_inv(mat1);
552
+ * // M * inv(M) = identity matrix
553
+ * print(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
554
554
  * ```
555
555
  */
556
556
  function ortho_inv(m1: Matrix4): Matrix4;
@@ -564,10 +564,10 @@ declare global {
564
564
  * @param v2 - vector onto which the first will be projected, must not have zero length
565
565
  * @returns the projected extent of the first vector onto the second
566
566
  * @example
567
- * ```lua
568
- * local v1 = vmath.vector3(1, 1, 0)
569
- * local v2 = vmath.vector3(2, 0, 0)
570
- * print(vmath.project(v1, v2)) --> 0.5
567
+ * ```ts
568
+ * const v1 = vmath.vector3(1, 1, 0);
569
+ * const v2 = vmath.vector3(2, 0, 0);
570
+ * print(vmath.project(v1, v2)); // => 0.5
571
571
  * ```
572
572
  */
573
573
  function project(v1: Vector3, v2: Vector3): number;
@@ -613,9 +613,9 @@ declare global {
613
613
  * @param w - w coordinate
614
614
  * @returns new quaternion
615
615
  * @example
616
- * ```lua
617
- * local quat = vmath.quat(1, 2, 3, 4)
618
- * print(quat) --> vmath.quat(1, 2, 3, 4)
616
+ * ```ts
617
+ * const quat = vmath.quat(1, 2, 3, 4);
618
+ * print(quat); // => vmath.quat(1, 2, 3, 4)
619
619
  * ```
620
620
  */
621
621
  function quat(x: number, y: number, z: number, w: number): Quaternion;
@@ -627,11 +627,11 @@ declare global {
627
627
  * @param angle - angle
628
628
  * @returns quaternion representing the axis-angle rotation
629
629
  * @example
630
- * ```lua
631
- * local axis = vmath.vector3(1, 0, 0)
632
- * local rot = vmath.quat_axis_angle(axis, 3.141592653)
633
- * local vec = vmath.vector3(1, 1, 0)
634
- * print(vmath.rotate(rot, vec)) --> vmath.vector3(1, -1, -8.7422776573476e-08)
630
+ * ```ts
631
+ * const axis = vmath.vector3(1, 0, 0);
632
+ * const rot = vmath.quat_axis_angle(axis, 3.141592653);
633
+ * const vec = vmath.vector3(1, 1, 0);
634
+ * print(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)
635
635
  * ```
636
636
  */
637
637
  function quat_axis_angle(v: Vector3, angle: number): Quaternion;
@@ -645,17 +645,17 @@ declare global {
645
645
  * @param z - z base vector
646
646
  * @returns quaternion representing the rotation of the specified base vectors
647
647
  * @example
648
- * ```lua
649
- * -- Axis rotated 90 degrees around z.
650
- * local rot_x = vmath.vector3(0, -1, 0)
651
- * local rot_y = vmath.vector3(1, 0, 0)
652
- * local z = vmath.vector3(0, 0, 1)
653
- * local rot1 = vmath.quat_basis(rot_x, rot_y, z)
654
- * local rot2 = vmath.quat_from_to(vmath.vector3(0, 1, 0), vmath.vector3(1, 0, 0))
655
- * if rot1 == rot2 then
656
- * -- These quaternions are equal!
657
- * print(rot2) --> vmath.quat(0, 0, -0.70710676908493, 0.70710676908493)
658
- * end
648
+ * ```ts
649
+ * // Axis rotated 90 degrees around z.
650
+ * const rot_x = vmath.vector3(0, -1, 0);
651
+ * const rot_y = vmath.vector3(1, 0, 0);
652
+ * const z = vmath.vector3(0, 0, 1);
653
+ * const rot1 = vmath.quat_basis(rot_x, rot_y, z);
654
+ * const rot2 = vmath.quat_from_to(vmath.vector3(0, 1, 0), vmath.vector3(1, 0, 0));
655
+ * if (rot1 === rot2) {
656
+ * // These quaternions are equal!
657
+ * print(rot2); // => vmath.quat(0, 0, -0.70710676908493, 0.70710676908493)
658
+ * }
659
659
  * ```
660
660
  */
661
661
  function quat_basis(x: Vector3, y: Vector3, z: Vector3): Quaternion;
@@ -670,11 +670,11 @@ declare global {
670
670
  * @param v2 - second unit vector, after rotation
671
671
  * @returns quaternion representing the rotation from first to second vector
672
672
  * @example
673
- * ```lua
674
- * local v1 = vmath.vector3(1, 0, 0)
675
- * local v2 = vmath.vector3(0, 1, 0)
676
- * local rot = vmath.quat_from_to(v1, v2)
677
- * print(vmath.rotate(rot, v1)) --> vmath.vector3(0, 0.99999994039536, 0)
673
+ * ```ts
674
+ * const v1 = vmath.vector3(1, 0, 0);
675
+ * const v2 = vmath.vector3(0, 1, 0);
676
+ * const rot = vmath.quat_from_to(v1, v2);
677
+ * print(vmath.rotate(rot, v1)); // => vmath.vector3(0, 0.99999994039536, 0)
678
678
  * ```
679
679
  */
680
680
  function quat_from_to(v1: Vector3, v2: Vector3): Quaternion;
@@ -693,10 +693,10 @@ declare global {
693
693
  * @param angle - angle in radians around x-axis
694
694
  * @returns quaternion representing the rotation around the x-axis
695
695
  * @example
696
- * ```lua
697
- * local rot = vmath.quat_rotation_x(3.141592653)
698
- * local vec = vmath.vector3(1, 1, 0)
699
- * print(vmath.rotate(rot, vec)) --> vmath.vector3(1, -1, -8.7422776573476e-08)
696
+ * ```ts
697
+ * const rot = vmath.quat_rotation_x(3.141592653);
698
+ * const vec = vmath.vector3(1, 1, 0);
699
+ * print(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)
700
700
  * ```
701
701
  */
702
702
  function quat_rotation_x(angle: number): Quaternion;
@@ -707,10 +707,10 @@ declare global {
707
707
  * @param angle - angle in radians around y-axis
708
708
  * @returns quaternion representing the rotation around the y-axis
709
709
  * @example
710
- * ```lua
711
- * local rot = vmath.quat_rotation_y(3.141592653)
712
- * local vec = vmath.vector3(1, 1, 0)
713
- * print(vmath.rotate(rot, vec)) --> vmath.vector3(-1, 1, 8.7422776573476e-08)
710
+ * ```ts
711
+ * const rot = vmath.quat_rotation_y(3.141592653);
712
+ * const vec = vmath.vector3(1, 1, 0);
713
+ * print(vmath.rotate(rot, vec)); // => vmath.vector3(-1, 1, 8.7422776573476e-08)
714
714
  * ```
715
715
  */
716
716
  function quat_rotation_y(angle: number): Quaternion;
@@ -721,10 +721,10 @@ declare global {
721
721
  * @param angle - angle in radians around z-axis
722
722
  * @returns quaternion representing the rotation around the z-axis
723
723
  * @example
724
- * ```lua
725
- * local rot = vmath.quat_rotation_z(3.141592653)
726
- * local vec = vmath.vector3(1, 1, 0)
727
- * print(vmath.rotate(rot, vec)) --> vmath.vector3(-0.99999988079071, -1, 0)
724
+ * ```ts
725
+ * const rot = vmath.quat_rotation_z(3.141592653);
726
+ * const vec = vmath.vector3(1, 1, 0);
727
+ * print(vmath.rotate(rot, vec)); // => vmath.vector3(-0.99999988079071, -1, 0)
728
728
  * ```
729
729
  */
730
730
  function quat_rotation_z(angle: number): Quaternion;
@@ -736,13 +736,14 @@ declare global {
736
736
  *
737
737
  * @param q - source quaternion
738
738
  * @example
739
- * ```lua
740
- * local q = vmath.quat_rotation_z(math.rad(90))
741
- * print(vmath.quat_to_euler(q)) --> 0 0 90
739
+ * ```ts
740
+ * const q = vmath.quat_rotation_z(math.rad(90));
741
+ * print(vmath.quat_to_euler(q)); // => 0 0 90
742
742
  *
743
- * local q2 = vmath.quat_rotation_y(math.rad(45)) * vmath.quat_rotation_z(math.rad(90))
744
- * local v = vmath.vector3(vmath.quat_to_euler(q2))
745
- * print(v) --> vmath.vector3(0, 45, 90)
743
+ * const q2 = vmath.quat_rotation_y(math.rad(45)).mul(vmath.quat_rotation_z(math.rad(90)));
744
+ * const [ex, ey, ez] = vmath.quat_to_euler(q2);
745
+ * const v = vmath.vector3(ex, ey, ez);
746
+ * print(v); // => vmath.vector3(0, 45, 90)
746
747
  * ```
747
748
  */
748
749
  function quat_to_euler(q: Quaternion): LuaMultiReturn<[number, number, number]>;
@@ -755,10 +756,10 @@ declare global {
755
756
  * @param v1 - vector to rotate
756
757
  * @returns the rotated vector
757
758
  * @example
758
- * ```lua
759
- * local vec = vmath.vector3(1, 1, 0)
760
- * local rot = vmath.quat_rotation_z(3.141592563)
761
- * print(vmath.rotate(rot, vec)) --> vmath.vector3(-1.0000002384186, -0.99999988079071, 0)
759
+ * ```ts
760
+ * const vec = vmath.vector3(1, 1, 0);
761
+ * const rot = vmath.quat_rotation_z(3.141592563);
762
+ * print(vmath.rotate(rot, vec)); // => vmath.vector3(-1.0000002384186, -0.99999988079071, 0)
762
763
  * ```
763
764
  */
764
765
  function rotate(q: Quaternion, v1: Vector3): Vector3;
@@ -777,20 +778,22 @@ declare global {
777
778
  * @param v2 - vector to slerp to
778
779
  * @returns the slerped vector
779
780
  * @example
780
- * ```lua
781
- * function init(self)
782
- * self.t = 0
783
- * end
781
+ * ```ts
782
+ * export default defineScript({
783
+ * init() {
784
+ * return { t: 0 };
785
+ * },
784
786
  *
785
- * function update(self, dt)
786
- * self.t = self.t + dt
787
- * if self.t <= 1 then
788
- * local startpos = vmath.vector3(0, 600, 0)
789
- * local endpos = vmath.vector3(600, 0, 0)
790
- * local pos = vmath.slerp(self.t, startpos, endpos)
791
- * go.set_position(pos, "go")
792
- * end
793
- * end
787
+ * update(self, dt) {
788
+ * self.t = self.t + dt;
789
+ * if (self.t <= 1) {
790
+ * const startpos = vmath.vector3(0, 600, 0);
791
+ * const endpos = vmath.vector3(600, 0, 0);
792
+ * const pos = vmath.slerp(self.t, startpos, endpos);
793
+ * go.set_position(pos, "go");
794
+ * }
795
+ * },
796
+ * });
794
797
  * ```
795
798
  */
796
799
  function slerp(t: number, v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
@@ -835,12 +838,12 @@ declare global {
835
838
  * @param t - table of numbers
836
839
  * @returns new vector
837
840
  * @example
838
- * ```lua
839
- * How to create a vector with custom data to be used for animation easing:
840
- * local values = { 0, 0.5, 0 }
841
- * local vec = vmath.vector(values)
842
- * print(vec) --> vmath.vector (size: 3)
843
- * print(vec[2]) --> 0.5
841
+ * ```ts
842
+ * // How to create a vector with custom data to be used for animation easing:
843
+ * const values = [0, 0.5, 0];
844
+ * const vec = vmath.vector(values);
845
+ * print(vec); // => vmath.vector (size: 3)
846
+ * print(vec[2]); // => 0.5
844
847
  * ```
845
848
  */
846
849
  function vector(t: number[]): Vector;
@@ -897,13 +900,13 @@ declare global {
897
900
  * @param z - z coordinate
898
901
  * @returns new vector
899
902
  * @example
900
- * ```lua
901
- * local vec = vmath.vector3(1.0, 2.0, 3.0)
902
- * print(vec) --> vmath.vector3(1, 2, 3)
903
- * print(-vec) --> vmath.vector3(-1, -2, -3)
904
- * print(vec * 2) --> vmath.vector3(2, 4, 6)
905
- * print(vec + vmath.vector3(2.0)) --> vmath.vector3(3, 4, 5)
906
- * print(vec - vmath.vector3(2.0)) --> vmath.vector3(-1, 0, 1)
903
+ * ```ts
904
+ * const vec = vmath.vector3(1.0, 2.0, 3.0);
905
+ * print(vec); // => vmath.vector3(1, 2, 3)
906
+ * print(vec.unm()); // => vmath.vector3(-1, -2, -3)
907
+ * print(vec.mul(2)); // => vmath.vector3(2, 4, 6)
908
+ * print(vec.add(vmath.vector3(2.0))); // => vmath.vector3(3, 4, 5)
909
+ * print(vec.sub(vmath.vector3(2.0))); // => vmath.vector3(-1, 0, 1)
907
910
  * ```
908
911
  */
909
912
  function vector3(x: number, y: number, z: number): Vector3;
@@ -961,13 +964,13 @@ declare global {
961
964
  * @param w - w coordinate
962
965
  * @returns new vector
963
966
  * @example
964
- * ```lua
965
- * local vec = vmath.vector4(1.0, 2.0, 3.0, 4.0)
966
- * print(vec) --> vmath.vector4(1, 2, 3, 4)
967
- * print(-vec) --> vmath.vector4(-1, -2, -3, -4)
968
- * print(vec * 2) --> vmath.vector4(2, 4, 6, 8)
969
- * print(vec + vmath.vector4(2.0)) --> vmath.vector4(3, 4, 5, 6)
970
- * print(vec - vmath.vector4(2.0)) --> vmath.vector4(-1, 0, 1, 2)
967
+ * ```ts
968
+ * const vec = vmath.vector4(1.0, 2.0, 3.0, 4.0);
969
+ * print(vec); // => vmath.vector4(1, 2, 3, 4)
970
+ * print(vec.unm()); // => vmath.vector4(-1, -2, -3, -4)
971
+ * print(vec.mul(2)); // => vmath.vector4(2, 4, 6, 8)
972
+ * print(vec.add(vmath.vector4(2.0))); // => vmath.vector4(3, 4, 5, 6)
973
+ * print(vec.sub(vmath.vector4(2.0))); // => vmath.vector4(-1, 0, 1, 2)
971
974
  * ```
972
975
  */
973
976
  function vector4(x: number, y: number, z: number, w: number): Vector4;