dgeoutils 2.2.1 → 2.2.2
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/DCircle.d.ts +3 -3
- package/dist/DCircle.js +3 -3
- package/dist/DLine.js +1 -5
- package/dist/DPoint.js +4 -1
- package/dist/DPolygon.d.ts +48 -7
- package/dist/DPolygon.js +134 -125
- package/dist/TraceMatrix.js +4 -4
- package/package.json +1 -1
package/dist/DCircle.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class DCircle {
|
|
|
13
13
|
/**
|
|
14
14
|
* Find intersection points with other circle.
|
|
15
15
|
*
|
|
16
|
-
* 
|
|
16
|
+
* 
|
|
17
17
|
* @param c
|
|
18
18
|
*/
|
|
19
19
|
findPoints(c: DCircle): DPoint[] | number;
|
|
@@ -21,7 +21,7 @@ export declare class DCircle {
|
|
|
21
21
|
/**
|
|
22
22
|
* Transform circle to polygon
|
|
23
23
|
*
|
|
24
|
-
* 
|
|
24
|
+
* 
|
|
25
25
|
* @param [pointCount=64]
|
|
26
26
|
*/
|
|
27
27
|
findPolygonInside(pointCount?: number): DPolygon;
|
|
@@ -34,7 +34,7 @@ export declare class DCircle {
|
|
|
34
34
|
* @remarks
|
|
35
35
|
* Radius should be in meters.
|
|
36
36
|
*
|
|
37
|
-
* 
|
|
37
|
+
* 
|
|
38
38
|
* @param [pointCount=64]
|
|
39
39
|
*/
|
|
40
40
|
findPolygonInsideOnSphere(pointCount?: number): DPolygon;
|
package/dist/DCircle.js
CHANGED
|
@@ -24,7 +24,7 @@ class DCircle {
|
|
|
24
24
|
/**
|
|
25
25
|
* Find intersection points with other circle.
|
|
26
26
|
*
|
|
27
|
-
* 
|
|
27
|
+
* 
|
|
28
28
|
* @param c
|
|
29
29
|
*/
|
|
30
30
|
findPoints(c) {
|
|
@@ -62,7 +62,7 @@ class DCircle {
|
|
|
62
62
|
/**
|
|
63
63
|
* Transform circle to polygon
|
|
64
64
|
*
|
|
65
|
-
* 
|
|
65
|
+
* 
|
|
66
66
|
* @param [pointCount=64]
|
|
67
67
|
*/
|
|
68
68
|
findPolygonInside(pointCount = 64) {
|
|
@@ -85,7 +85,7 @@ class DCircle {
|
|
|
85
85
|
* @remarks
|
|
86
86
|
* Radius should be in meters.
|
|
87
87
|
*
|
|
88
|
-
* 
|
|
88
|
+
* 
|
|
89
89
|
* @param [pointCount=64]
|
|
90
90
|
*/
|
|
91
91
|
findPolygonInsideOnSphere(pointCount = 64) {
|
package/dist/DLine.js
CHANGED
|
@@ -127,12 +127,8 @@ class DLine {
|
|
|
127
127
|
* @param d
|
|
128
128
|
*/
|
|
129
129
|
insideRange(p, d = 0) {
|
|
130
|
-
const {
|
|
131
|
-
const { x, y } = p;
|
|
130
|
+
const { p1, p2 } = this;
|
|
132
131
|
return this.inRange(p, d) && !p1.like(p, 0.00001) && !p2.like(p, 0.00001);
|
|
133
|
-
const isInX = x > minX - d && x < maxX + d;
|
|
134
|
-
const isInY = y > minY - d && y < maxY + d;
|
|
135
|
-
return isInX && isInY && !p1.like(p, 0.00001) && !p2.like(p, 0.00001);
|
|
136
132
|
}
|
|
137
133
|
get center() {
|
|
138
134
|
return this.p1
|
package/dist/DPoint.js
CHANGED
|
@@ -314,9 +314,12 @@ class DPoint {
|
|
|
314
314
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
315
315
|
}
|
|
316
316
|
like(p, d = 0.001) {
|
|
317
|
+
if (this.equal(p)) {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
317
320
|
const likeX = Math.abs(this.x - p.x) < d;
|
|
318
321
|
const likeY = Math.abs(this.y - p.y) < d;
|
|
319
|
-
const likeZ =
|
|
322
|
+
const likeZ = Math.abs((this.z || 0) - (p.z || 0)) < d;
|
|
320
323
|
return likeX && likeY && likeZ;
|
|
321
324
|
}
|
|
322
325
|
flipVertically(size) {
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -142,6 +142,7 @@ export declare class DPolygon {
|
|
|
142
142
|
/**
|
|
143
143
|
* Rotate polygon with center in point {0, 0}
|
|
144
144
|
* @param a Radians
|
|
145
|
+
* @deprecated Better to use loop
|
|
145
146
|
*/
|
|
146
147
|
rotate(a: number): DPolygon;
|
|
147
148
|
/**
|
|
@@ -149,25 +150,69 @@ export declare class DPolygon {
|
|
|
149
150
|
* @param f
|
|
150
151
|
*/
|
|
151
152
|
filter(f: (p: DPoint) => boolean): DPolygon;
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated Better to use loop
|
|
155
|
+
* @param [x=0]
|
|
156
|
+
* @param [y=x]
|
|
157
|
+
*/
|
|
152
158
|
move(x?: number | DPoint, y?: number): DPolygon;
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated Better to use loop
|
|
161
|
+
* @param [x=0]
|
|
162
|
+
* @param [y=x]
|
|
163
|
+
*/
|
|
153
164
|
scale(x?: number | DPoint, y?: number): DPolygon;
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated Better to use loop
|
|
167
|
+
* @param [x=0]
|
|
168
|
+
* @param [y=x]
|
|
169
|
+
*/
|
|
154
170
|
divide(x?: number | DPoint, y?: number): DPolygon;
|
|
171
|
+
/**
|
|
172
|
+
* @deprecated Better to use loop
|
|
173
|
+
*/
|
|
155
174
|
round(): DPolygon;
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Better to use loop
|
|
177
|
+
*/
|
|
156
178
|
floor(): DPolygon;
|
|
179
|
+
/**
|
|
180
|
+
* @deprecated Better to use loop
|
|
181
|
+
*/
|
|
157
182
|
ceil(): DPolygon;
|
|
183
|
+
/**
|
|
184
|
+
* @deprecated Better to use loop
|
|
185
|
+
* @param size
|
|
186
|
+
*/
|
|
158
187
|
flipVertically(size: DPoint | number): DPolygon;
|
|
188
|
+
/**
|
|
189
|
+
* @deprecated Better to use loop
|
|
190
|
+
* @param [n=2]
|
|
191
|
+
*/
|
|
159
192
|
toFixed(n?: number): DPolygon;
|
|
160
193
|
map(f: (r: DPoint, index?: number) => DPoint): DPolygon;
|
|
161
|
-
|
|
194
|
+
at(index: number): DPoint;
|
|
162
195
|
pop(): DPoint;
|
|
163
196
|
push(...args: DPoint[]): number;
|
|
164
197
|
shift(): DPoint;
|
|
165
198
|
unshift(...args: DPoint[]): number;
|
|
166
199
|
reverse(): DPolygon;
|
|
167
200
|
getValue(): string;
|
|
201
|
+
/**
|
|
202
|
+
* @deprecated Better to use loop
|
|
203
|
+
*/
|
|
168
204
|
degreeToMeters(): DPolygon;
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated Better to use loop
|
|
207
|
+
*/
|
|
169
208
|
metersToDegree(): DPolygon;
|
|
209
|
+
/**
|
|
210
|
+
* @deprecated Better to use loop
|
|
211
|
+
*/
|
|
170
212
|
radiansToMeters(): DPolygon;
|
|
213
|
+
/**
|
|
214
|
+
* @deprecated Better to use loop
|
|
215
|
+
*/
|
|
171
216
|
metersToRadians(): DPolygon;
|
|
172
217
|
toString(): string;
|
|
173
218
|
/**
|
|
@@ -181,6 +226,7 @@ export declare class DPolygon {
|
|
|
181
226
|
/**
|
|
182
227
|
* Set `height` (`z`)
|
|
183
228
|
* @param z
|
|
229
|
+
* @deprecated Better to use loop
|
|
184
230
|
*/
|
|
185
231
|
height(z: number): DPolygon;
|
|
186
232
|
add(poly: DPolygon): DPolygon;
|
|
@@ -270,14 +316,9 @@ export declare class DPolygon {
|
|
|
270
316
|
/**
|
|
271
317
|
* Divide polygon to triangles
|
|
272
318
|
*
|
|
273
|
-
* 
|
|
319
|
+
* 
|
|
274
320
|
*/
|
|
275
321
|
toTriangles(): DPolygon[];
|
|
276
|
-
/**
|
|
277
|
-
* @internal
|
|
278
|
-
*/
|
|
279
|
-
getTriangle(): DPolygon | void;
|
|
280
|
-
private innerAndNotIntersect;
|
|
281
322
|
private simpleIncludeX;
|
|
282
323
|
private simpleIncludeY;
|
|
283
324
|
private douglasPeucker;
|
package/dist/DPolygon.js
CHANGED
|
@@ -209,8 +209,8 @@ class DPolygon {
|
|
|
209
209
|
const closed = this.deintersection;
|
|
210
210
|
let sum = 0;
|
|
211
211
|
for (let i = 1; i < closed.length; i++) {
|
|
212
|
-
const cur = closed.
|
|
213
|
-
const prev = closed.
|
|
212
|
+
const cur = closed.at(i);
|
|
213
|
+
const prev = closed.at(i - 1);
|
|
214
214
|
sum += prev.x * cur.y - prev.y * cur.x;
|
|
215
215
|
}
|
|
216
216
|
return Math.abs(sum / 2) - this.holes.reduce((a, hole) => a + hole.area, 0);
|
|
@@ -222,8 +222,8 @@ class DPolygon {
|
|
|
222
222
|
const p = this.clone().close();
|
|
223
223
|
for (let i = 0; i < p.length - 1; i++) {
|
|
224
224
|
for (let j = i + 2; j < p.length - 1; j++) {
|
|
225
|
-
const firstLine = p.
|
|
226
|
-
const secondLine = p.
|
|
225
|
+
const firstLine = p.at(i).findLine(p.at(i + 1));
|
|
226
|
+
const secondLine = p.at(j).findLine(p.at(j + 1));
|
|
227
227
|
const intersectionPoint = firstLine.intersection(secondLine);
|
|
228
228
|
if (intersectionPoint &&
|
|
229
229
|
![...firstLine.points, ...secondLine.points].some((t) => t.like(intersectionPoint))) {
|
|
@@ -246,19 +246,19 @@ class DPolygon {
|
|
|
246
246
|
* Get first point
|
|
247
247
|
*/
|
|
248
248
|
get first() {
|
|
249
|
-
return this.
|
|
249
|
+
return this.at(0);
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
252
252
|
* Get second point
|
|
253
253
|
*/
|
|
254
254
|
get second() {
|
|
255
|
-
return this.
|
|
255
|
+
return this.at(1);
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
258
|
* Get last point
|
|
259
259
|
*/
|
|
260
260
|
get last() {
|
|
261
|
-
return this.
|
|
261
|
+
return this.at(this.length - 1);
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
264
264
|
* Get min area rectangle
|
|
@@ -268,21 +268,21 @@ class DPolygon {
|
|
|
268
268
|
let resultPolygon = new DPolygon();
|
|
269
269
|
let resultArea = Infinity;
|
|
270
270
|
for (let k = 0; k < p.length - 1; k++) {
|
|
271
|
-
const l = p.
|
|
271
|
+
const l = p.at(k).findLine(p.at(k + 1));
|
|
272
272
|
let maxWidth = 0;
|
|
273
273
|
let maxWidthPoint1 = null;
|
|
274
274
|
let maxWidthPoint2 = null;
|
|
275
275
|
let maxHeight = 0;
|
|
276
276
|
let maxHeightPoint = null;
|
|
277
277
|
for (let i = 0; i < p.length - 1; i++) {
|
|
278
|
-
const p1 = l.findPoint(l.findPerpendicular(p.
|
|
279
|
-
const h = p1.distance(p.
|
|
278
|
+
const p1 = l.findPoint(l.findPerpendicular(p.at(i)));
|
|
279
|
+
const h = p1.distance(p.at(i));
|
|
280
280
|
if (h >= maxHeight) {
|
|
281
281
|
maxHeight = h;
|
|
282
|
-
maxHeightPoint = p.
|
|
282
|
+
maxHeightPoint = p.at(i);
|
|
283
283
|
}
|
|
284
284
|
for (let j = i; j < p.length - 1; j++) {
|
|
285
|
-
const p2 = l.findPoint(l.findPerpendicular(p.
|
|
285
|
+
const p2 = l.findPoint(l.findPerpendicular(p.at(j)));
|
|
286
286
|
const w = p1.distance(p2);
|
|
287
287
|
if (w >= maxWidth) {
|
|
288
288
|
maxWidth = w;
|
|
@@ -338,9 +338,9 @@ class DPolygon {
|
|
|
338
338
|
p = p.deintersection;
|
|
339
339
|
l = p.length;
|
|
340
340
|
for (let i = 1; i < p.length - 1; i++) {
|
|
341
|
-
const p1 = p.
|
|
342
|
-
const p2 = p.
|
|
343
|
-
const p3 = p.
|
|
341
|
+
const p1 = p.at(i - 1);
|
|
342
|
+
const p2 = p.at(i);
|
|
343
|
+
const p3 = p.at(i + 1);
|
|
344
344
|
const d = p2.findInnerAngle(p1, p3);
|
|
345
345
|
if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
|
|
346
346
|
p.removePart(--i, 1);
|
|
@@ -360,8 +360,8 @@ class DPolygon {
|
|
|
360
360
|
let sum = 0;
|
|
361
361
|
const p = this.clone().close();
|
|
362
362
|
for (let i = 1; i < p.length; i++) {
|
|
363
|
-
const p1 = p.
|
|
364
|
-
const p2 = p.
|
|
363
|
+
const p1 = p.at(i - 1);
|
|
364
|
+
const p2 = p.at(i);
|
|
365
365
|
sum += (p2.x - p1.x) * (p2.y + p1.y);
|
|
366
366
|
}
|
|
367
367
|
return sum < 0;
|
|
@@ -406,7 +406,9 @@ class DPolygon {
|
|
|
406
406
|
* @param newCenter
|
|
407
407
|
*/
|
|
408
408
|
setCenter(newCenter) {
|
|
409
|
-
return this.
|
|
409
|
+
return this.loop()
|
|
410
|
+
.move(newCenter.clone().move(this.center.minus()))
|
|
411
|
+
.run();
|
|
410
412
|
}
|
|
411
413
|
toWKT() {
|
|
412
414
|
let h = '';
|
|
@@ -418,11 +420,10 @@ class DPolygon {
|
|
|
418
420
|
/**
|
|
419
421
|
* Rotate polygon with center in point {0, 0}
|
|
420
422
|
* @param a Radians
|
|
423
|
+
* @deprecated Better to use loop
|
|
421
424
|
*/
|
|
422
425
|
rotate(a) {
|
|
423
|
-
|
|
424
|
-
this.holes = this.holes.map((h) => h.rotate(a));
|
|
425
|
-
return this;
|
|
426
|
+
return this.map((h) => h.rotate(a));
|
|
426
427
|
}
|
|
427
428
|
/**
|
|
428
429
|
* Filter points
|
|
@@ -432,60 +433,70 @@ class DPolygon {
|
|
|
432
433
|
this.pPoints = this.pPoints.filter(f);
|
|
433
434
|
return this;
|
|
434
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* @deprecated Better to use loop
|
|
438
|
+
* @param [x=0]
|
|
439
|
+
* @param [y=x]
|
|
440
|
+
*/
|
|
435
441
|
move(x = 0, y) {
|
|
436
|
-
|
|
437
|
-
this.holes = this.holes.map((h) => h.move(x, y));
|
|
438
|
-
return this;
|
|
442
|
+
return this.map((h) => h.move(x, y));
|
|
439
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* @deprecated Better to use loop
|
|
446
|
+
* @param [x=0]
|
|
447
|
+
* @param [y=x]
|
|
448
|
+
*/
|
|
440
449
|
scale(x = 0, y) {
|
|
441
|
-
|
|
442
|
-
this.holes = this.holes.map((h) => h.scale(x, y));
|
|
443
|
-
return this;
|
|
450
|
+
return this.map((h) => h.scale(x, y));
|
|
444
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* @deprecated Better to use loop
|
|
454
|
+
* @param [x=0]
|
|
455
|
+
* @param [y=x]
|
|
456
|
+
*/
|
|
445
457
|
divide(x = 0, y) {
|
|
446
|
-
|
|
447
|
-
this.holes = this.holes.map((h) => h.divide(x, y));
|
|
448
|
-
return this;
|
|
458
|
+
return this.map((h) => h.divide(x, y));
|
|
449
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* @deprecated Better to use loop
|
|
462
|
+
*/
|
|
450
463
|
round() {
|
|
451
|
-
|
|
452
|
-
this.holes = this.holes.map((h) => h.round());
|
|
453
|
-
return this;
|
|
464
|
+
return this.map((h) => h.round());
|
|
454
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* @deprecated Better to use loop
|
|
468
|
+
*/
|
|
455
469
|
floor() {
|
|
456
|
-
|
|
457
|
-
this.holes = this.holes.map((h) => h.floor());
|
|
458
|
-
return this;
|
|
470
|
+
return this.map((h) => h.floor());
|
|
459
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* @deprecated Better to use loop
|
|
474
|
+
*/
|
|
460
475
|
ceil() {
|
|
461
|
-
|
|
462
|
-
this.holes = this.holes.map((h) => h.ceil());
|
|
463
|
-
return this;
|
|
476
|
+
return this.map((h) => h.ceil());
|
|
464
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* @deprecated Better to use loop
|
|
480
|
+
* @param size
|
|
481
|
+
*/
|
|
465
482
|
flipVertically(size) {
|
|
466
|
-
|
|
467
|
-
this.holes = this.holes.map((h) => h.flipVertically(size));
|
|
468
|
-
return this;
|
|
483
|
+
return this.map((h) => h.flipVertically(size));
|
|
469
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* @deprecated Better to use loop
|
|
487
|
+
* @param [n=2]
|
|
488
|
+
*/
|
|
470
489
|
toFixed(n = 2) {
|
|
471
|
-
|
|
472
|
-
this.holes = this.holes.map((h) => h.toFixed(n));
|
|
473
|
-
return this;
|
|
490
|
+
return this.map((h) => h.toFixed(n));
|
|
474
491
|
}
|
|
475
492
|
map(f) {
|
|
476
493
|
this.pPoints = this.pPoints.map(f);
|
|
477
494
|
this.holes = this.holes.map((h) => h.map(f));
|
|
478
495
|
return this;
|
|
479
496
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
while (t < 0) {
|
|
484
|
-
t += this.length;
|
|
485
|
-
}
|
|
486
|
-
return this.pPoints[t % this.length];
|
|
487
|
-
}
|
|
488
|
-
return this.pPoints[index];
|
|
497
|
+
at(index) {
|
|
498
|
+
const { length } = this;
|
|
499
|
+
return this.points[(index % length + length) % length];
|
|
489
500
|
}
|
|
490
501
|
pop() {
|
|
491
502
|
return this.pPoints.pop();
|
|
@@ -508,25 +519,29 @@ class DPolygon {
|
|
|
508
519
|
return (this.pPoints.map((r) => r.getValue()) + this.holes
|
|
509
520
|
.reduce((a, h) => a + h.getValue(), ''));
|
|
510
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* @deprecated Better to use loop
|
|
524
|
+
*/
|
|
511
525
|
degreeToMeters() {
|
|
512
|
-
|
|
513
|
-
this.holes = this.holes.map((h) => h.degreeToMeters());
|
|
514
|
-
return this;
|
|
526
|
+
return this.map((r) => r.degreeToMeters());
|
|
515
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* @deprecated Better to use loop
|
|
530
|
+
*/
|
|
516
531
|
metersToDegree() {
|
|
517
|
-
|
|
518
|
-
this.holes = this.holes.map((h) => h.metersToDegree());
|
|
519
|
-
return this;
|
|
532
|
+
return this.map((r) => r.metersToDegree());
|
|
520
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* @deprecated Better to use loop
|
|
536
|
+
*/
|
|
521
537
|
radiansToMeters() {
|
|
522
|
-
|
|
523
|
-
this.holes = this.holes.map((h) => h.radiansToMeters());
|
|
524
|
-
return this;
|
|
538
|
+
return this.map((r) => r.radiansToMeters());
|
|
525
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* @deprecated Better to use loop
|
|
542
|
+
*/
|
|
526
543
|
metersToRadians() {
|
|
527
|
-
|
|
528
|
-
this.holes = this.holes.map((h) => h.metersToRadians());
|
|
529
|
-
return this;
|
|
544
|
+
return this.map((r) => r.metersToRadians());
|
|
530
545
|
}
|
|
531
546
|
toString() {
|
|
532
547
|
return `(${this.pPoints.map((r) => r.toString()).join(', ')})`;
|
|
@@ -554,11 +569,10 @@ class DPolygon {
|
|
|
554
569
|
/**
|
|
555
570
|
* Set `height` (`z`)
|
|
556
571
|
* @param z
|
|
572
|
+
* @deprecated Better to use loop
|
|
557
573
|
*/
|
|
558
574
|
height(z) {
|
|
559
|
-
this.map((p) => p.height(z));
|
|
560
|
-
this.holes = this.holes.map((h) => h.height(z));
|
|
561
|
-
return this;
|
|
575
|
+
return this.map((p) => p.height(z));
|
|
562
576
|
}
|
|
563
577
|
add(poly) {
|
|
564
578
|
const res = new DPolygon([...this.points, ...poly.points]).close();
|
|
@@ -586,7 +600,7 @@ class DPolygon {
|
|
|
586
600
|
if (!(p instanceof DPolygon)) {
|
|
587
601
|
return false;
|
|
588
602
|
}
|
|
589
|
-
if (this.
|
|
603
|
+
if (this.length !== p.length || this.holes.length !== p.holes.length) {
|
|
590
604
|
return false;
|
|
591
605
|
}
|
|
592
606
|
return (this.same(p) &&
|
|
@@ -597,20 +611,18 @@ class DPolygon {
|
|
|
597
611
|
* @param p
|
|
598
612
|
*/
|
|
599
613
|
same(p) {
|
|
600
|
-
const pClone = p.clone().
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
pClone.
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
.toString());
|
|
613
|
-
}, false);
|
|
614
|
+
const pClone = p.clone().close();
|
|
615
|
+
const thisAsString = this.clone()
|
|
616
|
+
.close()
|
|
617
|
+
.toString();
|
|
618
|
+
for (let i = 0; i < pClone.length; i++) {
|
|
619
|
+
if (thisAsString === pClone.toString() || thisAsString === pClone.clone().reverse()
|
|
620
|
+
.toString()) {
|
|
621
|
+
return true;
|
|
622
|
+
}
|
|
623
|
+
pClone.nextStart();
|
|
624
|
+
}
|
|
625
|
+
return false;
|
|
614
626
|
}
|
|
615
627
|
findIndex(p) {
|
|
616
628
|
return this.points.findIndex((t) => t.equal(p));
|
|
@@ -708,7 +720,7 @@ class DPolygon {
|
|
|
708
720
|
const poly = this.deintersection;
|
|
709
721
|
const intersectionPoints = [];
|
|
710
722
|
for (let i = 0; i < poly.length - 1; i++) {
|
|
711
|
-
const polygonLine = poly.
|
|
723
|
+
const polygonLine = poly.at(i).findLine(poly.at(i + 1));
|
|
712
724
|
const intersection = line.intersection(polygonLine, CLOSE_TO_INTERSECTION_DISTANCE);
|
|
713
725
|
if (intersection) {
|
|
714
726
|
intersectionPoints.push(intersection);
|
|
@@ -733,8 +745,8 @@ class DPolygon {
|
|
|
733
745
|
return true;
|
|
734
746
|
}
|
|
735
747
|
for (let i = 0; i < poly.length - 1; i++) {
|
|
736
|
-
const p0 = poly.
|
|
737
|
-
const p1 = poly.
|
|
748
|
+
const p0 = poly.at(i);
|
|
749
|
+
const p1 = poly.at(i + 1);
|
|
738
750
|
const polygonLine = p0.findLine(p1);
|
|
739
751
|
const onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
|
|
740
752
|
if (onBorder) {
|
|
@@ -758,8 +770,8 @@ class DPolygon {
|
|
|
758
770
|
*/
|
|
759
771
|
removeDuplicates() {
|
|
760
772
|
for (let i = 0; i < this.length - 1; i++) {
|
|
761
|
-
const p1 = this.
|
|
762
|
-
const p2 = this.
|
|
773
|
+
const p1 = this.at(i);
|
|
774
|
+
const p2 = this.at(i + 1);
|
|
763
775
|
if (p1.equal(p2)) {
|
|
764
776
|
this.removePart(i, 1);
|
|
765
777
|
i--;
|
|
@@ -906,9 +918,36 @@ class DPolygon {
|
|
|
906
918
|
/**
|
|
907
919
|
* Divide polygon to triangles
|
|
908
920
|
*
|
|
909
|
-
* 
|
|
921
|
+
* 
|
|
910
922
|
*/
|
|
911
923
|
toTriangles() {
|
|
924
|
+
const innerAndNotIntersect = (poly, p1, p2) => {
|
|
925
|
+
const l = p1.findLine(p2);
|
|
926
|
+
const { center } = l;
|
|
927
|
+
const intersections = poly.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
|
|
928
|
+
.intersection(l, true).length), Boolean(poly.clone().close()
|
|
929
|
+
.intersection(l, true).length));
|
|
930
|
+
const contain = poly.holes.reduce((a, hole) => a && !hole
|
|
931
|
+
.contain(center), poly.contain(center));
|
|
932
|
+
return !intersections && contain;
|
|
933
|
+
};
|
|
934
|
+
const getTriangle = (poly) => {
|
|
935
|
+
for (let i = 0; i < poly.length; i++) {
|
|
936
|
+
const p0 = poly.at(0);
|
|
937
|
+
const p1 = poly.at(1);
|
|
938
|
+
const p2 = poly.at(2);
|
|
939
|
+
if (innerAndNotIntersect(poly, p0, p2)) {
|
|
940
|
+
poly.removePart(0, 1);
|
|
941
|
+
return new DPolygon([
|
|
942
|
+
p0.clone(),
|
|
943
|
+
p1.clone(),
|
|
944
|
+
p2.clone()
|
|
945
|
+
]);
|
|
946
|
+
}
|
|
947
|
+
poly.push(poly.shift());
|
|
948
|
+
}
|
|
949
|
+
return undefined;
|
|
950
|
+
};
|
|
912
951
|
const p = this.clone().clockWise.open();
|
|
913
952
|
while (p.holes.length) {
|
|
914
953
|
const h = p.holes.shift()
|
|
@@ -917,7 +956,7 @@ class DPolygon {
|
|
|
917
956
|
.reverse()
|
|
918
957
|
.close();
|
|
919
958
|
for (let i = 0; i < p.length; i++) {
|
|
920
|
-
if (
|
|
959
|
+
if (innerAndNotIntersect(p, p.first, h.first)) {
|
|
921
960
|
p.insertAfter(0, ...h.points, p.first);
|
|
922
961
|
break;
|
|
923
962
|
}
|
|
@@ -926,7 +965,7 @@ class DPolygon {
|
|
|
926
965
|
}
|
|
927
966
|
const res = [];
|
|
928
967
|
while (p.length > 3) {
|
|
929
|
-
const triangle =
|
|
968
|
+
const triangle = getTriangle(p);
|
|
930
969
|
if (triangle) {
|
|
931
970
|
res.push(triangle);
|
|
932
971
|
}
|
|
@@ -934,36 +973,6 @@ class DPolygon {
|
|
|
934
973
|
res.push(p);
|
|
935
974
|
return res;
|
|
936
975
|
}
|
|
937
|
-
/**
|
|
938
|
-
* @internal
|
|
939
|
-
*/
|
|
940
|
-
getTriangle() {
|
|
941
|
-
for (let i = 0; i < this.length; i++) {
|
|
942
|
-
const p0 = this.p(0);
|
|
943
|
-
const p1 = this.p(1);
|
|
944
|
-
const p2 = this.p(2);
|
|
945
|
-
if (this.innerAndNotIntersect(p0, p2)) {
|
|
946
|
-
this.removePart(0, 1);
|
|
947
|
-
return new DPolygon([
|
|
948
|
-
p0.clone(),
|
|
949
|
-
p1.clone(),
|
|
950
|
-
p2.clone()
|
|
951
|
-
]);
|
|
952
|
-
}
|
|
953
|
-
this.push(this.shift());
|
|
954
|
-
}
|
|
955
|
-
return undefined;
|
|
956
|
-
}
|
|
957
|
-
innerAndNotIntersect(p1, p2) {
|
|
958
|
-
const l = p1.findLine(p2);
|
|
959
|
-
const { center } = l;
|
|
960
|
-
const intersections = this.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
|
|
961
|
-
.intersection(l, true).length), Boolean(this.clone().close()
|
|
962
|
-
.intersection(l, true).length));
|
|
963
|
-
const contain = this.holes.reduce((a, hole) => a && !hole
|
|
964
|
-
.contain(center), this.contain(center));
|
|
965
|
-
return !intersections && contain;
|
|
966
|
-
}
|
|
967
976
|
simpleIncludeX(p) {
|
|
968
977
|
const { x } = p;
|
|
969
978
|
return this.minX <= x && this.maxX >= x;
|
|
@@ -996,7 +1005,7 @@ class DPolygon {
|
|
|
996
1005
|
const start = this.first;
|
|
997
1006
|
ctx.moveTo(start.x, start.y);
|
|
998
1007
|
for (let i = 1; i <= (steps % this.length); i++) {
|
|
999
|
-
const { x, y } = this.
|
|
1008
|
+
const { x, y } = this.at(i);
|
|
1000
1009
|
ctx.lineTo(x, y);
|
|
1001
1010
|
}
|
|
1002
1011
|
}
|
|
@@ -1012,8 +1021,8 @@ class DPolygon {
|
|
|
1012
1021
|
const poly = this.deintersection;
|
|
1013
1022
|
let totalFi = 0;
|
|
1014
1023
|
for (let i = 0; i < poly.length - 1; i++) {
|
|
1015
|
-
const p1 = poly.
|
|
1016
|
-
const p2 = poly.
|
|
1024
|
+
const p1 = poly.at(i);
|
|
1025
|
+
const p2 = poly.at(i + 1);
|
|
1017
1026
|
const line1 = new DLine_1.DLine(p1.x - p.x, p1.y - p.y, 0);
|
|
1018
1027
|
const line2 = new DLine_1.DLine(p2.x - p.x, p2.y - p.y, 0);
|
|
1019
1028
|
const fiDif = line1.findFi(line2);
|
package/dist/TraceMatrix.js
CHANGED
|
@@ -36,7 +36,7 @@ class TraceMatrix {
|
|
|
36
36
|
const marked = TraceMatrix.createMatrix(this.size, () => TraceMatrixValues.f);
|
|
37
37
|
setByPosition(marked, s, TraceMatrixValues.t);
|
|
38
38
|
while (startIndex < res.length) {
|
|
39
|
-
const r = res.
|
|
39
|
+
const r = res.at(startIndex);
|
|
40
40
|
for (let i = -1; i < 2; i++) {
|
|
41
41
|
for (let j = -1; j < 2; j++) {
|
|
42
42
|
const t = new DPoint_1.DPoint(r.x + i, r.y + j);
|
|
@@ -90,14 +90,14 @@ class TraceMatrix {
|
|
|
90
90
|
const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
|
|
91
91
|
const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
|
|
92
92
|
if (group.length < 2) {
|
|
93
|
-
const t = group.
|
|
93
|
+
const t = group.at(0).clone();
|
|
94
94
|
return new DPolygon_1.DPolygon([t, t, t]);
|
|
95
95
|
}
|
|
96
96
|
const points = new DPolygon_1.DPolygon();
|
|
97
97
|
let direction = 0;
|
|
98
98
|
let prevDirection = Infinity;
|
|
99
|
-
let p = group.
|
|
100
|
-
while (!p.equal(group.
|
|
99
|
+
let p = group.at(0);
|
|
100
|
+
while (!p.equal(group.at(0)) || points.length < 2) {
|
|
101
101
|
// eslint-disable-next-line no-constant-condition
|
|
102
102
|
while (true) {
|
|
103
103
|
const nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
|