rapid-render 0.1.21 → 1.0.0

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/dist/math.d.ts CHANGED
@@ -1,317 +1,4 @@
1
- import { IMathStruct as IMathObject, ITransformOptions, WebGLContext } from "./interface";
2
- /**
3
- * @ignore
4
- */
5
- export declare enum ArrayType {
6
- Float32 = 0,
7
- Uint32 = 1,
8
- Uint16 = 2
9
- }
10
- /**
11
- * @ignore
12
- */
13
- export declare class DynamicArrayBuffer {
14
- usedElemNum: number;
15
- protected typedArray: Float32Array | Uint32Array | Uint16Array;
16
- private arrayType;
17
- protected maxElemNum: number;
18
- readonly bytePerElem: number;
19
- private arraybuffer;
20
- private uint32?;
21
- private float32?;
22
- private uint16?;
23
- constructor(arrayType: ArrayType);
24
- getArrayType(arrayType: ArrayType): Uint16ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor;
25
- updateTypedArray(): void;
26
- clear(): void;
27
- /**
28
- * resize the array
29
- * @param size
30
- * @returns
31
- */
32
- resize(size?: number): void;
33
- protected setMaxSize(size?: number): void;
34
- pushUint32(value: number): void;
35
- pushFloat32(value: number): void;
36
- pushUint16(value: number): void;
37
- /**
38
- * pop a element
39
- * @param num
40
- */
41
- pop(num: number): void;
42
- /**
43
- * get the array
44
- * @param begin
45
- * @param end
46
- * @returns
47
- */
48
- getArray(begin?: number, end?: number): Uint16Array | Uint32Array | Float32Array;
49
- /**
50
- * length of the array
51
- */
52
- get length(): number;
53
- }
54
- /**
55
- * @ignore
56
- */
57
- export declare class WebglBufferArray extends DynamicArrayBuffer {
58
- buffer: WebGLBuffer;
59
- gl: WebGLContext;
60
- protected dirty: boolean;
61
- readonly type: number;
62
- /**
63
- * webglbuffer 中的大小
64
- */
65
- private webglBufferSize;
66
- readonly usage: number;
67
- constructor(gl: WebGLContext, arrayType: ArrayType, type?: number, usage?: number);
68
- pushFloat32(value: number): void;
69
- pushUint32(value: number): void;
70
- pushUint16(value: number): void;
71
- /**
72
- * bind buffer to gpu
73
- */
74
- bindBuffer(): void;
75
- /**
76
- * array data to gpu
77
- */
78
- bufferData(): void;
79
- }
80
- export declare class MatrixStack extends DynamicArrayBuffer {
81
- constructor();
82
- /**
83
- * push a matrix to the stack
84
- */
85
- pushMat(): void;
86
- /**
87
- * pop a matrix from the stack
88
- */
89
- popMat(): void;
90
- /**
91
- * push a matrix and indentiy it
92
- */
93
- pushIdentity(): void;
94
- /**
95
- * Translates the current matrix by the specified x and y values.
96
- * @param x - The amount to translate horizontally.
97
- * @param y - The amount to translate vertically.
98
- */
99
- translate(x: number | Vec2, y?: number): void;
100
- /**
101
- * Rotates the current matrix by the specified angle.
102
- * @param angle - The angle, in radians, to rotate the matrix by.
103
- */
104
- rotate(angle: number): void;
105
- /**
106
- * Multiplies the current matrix on the top of the stack by a scaling transformation.
107
- * @param x - The amount to scale the matrix horizontally.
108
- * @param y - The amount to scale the matrix vertically. If not specified, x is used for both horizontal and vertical scaling.
109
- */
110
- scale(x: number | Vec2, y?: number): void;
111
- /**
112
- * Transforms a point by applying the current matrix stack.
113
- * @returns The transformed point as an array `[newX, newY]`.
114
- */
115
- apply(x: number | Vec2, y?: number): Vec2 | number[];
116
- /**
117
- * Obtain the inverse matrix of the current matrix
118
- * @returns inverse matrix
119
- */
120
- getInverse(): Float32Array;
121
- /**
122
- * Get a copy of the current transformation matrix
123
- * @returns matrix
124
- */
125
- getTransform(): Float32Array;
126
- /**
127
- * Set the current transformation matrix
128
- * @param array
129
- */
130
- setTransform(array: Float32Array | number[]): void;
131
- /**
132
- * Get the global position in world space
133
- * @returns The current matrix position in world space
134
- */
135
- getGlobalPosition(): Vec2;
136
- /**
137
- * Set the global position in world space
138
- * @param x - x coordinate or Vec2 object
139
- * @param y - y coordinate (ignored if first parameter is Vec2)
140
- */
141
- setGlobalPosition(x: number | Vec2, y?: number): void;
142
- /**
143
- * Get the global rotation angle
144
- * @returns The current matrix rotation angle in radians
145
- */
146
- getGlobalRotation(): number;
147
- /**
148
- * Set the global rotation angle
149
- * @param angle - rotation angle in radians
150
- */
151
- setGlobalRotation(angle: number): void;
152
- /**
153
- * Get the global scale
154
- * @returns The current matrix scale values
155
- */
156
- getGlobalScale(): Vec2;
157
- /**
158
- * Set the global scale
159
- * @param x - x scale or Vec2 object
160
- * @param y - y scale (ignored if first parameter is Vec2)
161
- */
162
- setGlobalScale(x: number | Vec2, y?: number): void;
163
- globalToLocal(global: Vec2): Vec2;
164
- localToGlobal(local: Vec2): Vec2;
165
- /**
166
- * Convert the current matrix to a CSS transform string
167
- * @returns CSS transform string representation of the matrix
168
- */
169
- toCSSTransform(): string;
170
- /**
171
- * Reset the current matrix to identity matrix
172
- */
173
- identity(): void;
174
- /**
175
- * Apply the transform to the current matrix
176
- * @param transform - The transform to apply
177
- * @returns offset position
178
- */
179
- applyTransform(transform: ITransformOptions, width?: number, height?: number): {
180
- offsetX: number;
181
- offsetY: number;
182
- };
183
- applyTransformAfter(transform: ITransformOptions): void;
184
- }
185
- /**
186
- * @ignore
187
- */
188
- export declare class WebglElementBufferArray extends WebglBufferArray {
189
- constructor(gl: WebGLContext, elemVertPerObj: number, vertexPerObject: number, maxBatch: number);
190
- protected addObject(_vertex?: number): void;
191
- }
192
- /**
193
- * Represents a color with red, green, blue, and alpha (transparency) components.
194
- */
195
- export declare class Color implements IMathObject<Color> {
196
- private _r;
197
- private _g;
198
- private _b;
199
- private _a;
200
- uint32: number;
201
- /**
202
- * Creates an instance of Color.
203
- * @param r - The red component (0-255).
204
- * @param g - The green component (0-255).
205
- * @param b - The blue component (0-255).
206
- * @param a - The alpha component (0-255).
207
- */
208
- constructor(r: number, g: number, b: number, a?: number);
209
- /**
210
- * Gets the red component.
211
- */
212
- get r(): number;
213
- /**
214
- * Sets the red component and updates the uint32 representation.
215
- * @param value - The new red component (0-255).
216
- */
217
- set r(value: number);
218
- /**
219
- * Gets the green component.
220
- */
221
- get g(): number;
222
- /**
223
- * Sets the green component and updates the uint32 representation.
224
- * @param value - The new green component (0-255).
225
- */
226
- set g(value: number);
227
- /**
228
- * Gets the blue component.
229
- */
230
- get b(): number;
231
- /**
232
- * Sets the blue component and updates the uint32 representation.
233
- * @param value - The new blue component (0-255).
234
- */
235
- set b(value: number);
236
- /**
237
- * Gets the alpha component.
238
- */
239
- get a(): number;
240
- /**
241
- * Sets the alpha component and updates the uint32 representation.
242
- * @param value - The new alpha component (0-255).
243
- */
244
- set a(value: number);
245
- /**
246
- * Updates the uint32 representation of the color.
247
- * @private
248
- */
249
- private updateUint;
250
- /**
251
- * Sets the RGBA values of the color and updates the uint32 representation.
252
- * @param r - The red component (0-255).
253
- * @param g - The green component (0-255).
254
- * @param b - The blue component (0-255).
255
- * @param a - The alpha component (0-255).
256
- */
257
- setRGBA(r: number, g: number, b: number, a: number): void;
258
- /**
259
- * Copies the RGBA values from another color.
260
- * @param color - The color to copy from.
261
- */
262
- copy(color: Color): void;
263
- /**
264
- * Clone the current color
265
- * @returns A new `Color` instance with the same RGBA values.
266
- */
267
- clone(): Color;
268
- /**
269
- * Checks if the current color is equal to another color.
270
- * @param color - The color to compare with.
271
- * @returns True if the colors are equal, otherwise false.
272
- */
273
- equal(color: Color): boolean;
274
- /**
275
- * Creates a Color instance from a hexadecimal color string.
276
- * @param hexString - The hexadecimal color string, e.g., '#RRGGBB' or '#RRGGBBAA'.
277
- * @returns A new Color instance.
278
- */
279
- static fromHex(hexString: string): Color;
280
- /**
281
- * Adds the components of another color to this color, clamping the result to 255.
282
- * @param color - The color to add.
283
- * @returns A new Color instance with the result of the addition.
284
- */
285
- add(color: Color): Color;
286
- /**
287
- * Subtracts the components of another color from this color, clamping the result to 0.
288
- * @param color - The color to subtract.
289
- * @returns A new Color instance with the result of the subtraction.
290
- */
291
- subtract(color: Color): Color;
292
- divide(color: Color | number): Color;
293
- multiply(color: Color | number): Color;
294
- clamp(): void;
295
- static Red: Color;
296
- static Green: Color;
297
- static Blue: Color;
298
- static Yellow: Color;
299
- static Purple: Color;
300
- static Orange: Color;
301
- static Pink: Color;
302
- static Gray: Color;
303
- static Brown: Color;
304
- static Cyan: Color;
305
- static Magenta: Color;
306
- static Lime: Color;
307
- static White: Color;
308
- static Black: Color;
309
- static TRANSPARENT: Color;
310
- }
311
- /**
312
- * Represents a 2D vector with x and y components.
313
- */
314
- export declare class Vec2 implements IMathObject<Vec2> {
1
+ export declare class Vec2 {
315
2
  x: number;
316
3
  y: number;
317
4
  static ZERO: Vec2;
@@ -320,202 +7,40 @@ export declare class Vec2 implements IMathObject<Vec2> {
320
7
  static DOWN: Vec2;
321
8
  static LEFT: Vec2;
322
9
  static RIGHT: Vec2;
323
- /**
324
- * Creates an instance of Vec2.
325
- * @param x - The x coordinate (default is 0).
326
- * @param y - The y coordinate (default is 0).
327
- */
328
10
  constructor(x?: number, y?: number);
329
- set(x: number | number[], y?: number): this;
330
- /**
331
- * Adds another vector to this vector.
332
- * @param v - The vector to add.
333
- * @returns A new Vec2 instance with the result of the addition.
334
- */
11
+ set(x: number, y?: number): Vec2;
335
12
  add(v: Vec2): Vec2;
336
- /**
337
- * Subtracts another vector from this vector.
338
- * @param v - The vector to subtract.
339
- * @returns A new Vec2 instance with the result of the subtraction.
340
- */
341
13
  subtract(v: Vec2): Vec2;
342
- /**
343
- * Multiplies the vector by a scalar or another vector.
344
- * @param f - The scalar value or vector to multiply by.
345
- * @returns A new Vec2 instance with the result of the multiplication.
346
- */
14
+ sub(v: Vec2): Vec2;
347
15
  multiply(f: number | Vec2): Vec2;
348
- /**
349
- * Divides the vector by a scalar or another vector.
350
- * @param f - The scalar value or vector to divide by.
351
- * @returns A new Vec2 instance with the result of the division.
352
- */
16
+ mul(f: number | Vec2): Vec2;
353
17
  divide(f: number | Vec2): Vec2;
354
- /**
355
- * Calculates the dot product of this vector with another vector.
356
- * @param v - The other vector.
357
- * @returns The dot product result.
358
- */
359
18
  dot(v: Vec2): number;
360
- /**
361
- * Calculates the cross product of this vector with another vector.
362
- * @param v - The other vector.
363
- * @returns The cross product result.
364
- */
365
19
  cross(v: Vec2): number;
366
- /**
367
- * Calculates the distance to another point.
368
- * @param v - The other point.
369
- * @returns The distance between the two points.
370
- */
371
20
  distanceTo(v: Vec2): number;
372
- /**
373
- * Clones the vector.
374
- * @returns A new Vec2 instance with the same x and y values.
375
- */
376
21
  clone(): Vec2;
377
- /**
378
- * Copy the vector
379
- * @param vec - The vector to copy.
380
- */
381
- copy(vec: Vec2): void;
382
- /**
383
- * Check if the vector is equal to another vector.
384
- * @param vec - The vector to compare with.
385
- * @returns True if the vectors are equal, otherwise false.
386
- */
387
- equal(vec: Vec2): boolean;
388
- /**
389
- * Rotates the vector 90 degrees counterclockwise.
390
- * @returns The current instance with updated values.
391
- */
22
+ to(vec: Vec2): void;
23
+ copy(): Vec2;
24
+ equals(vec: Vec2): boolean;
392
25
  perpendicular(): this;
393
- /**
394
- * Inverts the direction of the vector.
395
- * @returns The current instance with updated values.
396
- */
397
26
  invert(): this;
398
- /**
399
- * Calculates the length of the vector.
400
- * @returns The length of the vector.
401
- */
27
+ inverted(): Vec2;
402
28
  length(): number;
403
- /**
404
- * Normalizes the vector to have a length of 1.
405
- * @returns The current instance with updated values.
406
- */
29
+ squaredLength(): number;
407
30
  normalize(): this;
408
- /**
409
- * Calculates the angle of the vector relative to the x-axis.
410
- * @returns The angle of the vector.
411
- */
31
+ normalized(): Vec2;
32
+ fix(limit?: number): void;
33
+ fixed(limit?: number): Vec2;
412
34
  angle(): number;
413
- /**
414
- * Calculates the middle point between the current vector and another vector.
415
- * @param other - The other vector.
416
- * @returns A new vector representing the middle point between the current vector and the other vector.
417
- */
418
- middle(other: Vec2): Vec2;
419
- /**
420
- * Returns a new vector with the absolute values of the components.
421
- * @returns A new vector with absolute values.
422
- */
423
35
  abs(): Vec2;
424
- /**
425
- * Returns a new vector with floored components.
426
- * @returns A new vector with components rounded down to the nearest integer.
427
- */
428
36
  floor(): Vec2;
429
- /**
430
- * Returns a new vector with ceiled components.
431
- * @returns A new vector with components rounded up to the nearest integer.
432
- */
433
37
  ceil(): Vec2;
434
- /**
435
- * Snaps the vector components to the nearest increment.
436
- * @param increment - The increment to snap to.
437
- * @returns A new vector with components snapped to the nearest increment.
438
- */
439
- snap(increment: number): Vec2;
440
- /**
441
- * Converts the vector to a string representation.
442
- * @returns A string containing the vector's x and y coordinates.
443
- */
444
38
  stringify(): string;
445
- /**
446
- * Converts an array of coordinate pairs into an array of Vec2 instances.
447
- * @param array - An array of [x, y] coordinate pairs.
448
- * @returns An array of Vec2 instances.
449
- */
39
+ clear(): void;
40
+ isPrettyMuchZero(): boolean;
41
+ isZero(): boolean;
42
+ isNotZero(): boolean;
43
+ setToPolar(azimuth: number, radius?: number): this;
450
44
  static FromArray(array: number[][]): Vec2[];
451
45
  static fromAngle(angle: number): Vec2;
452
- /**
453
- * Calculates the angle between two vectors.
454
- * @param v - The other vector.
455
- * @returns The angle between the two vectors in radians.
456
- */
457
- angleBetween(v: Vec2): number;
458
- }
459
- /**
460
- * Provides utility methods for mathematical conversions.
461
- */
462
- export declare class MathUtils {
463
- /**
464
- * Converts degrees to radians.
465
- * @param degrees - The angle in degrees.
466
- * @returns The equivalent angle in radians.
467
- */
468
- static deg2rad(degrees: number): number;
469
- /**
470
- * Converts radians to degrees.
471
- * @param rad - The angle in radians.
472
- * @returns The equivalent angle in degrees.
473
- */
474
- static rad2deg(rad: number): number;
475
- /**
476
- * Normalizes an angle in degrees to be within the range of 0 to 360 degrees.
477
- * @param degrees - The angle in degrees to be normalized.
478
- * @returns The normalized angle in degrees.
479
- */
480
- static normalizeDegrees(degrees: number): number;
481
- }
482
- export declare class Random {
483
- /**
484
- * 生成指定范围内的随机浮点数
485
- * @param min - 最小值
486
- * @param max - 最大值
487
- * @returns 随机浮点数
488
- */
489
- static float(min: number, max: number): number;
490
- /**
491
- * 生成指定范围内的随机整数
492
- * @param min - 最小值
493
- * @param max - 最大值
494
- * @returns 随机整数
495
- */
496
- static int(min: number, max: number): number;
497
- /**
498
- * 生成随机角度(0-360度)
499
- * @returns 随机角度(弧度)
500
- */
501
- static angle(): number;
502
- /**
503
- * 生成指定范围内的随机向量
504
- * @param minX - 最小X值
505
- * @param maxX - 最大X值
506
- * @param minY - 最小Y值
507
- * @param maxY - 最大Y值
508
- * @returns 随机向量
509
- */
510
- static vector(minX: number, maxX: number, minY: number, maxY: number): Vec2;
511
- /**
512
- * 生成具有随机方向和指定长度的向量
513
- * @param length - 向量长度
514
- * @returns 随机方向向量
515
- */
516
- static direction(length: number): Vec2;
517
- static randomColor(minColor: Color, maxColor: Color): Color;
518
- static pick(array: any[]): any;
519
- static pickWeight(array: [any, number][]): any;
520
- static scalarOrRange<T extends number | Vec2 | Color>(range?: T | [T, T], defaultValue?: T): T;
521
46
  }