adaptive-extender 0.7.2 → 0.8.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/CHANGELOG.md +10 -5
- package/dist/core/controller.d.ts +24 -0
- package/dist/core/controller.js +41 -0
- package/dist/core/controller.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/vector-1.d.ts +45 -0
- package/dist/core/vector-1.js +45 -0
- package/dist/core/vector-1.js.map +1 -1
- package/dist/core/vector-2.d.ts +49 -0
- package/dist/core/vector-2.js +49 -0
- package/dist/core/vector-2.js.map +1 -1
- package/dist/core/vector-3.d.ts +53 -0
- package/dist/core/vector-3.js +53 -0
- package/dist/core/vector-3.js.map +1 -1
- package/dist/core/vector.d.ts +170 -0
- package/dist/core/vector.js +58 -0
- package/dist/core/vector.js.map +1 -1
- package/dist/web/archive.d.ts +11 -29
- package/dist/web/archive.js +13 -7
- package/dist/web/archive.js.map +1 -1
- package/dist/web/element.d.ts +14 -0
- package/dist/web/element.js.map +1 -1
- package/dist/web/engine.d.ts +47 -1
- package/dist/web/engine.js +33 -3
- package/dist/web/engine.js.map +1 -1
- package/dist/web/parent-node.d.ts +26 -0
- package/dist/web/parent-node.js.map +1 -1
- package/package.json +1 -1
- package/dist/web/archive-manager.d.ts +0 -27
- package/dist/web/archive-manager.js +0 -51
- package/dist/web/archive-manager.js.map +0 -1
- package/vitest.config.ts +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
## 0.
|
|
2
|
-
- Added
|
|
1
|
+
## 0.8.0 (03.11.2025)
|
|
2
|
+
- Added missing documentation.
|
|
3
|
+
- Used `ImplementationError` errors for parts where implementation is missing.
|
|
4
|
+
- Added [controller](./src/core/controller.ts) module
|
|
5
|
+
|
|
6
|
+
## 0.7.3 (20.10.2025)
|
|
7
|
+
- Added module [archive](./src/web/archive.ts).
|
|
3
8
|
|
|
4
9
|
## 0.6.1 (27.09.2025)
|
|
5
|
-
- Added modules [promise](), [engine](), [parent-node](), [element]().
|
|
10
|
+
- Added modules [promise](./src/web/promise.ts), [engine](./src/web/engine.ts), [parent-node](./src/web/parent-node.ts), [element](./src/web/element.ts).
|
|
6
11
|
|
|
7
12
|
## 0.5.0 (19.09.2025)
|
|
8
|
-
- Added [timespan]() module.
|
|
13
|
+
- Added [timespan](./src/core/timespan.ts) module.
|
|
9
14
|
- Improved module separation.
|
|
10
15
|
- Optimized `Color.newBlack`.
|
|
11
16
|
- Added tests.
|
|
@@ -16,7 +21,7 @@
|
|
|
16
21
|
## 0.4.0 (26.08.2025)
|
|
17
22
|
- Improved package structure.
|
|
18
23
|
- Configured package for the latest stable ES version.
|
|
19
|
-
- Added modules [vector](), [vector-1](), [vector-2](), [vector-3]().
|
|
24
|
+
- Added modules [vector](./src/core/vector.ts), [vector-1](./src/core/vector-1.ts), [vector-2](./src/core/vector-2.ts), [vector-3](./src/core/vector-3.ts).
|
|
20
25
|
|
|
21
26
|
## 0.2.14 (20.08.2025)
|
|
22
27
|
- Added import support for `CommonJS` modules.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "./error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a controller that can be launched and handle errors.
|
|
4
|
+
* @abstract
|
|
5
|
+
*/
|
|
6
|
+
declare class Controller {
|
|
7
|
+
/**
|
|
8
|
+
* @throws {TypeError} If the constructor is called on ectly.
|
|
9
|
+
*/
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* When overridden in a derived class, executes the controller's logic.
|
|
13
|
+
*/
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* When overridden in a derived class, handles an error that occurred during the controller's execution.
|
|
17
|
+
*/
|
|
18
|
+
catch(error: Error): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of the controller and runs it.
|
|
21
|
+
*/
|
|
22
|
+
static launch(this: new () => Controller): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export { Controller };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import "./error.js";
|
|
3
|
+
//#region Controller
|
|
4
|
+
/**
|
|
5
|
+
* Represents a controller that can be launched and handle errors.
|
|
6
|
+
* @abstract
|
|
7
|
+
*/
|
|
8
|
+
class Controller {
|
|
9
|
+
/**
|
|
10
|
+
* @throws {TypeError} If the constructor is called on ectly.
|
|
11
|
+
*/
|
|
12
|
+
constructor() {
|
|
13
|
+
if (new.target === Controller)
|
|
14
|
+
throw new TypeError("Unable to create an instance of an abstract class");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* When overridden in a derived class, executes the controller's logic.
|
|
18
|
+
*/
|
|
19
|
+
async run() {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* When overridden in a derived class, handles an error that occurred during the controller's execution.
|
|
23
|
+
*/
|
|
24
|
+
async catch(error) {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of the controller and runs it.
|
|
28
|
+
*/
|
|
29
|
+
static async launch() {
|
|
30
|
+
const controller = Reflect.construct(this, []);
|
|
31
|
+
try {
|
|
32
|
+
await controller.run();
|
|
33
|
+
}
|
|
34
|
+
catch (reason) {
|
|
35
|
+
await controller.catch(Error.from(reason));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { Controller };
|
|
41
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/core/controller.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,YAAY,CAAC;AAEpB,oBAAoB;AACpB;;;GAGG;AACH,MAAM,UAAU;IACf;;OAEG;IACH;QACC,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU;YAAE,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC,CAAC;IACzG,CAAC;IACD;;OAEG;IACH,KAAK,CAAC,GAAG;IACT,CAAC;IACD;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,KAAY;IACxB,CAAC;IACD;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM;QAClB,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC;YACJ,MAAM,UAAU,CAAC,GAAG,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YACjB,MAAM,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC;CACD;AACD,YAAY;AAEZ,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
package/dist/core/vector-1.d.ts
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
1
1
|
import { Vector } from "./vector.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a 1D vector.
|
|
4
|
+
*/
|
|
2
5
|
declare class Vector1D extends Vector {
|
|
3
6
|
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Gets the x-component of the vector.
|
|
9
|
+
*/
|
|
4
10
|
get x(): number;
|
|
11
|
+
/**
|
|
12
|
+
* Sets the x-component of the vector.
|
|
13
|
+
*/
|
|
5
14
|
set x(value: number);
|
|
15
|
+
/**
|
|
16
|
+
* @param x The x-component of the vector.
|
|
17
|
+
*/
|
|
6
18
|
constructor(x: number);
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new `Vector1D` from a single scalar value.
|
|
21
|
+
* @param scalar The scalar value.
|
|
22
|
+
*/
|
|
7
23
|
static fromScalar(scalar: number): Vector1D;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new `Vector1D` from a generic `Vector`.
|
|
26
|
+
* @param vector The source vector.
|
|
27
|
+
*/
|
|
8
28
|
static fromVector(vector: Vector): Vector1D;
|
|
29
|
+
/**
|
|
30
|
+
* Tries to parse a string into a `Vector1D`.
|
|
31
|
+
* @param string The string to parse.
|
|
32
|
+
* @returns A `Vector1D` instance or `null`.
|
|
33
|
+
*/
|
|
9
34
|
static tryParse(string: string): Vector1D | null;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a string into a `Vector1D`.
|
|
37
|
+
* @param string The string to parse.
|
|
38
|
+
* @throws {SyntaxError} If the string is not a valid representation of a 1D vector.
|
|
39
|
+
*/
|
|
10
40
|
static parse(string: string): Vector1D;
|
|
41
|
+
/**
|
|
42
|
+
* Gets an iterator for the components of the vector.
|
|
43
|
+
*/
|
|
11
44
|
[Symbol.iterator](): IteratorObject<number, BuiltinIteratorReturn>;
|
|
45
|
+
/**
|
|
46
|
+
* A new `Vector1D` with `NaN` as its component.
|
|
47
|
+
*/
|
|
12
48
|
static get newNaN(): Vector1D;
|
|
49
|
+
/**
|
|
50
|
+
* A new `Vector1D` with zero as its component.
|
|
51
|
+
*/
|
|
13
52
|
static get newZero(): Vector1D;
|
|
53
|
+
/**
|
|
54
|
+
* A new `Vector1D` representing the unit vector in the x-direction.
|
|
55
|
+
*/
|
|
14
56
|
static get newUnitX(): Vector1D;
|
|
57
|
+
/**
|
|
58
|
+
* A new `Vector1D` with a magnitude of 1.
|
|
59
|
+
*/
|
|
15
60
|
static get newUnit(): Vector1D;
|
|
16
61
|
}
|
|
17
62
|
export { Vector1D };
|
package/dist/core/vector-1.js
CHANGED
|
@@ -1,25 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Vector } from "./vector.js";
|
|
3
3
|
//#region Vector 1D
|
|
4
|
+
/**
|
|
5
|
+
* Represents a 1D vector.
|
|
6
|
+
*/
|
|
4
7
|
class Vector1D extends Vector {
|
|
5
8
|
//#region Properties
|
|
6
9
|
#x;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the x-component of the vector.
|
|
12
|
+
*/
|
|
7
13
|
get x() {
|
|
8
14
|
return this.#x;
|
|
9
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Sets the x-component of the vector.
|
|
18
|
+
*/
|
|
10
19
|
set x(value) {
|
|
11
20
|
this.#x = value;
|
|
12
21
|
}
|
|
13
22
|
//#endregion
|
|
14
23
|
//#region Builders
|
|
24
|
+
/**
|
|
25
|
+
* @param x The x-component of the vector.
|
|
26
|
+
*/
|
|
15
27
|
constructor(x) {
|
|
16
28
|
super();
|
|
17
29
|
this.#x = x;
|
|
18
30
|
}
|
|
19
31
|
static #patternVector1D = /^\(\s*(\S+)\s*\)$/;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new `Vector1D` from a single scalar value.
|
|
34
|
+
* @param scalar The scalar value.
|
|
35
|
+
*/
|
|
20
36
|
static fromScalar(scalar) {
|
|
21
37
|
return new Vector1D(scalar);
|
|
22
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new `Vector1D` from a generic `Vector`.
|
|
41
|
+
* @param vector The source vector.
|
|
42
|
+
*/
|
|
23
43
|
static fromVector(vector) {
|
|
24
44
|
const metrics = vector[Symbol.iterator]();
|
|
25
45
|
const metric1 = metrics.next();
|
|
@@ -27,6 +47,11 @@ class Vector1D extends Vector {
|
|
|
27
47
|
return new Vector1D(0);
|
|
28
48
|
return new Vector1D(metric1.value);
|
|
29
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Tries to parse a string into a `Vector1D`.
|
|
52
|
+
* @param string The string to parse.
|
|
53
|
+
* @returns A `Vector1D` instance or `null`.
|
|
54
|
+
*/
|
|
30
55
|
static tryParse(string) {
|
|
31
56
|
const match = Vector1D.#patternVector1D.exec(string.trim());
|
|
32
57
|
if (match === null)
|
|
@@ -34,6 +59,11 @@ class Vector1D extends Vector {
|
|
|
34
59
|
const [, x] = match.map(Number);
|
|
35
60
|
return new Vector1D(x);
|
|
36
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Parses a string into a `Vector1D`.
|
|
64
|
+
* @param string The string to parse.
|
|
65
|
+
* @throws {SyntaxError} If the string is not a valid representation of a 1D vector.
|
|
66
|
+
*/
|
|
37
67
|
static parse(string) {
|
|
38
68
|
const vector = Vector1D.tryParse(string);
|
|
39
69
|
if (vector === null)
|
|
@@ -42,14 +72,29 @@ class Vector1D extends Vector {
|
|
|
42
72
|
}
|
|
43
73
|
//#endregion
|
|
44
74
|
//#region Converters
|
|
75
|
+
/**
|
|
76
|
+
* Gets an iterator for the components of the vector.
|
|
77
|
+
*/
|
|
45
78
|
*[Symbol.iterator]() {
|
|
46
79
|
yield this.x;
|
|
47
80
|
}
|
|
48
81
|
//#endregion
|
|
49
82
|
//#region Presets
|
|
83
|
+
/**
|
|
84
|
+
* A new `Vector1D` with `NaN` as its component.
|
|
85
|
+
*/
|
|
50
86
|
static get newNaN() { return Vector1D.fromScalar(NaN); }
|
|
87
|
+
/**
|
|
88
|
+
* A new `Vector1D` with zero as its component.
|
|
89
|
+
*/
|
|
51
90
|
static get newZero() { return Vector1D.fromScalar(0); }
|
|
91
|
+
/**
|
|
92
|
+
* A new `Vector1D` representing the unit vector in the x-direction.
|
|
93
|
+
*/
|
|
52
94
|
static get newUnitX() { return new Vector1D(1); }
|
|
95
|
+
/**
|
|
96
|
+
* A new `Vector1D` with a magnitude of 1.
|
|
97
|
+
*/
|
|
53
98
|
static get newUnit() { return Vector1D.fromScalar(1); }
|
|
54
99
|
}
|
|
55
100
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-1.js","sourceRoot":"","sources":["../../src/core/vector-1.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,mBAAmB;AACnB,MAAM,QAAS,SAAQ,MAAM;IAC5B,oBAAoB;IACpB,EAAE,CAAS;IACX,IAAI,CAAC;QACJ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AAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAClE;;OAEG;IACH,MAAM,KAAK,OAAO,KAAe,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE;;OAEG;IACH,MAAM,KAAK,QAAQ,KAAe,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D;;OAEG;IACH,MAAM,KAAK,OAAO,KAAe,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;AAGlE,YAAY;AAEZ,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/core/vector-2.d.ts
CHANGED
|
@@ -1,19 +1,68 @@
|
|
|
1
1
|
import { type Vector } from "./vector.js";
|
|
2
2
|
import { Vector1D } from "./vector-1.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a 2D vector.
|
|
5
|
+
*/
|
|
3
6
|
declare class Vector2D extends Vector1D {
|
|
4
7
|
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the y-component of the vector.
|
|
10
|
+
*/
|
|
5
11
|
get y(): number;
|
|
12
|
+
/**
|
|
13
|
+
* Sets the y-component of the vector.
|
|
14
|
+
*/
|
|
6
15
|
set y(value: number);
|
|
16
|
+
/**
|
|
17
|
+
* @param x The x-component of the vector.
|
|
18
|
+
* @param y The y-component of the vector.
|
|
19
|
+
*/
|
|
7
20
|
constructor(x: number, y: number);
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new `Vector2D` from a single scalar value.
|
|
23
|
+
* @param scalar The scalar value.
|
|
24
|
+
*/
|
|
8
25
|
static fromScalar(scalar: number): Vector2D;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new `Vector2D` from a generic `Vector`.
|
|
28
|
+
* @param vector The source vector.
|
|
29
|
+
*/
|
|
9
30
|
static fromVector(vector: Vector): Vector2D;
|
|
31
|
+
/**
|
|
32
|
+
* Tries to parse a string into a `Vector2D`.
|
|
33
|
+
* @param string The string to parse.
|
|
34
|
+
* @returns A `Vector2D` instance or `null`.
|
|
35
|
+
*/
|
|
10
36
|
static tryParse(string: string): Vector2D | null;
|
|
37
|
+
/**
|
|
38
|
+
* Parses a string into a `Vector2D`.
|
|
39
|
+
* @param string The string to parse.
|
|
40
|
+
* @throws {SyntaxError} If the string is not a valid representation of a 2D vector.
|
|
41
|
+
*/
|
|
11
42
|
static parse(string: string): Vector2D;
|
|
43
|
+
/**
|
|
44
|
+
* Gets an iterator for the components of the vector.
|
|
45
|
+
*/
|
|
12
46
|
[Symbol.iterator](): IteratorObject<number, BuiltinIteratorReturn>;
|
|
47
|
+
/**
|
|
48
|
+
* A new `Vector2D` with `NaN` as its components.
|
|
49
|
+
*/
|
|
13
50
|
static get newNaN(): Vector2D;
|
|
51
|
+
/**
|
|
52
|
+
* A new `Vector2D` with zero as its components.
|
|
53
|
+
*/
|
|
14
54
|
static get newZero(): Vector2D;
|
|
55
|
+
/**
|
|
56
|
+
* A new `Vector2D` representing the unit vector in the x-direction.
|
|
57
|
+
*/
|
|
15
58
|
static get newUnitX(): Vector2D;
|
|
59
|
+
/**
|
|
60
|
+
* A new `Vector2D` representing the unit vector in the y-direction.
|
|
61
|
+
*/
|
|
16
62
|
static get newUnitY(): Vector2D;
|
|
63
|
+
/**
|
|
64
|
+
* A new `Vector2D` with a magnitude of 1 in all directions.
|
|
65
|
+
*/
|
|
17
66
|
static get newUnit(): Vector2D;
|
|
18
67
|
}
|
|
19
68
|
export { Vector2D };
|
package/dist/core/vector-2.js
CHANGED
|
@@ -2,25 +2,46 @@
|
|
|
2
2
|
import {} from "./vector.js";
|
|
3
3
|
import { Vector1D } from "./vector-1.js";
|
|
4
4
|
//#region Vector 2D
|
|
5
|
+
/**
|
|
6
|
+
* Represents a 2D vector.
|
|
7
|
+
*/
|
|
5
8
|
class Vector2D extends Vector1D {
|
|
6
9
|
//#region Properties
|
|
7
10
|
#y;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the y-component of the vector.
|
|
13
|
+
*/
|
|
8
14
|
get y() {
|
|
9
15
|
return this.#y;
|
|
10
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Sets the y-component of the vector.
|
|
19
|
+
*/
|
|
11
20
|
set y(value) {
|
|
12
21
|
this.#y = value;
|
|
13
22
|
}
|
|
14
23
|
//#endregion
|
|
15
24
|
//#region Builders
|
|
25
|
+
/**
|
|
26
|
+
* @param x The x-component of the vector.
|
|
27
|
+
* @param y The y-component of the vector.
|
|
28
|
+
*/
|
|
16
29
|
constructor(x, y) {
|
|
17
30
|
super(x);
|
|
18
31
|
this.#y = y;
|
|
19
32
|
}
|
|
20
33
|
static #patternVector2D = /^\(\s*(\S+)\s*,\s*(\S+)\s*\)$/;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new `Vector2D` from a single scalar value.
|
|
36
|
+
* @param scalar The scalar value.
|
|
37
|
+
*/
|
|
21
38
|
static fromScalar(scalar) {
|
|
22
39
|
return new Vector2D(scalar, scalar);
|
|
23
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new `Vector2D` from a generic `Vector`.
|
|
43
|
+
* @param vector The source vector.
|
|
44
|
+
*/
|
|
24
45
|
static fromVector(vector) {
|
|
25
46
|
const metrics = vector[Symbol.iterator]();
|
|
26
47
|
const metric1 = metrics.next();
|
|
@@ -31,6 +52,11 @@ class Vector2D extends Vector1D {
|
|
|
31
52
|
return new Vector2D(metric1.value, 0);
|
|
32
53
|
return new Vector2D(metric1.value, metric2.value);
|
|
33
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Tries to parse a string into a `Vector2D`.
|
|
57
|
+
* @param string The string to parse.
|
|
58
|
+
* @returns A `Vector2D` instance or `null`.
|
|
59
|
+
*/
|
|
34
60
|
static tryParse(string) {
|
|
35
61
|
const match = Vector2D.#patternVector2D.exec(string.trim());
|
|
36
62
|
if (match === null)
|
|
@@ -38,6 +64,11 @@ class Vector2D extends Vector1D {
|
|
|
38
64
|
const [, x, y] = match.map(Number);
|
|
39
65
|
return new Vector2D(x, y);
|
|
40
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Parses a string into a `Vector2D`.
|
|
69
|
+
* @param string The string to parse.
|
|
70
|
+
* @throws {SyntaxError} If the string is not a valid representation of a 2D vector.
|
|
71
|
+
*/
|
|
41
72
|
static parse(string) {
|
|
42
73
|
const vector = Vector2D.tryParse(string);
|
|
43
74
|
if (vector === null)
|
|
@@ -46,16 +77,34 @@ class Vector2D extends Vector1D {
|
|
|
46
77
|
}
|
|
47
78
|
//#endregion
|
|
48
79
|
//#region Converters
|
|
80
|
+
/**
|
|
81
|
+
* Gets an iterator for the components of the vector.
|
|
82
|
+
*/
|
|
49
83
|
*[Symbol.iterator]() {
|
|
50
84
|
yield this.x;
|
|
51
85
|
yield this.y;
|
|
52
86
|
}
|
|
53
87
|
//#endregion
|
|
54
88
|
//#region Presets
|
|
89
|
+
/**
|
|
90
|
+
* A new `Vector2D` with `NaN` as its components.
|
|
91
|
+
*/
|
|
55
92
|
static get newNaN() { return Vector2D.fromScalar(NaN); }
|
|
93
|
+
/**
|
|
94
|
+
* A new `Vector2D` with zero as its components.
|
|
95
|
+
*/
|
|
56
96
|
static get newZero() { return Vector2D.fromScalar(0); }
|
|
97
|
+
/**
|
|
98
|
+
* A new `Vector2D` representing the unit vector in the x-direction.
|
|
99
|
+
*/
|
|
57
100
|
static get newUnitX() { return new Vector2D(1, 0); }
|
|
101
|
+
/**
|
|
102
|
+
* A new `Vector2D` representing the unit vector in the y-direction.
|
|
103
|
+
*/
|
|
58
104
|
static get newUnitY() { return new Vector2D(0, 1); }
|
|
105
|
+
/**
|
|
106
|
+
* A new `Vector2D` with a magnitude of 1 in all directions.
|
|
107
|
+
*/
|
|
59
108
|
static get newUnit() { return Vector2D.fromScalar(1); }
|
|
60
109
|
}
|
|
61
110
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-2.js","sourceRoot":"","sources":["../../src/core/vector-2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,MAAM,KAAK,QAAQ,KAAe,OAAO,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D;;OAEG;IACH,MAAM,KAAK,OAAO,KAAe,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;AAGlE,YAAY;AAEZ,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/core/vector-3.d.ts
CHANGED
|
@@ -1,20 +1,73 @@
|
|
|
1
1
|
import { type Vector } from "./vector.js";
|
|
2
2
|
import { Vector2D } from "./vector-2.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a 3D vector.
|
|
5
|
+
*/
|
|
3
6
|
declare class Vector3D extends Vector2D {
|
|
4
7
|
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the z-component of the vector.
|
|
10
|
+
*/
|
|
5
11
|
get z(): number;
|
|
12
|
+
/**
|
|
13
|
+
* Sets the z-component of the vector.
|
|
14
|
+
*/
|
|
6
15
|
set z(value: number);
|
|
16
|
+
/**
|
|
17
|
+
* @param x The x-component of the vector.
|
|
18
|
+
* @param y The y-component of the vector.
|
|
19
|
+
* @param z The z-component of the vector.
|
|
20
|
+
*/
|
|
7
21
|
constructor(x: number, y: number, z: number);
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new `Vector3D` from a single scalar value.
|
|
24
|
+
* @param scalar The scalar value.
|
|
25
|
+
*/
|
|
8
26
|
static fromScalar(scalar: number): Vector3D;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new `Vector3D` from a generic `Vector`.
|
|
29
|
+
* @param vector The source vector.
|
|
30
|
+
*/
|
|
9
31
|
static fromVector(vector: Vector): Vector3D;
|
|
32
|
+
/**
|
|
33
|
+
* Tries to parse a string into a `Vector3D`.
|
|
34
|
+
* @param string The string to parse.
|
|
35
|
+
* @returns A `Vector3D` instance or `null`.
|
|
36
|
+
*/
|
|
10
37
|
static tryParse(string: string): Vector3D | null;
|
|
38
|
+
/**
|
|
39
|
+
* Parses a string into a `Vector3D`.
|
|
40
|
+
* @param string The string to parse.
|
|
41
|
+
* @throws {SyntaxError} If the string is not a valid representation of a 3D vector.
|
|
42
|
+
*/
|
|
11
43
|
static parse(string: string): Vector3D;
|
|
44
|
+
/**
|
|
45
|
+
* Gets an iterator for the components of the vector.
|
|
46
|
+
*/
|
|
12
47
|
[Symbol.iterator](): IteratorObject<number, BuiltinIteratorReturn>;
|
|
48
|
+
/**
|
|
49
|
+
* A new `Vector3D` with `NaN` as its components.
|
|
50
|
+
*/
|
|
13
51
|
static get newNaN(): Vector3D;
|
|
52
|
+
/**
|
|
53
|
+
* A new `Vector3D` with zero as its components.
|
|
54
|
+
*/
|
|
14
55
|
static get newZero(): Vector3D;
|
|
56
|
+
/**
|
|
57
|
+
* A new `Vector3D` representing the unit vector in the x-direction.
|
|
58
|
+
*/
|
|
15
59
|
static get newUnitX(): Vector3D;
|
|
60
|
+
/**
|
|
61
|
+
* A new `Vector3D` representing the unit vector in the y-direction.
|
|
62
|
+
*/
|
|
16
63
|
static get newUnitY(): Vector3D;
|
|
64
|
+
/**
|
|
65
|
+
* A new `Vector3D` representing the unit vector in the z-direction.
|
|
66
|
+
*/
|
|
17
67
|
static get newUnitZ(): Vector3D;
|
|
68
|
+
/**
|
|
69
|
+
* A new `Vector3D` with a magnitude of 1 in all directions.
|
|
70
|
+
*/
|
|
18
71
|
static get newUnit(): Vector3D;
|
|
19
72
|
}
|
|
20
73
|
export { Vector3D };
|
package/dist/core/vector-3.js
CHANGED
|
@@ -2,25 +2,47 @@
|
|
|
2
2
|
import {} from "./vector.js";
|
|
3
3
|
import { Vector2D } from "./vector-2.js";
|
|
4
4
|
//#region Vector 3D
|
|
5
|
+
/**
|
|
6
|
+
* Represents a 3D vector.
|
|
7
|
+
*/
|
|
5
8
|
class Vector3D extends Vector2D {
|
|
6
9
|
//#region Properties
|
|
7
10
|
#z;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the z-component of the vector.
|
|
13
|
+
*/
|
|
8
14
|
get z() {
|
|
9
15
|
return this.#z;
|
|
10
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Sets the z-component of the vector.
|
|
19
|
+
*/
|
|
11
20
|
set z(value) {
|
|
12
21
|
this.#z = value;
|
|
13
22
|
}
|
|
14
23
|
//#endregion
|
|
15
24
|
//#region Builders
|
|
16
25
|
static #patternVector3D = /^\(\s*(\S+)\s*,\s*(\S+)\s*,\s*(\S+)\s*\)$/;
|
|
26
|
+
/**
|
|
27
|
+
* @param x The x-component of the vector.
|
|
28
|
+
* @param y The y-component of the vector.
|
|
29
|
+
* @param z The z-component of the vector.
|
|
30
|
+
*/
|
|
17
31
|
constructor(x, y, z) {
|
|
18
32
|
super(x, y);
|
|
19
33
|
this.#z = z;
|
|
20
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new `Vector3D` from a single scalar value.
|
|
37
|
+
* @param scalar The scalar value.
|
|
38
|
+
*/
|
|
21
39
|
static fromScalar(scalar) {
|
|
22
40
|
return new Vector3D(scalar, scalar, scalar);
|
|
23
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new `Vector3D` from a generic `Vector`.
|
|
44
|
+
* @param vector The source vector.
|
|
45
|
+
*/
|
|
24
46
|
static fromVector(vector) {
|
|
25
47
|
const metrics = vector[Symbol.iterator]();
|
|
26
48
|
const metric1 = metrics.next();
|
|
@@ -34,6 +56,11 @@ class Vector3D extends Vector2D {
|
|
|
34
56
|
return new Vector3D(metric1.value, metric2.value, 0);
|
|
35
57
|
return new Vector3D(metric1.value, metric2.value, metric3.value);
|
|
36
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Tries to parse a string into a `Vector3D`.
|
|
61
|
+
* @param string The string to parse.
|
|
62
|
+
* @returns A `Vector3D` instance or `null`.
|
|
63
|
+
*/
|
|
37
64
|
static tryParse(string) {
|
|
38
65
|
const match = Vector3D.#patternVector3D.exec(string.trim());
|
|
39
66
|
if (match === null)
|
|
@@ -41,6 +68,11 @@ class Vector3D extends Vector2D {
|
|
|
41
68
|
const [, x, y, z] = match.map(Number);
|
|
42
69
|
return new Vector3D(x, y, z);
|
|
43
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Parses a string into a `Vector3D`.
|
|
73
|
+
* @param string The string to parse.
|
|
74
|
+
* @throws {SyntaxError} If the string is not a valid representation of a 3D vector.
|
|
75
|
+
*/
|
|
44
76
|
static parse(string) {
|
|
45
77
|
const vector = Vector3D.tryParse(string);
|
|
46
78
|
if (vector === null)
|
|
@@ -49,6 +81,9 @@ class Vector3D extends Vector2D {
|
|
|
49
81
|
}
|
|
50
82
|
//#endregion
|
|
51
83
|
//#region Converters
|
|
84
|
+
/**
|
|
85
|
+
* Gets an iterator for the components of the vector.
|
|
86
|
+
*/
|
|
52
87
|
*[Symbol.iterator]() {
|
|
53
88
|
yield this.x;
|
|
54
89
|
yield this.y;
|
|
@@ -56,11 +91,29 @@ class Vector3D extends Vector2D {
|
|
|
56
91
|
}
|
|
57
92
|
//#endregion
|
|
58
93
|
//#region Presets
|
|
94
|
+
/**
|
|
95
|
+
* A new `Vector3D` with `NaN` as its components.
|
|
96
|
+
*/
|
|
59
97
|
static get newNaN() { return Vector3D.fromScalar(NaN); }
|
|
98
|
+
/**
|
|
99
|
+
* A new `Vector3D` with zero as its components.
|
|
100
|
+
*/
|
|
60
101
|
static get newZero() { return Vector3D.fromScalar(0); }
|
|
102
|
+
/**
|
|
103
|
+
* A new `Vector3D` representing the unit vector in the x-direction.
|
|
104
|
+
*/
|
|
61
105
|
static get newUnitX() { return new Vector3D(1, 0, 0); }
|
|
106
|
+
/**
|
|
107
|
+
* A new `Vector3D` representing the unit vector in the y-direction.
|
|
108
|
+
*/
|
|
62
109
|
static get newUnitY() { return new Vector3D(0, 1, 0); }
|
|
110
|
+
/**
|
|
111
|
+
* A new `Vector3D` representing the unit vector in the z-direction.
|
|
112
|
+
*/
|
|
63
113
|
static get newUnitZ() { return new Vector3D(0, 0, 1); }
|
|
114
|
+
/**
|
|
115
|
+
* A new `Vector3D` with a magnitude of 1 in all directions.
|
|
116
|
+
*/
|
|
64
117
|
static get newUnit() { return Vector3D.fromScalar(1); }
|
|
65
118
|
}
|
|
66
119
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-3.js","sourceRoot":"","sources":["../../src/core/vector-3.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAe,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,mBAAmB;AACnB,MAAM,QAAS,SAAQ,QAAQ;IAC9B,oBAAoB;IACpB,EAAE,CAAS;IACX,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,EAAE,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,CAAC,KAAa;QAClB,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC;IACjB,CAAC;IACD,YAAY;IACZ,kBAAkB;IAClB,MAAM,CAAC,gBAAgB,GAAW,2CAA2C,CAAC;IAC9E,YAAY,CAAS,EAAE,CAAS,EAAE,CAAS;QAC1C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACZ,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IACb,CAAC;IACD,MAAM,CAAC,UAAU,CAAC,MAAc;QAC/B,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,UAAU,CAAC,MAAc;QAC/B,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,IAAI;YAAE,OAAO,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,OAA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