dgeoutils 2.2.10 → 2.2.11
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/DPlane.d.ts +25 -0
- package/dist/DPlane.js +109 -0
- package/dist/DPoint.d.ts +4 -0
- package/dist/DPoint.js +29 -1
- package/dist/DPolygon.d.ts +1 -1
- package/dist/DPolygon.js +3 -3
- package/dist/DPolygonLoop.d.ts +3 -0
- package/dist/DPolygonLoop.js +58 -22
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +47 -1
- package/package.json +1 -1
package/dist/DPlane.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DPoint } from './DPoint';
|
|
2
|
+
import { DPolygon } from './DPolygon';
|
|
3
|
+
export declare class DPlane {
|
|
4
|
+
a: number;
|
|
5
|
+
b: number;
|
|
6
|
+
c: number;
|
|
7
|
+
d: number;
|
|
8
|
+
p1: DPoint;
|
|
9
|
+
p2: DPoint;
|
|
10
|
+
p3: DPoint;
|
|
11
|
+
constructor(a: number, b: number, c: number, d: number, p1?: DPoint, p2?: DPoint, p3?: DPoint);
|
|
12
|
+
static find(p1: DPoint, p2: DPoint, p3: DPoint): DPlane;
|
|
13
|
+
x(p: DPoint): DPoint;
|
|
14
|
+
x(p: DPolygon): DPolygon;
|
|
15
|
+
y(p: DPoint): DPoint;
|
|
16
|
+
y(p: DPolygon): DPolygon;
|
|
17
|
+
z(p: DPoint): DPoint;
|
|
18
|
+
z(p: DPolygon): DPolygon;
|
|
19
|
+
clone(): DPlane;
|
|
20
|
+
distance(p: DPoint): number;
|
|
21
|
+
distance(p: DPlane): number;
|
|
22
|
+
equal(p: DPlane): boolean;
|
|
23
|
+
same(p: DPlane): boolean;
|
|
24
|
+
parallel(p: DPlane): boolean;
|
|
25
|
+
}
|
package/dist/DPlane.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DPlane = void 0;
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const DNumbers_1 = require("./DNumbers");
|
|
7
|
+
class DPlane {
|
|
8
|
+
constructor(a, b, c, d, p1 = DPoint_1.DPoint.zero(), p2 = DPoint_1.DPoint.zero(), p3 = DPoint_1.DPoint.zero()) {
|
|
9
|
+
this.a = a;
|
|
10
|
+
this.b = b;
|
|
11
|
+
this.c = c;
|
|
12
|
+
this.d = d;
|
|
13
|
+
this.p1 = p1;
|
|
14
|
+
this.p2 = p2;
|
|
15
|
+
this.p3 = p3;
|
|
16
|
+
}
|
|
17
|
+
static find(p1, p2, p3) {
|
|
18
|
+
if (p1.x === p2.x && p2.x === p3.x) {
|
|
19
|
+
return new DPlane(1, 0, 0, -p1.x, p1, p2, p3);
|
|
20
|
+
}
|
|
21
|
+
if (p1.y === p2.y && p2.y === p3.y) {
|
|
22
|
+
return new DPlane(0, 1, 0, -p1.y, p1, p2, p3);
|
|
23
|
+
}
|
|
24
|
+
if (p1.z === p2.z && p2.z === p3.z) {
|
|
25
|
+
return new DPlane(0, 0, 1, -p1.z, p1, p2, p3);
|
|
26
|
+
}
|
|
27
|
+
const d = 1;
|
|
28
|
+
const [a, b, c] = (0, utils_1.gaussianElimination)([
|
|
29
|
+
[p1.x, p1.y, p1.z, -d],
|
|
30
|
+
[p2.x, p2.y, p2.z, -d],
|
|
31
|
+
[p3.x, p3.y, p3.z, -d]
|
|
32
|
+
]);
|
|
33
|
+
return new DPlane(a, b, c, d, p1, p2, p3);
|
|
34
|
+
}
|
|
35
|
+
x(p) {
|
|
36
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
37
|
+
const { a, b, c, d } = this;
|
|
38
|
+
const { y, z } = p;
|
|
39
|
+
p.x = -(b * y + c * z + d) / a;
|
|
40
|
+
return p;
|
|
41
|
+
}
|
|
42
|
+
return p.map((t) => this.x(t));
|
|
43
|
+
}
|
|
44
|
+
y(p) {
|
|
45
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
46
|
+
const { a, b, c, d } = this;
|
|
47
|
+
const { x, z } = p;
|
|
48
|
+
p.y = -(a * x + c * z + d) / b;
|
|
49
|
+
return p;
|
|
50
|
+
}
|
|
51
|
+
return p.map((t) => this.y(t));
|
|
52
|
+
}
|
|
53
|
+
z(p) {
|
|
54
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
55
|
+
const { a, b, c, d } = this;
|
|
56
|
+
const { x, y } = p;
|
|
57
|
+
p.z = -(a * x + b * y + d) / c;
|
|
58
|
+
return p;
|
|
59
|
+
}
|
|
60
|
+
return p.map((t) => this.z(t));
|
|
61
|
+
}
|
|
62
|
+
clone() {
|
|
63
|
+
const { a, b, c, d, p1, p2, p3 } = this;
|
|
64
|
+
return new DPlane(a, b, c, d, p1, p2, p3);
|
|
65
|
+
}
|
|
66
|
+
distance(p) {
|
|
67
|
+
if (p instanceof DPoint_1.DPoint) {
|
|
68
|
+
const { x, y, z } = p;
|
|
69
|
+
const { a, b, c, d } = this;
|
|
70
|
+
return Math.abs(a * x + b * y + c * z + d) / Math.sqrt(a * a + b * b + c * c);
|
|
71
|
+
}
|
|
72
|
+
const { a, b, c, d } = p;
|
|
73
|
+
const { d: r } = this;
|
|
74
|
+
return Math.abs(d - r) / Math.sqrt(a * a + b * b + c * c);
|
|
75
|
+
}
|
|
76
|
+
equal(p) {
|
|
77
|
+
const { a, b, c, d } = p;
|
|
78
|
+
const { a: q, b: w, c: e, d: r } = this;
|
|
79
|
+
return DNumbers_1.DNumbers.like(a, q) &&
|
|
80
|
+
DNumbers_1.DNumbers.like(b, w) &&
|
|
81
|
+
DNumbers_1.DNumbers.like(c, e) &&
|
|
82
|
+
DNumbers_1.DNumbers.like(d, r);
|
|
83
|
+
}
|
|
84
|
+
same(p) {
|
|
85
|
+
const { a, b, c, d } = p;
|
|
86
|
+
const { a: q, b: w, c: e, d: r } = this;
|
|
87
|
+
const t = a / q;
|
|
88
|
+
const y = b / w;
|
|
89
|
+
const u = c / e;
|
|
90
|
+
const i = d / r;
|
|
91
|
+
return DNumbers_1.DNumbers.like(t, y) &&
|
|
92
|
+
DNumbers_1.DNumbers.like(t, u) &&
|
|
93
|
+
DNumbers_1.DNumbers.like(t, c) &&
|
|
94
|
+
DNumbers_1.DNumbers.like(t, i);
|
|
95
|
+
}
|
|
96
|
+
parallel(p) {
|
|
97
|
+
const { a, b, c, d } = p;
|
|
98
|
+
const { a: q, b: w, c: e, d: r } = this;
|
|
99
|
+
const t = a / q;
|
|
100
|
+
const y = b / w;
|
|
101
|
+
const u = c / e;
|
|
102
|
+
const i = d / r;
|
|
103
|
+
return DNumbers_1.DNumbers.like(t, y) &&
|
|
104
|
+
DNumbers_1.DNumbers.like(t, u) &&
|
|
105
|
+
DNumbers_1.DNumbers.like(t, c) &&
|
|
106
|
+
!DNumbers_1.DNumbers.like(t, i);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.DPlane = DPlane;
|
package/dist/DPoint.d.ts
CHANGED
|
@@ -49,9 +49,13 @@ export declare class DPoint {
|
|
|
49
49
|
gtOrEqual(p: DPoint): boolean;
|
|
50
50
|
ltOrEqual(p: DPoint): boolean;
|
|
51
51
|
rotate(a: number): DPoint;
|
|
52
|
+
rotate3dX(a: number): DPoint;
|
|
53
|
+
rotate3dY(a: number): DPoint;
|
|
54
|
+
rotate3dZ(a: number): DPoint;
|
|
52
55
|
move(v: number): DPoint;
|
|
53
56
|
move(p: DPoint): DPoint;
|
|
54
57
|
move(x: number, y: number): DPoint;
|
|
58
|
+
move(x: number, y: number, z: number): DPoint;
|
|
55
59
|
degreeToMeters(): DPoint;
|
|
56
60
|
metersToDegree(): DPoint;
|
|
57
61
|
degreeToRadians(): DPoint;
|
package/dist/DPoint.js
CHANGED
|
@@ -164,19 +164,47 @@ class DPoint {
|
|
|
164
164
|
this.y = y;
|
|
165
165
|
return this;
|
|
166
166
|
}
|
|
167
|
-
|
|
167
|
+
rotate3dX(a) {
|
|
168
|
+
const { y, z } = this;
|
|
169
|
+
this.y = y * Math.cos(a) + z * Math.sin(a);
|
|
170
|
+
this.z = -y * Math.sin(a) + z * Math.cos(a);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
rotate3dY(a) {
|
|
174
|
+
const { x, z } = this;
|
|
175
|
+
this.x = x * Math.cos(a) + z * Math.sin(a);
|
|
176
|
+
this.z = -x * Math.sin(a) + z * Math.cos(a);
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
rotate3dZ(a) {
|
|
180
|
+
const { x, y } = this;
|
|
181
|
+
this.x = x * Math.cos(a) - y * Math.sin(a);
|
|
182
|
+
this.y = -x * Math.sin(a) + y * Math.cos(a);
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
move(x, y = x, z = x) {
|
|
168
186
|
let xV = 0;
|
|
169
187
|
let yV = 0;
|
|
188
|
+
let zV = undefined;
|
|
170
189
|
if (x instanceof DPoint) {
|
|
171
190
|
xV = this.x + x.x;
|
|
172
191
|
yV = this.y + x.y;
|
|
192
|
+
if (this.z && x.z) {
|
|
193
|
+
zV = this.z + x.z;
|
|
194
|
+
}
|
|
173
195
|
}
|
|
174
196
|
else {
|
|
175
197
|
xV = this.x + x;
|
|
176
198
|
yV = this.y + y;
|
|
199
|
+
if (this.z && z) {
|
|
200
|
+
zV = this.z + z;
|
|
201
|
+
}
|
|
177
202
|
}
|
|
178
203
|
this.x = xV;
|
|
179
204
|
this.y = yV;
|
|
205
|
+
if (zV) {
|
|
206
|
+
this.z = zV;
|
|
207
|
+
}
|
|
180
208
|
return this;
|
|
181
209
|
}
|
|
182
210
|
degreeToMeters() {
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export declare class DPolygon {
|
|
|
54
54
|
setCenter(newCenter: DPoint): DPolygon;
|
|
55
55
|
static WKT_LINESTRING: string;
|
|
56
56
|
static WKT_POLYGON: string;
|
|
57
|
-
toWKT(type?: string): string;
|
|
57
|
+
toWKT(type?: string, withZ?: boolean): string;
|
|
58
58
|
filter(f: (p: DPoint) => boolean): DPolygon;
|
|
59
59
|
map(f: (r: DPoint) => DPoint): DPolygon;
|
|
60
60
|
map(f: (r: DPoint, index: number) => DPoint): DPolygon;
|
package/dist/DPolygon.js
CHANGED
|
@@ -326,17 +326,17 @@ class DPolygon {
|
|
|
326
326
|
.move(newCenter.clone().move(this.center.minus()))
|
|
327
327
|
.run();
|
|
328
328
|
}
|
|
329
|
-
toWKT(type = DPolygon.WKT_POLYGON) {
|
|
329
|
+
toWKT(type = DPolygon.WKT_POLYGON, withZ = false) {
|
|
330
330
|
if (type === DPolygon.WKT_POLYGON) {
|
|
331
331
|
let h = '';
|
|
332
332
|
if (this.holes && this.holes.length) {
|
|
333
333
|
h = `, ${this.holes.map((hole) => hole.toString())
|
|
334
334
|
.join(', ')}`;
|
|
335
335
|
}
|
|
336
|
-
return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}`)
|
|
336
|
+
return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
337
337
|
.join(', ')})${h})`;
|
|
338
338
|
}
|
|
339
|
-
return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}`)
|
|
339
|
+
return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
340
340
|
.join(', ')})`;
|
|
341
341
|
}
|
|
342
342
|
filter(f) {
|
package/dist/DPolygonLoop.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export declare class DPolygonLoop {
|
|
|
17
17
|
setZ(z: number): DPolygonLoop;
|
|
18
18
|
setZ(f: SetterFunction): DPolygonLoop;
|
|
19
19
|
rotate(a: number): DPolygonLoop;
|
|
20
|
+
rotate3dX(a: number): DPolygonLoop;
|
|
21
|
+
rotate3dY(a: number): DPolygonLoop;
|
|
22
|
+
rotate3dZ(a: number): DPolygonLoop;
|
|
20
23
|
move(v: number): DPolygonLoop;
|
|
21
24
|
move(p: DPoint): DPolygonLoop;
|
|
22
25
|
move(x: number, y: number): DPolygonLoop;
|
package/dist/DPolygonLoop.js
CHANGED
|
@@ -10,28 +10,31 @@ var LoopFunctions;
|
|
|
10
10
|
LoopFunctions[LoopFunctions["setY"] = 4] = "setY";
|
|
11
11
|
LoopFunctions[LoopFunctions["setZ"] = 5] = "setZ";
|
|
12
12
|
LoopFunctions[LoopFunctions["rotate"] = 6] = "rotate";
|
|
13
|
-
LoopFunctions[LoopFunctions["
|
|
14
|
-
LoopFunctions[LoopFunctions["
|
|
15
|
-
LoopFunctions[LoopFunctions["
|
|
16
|
-
LoopFunctions[LoopFunctions["
|
|
17
|
-
LoopFunctions[LoopFunctions["
|
|
18
|
-
LoopFunctions[LoopFunctions["
|
|
19
|
-
LoopFunctions[LoopFunctions["
|
|
20
|
-
LoopFunctions[LoopFunctions["
|
|
21
|
-
LoopFunctions[LoopFunctions["
|
|
22
|
-
LoopFunctions[LoopFunctions["
|
|
23
|
-
LoopFunctions[LoopFunctions["
|
|
24
|
-
LoopFunctions[LoopFunctions["
|
|
25
|
-
LoopFunctions[LoopFunctions["
|
|
26
|
-
LoopFunctions[LoopFunctions["
|
|
27
|
-
LoopFunctions[LoopFunctions["
|
|
28
|
-
LoopFunctions[LoopFunctions["
|
|
29
|
-
LoopFunctions[LoopFunctions["
|
|
30
|
-
LoopFunctions[LoopFunctions["
|
|
31
|
-
LoopFunctions[LoopFunctions["
|
|
32
|
-
LoopFunctions[LoopFunctions["
|
|
33
|
-
LoopFunctions[LoopFunctions["
|
|
34
|
-
LoopFunctions[LoopFunctions["
|
|
13
|
+
LoopFunctions[LoopFunctions["rotate3dX"] = 7] = "rotate3dX";
|
|
14
|
+
LoopFunctions[LoopFunctions["rotate3dY"] = 8] = "rotate3dY";
|
|
15
|
+
LoopFunctions[LoopFunctions["rotate3dZ"] = 9] = "rotate3dZ";
|
|
16
|
+
LoopFunctions[LoopFunctions["move"] = 10] = "move";
|
|
17
|
+
LoopFunctions[LoopFunctions["round"] = 11] = "round";
|
|
18
|
+
LoopFunctions[LoopFunctions["ceil"] = 12] = "ceil";
|
|
19
|
+
LoopFunctions[LoopFunctions["floor"] = 13] = "floor";
|
|
20
|
+
LoopFunctions[LoopFunctions["toFixed"] = 14] = "toFixed";
|
|
21
|
+
LoopFunctions[LoopFunctions["abs"] = 15] = "abs";
|
|
22
|
+
LoopFunctions[LoopFunctions["scale"] = 16] = "scale";
|
|
23
|
+
LoopFunctions[LoopFunctions["divide"] = 17] = "divide";
|
|
24
|
+
LoopFunctions[LoopFunctions["degreeToRadians"] = 18] = "degreeToRadians";
|
|
25
|
+
LoopFunctions[LoopFunctions["radiansToDegrees"] = 19] = "radiansToDegrees";
|
|
26
|
+
LoopFunctions[LoopFunctions["radiansToMeters"] = 20] = "radiansToMeters";
|
|
27
|
+
LoopFunctions[LoopFunctions["metersToRadians"] = 21] = "metersToRadians";
|
|
28
|
+
LoopFunctions[LoopFunctions["hipPoint"] = 22] = "hipPoint";
|
|
29
|
+
LoopFunctions[LoopFunctions["xPoint"] = 23] = "xPoint";
|
|
30
|
+
LoopFunctions[LoopFunctions["yPoint"] = 24] = "yPoint";
|
|
31
|
+
LoopFunctions[LoopFunctions["wPoint"] = 25] = "wPoint";
|
|
32
|
+
LoopFunctions[LoopFunctions["hPoint"] = 26] = "hPoint";
|
|
33
|
+
LoopFunctions[LoopFunctions["setIfLessThan"] = 27] = "setIfLessThan";
|
|
34
|
+
LoopFunctions[LoopFunctions["minus"] = 28] = "minus";
|
|
35
|
+
LoopFunctions[LoopFunctions["degreeToMeters"] = 29] = "degreeToMeters";
|
|
36
|
+
LoopFunctions[LoopFunctions["metersToDegree"] = 30] = "metersToDegree";
|
|
37
|
+
LoopFunctions[LoopFunctions["flipVertically"] = 31] = "flipVertically";
|
|
35
38
|
})(LoopFunctions || (LoopFunctions = {}));
|
|
36
39
|
const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg, setterArg }) => {
|
|
37
40
|
let res = a;
|
|
@@ -64,6 +67,18 @@ const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg
|
|
|
64
67
|
res = (k) => a(k)
|
|
65
68
|
.rotate(numberArg);
|
|
66
69
|
break;
|
|
70
|
+
case LoopFunctions.rotate3dX:
|
|
71
|
+
res = (k) => a(k)
|
|
72
|
+
.rotate3dX(numberArg);
|
|
73
|
+
break;
|
|
74
|
+
case LoopFunctions.rotate3dY:
|
|
75
|
+
res = (k) => a(k)
|
|
76
|
+
.rotate3dY(numberArg);
|
|
77
|
+
break;
|
|
78
|
+
case LoopFunctions.rotate3dZ:
|
|
79
|
+
res = (k) => a(k)
|
|
80
|
+
.rotate3dZ(numberArg);
|
|
81
|
+
break;
|
|
67
82
|
case LoopFunctions.move:
|
|
68
83
|
res = (k) => a(k)
|
|
69
84
|
.move(numberPointArg, numberArg);
|
|
@@ -215,6 +230,27 @@ class DPolygonLoop {
|
|
|
215
230
|
});
|
|
216
231
|
return this;
|
|
217
232
|
}
|
|
233
|
+
rotate3dX(a) {
|
|
234
|
+
this.pool.push({
|
|
235
|
+
functionName: LoopFunctions.rotate3dX,
|
|
236
|
+
numberArg: a
|
|
237
|
+
});
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
rotate3dY(a) {
|
|
241
|
+
this.pool.push({
|
|
242
|
+
functionName: LoopFunctions.rotate3dY,
|
|
243
|
+
numberArg: a
|
|
244
|
+
});
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
rotate3dZ(a) {
|
|
248
|
+
this.pool.push({
|
|
249
|
+
functionName: LoopFunctions.rotate3dZ,
|
|
250
|
+
numberArg: a
|
|
251
|
+
});
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
218
254
|
move(x, y = x) {
|
|
219
255
|
this.pool.push({
|
|
220
256
|
functionName: LoopFunctions.move,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./DPolygon"), exports);
|
|
|
19
19
|
__exportStar(require("./FastSearch"), exports);
|
|
20
20
|
__exportStar(require("./TraceMatrix"), exports);
|
|
21
21
|
__exportStar(require("./DPolygonLoop"), exports);
|
|
22
|
+
__exportStar(require("./DPlane"), exports);
|
|
22
23
|
exports.DGeo = {
|
|
23
24
|
DEBUG: false
|
|
24
25
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -13,4 +13,6 @@ interface CheckFunction {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const checkFunction: (funcName: string) => CheckFunction;
|
|
15
15
|
export declare const createArray: (v: number) => number[];
|
|
16
|
+
export declare const createMatrix: ({ h, w }: DPoint) => number[][];
|
|
17
|
+
export declare const gaussianElimination: (matrix: number[][]) => number[];
|
|
16
18
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createArray = exports.checkFunction = exports.warn = void 0;
|
|
3
|
+
exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.warn = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
const DPoint_1 = require("./DPoint");
|
|
6
6
|
const warn = (...args) => {
|
|
@@ -65,3 +65,49 @@ const checkFunction = (funcName) => ({
|
|
|
65
65
|
exports.checkFunction = checkFunction;
|
|
66
66
|
const createArray = (v) => new Array(v).fill(0);
|
|
67
67
|
exports.createArray = createArray;
|
|
68
|
+
const createMatrix = ({ h, w }) => (0, exports.createArray)(h).map(() => (0, exports.createArray)(w));
|
|
69
|
+
exports.createMatrix = createMatrix;
|
|
70
|
+
const GAUSSIAN_ELIMINATION_MIN = 1e-10;
|
|
71
|
+
const gaussianElimination = (matrix) => {
|
|
72
|
+
const n = matrix.length;
|
|
73
|
+
const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
|
|
74
|
+
for (let i = 0; i < n; i++) {
|
|
75
|
+
for (let j = 0; j < n + 1; j++) {
|
|
76
|
+
matrix[i][j] = matrix[i][j] === 0 ? GAUSSIAN_ELIMINATION_MIN : matrix[i][j];
|
|
77
|
+
matrixClone[i][j] = matrix[i][j];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (let k = 0; k < n; k++) {
|
|
81
|
+
for (let i = 0; i < n + 1; i++) {
|
|
82
|
+
matrixClone[k][i] /= matrix[k][k];
|
|
83
|
+
}
|
|
84
|
+
for (let i = k + 1; i < n; i++) {
|
|
85
|
+
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
86
|
+
for (let j = 0; j < n + 1; j++) {
|
|
87
|
+
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (let i = 0; i < n; i++) {
|
|
91
|
+
for (let j = 0; j < n + 1; j++) {
|
|
92
|
+
matrix[i][j] = matrixClone[i][j];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (let k = n - 1; k > -1; k--) {
|
|
97
|
+
for (let i = n; i > -1; i--) {
|
|
98
|
+
matrixClone[k][i] /= matrix[k][k];
|
|
99
|
+
}
|
|
100
|
+
for (let i = k - 1; i > -1; i--) {
|
|
101
|
+
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
102
|
+
for (let j = n; j > -1; j--) {
|
|
103
|
+
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const answer = (0, exports.createArray)(n);
|
|
108
|
+
for (let i = 0; i < n; i++) {
|
|
109
|
+
answer[i] = matrixClone[i][n];
|
|
110
|
+
}
|
|
111
|
+
return answer;
|
|
112
|
+
};
|
|
113
|
+
exports.gaussianElimination = gaussianElimination;
|