dgeoutils 2.2.9 → 2.2.13
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 +6 -0
- package/dist/DPoint.js +54 -5
- package/dist/DPolygon.d.ts +3 -1
- package/dist/DPolygon.js +23 -3
- package/dist/DPolygonLoop.d.ts +3 -0
- package/dist/DPolygonLoop.js +58 -22
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -1
- package/dist/utils.d.ts +12 -2
- package/dist/utils.js +83 -2
- 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;
|
|
@@ -66,9 +70,11 @@ export declare class DPoint {
|
|
|
66
70
|
scale(v: number): DPoint;
|
|
67
71
|
scale(p: DPoint): DPoint;
|
|
68
72
|
scale(x: number, y: number): DPoint;
|
|
73
|
+
scale(x: number, y: number, z: number): DPoint;
|
|
69
74
|
divide(v: number): DPoint;
|
|
70
75
|
divide(p: DPoint): DPoint;
|
|
71
76
|
divide(x: number, y: number): DPoint;
|
|
77
|
+
divide(x: number, y: number, z: number): DPoint;
|
|
72
78
|
equal(p: DPoint): boolean;
|
|
73
79
|
like(p: DPoint, d?: number): boolean;
|
|
74
80
|
flipVertically(size: DPoint): 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) {
|
|
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 ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(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 ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
200
|
+
zV = this.z + z;
|
|
201
|
+
}
|
|
177
202
|
}
|
|
178
203
|
this.x = xV;
|
|
179
204
|
this.y = yV;
|
|
205
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
206
|
+
this.z = zV;
|
|
207
|
+
}
|
|
180
208
|
return this;
|
|
181
209
|
}
|
|
182
210
|
degreeToMeters() {
|
|
@@ -250,46 +278,67 @@ class DPoint {
|
|
|
250
278
|
this.y = Math.abs(this.y);
|
|
251
279
|
return this;
|
|
252
280
|
}
|
|
253
|
-
scale(x, y = x) {
|
|
281
|
+
scale(x, y = x, z) {
|
|
254
282
|
let xV = 0;
|
|
255
283
|
let yV = 0;
|
|
284
|
+
let zV = undefined;
|
|
256
285
|
if (x instanceof DPoint) {
|
|
257
286
|
xV = this.x * x.x;
|
|
258
287
|
yV = this.y * x.y;
|
|
288
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
|
|
289
|
+
zV = this.z * x.z;
|
|
290
|
+
}
|
|
259
291
|
}
|
|
260
292
|
else {
|
|
261
293
|
xV = this.x * x;
|
|
262
294
|
yV = this.y * y;
|
|
295
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
296
|
+
zV = this.z * z;
|
|
297
|
+
}
|
|
263
298
|
}
|
|
264
299
|
this.x = xV;
|
|
265
300
|
this.y = yV;
|
|
301
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
302
|
+
this.z = zV;
|
|
303
|
+
}
|
|
266
304
|
return this;
|
|
267
305
|
}
|
|
268
|
-
divide(x, y = x) {
|
|
306
|
+
divide(x, y = x, z) {
|
|
269
307
|
let xV = 0;
|
|
270
308
|
let yV = 0;
|
|
309
|
+
let zV = undefined;
|
|
271
310
|
if (x instanceof DPoint) {
|
|
272
311
|
xV = this.x / x.x;
|
|
273
312
|
yV = this.y / x.y;
|
|
313
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
|
|
314
|
+
zV = this.z / x.z;
|
|
315
|
+
}
|
|
274
316
|
}
|
|
275
317
|
else {
|
|
276
318
|
xV = this.x / x;
|
|
277
319
|
yV = this.y / y;
|
|
320
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
321
|
+
zV = this.z / z;
|
|
322
|
+
}
|
|
278
323
|
}
|
|
279
324
|
this.x = xV;
|
|
280
325
|
this.y = yV;
|
|
326
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
327
|
+
this.z = zV;
|
|
328
|
+
}
|
|
281
329
|
return this;
|
|
282
330
|
}
|
|
283
331
|
equal(p) {
|
|
284
332
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
285
333
|
}
|
|
286
334
|
like(p, d = 0.001) {
|
|
335
|
+
var _a, _b, _c, _d;
|
|
287
336
|
if (this.equal(p)) {
|
|
288
337
|
return true;
|
|
289
338
|
}
|
|
290
339
|
const likeX = Math.abs(this.x - p.x) < d;
|
|
291
340
|
const likeY = Math.abs(this.y - p.y) < d;
|
|
292
|
-
const likeZ = Math.abs((this.z
|
|
341
|
+
const likeZ = Math.abs(((_b = (_a = this.z) !== null && _a !== void 0 ? _a : p.z) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = p.z) !== null && _c !== void 0 ? _c : this.z) !== null && _d !== void 0 ? _d : 0)) < d;
|
|
293
342
|
return likeX && likeY && likeZ;
|
|
294
343
|
}
|
|
295
344
|
flipVertically(size) {
|
|
@@ -378,7 +427,7 @@ class DPoint {
|
|
|
378
427
|
return this;
|
|
379
428
|
}
|
|
380
429
|
minus() {
|
|
381
|
-
return this.
|
|
430
|
+
return this.scale(-1);
|
|
382
431
|
}
|
|
383
432
|
orthodromicPath(point, pointsCount = 360) {
|
|
384
433
|
(0, utils_1.checkFunction)('orthodromicPath')
|
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;
|
|
@@ -101,6 +101,8 @@ export declare class DPolygon {
|
|
|
101
101
|
getTrianglesPointIndexes(): number[];
|
|
102
102
|
get closed(): boolean;
|
|
103
103
|
buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
|
|
104
|
+
bezier(step?: number): DPolygon;
|
|
105
|
+
private getBezierPoint;
|
|
104
106
|
private simpleIncludeX;
|
|
105
107
|
private simpleIncludeY;
|
|
106
108
|
private douglasPeucker;
|
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) {
|
|
@@ -807,6 +807,26 @@ class DPolygon {
|
|
|
807
807
|
.getCoordinates();
|
|
808
808
|
return new DPolygon(points.map(({ x, y }) => new DPoint_1.DPoint(x, y)));
|
|
809
809
|
}
|
|
810
|
+
bezier(step = 0.1) {
|
|
811
|
+
const res = new DPolygon();
|
|
812
|
+
for (let i = 0; i < 1; i += step) {
|
|
813
|
+
res.push(this.clone().getBezierPoint(i));
|
|
814
|
+
}
|
|
815
|
+
return res;
|
|
816
|
+
}
|
|
817
|
+
getBezierPoint(v) {
|
|
818
|
+
if (this.length === 1) {
|
|
819
|
+
return this.first;
|
|
820
|
+
}
|
|
821
|
+
for (let i = 0; i < this.length - 1; i++) {
|
|
822
|
+
const p1 = this.at(i);
|
|
823
|
+
const p2 = this.at(i + 1);
|
|
824
|
+
p1.move(p2.clone().move(p1.clone().minus())
|
|
825
|
+
.scale(v));
|
|
826
|
+
}
|
|
827
|
+
this.pop();
|
|
828
|
+
return this.getBezierPoint(v);
|
|
829
|
+
}
|
|
810
830
|
simpleIncludeX(p) {
|
|
811
831
|
const { x } = p;
|
|
812
832
|
return this.minX <= x && this.maxX >= x;
|
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
|
@@ -6,6 +6,8 @@ export * from './DPolygon';
|
|
|
6
6
|
export * from './FastSearch';
|
|
7
7
|
export * from './TraceMatrix';
|
|
8
8
|
export * from './DPolygonLoop';
|
|
9
|
+
export * from './DPlane';
|
|
10
|
+
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull } from './utils';
|
|
9
11
|
export declare const DGeo: {
|
|
10
12
|
DEBUG: boolean;
|
|
11
13
|
};
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.DGeo = void 0;
|
|
13
|
+
exports.DGeo = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
|
|
14
14
|
__exportStar(require("./DCircle"), exports);
|
|
15
15
|
__exportStar(require("./DLine"), exports);
|
|
16
16
|
__exportStar(require("./DNumbers"), exports);
|
|
@@ -19,6 +19,13 @@ __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);
|
|
23
|
+
var utils_1 = require("./utils");
|
|
24
|
+
Object.defineProperty(exports, "gaussianElimination", { enumerable: true, get: function () { return utils_1.gaussianElimination; } });
|
|
25
|
+
Object.defineProperty(exports, "createCanvas", { enumerable: true, get: function () { return utils_1.createCanvas; } });
|
|
26
|
+
Object.defineProperty(exports, "createArray", { enumerable: true, get: function () { return utils_1.createArray; } });
|
|
27
|
+
Object.defineProperty(exports, "createMatrix", { enumerable: true, get: function () { return utils_1.createMatrix; } });
|
|
28
|
+
Object.defineProperty(exports, "isDefAndNotNull", { enumerable: true, get: function () { return utils_1.isDefAndNotNull; } });
|
|
22
29
|
exports.DGeo = {
|
|
23
30
|
DEBUG: false
|
|
24
31
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="offscreencanvas" />
|
|
1
2
|
import { DPoint } from './DPoint';
|
|
2
3
|
export declare const warn: (...args: any[]) => void;
|
|
3
4
|
declare type CheckFunc = (p: DPoint) => CheckFunction;
|
|
@@ -12,5 +13,14 @@ interface CheckFunction {
|
|
|
12
13
|
checkArgument: (argName: string) => CheckArgument;
|
|
13
14
|
}
|
|
14
15
|
export declare const checkFunction: (funcName: string) => CheckFunction;
|
|
15
|
-
export declare const createArray: (v: number) => number[];
|
|
16
|
-
export {};
|
|
16
|
+
export declare const createArray: (v: number, fillSymbol?: any) => number[];
|
|
17
|
+
export declare const createMatrix: ({ h, w }: DPoint, fillSymbol?: any) => number[][];
|
|
18
|
+
export declare const gaussianElimination: (matrix: number[][]) => number[];
|
|
19
|
+
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
20
|
+
declare function createCanvas(size: number): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
21
|
+
declare function createCanvas(size: number, offscreen: boolean): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
22
|
+
declare function createCanvas(w: number, h: number): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
23
|
+
declare function createCanvas(w: number, h: number, offscreen: boolean): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
24
|
+
declare function createCanvas(size: DPoint): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
25
|
+
declare function createCanvas(size: DPoint, offscreen: boolean): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
26
|
+
export { createCanvas };
|
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.createCanvas = exports.isDefAndNotNull = 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) => {
|
|
@@ -63,5 +63,86 @@ const checkFunction = (funcName) => ({
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
exports.checkFunction = checkFunction;
|
|
66
|
-
const createArray = (v) => new Array(v).fill(
|
|
66
|
+
const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
|
|
67
67
|
exports.createArray = createArray;
|
|
68
|
+
const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
|
|
69
|
+
.map(() => (0, exports.createArray)(w, fillSymbol));
|
|
70
|
+
exports.createMatrix = createMatrix;
|
|
71
|
+
const GAUSSIAN_ELIMINATION_MIN = 1e-10;
|
|
72
|
+
const gaussianElimination = (matrix) => {
|
|
73
|
+
const n = matrix.length;
|
|
74
|
+
const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
|
|
75
|
+
for (let i = 0; i < n; i++) {
|
|
76
|
+
for (let j = 0; j < n + 1; j++) {
|
|
77
|
+
matrix[i][j] = matrix[i][j] === 0 ? GAUSSIAN_ELIMINATION_MIN : matrix[i][j];
|
|
78
|
+
matrixClone[i][j] = matrix[i][j];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (let k = 0; k < n; k++) {
|
|
82
|
+
for (let i = 0; i < n + 1; i++) {
|
|
83
|
+
matrixClone[k][i] /= matrix[k][k];
|
|
84
|
+
}
|
|
85
|
+
for (let i = k + 1; i < n; i++) {
|
|
86
|
+
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
87
|
+
for (let j = 0; j < n + 1; j++) {
|
|
88
|
+
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (let i = 0; i < n; i++) {
|
|
92
|
+
for (let j = 0; j < n + 1; j++) {
|
|
93
|
+
matrix[i][j] = matrixClone[i][j];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (let k = n - 1; k > -1; k--) {
|
|
98
|
+
for (let i = n; i > -1; i--) {
|
|
99
|
+
matrixClone[k][i] /= matrix[k][k];
|
|
100
|
+
}
|
|
101
|
+
for (let i = k - 1; i > -1; i--) {
|
|
102
|
+
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
103
|
+
for (let j = n; j > -1; j--) {
|
|
104
|
+
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const answer = (0, exports.createArray)(n);
|
|
109
|
+
for (let i = 0; i < n; i++) {
|
|
110
|
+
answer[i] = matrixClone[i][n];
|
|
111
|
+
}
|
|
112
|
+
return answer;
|
|
113
|
+
};
|
|
114
|
+
exports.gaussianElimination = gaussianElimination;
|
|
115
|
+
const isDefAndNotNull = (a) => a != undefined;
|
|
116
|
+
exports.isDefAndNotNull = isDefAndNotNull;
|
|
117
|
+
function createCanvas(a, b, c) {
|
|
118
|
+
var _a;
|
|
119
|
+
let w = 0;
|
|
120
|
+
let h = 0;
|
|
121
|
+
let offscreen = false;
|
|
122
|
+
if (a instanceof DPoint_1.DPoint) {
|
|
123
|
+
const { x, y } = a;
|
|
124
|
+
w = x;
|
|
125
|
+
h = y;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
w = a;
|
|
129
|
+
h = a;
|
|
130
|
+
}
|
|
131
|
+
if (typeof b === 'boolean') {
|
|
132
|
+
offscreen = b;
|
|
133
|
+
}
|
|
134
|
+
else if (typeof b === 'number') {
|
|
135
|
+
h = b;
|
|
136
|
+
}
|
|
137
|
+
if (typeof c === 'boolean') {
|
|
138
|
+
offscreen = c;
|
|
139
|
+
}
|
|
140
|
+
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
141
|
+
if (!offscreen) {
|
|
142
|
+
canvas.width = w;
|
|
143
|
+
canvas.height = h;
|
|
144
|
+
}
|
|
145
|
+
const ctx = canvas.getContext('2d');
|
|
146
|
+
return [canvas, ctx];
|
|
147
|
+
}
|
|
148
|
+
exports.createCanvas = createCanvas;
|