forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
victor.d.ts
355 lines (293 loc) · 7.93 KB
/
victor.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
// Type definitions for Victor.js 0.2.5
// Project: http://victorjs.org/
// Definitions by: Ivane Gegia <https://twitter.com/ivanegegia>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface VictorCoordinates
{
x:number
y:number
}
declare class Victor
{
x:number;
y:number;
/**
* Can be used without the new keyword.
* @param x The X component
* @param y The Y component
*/
constructor(x:number,y:number);
/**
* Creates vector from array.
* @param arr array An array that contains the X component in the first element and the Y component in the second
*/
static fromArray(arr:Array<number>):Victor;
/**
* Creates vector from object.
* @param obj An object containing the X component in the x property and the Y component in the y property
*/
static fromObject(obj:VictorCoordinates):Victor;
/**
* Creates a new Victor with the same X and Y components.
*/
clone():Victor;
/**
* Copies the X component of another vector in to itself.
* @param vector
*/
copyX(vector:Victor):Victor;
/**
* Copies the Y component of another vector in to itself.
* @param vector
*/
copyY(vector:Victor):Victor;
/**
* Copies the X and Y components of another vector in to itself.
* @param vector
*/
copy(vector:Victor):Victor;
/**
* Returns a string representation of the X and Y components.
*/
toString():string;
/**
* Returns an array representation of the X and Y components.
*/
toArray():Array<number>;
/**
* Returns an object representation of tha X and Y components.
*/
toObject():VictorCoordinates;
/**
* Adds another vector's X component to itself.
* @param vector
*/
addX(vector:Victor):Victor;
/**
* Adds another vector's Y component to itself.
* @param vector
*/
addY(vector:Victor):Victor;
/**
* Adds another vector to itself.
* @param vector
*/
add(vector:Victor):Victor;
/**
* Subtracts another vector's X component from itself.
* @param vector
*/
subtractX(vector:Victor):Victor;
/**
* Subtracts another vector's Y component from itself.
* @param vector
*/
subtractY(vector:Victor):Victor;
/**
* Subtracts another vector from itself.
* @param vector
*/
subtract(vector:Victor):Victor;
/**
* Multiplies the X component with the X component of another vector.
* @param vector
*/
multiplyX(vector:Victor):Victor;
/**
* Multiplies the Y component with the Y component of another vector.
* @param vector
*/
multiplyY(vector:Victor):Victor;
/**
* Multiplies both components with another vector.
* @param vector
*/
multiply(vector:Victor):Victor;
/**
* Divides the X component by the X component of another vector.
* @param vector
*/
divideX(vector:Victor):Victor;
/**
* Divides the Y component by the Y component of another vector.
* @param vector
*/
divideY(vector:Victor):Victor;
/**
* Divides both components by another vector.
* @param scalar
*/
divide(scalar:Victor):Victor;
/**
* Inverts the X component.
*/
invertX():Victor;
/**
* Inverts the Y component.
*/
invertY():Victor;
/**
* Inverts both components.
*/
invert():Victor;
/**
* Performs a linear blend / interpolation of the X component towards another vector.
* @param vector Number amount Value between 0 and 1. Default: 0.5
* @param ammount
*/
mixX(vector:Victor, ammount:number):Victor;
/**
* Performs a linear blend / interpolation of the Y component towards another vector.
* @param vector
* @param ammount
*/
mixY(vector:Victor, ammount:number):Victor;
/**
* Performs a linear blend / interpolation towards another vector.
* @param vector
* @param ammount
*/
mix(vector:Victor, ammount:number):Victor;
/**
* Normalizes the vector by scaling it down to a length of 1 while keeping its direction.
*/
normalize():Victor;
/**
* Alias of normalize.
*/
norm():Victor;
/**
* If either component is greater than max, multiplies the component by multiplier.
* @param max
* @param multiplier
*/
limit(max:number, multiplier:number):Victor;
/**
* Rounds the components to integer numbers.
*/
unfloat():Victor;
/**
* Rotates the vector to a certain angle, in radians CCW from +X axis.
* @param angle
*/
rotate(angle:number):Victor;
/**
* Same as rotate but uses degrees
* @param angle
*/
rotateDeg(angle:number):Victor;
/**
* Rotates the vector by a rotation angle, given in radians CCW from +X axis.
* @param rotation
*/
rotateBy(rotation:number):Victor;
/**
* Same as rotateBy but uses degrees
* @param rotation
*/
rotateByDeg(rotation:number):Victor;
/**
* Randomizes the X component with a value between topLeft and bottomRight.
* @param topLeft
* @param bottomRight
*/
randomizeX(topLeft:Victor, bottomRight:Victor):Victor;
/**
* Randomizes the Y component with a value between topLeft and bottomRight.
* @param topLeft
* @param bottomRight
*/
randomizeY(topLeft:Victor, bottomRight:Victor):Victor;
/**
* Randomizes the components with a value between topLeft and bottomRight.
* @param topLeft
* @param bottomRight
*/
randomize(topLeft:Victor, bottomRight:Victor):Victor;
/**
* Randomly randomizes either the X component or the Y component with a value between topLeft and bottomRight.
* @param topLeft
* @param bottomRight
*/
randomizeAny(topLeft:Victor, bottomRight:Victor):Victor;
/**
* Returns the dot product of two vectors.
* @param vector
*/
dot(vector:Victor):number;
/**
* Returns the cross product of two vectors.
* @param vector
*/
cross(vector:Victor):number;
/**
* Returns the length / magnitude.
*/
length():number;
/**
* Alias for length.
*/
magnitude():number;
/**
* Returns the squared length / magnitude. If the length is only needed for comparison, this function is faster than length.
*/
lengthSq():number;
/**
* Returns the distance of the X component from another vector.
* @param vector
*/
distanceX(vector:Victor):number;
/**
* Same as distanceX but always returns an absolute value.
* @param vector
*/
absDistanceX(vector:Victor):number;
/**
* Returns the distance of the Y component from another vector.
* @param vector
*/
distanceY(vector:Victor):number;
/**
* Same as distanceY but always returns an absolute value.
* @param vector
*/
absDistanceY(vector:Victor):number;
/**
* Returns the euclidean distance between two vectors.
* @param vector
*/
distance(vector:Victor):number;
/**
* Returns the squared euclidean distance between two vectors. If the distance is only needed for comparison, this function is faster than distance.
* @param vector
*/
distanceSq(vector:Victor):number;
/**
* Returns the angle towards X in radians.
*/
horizontalAngle():number;
/**
* Alias for horizontalAngle.
*/
angle():number;
/**
* Alias for horizontalAngle.
*/
direction():number;
/**
* Same as horizontalAngle but returns degrees.
*/
horizontalAngleDeg():number;
/**
* Alias for horizontalAngleDeg.
*/
angleDeg():number;
/**
* Returns the angle towards Y in radians.
*/
verticalAngle():number;
/**
* Same as verticalAngle but returns degrees.
*/
verticalAngleDeg():number;
}