@oliversalzburg/js-utils 0.0.7 → 0.0.9

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 (172) hide show
  1. package/LICENSES.md +17 -0
  2. package/_site/assets/highlight.css +57 -0
  3. package/_site/assets/main.js +59 -0
  4. package/_site/assets/navigation.js +1 -0
  5. package/_site/assets/search.js +1 -0
  6. package/_site/assets/style.css +1383 -0
  7. package/_site/classes/AbstractError.html +28 -0
  8. package/_site/classes/Canvas.html +44 -0
  9. package/_site/classes/InternalError.html +32 -0
  10. package/_site/classes/InvalidArgumentError.html +28 -0
  11. package/_site/classes/InvalidOperationError.html +28 -0
  12. package/_site/classes/NotImplementedError.html +27 -0
  13. package/_site/classes/PermissionViolationError.html +28 -0
  14. package/_site/classes/Random.html +43 -0
  15. package/_site/classes/RenderLoop.html +30 -0
  16. package/_site/classes/ResourceConflictError.html +27 -0
  17. package/_site/classes/UnexpectedNilError.html +15 -0
  18. package/_site/classes/UnknownError.html +31 -0
  19. package/_site/classes/Vector2.html +113 -0
  20. package/_site/classes/Vector3.html +28 -0
  21. package/_site/functions/addVector2.html +5 -0
  22. package/_site/functions/blend.html +8 -0
  23. package/_site/functions/blendAdditive.html +8 -0
  24. package/_site/functions/blendSubtractive.html +8 -0
  25. package/_site/functions/cosDeg.html +4 -0
  26. package/_site/functions/deg2rad.html +4 -0
  27. package/_site/functions/difference.html +7 -0
  28. package/_site/functions/distance.html +7 -0
  29. package/_site/functions/errorToJSON.html +4 -0
  30. package/_site/functions/errorToRecord.html +4 -0
  31. package/_site/functions/errorToSimpleSerializable.html +4 -0
  32. package/_site/functions/filterType.html +7 -0
  33. package/_site/functions/formatString.html +7 -0
  34. package/_site/functions/formatStringTemplate.html +7 -0
  35. package/_site/functions/fromRGB.html +7 -0
  36. package/_site/functions/fromRGBA.html +7 -0
  37. package/_site/functions/getA.html +4 -0
  38. package/_site/functions/getB.html +4 -0
  39. package/_site/functions/getDocumentElementTypeById.html +9 -0
  40. package/_site/functions/getG.html +4 -0
  41. package/_site/functions/getR.html +4 -0
  42. package/_site/functions/intersect.html +8 -0
  43. package/_site/functions/is.html +7 -0
  44. package/_site/functions/isError.html +4 -0
  45. package/_site/functions/isInteger.html +4 -0
  46. package/_site/functions/isNil.html +5 -0
  47. package/_site/functions/isqrt.html +4 -0
  48. package/_site/functions/multiplyVector2.html +5 -0
  49. package/_site/functions/mustExist.html +6 -0
  50. package/_site/functions/nextPalette.html +2 -0
  51. package/_site/functions/putPixel32.html +7 -0
  52. package/_site/functions/putPixel32Add.html +7 -0
  53. package/_site/functions/putPixel32Sub.html +7 -0
  54. package/_site/functions/putSubPixel32.html +8 -0
  55. package/_site/functions/rad2deg.html +4 -0
  56. package/_site/functions/randomRange.html +6 -0
  57. package/_site/functions/safeRGBComponent.html +4 -0
  58. package/_site/functions/seedFromString.html +5 -0
  59. package/_site/functions/shuffleArray.html +5 -0
  60. package/_site/functions/sinDeg.html +4 -0
  61. package/_site/functions/sleep.html +4 -0
  62. package/_site/functions/somecolor.html +4 -0
  63. package/_site/functions/subtractVector2.html +5 -0
  64. package/_site/functions/toGrayScale.html +4 -0
  65. package/_site/functions/unknownToError.html +6 -0
  66. package/_site/index.html +1 -0
  67. package/_site/modules.html +72 -0
  68. package/_site/types/AnyConstructor.html +2 -0
  69. package/_site/types/AnyFunction.html +2 -0
  70. package/_site/types/ConstructorOf.html +2 -0
  71. package/_site/types/FunctionReturning.html +2 -0
  72. package/_site/types/Maybe.html +2 -0
  73. package/_site/types/Mixin.html +3 -0
  74. package/_site/types/Nil.html +3 -0
  75. package/_site/types/RenderLoopCallback.html +2 -0
  76. package/_site/types/SerializedError.html +2 -0
  77. package/_site/variables/PALETTES.html +2 -0
  78. package/_site/variables/TWO_PI.html +2 -0
  79. package/_site/variables/random-1.html +2 -0
  80. package/lib/array.d.ts +8 -0
  81. package/lib/array.js +8 -0
  82. package/lib/array.js.map +1 -1
  83. package/lib/dom/core.d.ts +13 -0
  84. package/lib/dom/core.js +24 -0
  85. package/lib/dom/core.js.map +1 -0
  86. package/lib/dom/index.d.ts +1 -0
  87. package/lib/dom/index.js +2 -0
  88. package/lib/dom/index.js.map +1 -0
  89. package/lib/error-serializer.d.ts +12 -6
  90. package/lib/error-serializer.js +11 -7
  91. package/lib/error-serializer.js.map +1 -1
  92. package/lib/error-serializer.test.d.ts +1 -0
  93. package/lib/error-serializer.test.js +117 -0
  94. package/lib/error-serializer.test.js.map +1 -0
  95. package/lib/errors/AbstractError.d.ts +4 -16
  96. package/lib/errors/AbstractError.js +4 -16
  97. package/lib/errors/AbstractError.js.map +1 -1
  98. package/lib/errors/InternalError.d.ts +6 -5
  99. package/lib/errors/InternalError.js +6 -7
  100. package/lib/errors/InternalError.js.map +1 -1
  101. package/lib/errors/InvalidArgumentError.d.ts +2 -1
  102. package/lib/errors/InvalidArgumentError.js +2 -1
  103. package/lib/errors/InvalidArgumentError.js.map +1 -1
  104. package/lib/errors/InvalidOperationError.d.ts +2 -1
  105. package/lib/errors/InvalidOperationError.js +2 -1
  106. package/lib/errors/InvalidOperationError.js.map +1 -1
  107. package/lib/errors/NotImplementedError.d.ts +2 -1
  108. package/lib/errors/NotImplementedError.js +2 -1
  109. package/lib/errors/NotImplementedError.js.map +1 -1
  110. package/lib/errors/PermissionViolationError.d.ts +2 -1
  111. package/lib/errors/PermissionViolationError.js +2 -1
  112. package/lib/errors/PermissionViolationError.js.map +1 -1
  113. package/lib/errors/ResourceConflictError.d.ts +2 -1
  114. package/lib/errors/ResourceConflictError.js +2 -1
  115. package/lib/errors/ResourceConflictError.js.map +1 -1
  116. package/lib/errors/UnknownError.d.ts +6 -5
  117. package/lib/errors/UnknownError.js +6 -5
  118. package/lib/errors/UnknownError.js.map +1 -1
  119. package/lib/graphics/canvas.d.ts +55 -19
  120. package/lib/graphics/canvas.js +66 -18
  121. package/lib/graphics/canvas.js.map +1 -1
  122. package/lib/graphics/core.d.ts +18 -0
  123. package/lib/graphics/core.js +18 -0
  124. package/lib/graphics/core.js.map +1 -1
  125. package/lib/graphics/render-loop.d.ts +25 -4
  126. package/lib/graphics/render-loop.js +19 -2
  127. package/lib/graphics/render-loop.js.map +1 -1
  128. package/lib/index.d.ts +1 -0
  129. package/lib/index.js +1 -0
  130. package/lib/index.js.map +1 -1
  131. package/lib/math/core.d.ts +12 -1
  132. package/lib/math/core.js +13 -2
  133. package/lib/math/core.js.map +1 -1
  134. package/lib/math/index.d.ts +2 -0
  135. package/lib/math/index.js +2 -0
  136. package/lib/math/index.js.map +1 -1
  137. package/lib/math/vector.d.ts +2 -33
  138. package/lib/math/vector.js +2 -41
  139. package/lib/math/vector.js.map +1 -1
  140. package/lib/math/vector2.d.ts +195 -0
  141. package/lib/math/vector2.js +299 -0
  142. package/lib/math/vector2.js.map +1 -0
  143. package/lib/math/vector3.d.ts +46 -0
  144. package/lib/math/vector3.js +59 -0
  145. package/lib/math/vector3.js.map +1 -0
  146. package/lib/nil.d.ts +1 -0
  147. package/lib/nil.js +1 -0
  148. package/lib/nil.js.map +1 -1
  149. package/lib/random.d.ts +40 -4
  150. package/lib/random.js +175 -14
  151. package/lib/random.js.map +1 -1
  152. package/lib/string-formatter.d.ts +2 -0
  153. package/lib/string-formatter.js +2 -0
  154. package/lib/string-formatter.js.map +1 -1
  155. package/package.json +10 -10
  156. package/docs/README.md +0 -3
  157. package/docs/classes/AbstractError.md +0 -271
  158. package/docs/classes/Canvas.md +0 -177
  159. package/docs/classes/InternalError.md +0 -301
  160. package/docs/classes/InvalidArgumentError.md +0 -277
  161. package/docs/classes/InvalidOperationError.md +0 -277
  162. package/docs/classes/NotImplementedError.md +0 -276
  163. package/docs/classes/PermissionViolationError.md +0 -277
  164. package/docs/classes/Random.md +0 -109
  165. package/docs/classes/RenderLoop.md +0 -49
  166. package/docs/classes/ResourceConflictError.md +0 -276
  167. package/docs/classes/UnexpectedNilError.md +0 -169
  168. package/docs/classes/UnknownError.md +0 -280
  169. package/docs/classes/Vector2.md +0 -79
  170. package/docs/classes/Vector3.md +0 -106
  171. package/docs/modules.md +0 -1313
  172. package/typedoc.json +0 -8
@@ -0,0 +1,195 @@
1
+ /**
2
+ * A vector with 2 components, labeled: `X`, `Y`.
3
+ * @group Math
4
+ */
5
+ export declare class Vector2 {
6
+ /**
7
+ * The X component of the vector.
8
+ */
9
+ x: number;
10
+ /**
11
+ * The Y component of the vector.
12
+ */
13
+ y: number;
14
+ /**
15
+ * Constructs a new {@linkcode Vector2}.
16
+ * @param x The X component.
17
+ * @param y The Y component.
18
+ */
19
+ constructor(x: number, y: number);
20
+ /**
21
+ * Sets the vector to new coordinates.
22
+ * @param vector The coordinates to set the vector to.
23
+ * @returns This instance.
24
+ */
25
+ set(vector: Vector2): this;
26
+ /**
27
+ * Sets the vector to new coordinates.
28
+ * @param x The new X component for the vector.
29
+ * @param y The new Y component for the vector.
30
+ * @returns This instance.
31
+ */
32
+ setXY(x: number, y: number): this;
33
+ /**
34
+ * Adds another vector to this vector.
35
+ * @param vector The vector to add to this vector.
36
+ * @returns This instance.
37
+ */
38
+ add(vector: Vector2): this;
39
+ /**
40
+ * Adds another vector to this vector.
41
+ * @param x The value to add to the X component.
42
+ * @param y The value to add to the Y component.
43
+ * @returns This instance.
44
+ */
45
+ addXY(x: number, y: number): this;
46
+ /**
47
+ * Scales another vector and adds it to this vector.
48
+ * @param vector The vector to add to this vector.
49
+ * @param scale The scaling to apply to the input vector.
50
+ * @returns This instance.
51
+ */
52
+ addMultiply(vector: Vector2, scale: number): this;
53
+ /**
54
+ * Scales another vector and adds it to this vector.
55
+ * @param x The value to add to the X component.
56
+ * @param y The value to add to the Y component.
57
+ * @param scale The scaling to apply to the input vector.
58
+ * @returns This instance.
59
+ */
60
+ addMultiplyXY(x: number, y: number, scale: number): this;
61
+ /**
62
+ * Subtracts another vector to this vector.
63
+ * @param vector The vector to subtract from this vector.
64
+ * @returns This instance.
65
+ */
66
+ subtract(vector: Vector2): this;
67
+ /**
68
+ * Subtracts another vector to this vector.
69
+ * @param x The value to subtract from the X component.
70
+ * @param y The value to subtract from the Y component.
71
+ * @returns This instance.
72
+ */
73
+ subtractXY(x: number, y: number): this;
74
+ /**
75
+ * Multiplies this vector by another vector.
76
+ * @param vector The vector to multiply with this vector.
77
+ * @returns This instance.
78
+ */
79
+ multiply(vector: Vector2): this;
80
+ /**
81
+ * Multiplies this vector by another vector.
82
+ * @param x The value to multiply with the X component.
83
+ * @param y The value to multiply with the Y component.
84
+ * @returns This instance.
85
+ */
86
+ multiplyXY(x: number, y: number): this;
87
+ /**
88
+ * Multiplies the vector by the given scale.
89
+ * @param scale The scaling to apply to the vector.
90
+ * @returns This instance.
91
+ */
92
+ multiplyScale(scale: number): this;
93
+ /**
94
+ * Divides this vector by another vector.
95
+ * @param vector The vector to divide this vector with.
96
+ * @returns This instance.
97
+ */
98
+ divide(vector: Vector2): this;
99
+ /**
100
+ * Divides this vector by another vector.
101
+ * @param x The value to divide the X component with.
102
+ * @param y The value to divide the Y component with.
103
+ * @returns This instance.
104
+ */
105
+ divideXY(x: number, y: number): this;
106
+ /**
107
+ * Divides the vector by the given scale.
108
+ * @param scale The scaling to apply to the vector.
109
+ * @returns This instance.
110
+ */
111
+ divideScale(scale: number): this;
112
+ /**
113
+ * Inverts the vector.
114
+ * @returns This instance.
115
+ */
116
+ invertAdd(): this;
117
+ /**
118
+ * Inverts the vectors scale.
119
+ * @returns This instance.
120
+ */
121
+ invertMultiply(): this;
122
+ /**
123
+ * Clamps the components of the vector at the given boundary.
124
+ * @param floor The lowest value to allow.
125
+ * @param ceil The largest value to allow.
126
+ * @returns This instance.
127
+ */
128
+ clamp(floor: number, ceil: number): this;
129
+ /**
130
+ * Calculates the length of the vector.
131
+ * @returns The length of the vector.
132
+ */
133
+ length(): number;
134
+ /**
135
+ * Normalizes the vector.
136
+ * @returns This instance.
137
+ */
138
+ normalize(): this;
139
+ /**
140
+ * Compares two vectors.
141
+ * @param vector The vector to compare this vector to.
142
+ * @returns `true` if the vectors are idently, `false` otherwise.
143
+ */
144
+ compare(vector: Readonly<Vector2>): boolean;
145
+ /**
146
+ * Linearly moves this vector towards a target vector.
147
+ * @param vector The target vector.
148
+ * @param t The location on the scale, from `0` to `1`.
149
+ * @returns This instance.
150
+ */
151
+ lerp(vector: Readonly<Vector2>, t: number): this;
152
+ /**
153
+ * Rotates the vector by the given angle.
154
+ * @param angle The angle in degrees.
155
+ * @returns This instance.
156
+ */
157
+ rotate(angle: number): this;
158
+ /**
159
+ * Returns the dot product between two vectors.
160
+ * @param vector The other vector.
161
+ * @returns The dot product between the two vectors.
162
+ */
163
+ dot(vector: Vector2): number;
164
+ /**
165
+ * Returns the dot product between two vectors.
166
+ * @param x The X component of the other vector.
167
+ * @param y The Y component of the other vector.
168
+ * @returns The dot product between the two vectors.
169
+ */
170
+ dotXY(x: number, y: number): number;
171
+ }
172
+ /**
173
+ * Adds two vectors and returns a new vector with the result.
174
+ * @param a The first input vector.
175
+ * @param b The second input vector.
176
+ * @returns A new {@linkcode Vector2}.
177
+ * @group Math
178
+ */
179
+ export declare const addVector2: (a: Vector2, b: Vector2) => Vector2;
180
+ /**
181
+ * Multiplies two vectors and returns a new vector with the result.
182
+ * @param a The first input vector.
183
+ * @param b The second input vector.
184
+ * @returns A new {@linkcode Vector2}.
185
+ * @group Math
186
+ */
187
+ export declare const multiplyVector2: (a: Vector2, b: Vector2) => Vector2;
188
+ /**
189
+ * Subtracts two vectors and returns a new vector with the result.
190
+ * @param a The first input vector.
191
+ * @param b The second input vector.
192
+ * @returns A new {@linkcode Vector2}.
193
+ * @group Math
194
+ */
195
+ export declare const subtractVector2: (a: Vector2, b: Vector2) => Vector2;
@@ -0,0 +1,299 @@
1
+ /**
2
+ * A vector with 2 components, labeled: `X`, `Y`.
3
+ * @group Math
4
+ */
5
+ export class Vector2 {
6
+ /**
7
+ * The X component of the vector.
8
+ */
9
+ x;
10
+ /**
11
+ * The Y component of the vector.
12
+ */
13
+ y;
14
+ /**
15
+ * Constructs a new {@linkcode Vector2}.
16
+ * @param x The X component.
17
+ * @param y The Y component.
18
+ */
19
+ constructor(x, y) {
20
+ this.x = x;
21
+ this.y = y;
22
+ }
23
+ /**
24
+ * Sets the vector to new coordinates.
25
+ * @param vector The coordinates to set the vector to.
26
+ * @returns This instance.
27
+ */
28
+ set(vector) {
29
+ return this.setXY(vector.x, vector.y);
30
+ }
31
+ /**
32
+ * Sets the vector to new coordinates.
33
+ * @param x The new X component for the vector.
34
+ * @param y The new Y component for the vector.
35
+ * @returns This instance.
36
+ */
37
+ setXY(x, y) {
38
+ this.x = x;
39
+ this.y = y;
40
+ return this;
41
+ }
42
+ /**
43
+ * Adds another vector to this vector.
44
+ * @param vector The vector to add to this vector.
45
+ * @returns This instance.
46
+ */
47
+ add(vector) {
48
+ return this.addXY(vector.x, vector.y);
49
+ }
50
+ /**
51
+ * Adds another vector to this vector.
52
+ * @param x The value to add to the X component.
53
+ * @param y The value to add to the Y component.
54
+ * @returns This instance.
55
+ */
56
+ addXY(x, y) {
57
+ this.x += x;
58
+ this.y += y;
59
+ return this;
60
+ }
61
+ /**
62
+ * Scales another vector and adds it to this vector.
63
+ * @param vector The vector to add to this vector.
64
+ * @param scale The scaling to apply to the input vector.
65
+ * @returns This instance.
66
+ */
67
+ addMultiply(vector, scale) {
68
+ return this.addMultiplyXY(vector.x, vector.y, scale);
69
+ }
70
+ /**
71
+ * Scales another vector and adds it to this vector.
72
+ * @param x The value to add to the X component.
73
+ * @param y The value to add to the Y component.
74
+ * @param scale The scaling to apply to the input vector.
75
+ * @returns This instance.
76
+ */
77
+ addMultiplyXY(x, y, scale) {
78
+ this.x += x * scale;
79
+ this.y += y * scale;
80
+ return this;
81
+ }
82
+ /**
83
+ * Subtracts another vector to this vector.
84
+ * @param vector The vector to subtract from this vector.
85
+ * @returns This instance.
86
+ */
87
+ subtract(vector) {
88
+ return this.subtractXY(vector.x, vector.y);
89
+ }
90
+ /**
91
+ * Subtracts another vector to this vector.
92
+ * @param x The value to subtract from the X component.
93
+ * @param y The value to subtract from the Y component.
94
+ * @returns This instance.
95
+ */
96
+ subtractXY(x, y) {
97
+ this.x -= x;
98
+ this.y -= y;
99
+ return this;
100
+ }
101
+ /**
102
+ * Multiplies this vector by another vector.
103
+ * @param vector The vector to multiply with this vector.
104
+ * @returns This instance.
105
+ */
106
+ multiply(vector) {
107
+ return this.multiplyXY(vector.x, vector.y);
108
+ }
109
+ /**
110
+ * Multiplies this vector by another vector.
111
+ * @param x The value to multiply with the X component.
112
+ * @param y The value to multiply with the Y component.
113
+ * @returns This instance.
114
+ */
115
+ multiplyXY(x, y) {
116
+ this.x *= x;
117
+ this.y *= y;
118
+ return this;
119
+ }
120
+ /**
121
+ * Multiplies the vector by the given scale.
122
+ * @param scale The scaling to apply to the vector.
123
+ * @returns This instance.
124
+ */
125
+ multiplyScale(scale) {
126
+ this.x *= scale;
127
+ this.y *= scale;
128
+ return this;
129
+ }
130
+ /**
131
+ * Divides this vector by another vector.
132
+ * @param vector The vector to divide this vector with.
133
+ * @returns This instance.
134
+ */
135
+ divide(vector) {
136
+ return this.divideXY(vector.x, vector.y);
137
+ }
138
+ /**
139
+ * Divides this vector by another vector.
140
+ * @param x The value to divide the X component with.
141
+ * @param y The value to divide the Y component with.
142
+ * @returns This instance.
143
+ */
144
+ divideXY(x, y) {
145
+ this.x /= x;
146
+ this.y /= y;
147
+ return this;
148
+ }
149
+ /**
150
+ * Divides the vector by the given scale.
151
+ * @param scale The scaling to apply to the vector.
152
+ * @returns This instance.
153
+ */
154
+ divideScale(scale) {
155
+ this.x /= scale;
156
+ this.y /= scale;
157
+ return this;
158
+ }
159
+ /**
160
+ * Inverts the vector.
161
+ * @returns This instance.
162
+ */
163
+ invertAdd() {
164
+ this.x = -this.x;
165
+ this.y = -this.y;
166
+ return this;
167
+ }
168
+ /**
169
+ * Inverts the vectors scale.
170
+ * @returns This instance.
171
+ */
172
+ invertMultiply() {
173
+ this.x = 1 / this.x;
174
+ this.y = 1 / this.y;
175
+ return this;
176
+ }
177
+ /**
178
+ * Clamps the components of the vector at the given boundary.
179
+ * @param floor The lowest value to allow.
180
+ * @param ceil The largest value to allow.
181
+ * @returns This instance.
182
+ */
183
+ clamp(floor, ceil) {
184
+ if (this.x < floor) {
185
+ this.x = floor;
186
+ }
187
+ if (this.x > ceil) {
188
+ this.x = ceil;
189
+ }
190
+ if (this.y < floor) {
191
+ this.y = floor;
192
+ }
193
+ if (this.y > ceil) {
194
+ this.y = ceil;
195
+ }
196
+ return this;
197
+ }
198
+ /**
199
+ * Calculates the length of the vector.
200
+ * @returns The length of the vector.
201
+ */
202
+ length() {
203
+ return Math.sqrt(this.x * this.x + this.y * this.y);
204
+ }
205
+ /**
206
+ * Normalizes the vector.
207
+ * @returns This instance.
208
+ */
209
+ normalize() {
210
+ const length = this.length();
211
+ if (length === 0) {
212
+ return this;
213
+ }
214
+ this.x /= length;
215
+ this.y /= length;
216
+ return this;
217
+ }
218
+ /**
219
+ * Compares two vectors.
220
+ * @param vector The vector to compare this vector to.
221
+ * @returns `true` if the vectors are idently, `false` otherwise.
222
+ */
223
+ compare(vector) {
224
+ return vector.x === this.x && vector.y === this.y;
225
+ }
226
+ /**
227
+ * Linearly moves this vector towards a target vector.
228
+ * @param vector The target vector.
229
+ * @param t The location on the scale, from `0` to `1`.
230
+ * @returns This instance.
231
+ */
232
+ lerp(vector, t) {
233
+ const tn = 1.0 - t;
234
+ this.x = this.x * tn + vector.x * t;
235
+ this.y = this.y * tn + vector.y * t;
236
+ return this;
237
+ }
238
+ /**
239
+ * Rotates the vector by the given angle.
240
+ * @param angle The angle in degrees.
241
+ * @returns This instance.
242
+ */
243
+ rotate(angle) {
244
+ angle = -angle * (Math.PI / 180);
245
+ const cos = Math.cos(angle);
246
+ const sin = Math.sin(angle);
247
+ this.x = this.x * cos - this.y * sin;
248
+ this.y = this.x * sin + this.y * cos;
249
+ return this;
250
+ }
251
+ /**
252
+ * Returns the dot product between two vectors.
253
+ * @param vector The other vector.
254
+ * @returns The dot product between the two vectors.
255
+ */
256
+ dot(vector) {
257
+ return this.dotXY(vector.x, vector.y);
258
+ }
259
+ /**
260
+ * Returns the dot product between two vectors.
261
+ * @param x The X component of the other vector.
262
+ * @param y The Y component of the other vector.
263
+ * @returns The dot product between the two vectors.
264
+ */
265
+ dotXY(x, y) {
266
+ return this.x * x + this.y * y;
267
+ }
268
+ }
269
+ /**
270
+ * Adds two vectors and returns a new vector with the result.
271
+ * @param a The first input vector.
272
+ * @param b The second input vector.
273
+ * @returns A new {@linkcode Vector2}.
274
+ * @group Math
275
+ */
276
+ export const addVector2 = (a, b) => {
277
+ return new Vector2(a.x * b.x, a.y * b.y);
278
+ };
279
+ /**
280
+ * Multiplies two vectors and returns a new vector with the result.
281
+ * @param a The first input vector.
282
+ * @param b The second input vector.
283
+ * @returns A new {@linkcode Vector2}.
284
+ * @group Math
285
+ */
286
+ export const multiplyVector2 = (a, b) => {
287
+ return new Vector2(a.x * b.x, a.y * b.y);
288
+ };
289
+ /**
290
+ * Subtracts two vectors and returns a new vector with the result.
291
+ * @param a The first input vector.
292
+ * @param b The second input vector.
293
+ * @returns A new {@linkcode Vector2}.
294
+ * @group Math
295
+ */
296
+ export const subtractVector2 = (a, b) => {
297
+ return new Vector2(a.x - b.x, a.y - b.y);
298
+ };
299
+ //# sourceMappingURL=vector2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector2.js","sourceRoot":"","sources":["../../source/math/vector2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,OAAO;IAClB;;OAEG;IACH,CAAC,CAAS;IAEV;;OAEG;IACH,CAAC,CAAS;IAEV;;;;OAIG;IACH,YAAY,CAAS,EAAE,CAAS;QAC9B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,MAAe;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,E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AC3C,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAU,EAAE,CAAU,EAAW,EAAE;IACjE,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAU,EAAE,CAAU,EAAW,EAAE;IACjE,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * A vector with 3 components, labeled: `X`, `Y`, `Z`.
3
+ * @group Math
4
+ */
5
+ export declare class Vector3 {
6
+ /**
7
+ * The X component of the vector.
8
+ */
9
+ x: number;
10
+ /**
11
+ * The Y component of the vector.
12
+ */
13
+ y: number;
14
+ /**
15
+ * The Z component of the vector.
16
+ */
17
+ z: number;
18
+ /**
19
+ * Constructs a new {@linkcode Vector3}.
20
+ * @param x The X component.
21
+ * @param y The Y component.
22
+ * @param z The Z component.
23
+ */
24
+ constructor(x: number, y: number, z: number);
25
+ /**
26
+ * Sets the vector to new coordinates.
27
+ * @param x The new X component for the vector.
28
+ * @param y The new Y component for the vector.
29
+ * @param z The new Z component for the vector.
30
+ */
31
+ setXYZ(x: number, y: number, z: number): void;
32
+ /**
33
+ * Returns the dot product between two vectors.
34
+ * @param vector The other vector.
35
+ * @returns The dot product between the two vectors.
36
+ */
37
+ dot(vector: Vector3): number;
38
+ /**
39
+ * Returns the dot product between two vectors.
40
+ * @param x The X component of the other vector.
41
+ * @param y The Y component of the other vector.
42
+ * @param z The Z component of the other vector.
43
+ * @returns The dot product between the two vectors.
44
+ */
45
+ dotXYZ(x: number, y: number, z: number): number;
46
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A vector with 3 components, labeled: `X`, `Y`, `Z`.
3
+ * @group Math
4
+ */
5
+ export class Vector3 {
6
+ /**
7
+ * The X component of the vector.
8
+ */
9
+ x;
10
+ /**
11
+ * The Y component of the vector.
12
+ */
13
+ y;
14
+ /**
15
+ * The Z component of the vector.
16
+ */
17
+ z;
18
+ /**
19
+ * Constructs a new {@linkcode Vector3}.
20
+ * @param x The X component.
21
+ * @param y The Y component.
22
+ * @param z The Z component.
23
+ */
24
+ constructor(x, y, z) {
25
+ this.x = x;
26
+ this.y = y;
27
+ this.z = z;
28
+ }
29
+ /**
30
+ * Sets the vector to new coordinates.
31
+ * @param x The new X component for the vector.
32
+ * @param y The new Y component for the vector.
33
+ * @param z The new Z component for the vector.
34
+ */
35
+ setXYZ(x, y, z) {
36
+ this.x = x;
37
+ this.y = y;
38
+ this.z = z;
39
+ }
40
+ /**
41
+ * Returns the dot product between two vectors.
42
+ * @param vector The other vector.
43
+ * @returns The dot product between the two vectors.
44
+ */
45
+ dot(vector) {
46
+ return this.dotXYZ(vector.x, vector.y, vector.z);
47
+ }
48
+ /**
49
+ * Returns the dot product between two vectors.
50
+ * @param x The X component of the other vector.
51
+ * @param y The Y component of the other vector.
52
+ * @param z The Z component of the other vector.
53
+ * @returns The dot product between the two vectors.
54
+ */
55
+ dotXYZ(x, y, z) {
56
+ return this.x * x + this.y * y + this.z * z;
57
+ }
58
+ }
59
+ //# sourceMappingURL=vector3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector3.js","sourceRoot":"","sources":["../../source/math/vector3.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,OAAO;IAClB;;OAEG;IACH,CAAC,CAAS;IAEV;;OAEG;IACH,CAAC,CAAS;IAEV;;OAEG;IACH,CAAC,CAAS;IAEV;;;;;OAKG;IACH,YAAY,CAAS,EAAE,CAAS,EAAE,CAAS;QACzC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;QACpC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,MAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;QACpC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;CACF"}
package/lib/nil.d.ts CHANGED
@@ -26,6 +26,7 @@ export declare function isNil<T>(subject: Maybe<T>): subject is Nil;
26
26
  export declare function is<T>(nilable: Maybe<T>, InstanceType: ConstructorOf<T>): nilable is T;
27
27
  /**
28
28
  * Thrown when an unexpected nil value was encountered.
29
+ * @group Errors
29
30
  */
30
31
  export declare class UnexpectedNilError extends Error {
31
32
  /**
package/lib/nil.js CHANGED
@@ -20,6 +20,7 @@ export function is(nilable, InstanceType) {
20
20
  }
21
21
  /**
22
22
  * Thrown when an unexpected nil value was encountered.
23
+ * @group Errors
23
24
  */
24
25
  export class UnexpectedNilError extends Error {
25
26
  /**
package/lib/nil.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"nil.js","sourceRoot":"","sources":["../source/nil.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,UAAU,KAAK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