@defold-typescript/types 0.18.2 → 0.18.4

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.
package/api-targets.json CHANGED
@@ -73,7 +73,12 @@
73
73
  { "namespace": "tilemap", "fixture": "tilemap_doc.json", "outFile": "tilemap.d.ts" },
74
74
  { "namespace": "timer", "fixture": "timer_doc.json", "outFile": "timer.d.ts" },
75
75
  { "namespace": "types", "fixture": "types_doc.json", "outFile": "types.d.ts" },
76
- { "namespace": "vmath", "fixture": "vmath_doc.json", "outFile": "vmath.d.ts" },
76
+ {
77
+ "namespace": "vmath",
78
+ "fixture": "vmath_doc.json",
79
+ "outFile": "vmath.d.ts",
80
+ "skipFunctions": ["clamp", "lerp", "slerp", "mul_per_elem", "normalize"]
81
+ },
77
82
  { "namespace": "webview", "fixture": "webview_doc.json", "outFile": "webview.d.ts" },
78
83
  { "namespace": "window", "fixture": "window_doc.json", "outFile": "window.d.ts" },
79
84
  { "namespace": "zlib", "fixture": "zlib_doc.json", "outFile": "zlib.d.ts" }
@@ -41,6 +41,7 @@ import "../../src/engine-globals";
41
41
  import "../../src/go-overloads";
42
42
  import "../../src/message-guard";
43
43
  import "../../src/msg-overloads";
44
+ import "../../src/vmath-overloads";
44
45
  import "../../src/window-event-guard";
45
46
  import "../builtin-messages";
46
47
  import "../gui";
@@ -41,6 +41,7 @@ import "../../src/engine-globals";
41
41
  import "../../src/go-overloads";
42
42
  import "../../src/message-guard";
43
43
  import "../../src/msg-overloads";
44
+ import "../../src/vmath-overloads";
44
45
  import "../../src/window-event-guard";
45
46
  import "../builtin-messages";
46
47
  import "../render";
@@ -41,6 +41,7 @@ import "../../src/engine-globals";
41
41
  import "../../src/go-overloads";
42
42
  import "../../src/message-guard";
43
43
  import "../../src/msg-overloads";
44
+ import "../../src/vmath-overloads";
44
45
  import "../../src/window-event-guard";
45
46
  import "../builtin-messages";
46
47
 
@@ -32,29 +32,6 @@ declare global {
32
32
  * : indexed by number 1 to the vector length. Example: `v[3]`
33
33
  */
34
34
  namespace vmath {
35
- /**
36
- * Clamp input value to be in range of [min, max]. In case if input value has vector3|vector4 type
37
- * return new vector3|vector4 with clamped value at every vector's element.
38
- * Min/max arguments can be vector3|vector4. In that case clamp excuted per every vector's element
39
- *
40
- * @param value - Input value or vector of values
41
- * @param min - Min value(s) border
42
- * @param max - Max value(s) border
43
- * @returns Clamped value or vector
44
- * @example
45
- * ```ts
46
- * const value1 = 56;
47
- * print(vmath.clamp(value1, 89, 134)); // => 89
48
- * const v2 = vmath.vector3(190, 190, -10);
49
- * print(vmath.clamp(v2, -50, 150)); // => vmath.vector3(150, 150, -10)
50
- * const v3 = vmath.vector4(30, -30, 45, 1);
51
- * print(vmath.clamp(v3, 0, 20)); // => vmath.vector4(20, 0, 20, 1)
52
- *
53
- * const min_v = vmath.vector4(0, -10, -10, 1);
54
- * print(vmath.clamp(v3, min_v, 20)); // => vmath.vector4(20, -10, 20, 1)
55
- * ```
56
- */
57
- function clamp(value: number | Vector3 | Vector4, min: number | Vector3 | Vector4, max: number | Vector3 | Vector4): number | Vector3 | Vector4;
58
35
  /**
59
36
  * Calculates the conjugate of a quaternion. The result is a
60
37
  * quaternion with the same magnitudes but with the sign of
@@ -185,97 +162,6 @@ declare global {
185
162
  * ```
186
163
  */
187
164
  function length_sqr(v: Vector3 | Vector4 | Quaternion): number;
188
- /**
189
- * Linearly interpolate between two vectors. The function
190
- * treats the vectors as positions and interpolates between
191
- * the positions in a straight line. Lerp is useful to describe
192
- * transitions from one place to another over time.
193
- * The function does not clamp t between 0 and 1.
194
- *
195
- * @param t - interpolation parameter, 0-1
196
- * @param v1 - vector to lerp from
197
- * @param v2 - vector to lerp to
198
- * @returns the lerped vector
199
- * @example
200
- * ```ts
201
- * export default defineScript({
202
- * init() {
203
- * return { t: 0 };
204
- * },
205
- *
206
- * update(self, dt) {
207
- * self.t = self.t + dt;
208
- * if (self.t <= 1) {
209
- * const startpos = vmath.vector3(0, 600, 0);
210
- * const endpos = vmath.vector3(600, 0, 0);
211
- * const pos = vmath.lerp(self.t, startpos, endpos);
212
- * go.set_position(pos, "go");
213
- * }
214
- * },
215
- * });
216
- * ```
217
- */
218
- function lerp(t: number, v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
219
- /**
220
- * Linearly interpolate between two quaternions. Linear
221
- * interpolation of rotations are only useful for small
222
- * rotations. For interpolations of arbitrary rotations,
223
- * vmath.slerp yields much better results.
224
- * The function does not clamp t between 0 and 1.
225
- *
226
- * @param t - interpolation parameter, 0-1
227
- * @param q1 - quaternion to lerp from
228
- * @param q2 - quaternion to lerp to
229
- * @returns the lerped quaternion
230
- * @example
231
- * ```ts
232
- * export default defineScript({
233
- * init(self) {
234
- * self.t = 0;
235
- * },
236
- *
237
- * update(self, dt) {
238
- * self.t = self.t + dt;
239
- * if (self.t <= 1) {
240
- * const startrot = vmath.quat_rotation_z(0);
241
- * const endrot = vmath.quat_rotation_z(3.141592653);
242
- * const rot = vmath.lerp(self.t, startrot, endrot);
243
- * go.set_rotation(rot, "go");
244
- * }
245
- * },
246
- * });
247
- * ```
248
- */
249
- function lerp(t: number, q1: Quaternion, q2: Quaternion): Quaternion;
250
- /**
251
- * Linearly interpolate between two values. Lerp is useful
252
- * to describe transitions from one value to another over time.
253
- * The function does not clamp t between 0 and 1.
254
- *
255
- * @param t - interpolation parameter, 0-1
256
- * @param n1 - number to lerp from
257
- * @param n2 - number to lerp to
258
- * @returns the lerped number
259
- * @example
260
- * ```ts
261
- * export default defineScript({
262
- * init(self) {
263
- * self.t = 0;
264
- * },
265
- *
266
- * update(self, dt) {
267
- * self.t = self.t + dt;
268
- * if (self.t <= 1) {
269
- * const startx = 0;
270
- * const endx = 600;
271
- * const x = vmath.lerp(self.t, startx, endx);
272
- * go.set_position(vmath.vector3(x, 100, 0), "go");
273
- * }
274
- * },
275
- * });
276
- * ```
277
- */
278
- function lerp(t: number, n1: number, n2: number): number;
279
165
  /**
280
166
  * The resulting identity matrix describes a transform with
281
167
  * no translation or rotation.
@@ -541,37 +427,6 @@ declare global {
541
427
  * ```
542
428
  */
543
429
  function matrix4_translation(position: Vector3 | Vector4): Matrix4;
544
- /**
545
- * Performs an element wise multiplication between two vectors of the same type
546
- * The returned value is a vector defined as (e.g. for a vector3):
547
- * `v = vmath.mul_per_elem(a, b) = vmath.vector3(a.x * b.x, a.y * b.y, a.z * b.z)`
548
- *
549
- * @param v1 - first vector
550
- * @param v2 - second vector
551
- * @returns multiplied vector
552
- * @example
553
- * ```ts
554
- * const blend_color = vmath.mul_per_elem(color1, color2);
555
- * ```
556
- */
557
- function mul_per_elem(v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
558
- /**
559
- * Normalizes a vector, i.e. returns a new vector with the same
560
- * direction as the input vector, but with length 1.
561
- * The length of the vector must be above 0, otherwise a
562
- * division-by-zero will occur.
563
- *
564
- * @param v1 - vector to normalize
565
- * @returns new normalized vector
566
- * @example
567
- * ```ts
568
- * const vec = vmath.vector3(1, 2, 3);
569
- * const norm_vec = vmath.normalize(vec);
570
- * print(norm_vec); // => vmath.vector3(0.26726123690605, 0.5345224738121, 0.80178368091583)
571
- * print(vmath.length(norm_vec)); // => 0.99999994039536
572
- * ```
573
- */
574
- function normalize(v1: Vector3 | Vector4 | Quaternion): Vector3 | Vector4 | Quaternion;
575
430
  /**
576
431
  * The resulting matrix is the inverse of the supplied matrix.
577
432
  * The supplied matrix has to be an ortho-normal matrix, e.g.
@@ -799,73 +654,6 @@ declare global {
799
654
  * ```
800
655
  */
801
656
  function rotate(q: Quaternion, v1: Vector3): Vector3;
802
- /**
803
- * Spherically interpolates between two vectors. The difference to
804
- * lerp is that slerp treats the vectors as directions instead of
805
- * positions in space.
806
- * The direction of the returned vector is interpolated by the angle
807
- * and the magnitude is interpolated between the magnitudes of the
808
- * from and to vectors.
809
- * Slerp is computationally more expensive than lerp.
810
- * The function does not clamp t between 0 and 1.
811
- *
812
- * @param t - interpolation parameter, 0-1
813
- * @param v1 - vector to slerp from
814
- * @param v2 - vector to slerp to
815
- * @returns the slerped vector
816
- * @example
817
- * ```ts
818
- * export default defineScript({
819
- * init() {
820
- * return { t: 0 };
821
- * },
822
- *
823
- * update(self, dt) {
824
- * self.t = self.t + dt;
825
- * if (self.t <= 1) {
826
- * const startpos = vmath.vector3(0, 600, 0);
827
- * const endpos = vmath.vector3(600, 0, 0);
828
- * const pos = vmath.slerp(self.t, startpos, endpos);
829
- * go.set_position(pos, "go");
830
- * }
831
- * },
832
- * });
833
- * ```
834
- */
835
- function slerp(t: number, v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
836
- /**
837
- * Slerp travels the torque-minimal path maintaining constant
838
- * velocity, which means it travels along the straightest path along
839
- * the rounded surface of a sphere. Slerp is useful for interpolation
840
- * of rotations.
841
- * Slerp travels the torque-minimal path, which means it travels
842
- * along the straightest path the rounded surface of a sphere.
843
- * The function does not clamp t between 0 and 1.
844
- *
845
- * @param t - interpolation parameter, 0-1
846
- * @param q1 - quaternion to slerp from
847
- * @param q2 - quaternion to slerp to
848
- * @returns the slerped quaternion
849
- * @example
850
- * ```ts
851
- * export default defineScript({
852
- * init(self) {
853
- * self.t = 0;
854
- * },
855
- *
856
- * update(self, dt) {
857
- * self.t = self.t + dt;
858
- * if (self.t <= 1) {
859
- * const startrot = vmath.quat_rotation_z(0);
860
- * const endrot = vmath.quat_rotation_z(3.141592653);
861
- * const rot = vmath.slerp(self.t, startrot, endrot);
862
- * go.set_rotation(rot, "go");
863
- * }
864
- * },
865
- * });
866
- * ```
867
- */
868
- function slerp(t: number, q1: Quaternion, q2: Quaternion): Quaternion;
869
657
  /**
870
658
  * Creates a vector of arbitrary size. The vector is initialized
871
659
  * with numeric values from a table.
package/index.d.ts CHANGED
@@ -42,6 +42,7 @@ import "./generated/tilemap";
42
42
  import "./generated/timer";
43
43
  import "./generated/types";
44
44
  import "./generated/vmath";
45
+ import "./src/vmath-overloads";
45
46
  import "./generated/webview";
46
47
  import "./generated/window";
47
48
  import "./generated/zlib";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.18.2",
3
+ "version": "0.18.4",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/scripts/regen.ts CHANGED
@@ -244,6 +244,7 @@ const UNIVERSAL_EXTRA_IMPORTS: readonly string[] = [
244
244
  "../../src/message-guard",
245
245
  "../../src/window-event-guard",
246
246
  "../../src/go-overloads",
247
+ "../../src/vmath-overloads",
247
248
  ];
248
249
 
249
250
  export interface KindManifestEntry {
@@ -21,6 +21,7 @@ export const DEBUG_SIGNATURES_PATH = resolve(import.meta.dir, "..", "signatures"
21
21
  export const PACKAGE_SIGNATURES_PATH = resolve(import.meta.dir, "..", "signatures", "package.json");
22
22
  export const BASE_SIGNATURES_PATH = resolve(import.meta.dir, "..", "signatures", "base.json");
23
23
  export const SOCKET_SIGNATURES_PATH = resolve(import.meta.dir, "..", "signatures", "socket.json");
24
+ export const VMATH_SIGNATURES_PATH = resolve(import.meta.dir, "..", "signatures", "vmath.json");
24
25
 
25
26
  export function loadSignatureFile(path: string): SignatureStore {
26
27
  let raw: string;
package/src/emit-dts.ts CHANGED
@@ -167,6 +167,12 @@ export const OVERLOAD_COVERED_SKIPS = new Set([
167
167
  // msg-overloads.d.ts supplies the typed msg.url shape (0 / 1-string / 3-arg
168
168
  // arities; the runtime-invalid two-arg form is intentionally omitted).
169
169
  "msg.url",
170
+ // vmath-overloads.d.ts supplies the generic covariant signatures.
171
+ "vmath.clamp",
172
+ "vmath.lerp",
173
+ "vmath.slerp",
174
+ "vmath.mul_per_elem",
175
+ "vmath.normalize",
170
176
  ]);
171
177
 
172
178
  // Element names whose `table` slot is a prose-only `a table mapping X to Y`
@@ -0,0 +1,109 @@
1
+ /** @noSelfInFile */
2
+
3
+ import type { Quaternion, Vector3, Vector4 } from "./core-types";
4
+
5
+ declare global {
6
+ namespace vmath {
7
+ /**
8
+ * Clamp input value to be in range of [min, max]. In case if input value has vector3|vector4 type
9
+ * return new vector3|vector4 with clamped value at every vector's element.
10
+ * Min/max arguments can be vector3|vector4. In that case clamp excuted per every vector's element
11
+ *
12
+ * @param value - Input value or vector of values
13
+ * @param min - Min value(s) border
14
+ * @param max - Max value(s) border
15
+ * @returns Clamped value or vector
16
+ */
17
+ function clamp<T extends number | Vector3 | Vector4>(
18
+ value: T,
19
+ min: number | T,
20
+ max: number | T,
21
+ ): T;
22
+ /**
23
+ * Linearly interpolate between two vectors. The function
24
+ * treats the vectors as positions and interpolates between
25
+ * the positions in a straight line. Lerp is useful to describe
26
+ * transitions from one place to another over time.
27
+ * The function does not clamp t between 0 and 1.
28
+ *
29
+ * @param t - interpolation parameter, 0-1
30
+ * @param v1 - vector to lerp from
31
+ * @param v2 - vector to lerp to
32
+ * @returns the lerped vector
33
+ */
34
+ function lerp<T extends Vector3 | Vector4>(t: number, v1: T, v2: T): T;
35
+ /**
36
+ * Linearly interpolate between two quaternions. Linear
37
+ * interpolation of rotations are only useful for small
38
+ * rotations. For interpolations of arbitrary rotations,
39
+ * vmath.slerp yields much better results.
40
+ * The function does not clamp t between 0 and 1.
41
+ *
42
+ * @param t - interpolation parameter, 0-1
43
+ * @param q1 - quaternion to lerp from
44
+ * @param q2 - quaternion to lerp to
45
+ * @returns the lerped quaternion
46
+ */
47
+ function lerp(t: number, q1: Quaternion, q2: Quaternion): Quaternion;
48
+ /**
49
+ * Linearly interpolate between two values. Lerp is useful
50
+ * to describe transitions from one value to another over time.
51
+ * The function does not clamp t between 0 and 1.
52
+ *
53
+ * @param t - interpolation parameter, 0-1
54
+ * @param n1 - number to lerp from
55
+ * @param n2 - number to lerp to
56
+ * @returns the lerped number
57
+ */
58
+ function lerp(t: number, n1: number, n2: number): number;
59
+ /**
60
+ * Performs an element wise multiplication between two vectors of the same type
61
+ * The returned value is a vector defined as (e.g. for a vector3):
62
+ * `v = vmath.mul_per_elem(a, b) = vmath.vector3(a.x * b.x, a.y * b.y, a.z * b.z)`
63
+ *
64
+ * @param v1 - first vector
65
+ * @param v2 - second vector
66
+ * @returns multiplied vector
67
+ */
68
+ function mul_per_elem<T extends Vector3 | Vector4>(v1: T, v2: T): T;
69
+ /**
70
+ * Normalizes a vector, i.e. returns a new vector with the same
71
+ * direction as the input vector, but with length 1.
72
+ * The length of the vector must be above 0, otherwise a
73
+ * division-by-zero will occur.
74
+ *
75
+ * @param v1 - vector to normalize
76
+ * @returns new normalized vector
77
+ */
78
+ function normalize<T extends Vector3 | Vector4 | Quaternion>(v1: T): T;
79
+ /**
80
+ * Spherically interpolates between two vectors. The difference to
81
+ * lerp is that slerp treats the vectors as directions instead of
82
+ * positions in space.
83
+ * The direction of the returned vector is interpolated by the angle
84
+ * and the magnitude is interpolated between the magnitudes of the
85
+ * from and to vectors.
86
+ * Slerp is computationally more expensive than lerp.
87
+ * The function does not clamp t between 0 and 1.
88
+ *
89
+ * @param t - interpolation parameter, 0-1
90
+ * @param v1 - vector to slerp from
91
+ * @param v2 - vector to slerp to
92
+ * @returns the slerped vector
93
+ */
94
+ function slerp<T extends Vector3 | Vector4>(t: number, v1: T, v2: T): T;
95
+ /**
96
+ * Slerp travels the torque-minimal path maintaining constant
97
+ * velocity, which means it travels along the straightest path along
98
+ * the rounded surface of a sphere. Slerp is useful for interpolation
99
+ * of rotations.
100
+ * The function does not clamp t between 0 and 1.
101
+ *
102
+ * @param t - interpolation parameter, 0-1
103
+ * @param q1 - quaternion to slerp from
104
+ * @param q2 - quaternion to slerp to
105
+ * @returns the slerped quaternion
106
+ */
107
+ function slerp(t: number, q1: Quaternion, q2: Quaternion): Quaternion;
108
+ }
109
+ }