@oliversalzburg/js-utils 0.0.8 → 0.0.10
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/README.md +4 -0
- package/_site/assets/highlight.css +57 -0
- package/_site/assets/main.js +59 -0
- package/_site/assets/navigation.js +1 -0
- package/_site/assets/search.js +1 -0
- package/_site/assets/style.css +1383 -0
- package/_site/classes/AbstractError.html +28 -0
- package/_site/classes/Canvas.html +44 -0
- package/_site/classes/InternalError.html +32 -0
- package/_site/classes/InvalidArgumentError.html +28 -0
- package/_site/classes/InvalidOperationError.html +28 -0
- package/_site/classes/NotImplementedError.html +27 -0
- package/_site/classes/PermissionViolationError.html +28 -0
- package/_site/classes/Random.html +43 -0
- package/_site/classes/RenderLoop.html +30 -0
- package/_site/classes/ResourceConflictError.html +27 -0
- package/_site/classes/UnexpectedNilError.html +15 -0
- package/_site/classes/UnknownError.html +31 -0
- package/_site/classes/Vector2.html +113 -0
- package/_site/classes/Vector3.html +28 -0
- package/_site/functions/addVector2.html +5 -0
- package/_site/functions/blend.html +8 -0
- package/_site/functions/blendAdditive.html +8 -0
- package/_site/functions/blendSubtractive.html +8 -0
- package/_site/functions/cosDeg.html +4 -0
- package/_site/functions/deg2rad.html +4 -0
- package/_site/functions/difference.html +7 -0
- package/_site/functions/distance.html +7 -0
- package/_site/functions/errorToJSON.html +4 -0
- package/_site/functions/errorToRecord.html +4 -0
- package/_site/functions/errorToSimpleSerializable.html +4 -0
- package/_site/functions/filterType.html +7 -0
- package/_site/functions/formatString.html +7 -0
- package/_site/functions/formatStringTemplate.html +7 -0
- package/_site/functions/fromRGB.html +7 -0
- package/_site/functions/fromRGBA.html +7 -0
- package/_site/functions/getA.html +4 -0
- package/_site/functions/getB.html +4 -0
- package/_site/functions/getDocumentElementTypeById.html +9 -0
- package/_site/functions/getG.html +4 -0
- package/_site/functions/getR.html +4 -0
- package/_site/functions/intersect.html +8 -0
- package/_site/functions/is.html +7 -0
- package/_site/functions/isError.html +4 -0
- package/_site/functions/isInteger.html +4 -0
- package/_site/functions/isNil.html +5 -0
- package/_site/functions/isqrt.html +4 -0
- package/_site/functions/multiplyVector2.html +5 -0
- package/_site/functions/mustExist.html +6 -0
- package/_site/functions/nextPalette.html +2 -0
- package/_site/functions/putPixel32.html +7 -0
- package/_site/functions/putPixel32Add.html +7 -0
- package/_site/functions/putPixel32Sub.html +7 -0
- package/_site/functions/putSubPixel32.html +8 -0
- package/_site/functions/rad2deg.html +4 -0
- package/_site/functions/randomRange.html +6 -0
- package/_site/functions/safeRGBComponent.html +4 -0
- package/_site/functions/seedFromString.html +5 -0
- package/_site/functions/shuffleArray.html +5 -0
- package/_site/functions/sinDeg.html +4 -0
- package/_site/functions/sleep.html +4 -0
- package/_site/functions/somecolor.html +4 -0
- package/_site/functions/subtractVector2.html +5 -0
- package/_site/functions/toGrayScale.html +4 -0
- package/_site/functions/unknownToError.html +6 -0
- package/_site/index.html +1 -0
- package/_site/modules.html +72 -0
- package/_site/types/AnyConstructor.html +2 -0
- package/_site/types/AnyFunction.html +2 -0
- package/_site/types/ConstructorOf.html +2 -0
- package/_site/types/FunctionReturning.html +2 -0
- package/_site/types/Maybe.html +2 -0
- package/_site/types/Mixin.html +3 -0
- package/_site/types/Nil.html +3 -0
- package/_site/types/RenderLoopCallback.html +2 -0
- package/_site/types/SerializedError.html +2 -0
- package/_site/variables/PALETTES.html +2 -0
- package/_site/variables/TWO_PI.html +2 -0
- package/_site/variables/random-1.html +2 -0
- package/lib/array.d.ts +8 -0
- package/lib/array.js +8 -0
- package/lib/array.js.map +1 -1
- package/lib/dom/core.d.ts +3 -2
- package/lib/dom/core.js +3 -2
- package/lib/dom/core.js.map +1 -1
- package/lib/error-serializer.d.ts +12 -6
- package/lib/error-serializer.js +10 -5
- package/lib/error-serializer.js.map +1 -1
- package/lib/errors/AbstractError.d.ts +4 -16
- package/lib/errors/AbstractError.js +9 -19
- package/lib/errors/AbstractError.js.map +1 -1
- package/lib/errors/InternalError.d.ts +6 -5
- package/lib/errors/InternalError.js +11 -10
- package/lib/errors/InternalError.js.map +1 -1
- package/lib/errors/InvalidArgumentError.d.ts +2 -1
- package/lib/errors/InvalidArgumentError.js +7 -4
- package/lib/errors/InvalidArgumentError.js.map +1 -1
- package/lib/errors/InvalidOperationError.d.ts +2 -1
- package/lib/errors/InvalidOperationError.js +7 -4
- package/lib/errors/InvalidOperationError.js.map +1 -1
- package/lib/errors/NotImplementedError.d.ts +2 -1
- package/lib/errors/NotImplementedError.js +7 -4
- package/lib/errors/NotImplementedError.js.map +1 -1
- package/lib/errors/PermissionViolationError.d.ts +2 -1
- package/lib/errors/PermissionViolationError.js +7 -4
- package/lib/errors/PermissionViolationError.js.map +1 -1
- package/lib/errors/ResourceConflictError.d.ts +2 -1
- package/lib/errors/ResourceConflictError.js +7 -4
- package/lib/errors/ResourceConflictError.js.map +1 -1
- package/lib/errors/UnknownError.d.ts +6 -5
- package/lib/errors/UnknownError.js +11 -8
- package/lib/errors/UnknownError.js.map +1 -1
- package/lib/graphics/canvas.d.ts +60 -27
- package/lib/graphics/canvas.js +77 -26
- package/lib/graphics/canvas.js.map +1 -1
- package/lib/graphics/core.d.ts +18 -0
- package/lib/graphics/core.js +18 -0
- package/lib/graphics/core.js.map +1 -1
- package/lib/graphics/render-loop.d.ts +37 -6
- package/lib/graphics/render-loop.js +36 -14
- package/lib/graphics/render-loop.js.map +1 -1
- package/lib/math/core.d.ts +12 -1
- package/lib/math/core.js +12 -1
- package/lib/math/core.js.map +1 -1
- package/lib/math/vector2.d.ts +38 -2
- package/lib/math/vector2.js +53 -2
- package/lib/math/vector2.js.map +1 -1
- package/lib/math/vector3.d.ts +2 -1
- package/lib/math/vector3.js +2 -1
- package/lib/math/vector3.js.map +1 -1
- package/lib/nil.d.ts +1 -0
- package/lib/nil.js +1 -0
- package/lib/nil.js.map +1 -1
- package/lib/random.d.ts +34 -1
- package/lib/random.js +160 -2
- package/lib/random.js.map +1 -1
- package/lib/string-formatter.d.ts +2 -0
- package/lib/string-formatter.js +2 -0
- package/lib/string-formatter.js.map +1 -1
- package/package.json +3 -1
|
@@ -1,27 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Conveniently provides a way to have a render loop called at
|
|
3
3
|
* a constant frame rate.
|
|
4
|
+
* @group Graphics
|
|
4
5
|
*/
|
|
5
6
|
export class RenderLoop {
|
|
6
7
|
/**
|
|
7
|
-
* The {@
|
|
8
|
+
* The {@linkcode Canvas} we're rendering to.
|
|
8
9
|
*/
|
|
9
10
|
canvas;
|
|
10
11
|
/**
|
|
11
12
|
* A function that we call when a new frame should be drawn.
|
|
12
13
|
*/
|
|
13
14
|
renderLoop;
|
|
15
|
+
/**
|
|
16
|
+
* The configuration that was used for this render loop.
|
|
17
|
+
*/
|
|
18
|
+
options;
|
|
19
|
+
/**
|
|
20
|
+
* The timestamp we got for the previous frame.
|
|
21
|
+
*/
|
|
14
22
|
previousTimestamp;
|
|
23
|
+
/**
|
|
24
|
+
* Our `#main` function bound to this classes
|
|
25
|
+
* for easier invokation through external callers.
|
|
26
|
+
*/
|
|
15
27
|
boundMain;
|
|
28
|
+
/**
|
|
29
|
+
* The ID of our {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame requestAnimationFrame} request.
|
|
30
|
+
*/
|
|
16
31
|
frameRequestId = null;
|
|
17
32
|
/**
|
|
18
|
-
* Constructs a new {@
|
|
33
|
+
* Constructs a new {@linkcode RenderLoop}.
|
|
19
34
|
* @param renderLoop The function to call when a new frame should be drawn.
|
|
20
|
-
* @param canvas
|
|
21
|
-
*
|
|
35
|
+
* @param canvas The {@linkcode Canvas} we're rendering to.
|
|
36
|
+
* @param options The configuration for thie {@linkcode RenderLoop}.
|
|
22
37
|
*/
|
|
23
|
-
constructor(renderLoop, canvas) {
|
|
38
|
+
constructor(renderLoop, canvas, options = {}) {
|
|
24
39
|
this.canvas = canvas;
|
|
40
|
+
this.options = options;
|
|
25
41
|
this.renderLoop = renderLoop;
|
|
26
42
|
this.previousTimestamp = 0;
|
|
27
43
|
this.boundMain = this.#main.bind(this);
|
|
@@ -59,16 +75,22 @@ export class RenderLoop {
|
|
|
59
75
|
*/
|
|
60
76
|
#drawFrame(timestamp, delta) {
|
|
61
77
|
this.renderLoop(delta, timestamp);
|
|
62
|
-
if (!this.canvas) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
78
|
this.canvas.update();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
if (this.options.onRefresh === "fade") {
|
|
80
|
+
this.canvas.fade();
|
|
81
|
+
}
|
|
82
|
+
if (this.options.onRefresh === "clear") {
|
|
83
|
+
this.canvas.clearWith(0);
|
|
84
|
+
}
|
|
85
|
+
if (this.options.drawFps) {
|
|
86
|
+
const fps = `${Math.round(1000 / delta)}fps`;
|
|
87
|
+
this.canvas.context.strokeStyle = "rgba( 255, 255, 255, 0.85 )";
|
|
88
|
+
this.canvas.context.lineWidth = 5;
|
|
89
|
+
this.canvas.context.strokeText(fps, 4, 14);
|
|
90
|
+
this.canvas.context.fillStyle = "#000000";
|
|
91
|
+
this.canvas.context.fillText(fps, 4, 14);
|
|
92
|
+
}
|
|
93
|
+
this.canvas.render();
|
|
72
94
|
}
|
|
73
95
|
}
|
|
74
96
|
//# sourceMappingURL=render-loop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-loop.js","sourceRoot":"","sources":["../../source/graphics/render-loop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-loop.js","sourceRoot":"","sources":["../../source/graphics/render-loop.ts"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACrB;;OAEG;IACM,MAAM,CAAS;IAExB;;OAEG;IACM,UAAU,CAAqB;IAExC;;OAEG;IACM,OAAO,CAAuC;IAEvD;;OAEG;IACK,iBAAiB,CAAS;IAElC;;;OA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,EAAE,CAAC;SACpB;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,KAAK,OAAO,EAAE;YACtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SAC1B;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACxB,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,6BAA6B,CAAC;YAChE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;YAC1C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;SAC1C;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF"}
|
package/lib/math/core.d.ts
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `PI` times 2.
|
|
3
|
+
* @group Math
|
|
4
|
+
*/
|
|
1
5
|
export declare const TWO_PI: number;
|
|
2
6
|
/**
|
|
3
7
|
* Converts the degrees to radians.
|
|
4
8
|
* @param degrees The degrees to convert to radians.
|
|
5
9
|
* @returns The degrees in radians.
|
|
10
|
+
* @group Math
|
|
6
11
|
*/
|
|
7
12
|
export declare const deg2rad: (degrees: number) => number;
|
|
8
13
|
/**
|
|
9
14
|
* Convertrs the radians to degrees.
|
|
10
15
|
* @param radians The radians to convert to degrees.
|
|
11
16
|
* @returns The radians as degrees.
|
|
17
|
+
* @group Math
|
|
12
18
|
*/
|
|
13
19
|
export declare const rad2deg: (radians: number) => number;
|
|
14
20
|
/**
|
|
15
21
|
* Calculates the sine for a given degree value.
|
|
16
22
|
* @param value The value in degrees to calculate the sine for.
|
|
17
23
|
* @returns The sine for the given value.
|
|
24
|
+
* @group Math
|
|
18
25
|
*/
|
|
19
26
|
export declare const sinDeg: (value: number) => number;
|
|
20
27
|
/**
|
|
21
28
|
* Calculates the cosine for a given degree value.
|
|
22
29
|
* @param value The value in degrees to calculate the cosine for.
|
|
23
30
|
* @returns The cosine for the given value.
|
|
31
|
+
* @group Math
|
|
24
32
|
*/
|
|
25
33
|
export declare const cosDeg: (value: number) => number;
|
|
26
34
|
/**
|
|
@@ -30,17 +38,20 @@ export declare const cosDeg: (value: number) => number;
|
|
|
30
38
|
* @param x2 The X component of the second vector.
|
|
31
39
|
* @param y2 The Y component of the second vector.
|
|
32
40
|
* @returns The distance between the two vectors.
|
|
41
|
+
* @group Math
|
|
33
42
|
*/
|
|
34
43
|
export declare const distance: (x1: number, y1: number, x2: number, y2: number) => number;
|
|
35
44
|
/**
|
|
36
45
|
* Finds the integer square root of a positive number.
|
|
37
46
|
* @param value The value to calcuate the square root for.
|
|
38
47
|
* @returns The square root for the given value.
|
|
48
|
+
* @group Math
|
|
39
49
|
*/
|
|
40
|
-
export declare const
|
|
50
|
+
export declare const isqrt: (value: number) => number;
|
|
41
51
|
/**
|
|
42
52
|
* Checks whether a number is an integer.
|
|
43
53
|
* @param value The value to check.
|
|
44
54
|
* @returns `true` when the value is an integer, `false` otherwise.
|
|
55
|
+
* @group Math
|
|
45
56
|
*/
|
|
46
57
|
export declare const isInteger: (value: number) => boolean;
|
package/lib/math/core.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `PI` times 2.
|
|
3
|
+
* @group Math
|
|
4
|
+
*/
|
|
1
5
|
export const TWO_PI = /* @__PURE__ */ Math.PI * 2;
|
|
2
6
|
/**
|
|
3
7
|
* Converts the degrees to radians.
|
|
4
8
|
* @param degrees The degrees to convert to radians.
|
|
5
9
|
* @returns The degrees in radians.
|
|
10
|
+
* @group Math
|
|
6
11
|
*/
|
|
7
12
|
export const deg2rad = (degrees) => {
|
|
8
13
|
return degrees * (Math.PI / 180);
|
|
@@ -11,6 +16,7 @@ export const deg2rad = (degrees) => {
|
|
|
11
16
|
* Convertrs the radians to degrees.
|
|
12
17
|
* @param radians The radians to convert to degrees.
|
|
13
18
|
* @returns The radians as degrees.
|
|
19
|
+
* @group Math
|
|
14
20
|
*/
|
|
15
21
|
export const rad2deg = (radians) => {
|
|
16
22
|
return radians * (180 / Math.PI);
|
|
@@ -19,6 +25,7 @@ export const rad2deg = (radians) => {
|
|
|
19
25
|
* Calculates the sine for a given degree value.
|
|
20
26
|
* @param value The value in degrees to calculate the sine for.
|
|
21
27
|
* @returns The sine for the given value.
|
|
28
|
+
* @group Math
|
|
22
29
|
*/
|
|
23
30
|
export const sinDeg = (value) => {
|
|
24
31
|
return Math.sin(deg2rad(value));
|
|
@@ -27,6 +34,7 @@ export const sinDeg = (value) => {
|
|
|
27
34
|
* Calculates the cosine for a given degree value.
|
|
28
35
|
* @param value The value in degrees to calculate the cosine for.
|
|
29
36
|
* @returns The cosine for the given value.
|
|
37
|
+
* @group Math
|
|
30
38
|
*/
|
|
31
39
|
export const cosDeg = (value) => {
|
|
32
40
|
return Math.cos(deg2rad(value));
|
|
@@ -38,6 +46,7 @@ export const cosDeg = (value) => {
|
|
|
38
46
|
* @param x2 The X component of the second vector.
|
|
39
47
|
* @param y2 The Y component of the second vector.
|
|
40
48
|
* @returns The distance between the two vectors.
|
|
49
|
+
* @group Math
|
|
41
50
|
*/
|
|
42
51
|
export const distance = (x1, y1, x2, y2) => {
|
|
43
52
|
const distx = x2 - x1;
|
|
@@ -48,8 +57,9 @@ export const distance = (x1, y1, x2, y2) => {
|
|
|
48
57
|
* Finds the integer square root of a positive number.
|
|
49
58
|
* @param value The value to calcuate the square root for.
|
|
50
59
|
* @returns The square root for the given value.
|
|
60
|
+
* @group Math
|
|
51
61
|
*/
|
|
52
|
-
export const
|
|
62
|
+
export const isqrt = (value) => {
|
|
53
63
|
if (0 === value) {
|
|
54
64
|
return 0;
|
|
55
65
|
} // Avoid zero divide
|
|
@@ -65,6 +75,7 @@ export const Isqrt = (value) => {
|
|
|
65
75
|
* Checks whether a number is an integer.
|
|
66
76
|
* @param value The value to check.
|
|
67
77
|
* @returns `true` when the value is an integer, `false` otherwise.
|
|
78
|
+
* @group Math
|
|
68
79
|
*/
|
|
69
80
|
export const isInteger = (value) => {
|
|
70
81
|
return Math.trunc(value) === value;
|
package/lib/math/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../source/math/core.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../source/math/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE;IACzC,OAAO,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE;IACzC,OAAO,OAAO,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE;IACtC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;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
|
/**
|
|
2
2
|
* A vector with 2 components, labeled: `X`, `Y`.
|
|
3
|
+
* @group Math
|
|
3
4
|
*/
|
|
4
5
|
export declare class Vector2 {
|
|
5
6
|
/**
|
|
@@ -11,7 +12,7 @@ export declare class Vector2 {
|
|
|
11
12
|
*/
|
|
12
13
|
y: number;
|
|
13
14
|
/**
|
|
14
|
-
* Constructs a new {@
|
|
15
|
+
* Constructs a new {@linkcode Vector2}.
|
|
15
16
|
* @param x The X component.
|
|
16
17
|
* @param y The Y component.
|
|
17
18
|
*/
|
|
@@ -109,7 +110,7 @@ export declare class Vector2 {
|
|
|
109
110
|
*/
|
|
110
111
|
divideScale(scale: number): this;
|
|
111
112
|
/**
|
|
112
|
-
* Inverts the vector.
|
|
113
|
+
* Inverts the sign of the vector.
|
|
113
114
|
* @returns This instance.
|
|
114
115
|
*/
|
|
115
116
|
invertAdd(): this;
|
|
@@ -148,6 +149,12 @@ export declare class Vector2 {
|
|
|
148
149
|
* @returns This instance.
|
|
149
150
|
*/
|
|
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;
|
|
151
158
|
/**
|
|
152
159
|
* Returns the dot product between two vectors.
|
|
153
160
|
* @param vector The other vector.
|
|
@@ -161,4 +168,33 @@ export declare class Vector2 {
|
|
|
161
168
|
* @returns The dot product between the two vectors.
|
|
162
169
|
*/
|
|
163
170
|
dotXY(x: number, y: number): number;
|
|
171
|
+
/**
|
|
172
|
+
* Return the components of this vector as an array.
|
|
173
|
+
* @returns The components of this vector as an array.
|
|
174
|
+
*/
|
|
175
|
+
asArray(): [number, number];
|
|
164
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Adds two vectors and returns a new vector with the result.
|
|
179
|
+
* @param a The first input vector.
|
|
180
|
+
* @param b The second input vector.
|
|
181
|
+
* @returns A new {@linkcode Vector2}.
|
|
182
|
+
* @group Math
|
|
183
|
+
*/
|
|
184
|
+
export declare const addVector2: (a: Vector2, b: Vector2) => Vector2;
|
|
185
|
+
/**
|
|
186
|
+
* Multiplies two vectors and returns a new vector with the result.
|
|
187
|
+
* @param a The first input vector.
|
|
188
|
+
* @param b The second input vector.
|
|
189
|
+
* @returns A new {@linkcode Vector2}.
|
|
190
|
+
* @group Math
|
|
191
|
+
*/
|
|
192
|
+
export declare const multiplyVector2: (a: Vector2, b: Vector2) => Vector2;
|
|
193
|
+
/**
|
|
194
|
+
* Subtracts two vectors and returns a new vector with the result.
|
|
195
|
+
* @param a The first input vector.
|
|
196
|
+
* @param b The second input vector.
|
|
197
|
+
* @returns A new {@linkcode Vector2}.
|
|
198
|
+
* @group Math
|
|
199
|
+
*/
|
|
200
|
+
export declare const subtractVector2: (a: Vector2, b: Vector2) => Vector2;
|
package/lib/math/vector2.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A vector with 2 components, labeled: `X`, `Y`.
|
|
3
|
+
* @group Math
|
|
3
4
|
*/
|
|
4
5
|
export class Vector2 {
|
|
5
6
|
/**
|
|
@@ -11,7 +12,7 @@ export class Vector2 {
|
|
|
11
12
|
*/
|
|
12
13
|
y;
|
|
13
14
|
/**
|
|
14
|
-
* Constructs a new {@
|
|
15
|
+
* Constructs a new {@linkcode Vector2}.
|
|
15
16
|
* @param x The X component.
|
|
16
17
|
* @param y The Y component.
|
|
17
18
|
*/
|
|
@@ -156,7 +157,7 @@ export class Vector2 {
|
|
|
156
157
|
return this;
|
|
157
158
|
}
|
|
158
159
|
/**
|
|
159
|
-
* Inverts the vector.
|
|
160
|
+
* Inverts the sign of the vector.
|
|
160
161
|
* @returns This instance.
|
|
161
162
|
*/
|
|
162
163
|
invertAdd() {
|
|
@@ -234,6 +235,19 @@ export class Vector2 {
|
|
|
234
235
|
this.y = this.y * tn + vector.y * t;
|
|
235
236
|
return this;
|
|
236
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
|
+
}
|
|
237
251
|
/**
|
|
238
252
|
* Returns the dot product between two vectors.
|
|
239
253
|
* @param vector The other vector.
|
|
@@ -251,5 +265,42 @@ export class Vector2 {
|
|
|
251
265
|
dotXY(x, y) {
|
|
252
266
|
return this.x * x + this.y * y;
|
|
253
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Return the components of this vector as an array.
|
|
270
|
+
* @returns The components of this vector as an array.
|
|
271
|
+
*/
|
|
272
|
+
asArray() {
|
|
273
|
+
return [this.x, this.y];
|
|
274
|
+
}
|
|
254
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Adds two vectors and returns a new vector with the result.
|
|
278
|
+
* @param a The first input vector.
|
|
279
|
+
* @param b The second input vector.
|
|
280
|
+
* @returns A new {@linkcode Vector2}.
|
|
281
|
+
* @group Math
|
|
282
|
+
*/
|
|
283
|
+
export const addVector2 = (a, b) => {
|
|
284
|
+
return new Vector2(a.x * b.x, a.y * b.y);
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Multiplies two vectors and returns a new vector with the result.
|
|
288
|
+
* @param a The first input vector.
|
|
289
|
+
* @param b The second input vector.
|
|
290
|
+
* @returns A new {@linkcode Vector2}.
|
|
291
|
+
* @group Math
|
|
292
|
+
*/
|
|
293
|
+
export const multiplyVector2 = (a, b) => {
|
|
294
|
+
return new Vector2(a.x * b.x, a.y * b.y);
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* Subtracts two vectors and returns a new vector with the result.
|
|
298
|
+
* @param a The first input vector.
|
|
299
|
+
* @param b The second input vector.
|
|
300
|
+
* @returns A new {@linkcode Vector2}.
|
|
301
|
+
* @group Math
|
|
302
|
+
*/
|
|
303
|
+
export const subtractVector2 = (a, b) => {
|
|
304
|
+
return new Vector2(a.x - b.x, a.y - b.y);
|
|
305
|
+
};
|
|
255
306
|
//# sourceMappingURL=vector2.js.map
|
package/lib/math/vector2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector2.js","sourceRoot":"","sources":["../../source/math/vector2.ts"],"names":[],"mappings":"AAAA
|
|
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,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,CAAS,EAAE,CAAS;QACxB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,MAAe;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,CAAS,EAAE,CAAS;QACxB,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Ae,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"}
|
package/lib/math/vector3.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A vector with 3 components, labeled: `X`, `Y`, `Z`.
|
|
3
|
+
* @group Math
|
|
3
4
|
*/
|
|
4
5
|
export declare class Vector3 {
|
|
5
6
|
/**
|
|
@@ -15,7 +16,7 @@ export declare class Vector3 {
|
|
|
15
16
|
*/
|
|
16
17
|
z: number;
|
|
17
18
|
/**
|
|
18
|
-
* Constructs a new {@
|
|
19
|
+
* Constructs a new {@linkcode Vector3}.
|
|
19
20
|
* @param x The X component.
|
|
20
21
|
* @param y The Y component.
|
|
21
22
|
* @param z The Z component.
|
package/lib/math/vector3.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A vector with 3 components, labeled: `X`, `Y`, `Z`.
|
|
3
|
+
* @group Math
|
|
3
4
|
*/
|
|
4
5
|
export class Vector3 {
|
|
5
6
|
/**
|
|
@@ -15,7 +16,7 @@ export class Vector3 {
|
|
|
15
16
|
*/
|
|
16
17
|
z;
|
|
17
18
|
/**
|
|
18
|
-
* Constructs a new {@
|
|
19
|
+
* Constructs a new {@linkcode Vector3}.
|
|
19
20
|
* @param x The X component.
|
|
20
21
|
* @param y The Y component.
|
|
21
22
|
* @param z The Z component.
|
package/lib/math/vector3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector3.js","sourceRoot":"","sources":["../../source/math/vector3.ts"],"names":[],"mappings":"AAAA
|
|
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
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,CAAI,OAAiB;IACxC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,EAAE,CAAI,OAAiB,EAAE,YAA8B;IACrE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,YAAY,YAAY,CAAC;AAC5D,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"nil.js","sourceRoot":"","sources":["../source/nil.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAI,OAAiB;IACxC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,EAAE,CAAI,OAAiB,EAAE,YAA8B;IACrE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,YAAY,YAAY,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C;;;OAGG;IACH,YAAY,OAAO,GAAG,sBAAsB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAI,OAAiB,EAAE,YAAqB;IACnE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE;QAClB,MAAM,IAAI,kBAAkB,CAAC,YAAY,CAAC,CAAC;KAC5C;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/lib/random.d.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helps with generating random numbers.
|
|
3
|
+
* @group Random
|
|
3
4
|
*/
|
|
4
5
|
export declare class Random {
|
|
6
|
+
/**
|
|
7
|
+
* The value this PRNG was seeded with.
|
|
8
|
+
*/
|
|
5
9
|
private _seed;
|
|
10
|
+
/**
|
|
11
|
+
* The permutation table for simplex noise.
|
|
12
|
+
*/
|
|
6
13
|
private _perm;
|
|
14
|
+
/**
|
|
15
|
+
* The gradient map for simplex noise.
|
|
16
|
+
*/
|
|
7
17
|
private _gradP;
|
|
18
|
+
/**
|
|
19
|
+
* Skewing and unskewing factors for 2, 3, and 4 dimensions.
|
|
20
|
+
*/
|
|
8
21
|
private _F2;
|
|
22
|
+
/**
|
|
23
|
+
* Skewing and unskewing factors for 2, 3, and 4 dimensions.
|
|
24
|
+
*/
|
|
9
25
|
private _G2;
|
|
10
26
|
/**
|
|
11
27
|
* Creates a pseudo-random value generator. The seed must be an integer.
|
|
@@ -40,13 +56,25 @@ export declare class Random {
|
|
|
40
56
|
* @returns The noise value for the input coordinates.
|
|
41
57
|
*/
|
|
42
58
|
simplex2(x: number, y: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a 3D simplex noise value for a given input coordinate.
|
|
61
|
+
* @license ISC
|
|
62
|
+
* @author Joseph Gentle
|
|
63
|
+
* @see https://github.com/josephg/noisejs
|
|
64
|
+
* @param x The X input coordinate.
|
|
65
|
+
* @param y The Y input coordinate.
|
|
66
|
+
* @param z The Z input coordinate.
|
|
67
|
+
* @returns The noise value for the input coordinates.
|
|
68
|
+
*/
|
|
69
|
+
simplex3(x: number, y: number, z: number): number;
|
|
43
70
|
}
|
|
44
71
|
/**
|
|
45
72
|
* Returns a random value in a given range.
|
|
46
|
-
* Uses the JS-internal `Math.random()`. Use {
|
|
73
|
+
* Uses the JS-internal `Math.random()`. Use {@linkcode Random} for a PRNG with more features.
|
|
47
74
|
* @param min The lower bound.
|
|
48
75
|
* @param max The upper bound.
|
|
49
76
|
* @returns A random value between the lower and upper bound.
|
|
77
|
+
* @group Random
|
|
50
78
|
*/
|
|
51
79
|
export declare const randomRange: (min: number, max: number) => number;
|
|
52
80
|
/**
|
|
@@ -54,6 +82,11 @@ export declare const randomRange: (min: number, max: number) => number;
|
|
|
54
82
|
* from a string.
|
|
55
83
|
* @param input The string to use as a seed.
|
|
56
84
|
* @returns A numeric seed value for a PRNG.
|
|
85
|
+
* @group Random
|
|
57
86
|
*/
|
|
58
87
|
export declare const seedFromString: (input: string) => number;
|
|
88
|
+
/**
|
|
89
|
+
* A global PRNG instance that is ready-to-use.
|
|
90
|
+
* @group Random
|
|
91
|
+
*/
|
|
59
92
|
export declare const random: Random;
|