dgeoutils 2.2.23 → 2.3.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.
Files changed (50) hide show
  1. package/README.md +7 -0
  2. package/dist/{DCircle.d.ts → cjs/DCircle.d.ts} +0 -0
  3. package/dist/cjs/DCircle.js +102 -0
  4. package/dist/{DLine.d.ts → cjs/DLine.d.ts} +0 -0
  5. package/dist/cjs/DLine.js +300 -0
  6. package/dist/{DNumbers.d.ts → cjs/DNumbers.d.ts} +0 -0
  7. package/dist/cjs/DNumbers.js +30 -0
  8. package/dist/{DPlane.d.ts → cjs/DPlane.d.ts} +0 -0
  9. package/dist/cjs/DPlane.js +132 -0
  10. package/dist/{DPoint.d.ts → cjs/DPoint.d.ts} +0 -0
  11. package/dist/cjs/DPoint.js +574 -0
  12. package/dist/{DPolygon.d.ts → cjs/DPolygon.d.ts} +7 -1
  13. package/dist/cjs/DPolygon.js +1555 -0
  14. package/dist/{DPolygonLoop.d.ts → cjs/DPolygonLoop.d.ts} +0 -0
  15. package/dist/cjs/DPolygonLoop.js +401 -0
  16. package/dist/{FastSearch.d.ts → cjs/FastSearch.d.ts} +0 -0
  17. package/dist/cjs/FastSearch.js +53 -0
  18. package/dist/{TraceMatrix.d.ts → cjs/TraceMatrix.d.ts} +0 -0
  19. package/dist/cjs/TraceMatrix.js +256 -0
  20. package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  21. package/dist/{index.js → cjs/index.js} +0 -0
  22. package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
  23. package/dist/cjs/utils.js +191 -0
  24. package/dist/{DCircle.js → es2015/DCircle.js} +14 -18
  25. package/dist/{DLine.js → es2015/DLine.js} +24 -28
  26. package/dist/es2015/DNumbers.js +22 -0
  27. package/dist/{DPlane.js → es2015/DPlane.js} +22 -26
  28. package/dist/{DPoint.js → es2015/DPoint.js} +52 -56
  29. package/dist/{DPolygon.js → es2015/DPolygon.js} +90 -86
  30. package/dist/{DPolygonLoop.js → es2015/DPolygonLoop.js} +1 -5
  31. package/dist/{FastSearch.js → es2015/FastSearch.js} +1 -5
  32. package/dist/{TraceMatrix.js → es2015/TraceMatrix.js} +35 -39
  33. package/dist/es2015/index.js +13 -0
  34. package/dist/{utils.js → es2015/utils.js} +26 -36
  35. package/dist/esm/DCircle.js +99 -0
  36. package/dist/esm/DLine.js +297 -0
  37. package/dist/esm/DNumbers.js +27 -0
  38. package/dist/esm/DPlane.js +129 -0
  39. package/dist/esm/DPoint.js +571 -0
  40. package/dist/esm/DPolygon.js +1552 -0
  41. package/dist/esm/DPolygonLoop.js +398 -0
  42. package/dist/esm/FastSearch.js +50 -0
  43. package/dist/esm/TraceMatrix.js +253 -0
  44. package/dist/esm/index.js +13 -0
  45. package/dist/esm/utils.js +181 -0
  46. package/dist/umd/dgeoutils.js +3569 -0
  47. package/dist/umd/dgeoutils.min.js +1 -0
  48. package/dist/umd/dgeoutils.min.js.map +1 -0
  49. package/package.json +17 -10
  50. package/dist/DNumbers.js +0 -26
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DPolygon = exports.MIN_POINTS_IN_VALID_POLYGON = void 0;
4
- const DPoint_1 = require("./DPoint");
5
- const DLine_1 = require("./DLine");
6
- const DCircle_1 = require("./DCircle");
7
- const DNumbers_1 = require("./DNumbers");
8
- const jsts_1 = require("jsts");
9
- const DPolygonLoop_1 = require("./DPolygonLoop");
10
- const utils_1 = require("./utils");
11
- const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = jsts_1.operation;
12
- exports.MIN_POINTS_IN_VALID_POLYGON = 3;
1
+ import { DPoint } from './DPoint';
2
+ import { DLine } from './DLine';
3
+ import { DCircle } from './DCircle';
4
+ import { DNumbers } from './DNumbers';
5
+ import { io as jstsIo, operation } from 'jsts';
6
+ import { DPolygonLoop } from './DPolygonLoop';
7
+ import { isDefAndNotNull } from './utils';
8
+ const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = operation;
9
+ export const MIN_POINTS_IN_VALID_POLYGON = 3;
13
10
  const APPROXIMATION_VALUE = 0.1;
14
11
  const MAX_CONVEX_ITERATIONS = 100;
15
12
  const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
@@ -26,8 +23,8 @@ const containCalculator = (poly, p) => {
26
23
  }
27
24
  let totalFi = 0;
28
25
  for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
29
- const line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
30
- const line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
26
+ const line1 = new DLine(x - p.x, y - p.y, 0);
27
+ const line2 = new DLine(a - p.x, b - p.y, 0);
31
28
  const fiDif = line1.findFi(line2);
32
29
  if (line1.vectorProduct(line2).c > 0) {
33
30
  totalFi += fiDif;
@@ -50,7 +47,7 @@ const containCalculator = (poly, p) => {
50
47
  }
51
48
  return result;
52
49
  };
53
- class DPolygon {
50
+ export class DPolygon {
54
51
  constructor(pPoints = []) {
55
52
  this.pPoints = pPoints;
56
53
  this.properties = {};
@@ -58,7 +55,7 @@ class DPolygon {
58
55
  this.searchStore = {};
59
56
  }
60
57
  static arrayOfTrianglesToVertices(triangles, height) {
61
- return triangles.map((v) => ((0, utils_1.isDefAndNotNull)(height) ? v
58
+ return triangles.map((v) => (isDefAndNotNull(height) ? v
62
59
  .loop()
63
60
  .height(height)
64
61
  .run() : v)
@@ -67,7 +64,7 @@ class DPolygon {
67
64
  }
68
65
  static minAreaRectangleSize(poly) {
69
66
  const { first, second, last } = poly.clone().open();
70
- return new DPoint_1.DPoint(first.distance(second), first.distance(last));
67
+ return new DPoint(first.distance(second), first.distance(last));
71
68
  }
72
69
  static toDash(poly) {
73
70
  let p = new DPolygon();
@@ -107,7 +104,7 @@ class DPolygon {
107
104
  const [path, ...holes] = reg.groups.data
108
105
  .split('), (')
109
106
  .map((p) => new DPolygon(p.split(', ')
110
- .map((pares) => DPoint_1.DPoint.parse(pares.split(' ').map(Number)))));
107
+ .map((pares) => DPoint.parse(pares.split(' ').map(Number)))));
111
108
  if (holes && holes.length) {
112
109
  path.holes = holes;
113
110
  }
@@ -117,18 +114,18 @@ class DPolygon {
117
114
  const regexp = /LINESTRING \((?<data>(?:(?!\)$).)*?)\)$/miu;
118
115
  const reg = regexp.exec(data);
119
116
  res = new DPolygon(reg.groups.data
120
- .split(', ').map((t) => DPoint_1.DPoint.parse(t.split(' ').map(Number))));
117
+ .split(', ').map((t) => DPoint.parse(t.split(' ').map(Number))));
121
118
  }
122
119
  if (data.indexOf('POINT') === 0) {
123
- res = new DPolygon([DPoint_1.DPoint.parseFromWKT(data)]);
120
+ res = new DPolygon([DPoint.parseFromWKT(data)]);
124
121
  }
125
122
  return res;
126
123
  }
127
124
  static createSquareBySize(size) {
128
- return new DPolygon([DPoint_1.DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
125
+ return new DPolygon([DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
129
126
  }
130
127
  loop() {
131
- return new DPolygonLoop_1.DPolygonLoop(this);
128
+ return new DPolygonLoop(this);
132
129
  }
133
130
  set points(p) {
134
131
  this.pPoints = p;
@@ -137,16 +134,16 @@ class DPolygon {
137
134
  return this.pPoints;
138
135
  }
139
136
  get maxX() {
140
- return this.pPoints.reduce((a, r) => Math.max(a, r.x), -Infinity);
137
+ return this.reduce((a, r) => Math.max(a, r.x), -Infinity);
141
138
  }
142
139
  get minX() {
143
- return this.pPoints.reduce((a, r) => Math.min(a, r.x), Infinity);
140
+ return this.reduce((a, r) => Math.min(a, r.x), Infinity);
144
141
  }
145
142
  get maxY() {
146
- return this.pPoints.reduce((a, r) => Math.max(a, r.y), -Infinity);
143
+ return this.reduce((a, r) => Math.max(a, r.y), -Infinity);
147
144
  }
148
145
  get minY() {
149
- return this.pPoints.reduce((a, r) => Math.min(a, r.y), Infinity);
146
+ return this.reduce((a, r) => Math.min(a, r.y), Infinity);
150
147
  }
151
148
  get center() {
152
149
  return this.leftTop.move(this.size.divide(2));
@@ -166,24 +163,24 @@ class DPolygon {
166
163
  get extend() {
167
164
  const { minX, minY, maxX, maxY } = this;
168
165
  return new DPolygon([
169
- new DPoint_1.DPoint(minX, minY),
170
- new DPoint_1.DPoint(maxX, minY),
171
- new DPoint_1.DPoint(maxX, maxY),
172
- new DPoint_1.DPoint(minX, maxY),
173
- new DPoint_1.DPoint(minX, minY)
166
+ new DPoint(minX, minY),
167
+ new DPoint(maxX, minY),
168
+ new DPoint(maxX, maxY),
169
+ new DPoint(minX, maxY),
170
+ new DPoint(minX, minY)
174
171
  ]);
175
172
  }
176
173
  get size() {
177
174
  const { w, h } = this;
178
- return new DPoint_1.DPoint(w, h);
175
+ return new DPoint(w, h);
179
176
  }
180
177
  get leftTop() {
181
178
  const { minX, minY } = this;
182
- return new DPoint_1.DPoint(minX, minY);
179
+ return new DPoint(minX, minY);
183
180
  }
184
181
  get rightBottom() {
185
182
  const { maxX, maxY } = this;
186
- return new DPoint_1.DPoint(maxX, maxY);
183
+ return new DPoint(maxX, maxY);
187
184
  }
188
185
  get length() {
189
186
  return this.pPoints.length;
@@ -233,8 +230,7 @@ class DPolygon {
233
230
  const d = record[j] - record[j - 1];
234
231
  if (d > 1) {
235
232
  const part = new DPolygon(origin.removePart(record[j - 1], d));
236
- const allInside = part.points
237
- .reduce((a, e) => a && containCalculator(origin, e), true);
233
+ const allInside = part.reduce((a, e) => a && containCalculator(origin, e), true);
238
234
  if (allInside && origin.isClockwise === part.isClockwise) {
239
235
  origin.insertAfter(record[j - 1] - 1, ...part.reverse().points);
240
236
  p = origin;
@@ -246,7 +242,7 @@ class DPolygon {
246
242
  return p;
247
243
  }
248
244
  get valid() {
249
- return this.length > exports.MIN_POINTS_IN_VALID_POLYGON;
245
+ return this.length > MIN_POINTS_IN_VALID_POLYGON;
250
246
  }
251
247
  get first() {
252
248
  return this.at(0);
@@ -315,7 +311,7 @@ class DPolygon {
315
311
  const p2 = p.first;
316
312
  const p3 = p.second;
317
313
  const d = p2.findInnerAngle(p1, p3);
318
- if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
314
+ if (d > Math.PI || DNumbers.likeZero(DNumbers.rad2Deg(d)) || DNumbers.likePI(d) || DNumbers.like2PI(d)) {
319
315
  p.removePart(-1, 1);
320
316
  }
321
317
  else {
@@ -332,7 +328,7 @@ class DPolygon {
332
328
  const p2 = p.at(i);
333
329
  const p3 = p.at(i + 1);
334
330
  const d = p2.findInnerAngle(p1, p3);
335
- if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
331
+ if (d > Math.PI || DNumbers.likeZero(DNumbers.rad2Deg(d)) || DNumbers.likePI(d) || DNumbers.like2PI(d)) {
336
332
  p.removePart(--i, 1);
337
333
  }
338
334
  }
@@ -362,6 +358,9 @@ class DPolygon {
362
358
  res.holes = [];
363
359
  return res;
364
360
  }
361
+ reduce(f, v) {
362
+ return this.pPoints.reduce(f, v);
363
+ }
365
364
  intersection(l, includeOnly = false) {
366
365
  const res = [];
367
366
  for (const [, , line] of this.loopPointsGenerator(true)()) {
@@ -384,10 +383,10 @@ class DPolygon {
384
383
  h = `, ${this.holes.map((hole) => hole.toString())
385
384
  .join(', ')}`;
386
385
  }
387
- return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
386
+ return `POLYGON ((${this.deintersection.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
388
387
  .join(', ')})${h})`;
389
388
  }
390
- return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
389
+ return `LINESTRING (${this.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
391
390
  .join(', ')})`;
392
391
  }
393
392
  filter(f) {
@@ -395,10 +394,13 @@ class DPolygon {
395
394
  return this;
396
395
  }
397
396
  map(f) {
398
- this.pPoints = this.pPoints.map(f);
397
+ this.pPoints = this.mapArray(f);
399
398
  this.holes = this.holes.map((h) => h.map(f));
400
399
  return this;
401
400
  }
401
+ mapArray(f) {
402
+ return this.pPoints.map(f);
403
+ }
402
404
  sort(f) {
403
405
  this.points.sort(f);
404
406
  return this;
@@ -429,7 +431,7 @@ class DPolygon {
429
431
  .reduce((a, h) => a + h.getValue(), ''));
430
432
  }
431
433
  toString() {
432
- return `(${this.pPoints.map((r) => r.toString()).join(', ')})`;
434
+ return `(${this.mapArray((r) => r.toString()).join(', ')})`;
433
435
  }
434
436
  close() {
435
437
  const p0 = this.first;
@@ -483,8 +485,11 @@ class DPolygon {
483
485
  }
484
486
  return false;
485
487
  }
486
- findIndex(p) {
487
- return this.points.findIndex((t) => t.equal(p));
488
+ findIndex(a) {
489
+ if (a instanceof DPoint) {
490
+ return this.points.findIndex((t) => t.equal(a));
491
+ }
492
+ return this.points.findIndex(a);
488
493
  }
489
494
  approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
490
495
  return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
@@ -508,36 +513,36 @@ class DPolygon {
508
513
  return this.simpleIncludeX(p) && this.simpleIncludeY(p);
509
514
  }
510
515
  drawPolygonOnCanvas(canvas, fillColor, strokeColor, shadowColor, lineWidth = 1, steps = this.length - 1) {
511
- if (this.length < 2) {
512
- return;
513
- }
514
- const ctx = canvas.getContext('2d');
515
- if (fillColor) {
516
- ctx.fillStyle = fillColor;
517
- }
518
- if (strokeColor) {
519
- ctx.strokeStyle = strokeColor;
520
- }
521
- if (lineWidth) {
522
- ctx.lineWidth = lineWidth;
523
- }
524
- if (fillColor || strokeColor) {
525
- ctx.beginPath();
526
- }
527
- this.goByPath(ctx, steps % this.length);
528
- if (shadowColor) {
529
- ctx.shadowColor = shadowColor;
530
- ctx.shadowBlur = 0;
531
- ctx.shadowOffsetX = 1;
532
- ctx.shadowOffsetY = 1;
533
- }
534
- if (fillColor) {
535
- ctx.closePath();
536
- ctx.fill();
537
- }
538
- if (strokeColor) {
539
- ctx.stroke();
516
+ if (this.length > 1) {
517
+ const ctx = canvas.getContext('2d');
518
+ if (fillColor) {
519
+ ctx.fillStyle = fillColor;
520
+ }
521
+ if (strokeColor) {
522
+ ctx.strokeStyle = strokeColor;
523
+ }
524
+ if (lineWidth) {
525
+ ctx.lineWidth = lineWidth;
526
+ }
527
+ if (fillColor || strokeColor) {
528
+ ctx.beginPath();
529
+ }
530
+ this.goByPath(ctx, steps % this.length);
531
+ if (shadowColor) {
532
+ ctx.shadowColor = shadowColor;
533
+ ctx.shadowBlur = 0;
534
+ ctx.shadowOffsetX = 1;
535
+ ctx.shadowOffsetY = 1;
536
+ }
537
+ if (fillColor) {
538
+ ctx.closePath();
539
+ ctx.fill();
540
+ }
541
+ if (strokeColor) {
542
+ ctx.stroke();
543
+ }
540
544
  }
545
+ return this;
541
546
  }
542
547
  clearPolygonOnCanvas(canvas) {
543
548
  const ctx = canvas.getContext('2d');
@@ -559,8 +564,8 @@ class DPolygon {
559
564
  const poly = this.deintersection;
560
565
  let totalFi = 0;
561
566
  for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
562
- const line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
563
- const line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
567
+ const line1 = new DLine(x - p.x, y - p.y, 0);
568
+ const line2 = new DLine(a - p.x, b - p.y, 0);
564
569
  const fiDif = line1.findFi(line2);
565
570
  if (line1.vectorProduct(line2).c > 0) {
566
571
  totalFi += fiDif;
@@ -614,10 +619,10 @@ class DPolygon {
614
619
  return this;
615
620
  }
616
621
  static parse(a) {
617
- return new DPolygon(a.map((r) => DPoint_1.DPoint.parse(r)));
622
+ return new DPolygon(a.map((r) => DPoint.parse(r)));
618
623
  }
619
624
  toArrayOfCoords() {
620
- return this.pPoints.map((r) => r.toCoords());
625
+ return this.mapArray((r) => r.toCoords());
621
626
  }
622
627
  divideToPieces(piecesCount) {
623
628
  const { fullLength } = this;
@@ -630,7 +635,7 @@ class DPolygon {
630
635
  currentPieceLength = pieceLength;
631
636
  }
632
637
  else if (d - currentPieceLength > 0) {
633
- const circle = new DCircle_1.DCircle(p1, currentPieceLength);
638
+ const circle = new DCircle(p1, currentPieceLength);
634
639
  const line = p1.findLine(p2);
635
640
  const intersectionPoint = line.intersectionWithCircle(circle)
636
641
  .filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
@@ -842,13 +847,13 @@ class DPolygon {
842
847
  return this.first.equal(this.last);
843
848
  }
844
849
  buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
845
- const reader = new jsts_1.io.WKTReader();
850
+ const reader = new jstsIo.WKTReader();
846
851
  const { noHoles, closed } = this;
847
852
  const points = reader
848
853
  .read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
849
854
  .buffer(v, quadrantSegments, type)
850
855
  .getCoordinates();
851
- return new DPolygon(points.map(({ x, y }) => new DPoint_1.DPoint(x, y)));
856
+ return new DPolygon(points.map(({ x, y }) => new DPoint(x, y)));
852
857
  }
853
858
  sideBuffers(v, quadrantSegments = 64) {
854
859
  const { first, last } = this;
@@ -941,7 +946,7 @@ class DPolygon {
941
946
  }
942
947
  getJSTSGeometry(p, unionThis, unionThat) {
943
948
  const unionOrIntersection = unionThat === unionThis;
944
- const reader = new jsts_1.io.WKTReader();
949
+ const reader = new jstsIo.WKTReader();
945
950
  const a = reader.read(this.noHoles.toWKT());
946
951
  const b = reader.read(p.noHoles.toWKT());
947
952
  if (!unionOrIntersection) {
@@ -962,11 +967,11 @@ class DPolygon {
962
967
  if (coordinates.length) {
963
968
  let result = coordinates.reduce((ak, { x, y }, index) => {
964
969
  const lastIndex = ak.length - 1;
965
- const t = new DPoint_1.DPoint(x, y);
970
+ const t = new DPoint(x, y);
966
971
  const { first } = ak[lastIndex];
967
972
  if (t.equal(first)) {
968
973
  if (coordinates[index + 1]) {
969
- const nextPoint = new DPoint_1.DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
974
+ const nextPoint = new DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
970
975
  if (ak[lastIndex].length > 1) {
971
976
  ak.push(new DPolygon([nextPoint]));
972
977
  }
@@ -976,7 +981,7 @@ class DPolygon {
976
981
  ak[lastIndex].push(t);
977
982
  }
978
983
  return ak;
979
- }, [new DPolygon([new DPoint_1.DPoint(coordinates[0].x, coordinates[0].y)])]);
984
+ }, [new DPolygon([new DPoint(coordinates[0].x, coordinates[0].y)])]);
980
985
  if (unionThat && unionThis && result.length > 1) {
981
986
  for (const q of result) {
982
987
  for (const r of result) {
@@ -1024,7 +1029,6 @@ class DPolygon {
1024
1029
  return null;
1025
1030
  }
1026
1031
  }
1027
- exports.DPolygon = DPolygon;
1028
1032
  DPolygon.CAP_ROUND = CAP_ROUND;
1029
1033
  DPolygon.CAP_FLAT = CAP_FLAT;
1030
1034
  DPolygon.CAP_SQUARE = CAP_SQUARE;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DPolygonLoop = void 0;
4
1
  var LoopFunctions;
5
2
  (function (LoopFunctions) {
6
3
  LoopFunctions[LoopFunctions["getTileFromCoords"] = 0] = "getTileFromCoords";
@@ -170,7 +167,7 @@ const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg
170
167
  }
171
168
  return res;
172
169
  };
173
- class DPolygonLoop {
170
+ export class DPolygonLoop {
174
171
  constructor(parent) {
175
172
  this.parent = parent;
176
173
  this.pool = [];
@@ -393,4 +390,3 @@ class DPolygonLoop {
393
390
  return this;
394
391
  }
395
392
  }
396
- exports.DPolygonLoop = DPolygonLoop;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FastSearch = void 0;
4
- class FastSearch {
1
+ export class FastSearch {
5
2
  constructor() {
6
3
  this.searchStore = {};
7
4
  }
@@ -26,4 +23,3 @@ class FastSearch {
26
23
  return this.searchStore[x][y][z || 'undefined'];
27
24
  }
28
25
  }
29
- exports.FastSearch = FastSearch;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TraceMatrix = exports.TraceMatrixValues = void 0;
4
- const DPoint_1 = require("./DPoint");
5
- const DPolygon_1 = require("./DPolygon");
6
- const FastSearch_1 = require("./FastSearch");
7
- const utils_1 = require("./utils");
8
- var TraceMatrixValues;
1
+ import { DPoint } from './DPoint';
2
+ import { DPolygon, MIN_POINTS_IN_VALID_POLYGON } from './DPolygon';
3
+ import { FastSearch } from './FastSearch';
4
+ import { createArray } from './utils';
5
+ export var TraceMatrixValues;
9
6
  (function (TraceMatrixValues) {
10
7
  TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
11
8
  TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
12
- })(TraceMatrixValues = exports.TraceMatrixValues || (exports.TraceMatrixValues = {}));
9
+ })(TraceMatrixValues || (TraceMatrixValues = {}));
13
10
  const getByPosition = (m, p, defaultValue = TraceMatrixValues.f) => {
14
11
  if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
15
12
  return defaultValue;
@@ -23,11 +20,11 @@ const setByPosition = (m, p, value) => {
23
20
  m[p.y][p.x] = value;
24
21
  return m[p.y][p.x];
25
22
  };
26
- class TraceMatrix {
23
+ export class TraceMatrix {
27
24
  constructor(size, f) {
28
25
  this.size = size;
29
26
  this.findGroupByIndex = (m, s) => {
30
- const res = new DPolygon_1.DPolygon();
27
+ const res = new DPolygon();
31
28
  if (s && getByPosition(m, s) === TraceMatrixValues.t) {
32
29
  res.push(s);
33
30
  let startIndex = 0;
@@ -37,7 +34,7 @@ class TraceMatrix {
37
34
  const r = res.at(startIndex);
38
35
  for (let i = -1; i < 2; i++) {
39
36
  for (let j = -1; j < 2; j++) {
40
- const t = new DPoint_1.DPoint(r.x + i, r.y + j);
37
+ const t = new DPoint(r.x + i, r.y + j);
41
38
  if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
42
39
  getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
43
40
  res.push(t);
@@ -59,7 +56,7 @@ class TraceMatrix {
59
56
  const groups = [group];
60
57
  let groupSum = group.length;
61
58
  let allGroups = [...group.points];
62
- const fs = new FastSearch_1.FastSearch();
59
+ const fs = new FastSearch();
63
60
  fs.add(allGroups);
64
61
  while (groupSum < this.totalCountInMatrix(m)) {
65
62
  let mark = this.findMarked(m);
@@ -76,22 +73,22 @@ class TraceMatrix {
76
73
  };
77
74
  this.traceGroup = (m, group) => {
78
75
  const traceDirections = [
79
- new DPoint_1.DPoint(-1, -1),
80
- new DPoint_1.DPoint(-1, 0),
81
- new DPoint_1.DPoint(-1, 1),
82
- new DPoint_1.DPoint(0, 1),
83
- new DPoint_1.DPoint(1, 1),
84
- new DPoint_1.DPoint(1, 0),
85
- new DPoint_1.DPoint(1, -1),
86
- new DPoint_1.DPoint(0, -1)
76
+ new DPoint(-1, -1),
77
+ new DPoint(-1, 0),
78
+ new DPoint(-1, 1),
79
+ new DPoint(0, 1),
80
+ new DPoint(1, 1),
81
+ new DPoint(1, 0),
82
+ new DPoint(1, -1),
83
+ new DPoint(0, -1)
87
84
  ];
88
85
  const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
89
86
  const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
90
87
  if (group.length < 2) {
91
88
  const t = group.at(0).clone();
92
- return new DPolygon_1.DPolygon([t, t, t]);
89
+ return new DPolygon([t, t, t]);
93
90
  }
94
- const points = new DPolygon_1.DPolygon();
91
+ const points = new DPolygon();
95
92
  let direction = 0;
96
93
  let prevDirection = Infinity;
97
94
  let p = group.at(0);
@@ -115,22 +112,22 @@ class TraceMatrix {
115
112
  };
116
113
  this.createHoleMatrix = (group) => {
117
114
  const fullTraceDirections = [
118
- new DPoint_1.DPoint(-1, 0),
119
- new DPoint_1.DPoint(0, 1),
120
- new DPoint_1.DPoint(1, 0),
121
- new DPoint_1.DPoint(0, -1)
115
+ new DPoint(-1, 0),
116
+ new DPoint(0, 1),
117
+ new DPoint(1, 0),
118
+ new DPoint(0, -1)
122
119
  ];
123
120
  group.prepareToFastSearch();
124
121
  const tmpMatrix = TraceMatrix
125
122
  .createMatrix(this.size, (p) => group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f);
126
- const startCoords = new DPolygon_1.DPolygon();
123
+ const startCoords = new DPolygon();
127
124
  for (let i = 0; i < this.size.w; i++) {
128
- startCoords.push(new DPoint_1.DPoint(i, -1));
129
- startCoords.push(new DPoint_1.DPoint(i, this.size.h));
125
+ startCoords.push(new DPoint(i, -1));
126
+ startCoords.push(new DPoint(i, this.size.h));
130
127
  }
131
128
  for (let i = 0; i < this.size.h; i++) {
132
- startCoords.push(new DPoint_1.DPoint(-1, i));
133
- startCoords.push(new DPoint_1.DPoint(this.size.w, i));
129
+ startCoords.push(new DPoint(-1, i));
130
+ startCoords.push(new DPoint(this.size.w, i));
134
131
  }
135
132
  while (startCoords.length) {
136
133
  const point = startCoords.pop();
@@ -154,7 +151,7 @@ class TraceMatrix {
154
151
  const holeMatrixs = groups.map(this.createHoleMatrix);
155
152
  const holesGroups = holeMatrixs.map((m) => m && this.findAllGroupsInMatrix(m));
156
153
  const holesPaths = holesGroups.map((hg, index) => hg && hg.map((g) => this
157
- .traceGroup(holeMatrixs[index], g)).filter((r) => r.length > DPolygon_1.MIN_POINTS_IN_VALID_POLYGON));
154
+ .traceGroup(holeMatrixs[index], g)).filter((r) => r.length > MIN_POINTS_IN_VALID_POLYGON));
158
155
  return groups.map((g, index) => {
159
156
  const res = paths[index];
160
157
  if (holesGroups[index] && holesGroups[index].length) {
@@ -177,8 +174,8 @@ class TraceMatrix {
177
174
  ini = true;
178
175
  continue;
179
176
  }
180
- if (getByPosition(m, new DPoint_1.DPoint(i, j)) === TraceMatrixValues.t) {
181
- return new DPoint_1.DPoint(i, j);
177
+ if (getByPosition(m, new DPoint(i, j)) === TraceMatrixValues.t) {
178
+ return new DPoint(i, j);
182
179
  }
183
180
  }
184
181
  }
@@ -189,7 +186,7 @@ class TraceMatrix {
189
186
  const s = this.size;
190
187
  for (let i = 0; i < s.w; i++) {
191
188
  for (let j = 0; j < s.h; j++) {
192
- if (getByPosition(m, new DPoint_1.DPoint(i, j))) {
189
+ if (getByPosition(m, new DPoint(i, j))) {
193
190
  res++;
194
191
  }
195
192
  }
@@ -197,8 +194,7 @@ class TraceMatrix {
197
194
  return res;
198
195
  }
199
196
  static createMatrix(size, f = () => TraceMatrixValues.f) {
200
- return (0, utils_1.createArray)(size.h)
201
- .map((v, i) => (0, utils_1.createArray)(size.w).map((v2, j) => f(new DPoint_1.DPoint(j, i))));
197
+ return createArray(size.h)
198
+ .map((v, i) => createArray(size.w).map((v2, j) => f(new DPoint(j, i))));
202
199
  }
203
200
  }
204
- exports.TraceMatrix = TraceMatrix;
@@ -0,0 +1,13 @@
1
+ export * from './DCircle';
2
+ export * from './DLine';
3
+ export * from './DNumbers';
4
+ export * from './DPoint';
5
+ export * from './DPolygon';
6
+ export * from './FastSearch';
7
+ export * from './TraceMatrix';
8
+ export * from './DPolygonLoop';
9
+ export * from './DPlane';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull } from './utils';
11
+ export const DGeo = {
12
+ DEBUG: false
13
+ };