dgeoutils 2.3.6 → 2.4.1
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/cjs/DCircle.js +52 -63
- package/dist/cjs/DLine.js +132 -181
- package/dist/cjs/DNumbers.js +16 -20
- package/dist/cjs/DPlane.js +56 -79
- package/dist/cjs/DPoint.js +240 -338
- package/dist/cjs/DPolygon.d.ts +1 -1
- package/dist/cjs/DPolygon.js +638 -1149
- package/dist/cjs/DPolygonLoop.js +138 -143
- package/dist/cjs/FastSearch.js +13 -37
- package/dist/cjs/TraceMatrix.js +87 -139
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/utils.d.ts +2 -1
- package/dist/cjs/utils.js +69 -97
- package/dist/es2015/DPolygon.js +5 -1
- package/dist/es2015/index.js +1 -1
- package/dist/es2015/utils.js +13 -0
- package/dist/esm/DPolygon.js +6 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/utils.js +13 -0
- package/dist/umd/dgeoutils.js +21 -2
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/DPolygon.js
CHANGED
|
@@ -1,128 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (_) try {
|
|
9
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var __values = (this && this.__values) || function(o) {
|
|
30
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
31
|
-
if (m) return m.call(o);
|
|
32
|
-
if (o && typeof o.length === "number") return {
|
|
33
|
-
next: function () {
|
|
34
|
-
if (o && i >= o.length) o = void 0;
|
|
35
|
-
return { value: o && o[i++], done: !o };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
39
|
-
};
|
|
40
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
41
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
42
|
-
if (!m) return o;
|
|
43
|
-
var i = m.call(o), r, ar = [], e;
|
|
44
|
-
try {
|
|
45
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
46
|
-
}
|
|
47
|
-
catch (error) { e = { error: error }; }
|
|
48
|
-
finally {
|
|
49
|
-
try {
|
|
50
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
51
|
-
}
|
|
52
|
-
finally { if (e) throw e.error; }
|
|
53
|
-
}
|
|
54
|
-
return ar;
|
|
55
|
-
};
|
|
56
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
57
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
58
|
-
if (ar || !(i in from)) {
|
|
59
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
60
|
-
ar[i] = from[i];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
64
|
-
};
|
|
65
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
3
|
exports.DPolygon = exports.MIN_POINTS_IN_VALID_POLYGON = void 0;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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;
|
|
75
12
|
exports.MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var hasSamePoint = poly.points.some(function (point) { return point.equal(p); });
|
|
13
|
+
const APPROXIMATION_VALUE = 0.1;
|
|
14
|
+
const MAX_CONVEX_ITERATIONS = 100;
|
|
15
|
+
const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
16
|
+
const containCalculator = (poly, p) => {
|
|
17
|
+
const hasSamePoint = poly.points.some((point) => point.equal(p));
|
|
82
18
|
if (hasSamePoint) {
|
|
83
19
|
return true;
|
|
84
20
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (onBorder) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
21
|
+
for (const [, , polygonLine] of poly.loopPointsGenerator(true)()) {
|
|
22
|
+
const onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
|
|
23
|
+
if (onBorder) {
|
|
24
|
+
return true;
|
|
92
25
|
}
|
|
93
26
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var totalFi = 0;
|
|
102
|
-
try {
|
|
103
|
-
for (var _f = __values(poly.loopPointsGenerator()()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
104
|
-
var _h = __read(_g.value, 2), _j = _h[0], x = _j.x, y = _j.y, _k = _h[1], a = _k.x, b = _k.y;
|
|
105
|
-
var line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
|
|
106
|
-
var line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
|
|
107
|
-
var fiDif = line1.findFi(line2);
|
|
108
|
-
if (line1.vectorProduct(line2).c > 0) {
|
|
109
|
-
totalFi += fiDif;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
totalFi -= fiDif;
|
|
113
|
-
}
|
|
27
|
+
let totalFi = 0;
|
|
28
|
+
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);
|
|
31
|
+
const fiDif = line1.findFi(line2);
|
|
32
|
+
if (line1.vectorProduct(line2).c > 0) {
|
|
33
|
+
totalFi += fiDif;
|
|
114
34
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
finally {
|
|
118
|
-
try {
|
|
119
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
35
|
+
else {
|
|
36
|
+
totalFi -= fiDif;
|
|
120
37
|
}
|
|
121
|
-
finally { if (e_2) throw e_2.error; }
|
|
122
38
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
39
|
+
const eps = Math.PI / 10000;
|
|
40
|
+
let result = false;
|
|
41
|
+
const absTotalFi = Math.abs(totalFi);
|
|
126
42
|
if (absTotalFi < eps) {
|
|
127
43
|
result = false;
|
|
128
44
|
}
|
|
@@ -134,58 +50,46 @@ var containCalculator = function (poly, p) {
|
|
|
134
50
|
}
|
|
135
51
|
return result;
|
|
136
52
|
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (pPoints === void 0) { pPoints = []; }
|
|
53
|
+
class DPolygon {
|
|
54
|
+
constructor(pPoints = []) {
|
|
140
55
|
this.pPoints = pPoints;
|
|
141
56
|
this.properties = {};
|
|
142
57
|
this.holes = [];
|
|
143
58
|
this.searchStore = {};
|
|
144
59
|
}
|
|
145
|
-
|
|
146
|
-
return triangles.map(
|
|
60
|
+
static arrayOfTrianglesToVertices(triangles, height) {
|
|
61
|
+
return triangles.map((v) => ((0, utils_1.isDefAndNotNull)(height) ? v
|
|
147
62
|
.loop()
|
|
148
63
|
.height(height)
|
|
149
64
|
.run() : v)
|
|
150
|
-
.toArrayOfCoords()
|
|
65
|
+
.toArrayOfCoords())
|
|
151
66
|
.flat(2);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
67
|
+
}
|
|
68
|
+
static minAreaRectangleSize(poly) {
|
|
69
|
+
const { first, second, last } = poly.clone().open();
|
|
155
70
|
return new DPoint_1.DPoint(first.distance(second), first.distance(last));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
71
|
+
}
|
|
72
|
+
static toDash(poly) {
|
|
73
|
+
let p = new DPolygon();
|
|
74
|
+
const result = [p];
|
|
75
|
+
let trigger = true;
|
|
76
|
+
for (const point of poly.points) {
|
|
77
|
+
if (trigger) {
|
|
78
|
+
p.push(point.clone());
|
|
79
|
+
}
|
|
80
|
+
if (point.properties.pieceBorder) {
|
|
81
|
+
trigger = !trigger;
|
|
165
82
|
if (trigger) {
|
|
83
|
+
p = new DPolygon();
|
|
84
|
+
result.push(p);
|
|
166
85
|
p.push(point.clone());
|
|
167
86
|
}
|
|
168
|
-
if (point.properties.pieceBorder) {
|
|
169
|
-
trigger = !trigger;
|
|
170
|
-
if (trigger) {
|
|
171
|
-
p = new DPolygon();
|
|
172
|
-
result.push(p);
|
|
173
|
-
p.push(point.clone());
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
179
|
-
finally {
|
|
180
|
-
try {
|
|
181
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
182
87
|
}
|
|
183
|
-
finally { if (e_3) throw e_3.error; }
|
|
184
88
|
}
|
|
185
89
|
return result;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
90
|
+
}
|
|
91
|
+
static minAreaRectangleDirection(poly) {
|
|
92
|
+
const { first, second, last } = poly.clone().open();
|
|
189
93
|
if (!first || !second || !last) {
|
|
190
94
|
return 0;
|
|
191
95
|
}
|
|
@@ -193,581 +97,374 @@ var DPolygon = (function () {
|
|
|
193
97
|
return first.findLine(second).getFi();
|
|
194
98
|
}
|
|
195
99
|
return first.findLine(last).getFi();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
100
|
+
}
|
|
101
|
+
static parseFromWKT(wkt) {
|
|
102
|
+
const data = wkt.trim().toUpperCase();
|
|
103
|
+
let res = new DPolygon();
|
|
200
104
|
if (data.indexOf('POLYGON') === 0) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
105
|
+
const regexp = /POLYGON \(\((?<data>(?:(?!\)\)$).)*?)\)\)$/miu;
|
|
106
|
+
const reg = regexp.exec(data);
|
|
107
|
+
const [path, ...holes] = reg.groups.data
|
|
204
108
|
.split('), (')
|
|
205
|
-
.map(
|
|
206
|
-
.map(
|
|
109
|
+
.map((p) => new DPolygon(p.split(', ')
|
|
110
|
+
.map((pares) => DPoint_1.DPoint.parse(pares.split(' ').map(Number)))));
|
|
207
111
|
if (holes && holes.length) {
|
|
208
112
|
path.holes = holes;
|
|
209
113
|
}
|
|
210
114
|
res = path;
|
|
211
115
|
}
|
|
212
116
|
if (data.indexOf('LINESTRING') === 0) {
|
|
213
|
-
|
|
214
|
-
|
|
117
|
+
const regexp = /LINESTRING \((?<data>(?:(?!\)$).)*?)\)$/miu;
|
|
118
|
+
const reg = regexp.exec(data);
|
|
215
119
|
res = new DPolygon(reg.groups.data
|
|
216
|
-
.split(', ').map(
|
|
120
|
+
.split(', ').map((t) => DPoint_1.DPoint.parse(t.split(' ').map(Number))));
|
|
217
121
|
}
|
|
218
122
|
if (data.indexOf('POINT') === 0) {
|
|
219
123
|
res = new DPolygon([DPoint_1.DPoint.parseFromWKT(data)]);
|
|
220
124
|
}
|
|
221
125
|
return res;
|
|
222
|
-
}
|
|
223
|
-
|
|
126
|
+
}
|
|
127
|
+
static createSquareBySize(size) {
|
|
224
128
|
return new DPolygon([DPoint_1.DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
|
|
225
|
-
}
|
|
226
|
-
|
|
129
|
+
}
|
|
130
|
+
loop() {
|
|
227
131
|
return new DPolygonLoop_1.DPolygonLoop(this);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
enumerable: false,
|
|
322
|
-
configurable: true
|
|
323
|
-
});
|
|
324
|
-
Object.defineProperty(DPolygon.prototype, "leftTop", {
|
|
325
|
-
get: function () {
|
|
326
|
-
var _a = this, minX = _a.minX, minY = _a.minY;
|
|
327
|
-
return new DPoint_1.DPoint(minX, minY);
|
|
328
|
-
},
|
|
329
|
-
enumerable: false,
|
|
330
|
-
configurable: true
|
|
331
|
-
});
|
|
332
|
-
Object.defineProperty(DPolygon.prototype, "rightBottom", {
|
|
333
|
-
get: function () {
|
|
334
|
-
var _a = this, maxX = _a.maxX, maxY = _a.maxY;
|
|
335
|
-
return new DPoint_1.DPoint(maxX, maxY);
|
|
336
|
-
},
|
|
337
|
-
enumerable: false,
|
|
338
|
-
configurable: true
|
|
339
|
-
});
|
|
340
|
-
Object.defineProperty(DPolygon.prototype, "length", {
|
|
341
|
-
get: function () {
|
|
342
|
-
return this.pPoints.length;
|
|
343
|
-
},
|
|
344
|
-
enumerable: false,
|
|
345
|
-
configurable: true
|
|
346
|
-
});
|
|
347
|
-
Object.defineProperty(DPolygon.prototype, "fullLength", {
|
|
348
|
-
get: function () {
|
|
349
|
-
return this.clone().open().perimeter;
|
|
350
|
-
},
|
|
351
|
-
enumerable: false,
|
|
352
|
-
configurable: true
|
|
353
|
-
});
|
|
354
|
-
Object.defineProperty(DPolygon.prototype, "perimeter", {
|
|
355
|
-
get: function () {
|
|
356
|
-
var e_4, _a;
|
|
357
|
-
var p = 0;
|
|
358
|
-
try {
|
|
359
|
-
for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
360
|
-
var _d = __read(_c.value, 2), p1 = _d[0], p2 = _d[1];
|
|
361
|
-
p += p1.distance(p2);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
365
|
-
finally {
|
|
366
|
-
try {
|
|
367
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
368
|
-
}
|
|
369
|
-
finally { if (e_4) throw e_4.error; }
|
|
370
|
-
}
|
|
371
|
-
return p;
|
|
372
|
-
},
|
|
373
|
-
enumerable: false,
|
|
374
|
-
configurable: true
|
|
375
|
-
});
|
|
376
|
-
Object.defineProperty(DPolygon.prototype, "area", {
|
|
377
|
-
get: function () {
|
|
378
|
-
var e_5, _a;
|
|
379
|
-
var sum = 0;
|
|
380
|
-
try {
|
|
381
|
-
for (var _b = __values(this.deintersection.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
382
|
-
var _d = __read(_c.value, 2), _e = _d[0], x = _e.x, y = _e.y, _f = _d[1], a = _f.x, b = _f.y;
|
|
383
|
-
sum += x * b - y * a;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
387
|
-
finally {
|
|
388
|
-
try {
|
|
389
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
390
|
-
}
|
|
391
|
-
finally { if (e_5) throw e_5.error; }
|
|
392
|
-
}
|
|
393
|
-
return Math.abs(sum / 2) - this.holes.reduce(function (a, hole) { return a + hole.area; }, 0);
|
|
394
|
-
},
|
|
395
|
-
enumerable: false,
|
|
396
|
-
configurable: true
|
|
397
|
-
});
|
|
398
|
-
Object.defineProperty(DPolygon.prototype, "deintersection", {
|
|
399
|
-
get: function () {
|
|
400
|
-
var e_6, _a;
|
|
401
|
-
var p = this.clone().close();
|
|
402
|
-
var store = {};
|
|
403
|
-
for (var i = 0; i < p.length - 1; i++) {
|
|
404
|
-
var k = p.at(i).toString();
|
|
405
|
-
store[k] = store[k] || [];
|
|
406
|
-
store[k].push(i);
|
|
407
|
-
var _loop_1 = function (j) {
|
|
408
|
-
var firstLine = p.at(i).findLine(p.at(i + 1));
|
|
409
|
-
var secondLine = p.at(j).findLine(p.at(j + 1));
|
|
410
|
-
var intersectionPoint = firstLine.intersection(secondLine);
|
|
411
|
-
if (intersectionPoint &&
|
|
412
|
-
!__spreadArray(__spreadArray([], __read(firstLine.points), false), __read(secondLine.points), false).some(function (t) { return t.like(intersectionPoint); })) {
|
|
413
|
-
var part = p.removePart(i, j - i).reverse();
|
|
414
|
-
p.insertAfter.apply(p, __spreadArray([i], __read(part), false));
|
|
415
|
-
p.insertAfter(j, intersectionPoint);
|
|
416
|
-
p.insertAfter(i, intersectionPoint);
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
for (var j = i + 2; j < p.length - 1; j++) {
|
|
420
|
-
_loop_1(j);
|
|
132
|
+
}
|
|
133
|
+
set points(p) {
|
|
134
|
+
this.pPoints = p;
|
|
135
|
+
}
|
|
136
|
+
get points() {
|
|
137
|
+
return this.pPoints;
|
|
138
|
+
}
|
|
139
|
+
get maxX() {
|
|
140
|
+
return this.reduce((a, r) => Math.max(a, r.x), -Infinity);
|
|
141
|
+
}
|
|
142
|
+
get minX() {
|
|
143
|
+
return this.reduce((a, r) => Math.min(a, r.x), Infinity);
|
|
144
|
+
}
|
|
145
|
+
get maxY() {
|
|
146
|
+
return this.reduce((a, r) => Math.max(a, r.y), -Infinity);
|
|
147
|
+
}
|
|
148
|
+
get minY() {
|
|
149
|
+
return this.reduce((a, r) => Math.min(a, r.y), Infinity);
|
|
150
|
+
}
|
|
151
|
+
get center() {
|
|
152
|
+
return this.leftTop.move(this.size.divide(2));
|
|
153
|
+
}
|
|
154
|
+
get h() {
|
|
155
|
+
return this.maxY - this.minY;
|
|
156
|
+
}
|
|
157
|
+
get w() {
|
|
158
|
+
return this.maxX - this.minX;
|
|
159
|
+
}
|
|
160
|
+
get dY() {
|
|
161
|
+
return this.h;
|
|
162
|
+
}
|
|
163
|
+
get dX() {
|
|
164
|
+
return this.w;
|
|
165
|
+
}
|
|
166
|
+
get extend() {
|
|
167
|
+
const { minX, minY, maxX, maxY } = this;
|
|
168
|
+
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)
|
|
174
|
+
]);
|
|
175
|
+
}
|
|
176
|
+
get size() {
|
|
177
|
+
const { w, h } = this;
|
|
178
|
+
return new DPoint_1.DPoint(w, h);
|
|
179
|
+
}
|
|
180
|
+
get leftTop() {
|
|
181
|
+
const { minX, minY } = this;
|
|
182
|
+
return new DPoint_1.DPoint(minX, minY);
|
|
183
|
+
}
|
|
184
|
+
get rightBottom() {
|
|
185
|
+
const { maxX, maxY } = this;
|
|
186
|
+
return new DPoint_1.DPoint(maxX, maxY);
|
|
187
|
+
}
|
|
188
|
+
get length() {
|
|
189
|
+
return this.pPoints.length;
|
|
190
|
+
}
|
|
191
|
+
get fullLength() {
|
|
192
|
+
return this.clone().open().perimeter;
|
|
193
|
+
}
|
|
194
|
+
get perimeter() {
|
|
195
|
+
let p = 0;
|
|
196
|
+
for (const [p1, p2] of this.loopPointsGenerator()()) {
|
|
197
|
+
p += p1.distance(p2);
|
|
198
|
+
}
|
|
199
|
+
return p;
|
|
200
|
+
}
|
|
201
|
+
get area() {
|
|
202
|
+
let sum = 0;
|
|
203
|
+
for (const [{ x, y }, { x: a, y: b }] of this.deintersection.loopPointsGenerator()()) {
|
|
204
|
+
sum += x * b - y * a;
|
|
205
|
+
}
|
|
206
|
+
return Math.abs(sum / 2) - this.holes.reduce((a, hole) => a + hole.area, 0);
|
|
207
|
+
}
|
|
208
|
+
get deintersection() {
|
|
209
|
+
let p = this.clone().close();
|
|
210
|
+
const store = {};
|
|
211
|
+
for (let i = 0; i < p.length - 1; i++) {
|
|
212
|
+
const k = p.at(i).toString();
|
|
213
|
+
store[k] = store[k] || [];
|
|
214
|
+
store[k].push(i);
|
|
215
|
+
for (let j = i + 2; j < p.length - 1; j++) {
|
|
216
|
+
const firstLine = p.at(i).findLine(p.at(i + 1));
|
|
217
|
+
const secondLine = p.at(j).findLine(p.at(j + 1));
|
|
218
|
+
const intersectionPoint = firstLine.intersection(secondLine);
|
|
219
|
+
if (intersectionPoint &&
|
|
220
|
+
![...firstLine.points, ...secondLine.points].some((t) => t.like(intersectionPoint))) {
|
|
221
|
+
const part = p.removePart(i, j - i).reverse();
|
|
222
|
+
p.insertAfter(i, ...part);
|
|
223
|
+
p.insertAfter(j, intersectionPoint);
|
|
224
|
+
p.insertAfter(i, intersectionPoint);
|
|
421
225
|
}
|
|
422
226
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
p = origin_1;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
for (var j = record.length - 1; j > 0; j--) {
|
|
441
|
-
_loop_2(j);
|
|
227
|
+
}
|
|
228
|
+
for (const key of Object.keys(store)) {
|
|
229
|
+
const record = store[key];
|
|
230
|
+
if (record.length > 1) {
|
|
231
|
+
for (let j = record.length - 1; j > 0; j--) {
|
|
232
|
+
const origin = p.clone();
|
|
233
|
+
const d = record[j] - record[j - 1];
|
|
234
|
+
if (d > 1) {
|
|
235
|
+
const part = new DPolygon(origin.removePart(record[j - 1], d));
|
|
236
|
+
const allInside = part.reduce((a, e) => a && containCalculator(origin, e), true);
|
|
237
|
+
if (allInside && origin.isClockwise === part.isClockwise) {
|
|
238
|
+
origin.insertAfter(record[j - 1] - 1, ...part.reverse().points);
|
|
239
|
+
p = origin;
|
|
442
240
|
}
|
|
443
241
|
}
|
|
444
242
|
}
|
|
445
243
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
244
|
+
}
|
|
245
|
+
return p;
|
|
246
|
+
}
|
|
247
|
+
get valid() {
|
|
248
|
+
return this.length > exports.MIN_POINTS_IN_VALID_POLYGON;
|
|
249
|
+
}
|
|
250
|
+
get first() {
|
|
251
|
+
return this.at(0);
|
|
252
|
+
}
|
|
253
|
+
get second() {
|
|
254
|
+
return this.at(1);
|
|
255
|
+
}
|
|
256
|
+
get last() {
|
|
257
|
+
return this.at(this.length - 1);
|
|
258
|
+
}
|
|
259
|
+
get minAreaRectangle() {
|
|
260
|
+
const p = this.convex;
|
|
261
|
+
let resultPolygon = new DPolygon();
|
|
262
|
+
let resultArea = Infinity;
|
|
263
|
+
for (const [, , l] of p.loopPointsGenerator(true)()) {
|
|
264
|
+
let maxWidth = 0;
|
|
265
|
+
let maxWidthPoint1 = null;
|
|
266
|
+
let maxWidthPoint2 = null;
|
|
267
|
+
let maxHeight = 0;
|
|
268
|
+
let maxHeightPoint = null;
|
|
269
|
+
for (const [z, , , i] of p.loopPointsGenerator()()) {
|
|
270
|
+
const p1 = l.findPoint(l.findPerpendicular(z));
|
|
271
|
+
const h = p1.distance(z);
|
|
272
|
+
if (h >= maxHeight) {
|
|
273
|
+
maxHeight = h;
|
|
274
|
+
maxHeightPoint = z;
|
|
450
275
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
Object.defineProperty(DPolygon.prototype, "valid", {
|
|
459
|
-
get: function () {
|
|
460
|
-
return this.length > exports.MIN_POINTS_IN_VALID_POLYGON;
|
|
461
|
-
},
|
|
462
|
-
enumerable: false,
|
|
463
|
-
configurable: true
|
|
464
|
-
});
|
|
465
|
-
Object.defineProperty(DPolygon.prototype, "first", {
|
|
466
|
-
get: function () {
|
|
467
|
-
return this.at(0);
|
|
468
|
-
},
|
|
469
|
-
enumerable: false,
|
|
470
|
-
configurable: true
|
|
471
|
-
});
|
|
472
|
-
Object.defineProperty(DPolygon.prototype, "second", {
|
|
473
|
-
get: function () {
|
|
474
|
-
return this.at(1);
|
|
475
|
-
},
|
|
476
|
-
enumerable: false,
|
|
477
|
-
configurable: true
|
|
478
|
-
});
|
|
479
|
-
Object.defineProperty(DPolygon.prototype, "last", {
|
|
480
|
-
get: function () {
|
|
481
|
-
return this.at(this.length - 1);
|
|
482
|
-
},
|
|
483
|
-
enumerable: false,
|
|
484
|
-
configurable: true
|
|
485
|
-
});
|
|
486
|
-
Object.defineProperty(DPolygon.prototype, "minAreaRectangle", {
|
|
487
|
-
get: function () {
|
|
488
|
-
var e_7, _a, e_8, _b;
|
|
489
|
-
var p = this.convex;
|
|
490
|
-
var resultPolygon = new DPolygon();
|
|
491
|
-
var resultArea = Infinity;
|
|
492
|
-
try {
|
|
493
|
-
for (var _c = __values(p.loopPointsGenerator(true)()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
494
|
-
var _e = __read(_d.value, 3), l = _e[2];
|
|
495
|
-
var maxWidth = 0;
|
|
496
|
-
var maxWidthPoint1 = null;
|
|
497
|
-
var maxWidthPoint2 = null;
|
|
498
|
-
var maxHeight = 0;
|
|
499
|
-
var maxHeightPoint = null;
|
|
500
|
-
try {
|
|
501
|
-
for (var _f = (e_8 = void 0, __values(p.loopPointsGenerator()())), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
502
|
-
var _h = __read(_g.value, 4), z = _h[0], i = _h[3];
|
|
503
|
-
var p1 = l.findPoint(l.findPerpendicular(z));
|
|
504
|
-
var h = p1.distance(z);
|
|
505
|
-
if (h >= maxHeight) {
|
|
506
|
-
maxHeight = h;
|
|
507
|
-
maxHeightPoint = z;
|
|
508
|
-
}
|
|
509
|
-
for (var j = i; j < p.length - 1; j++) {
|
|
510
|
-
var p2 = l.findPoint(l.findPerpendicular(p.at(j)));
|
|
511
|
-
var w = p1.distance(p2);
|
|
512
|
-
if (w >= maxWidth) {
|
|
513
|
-
maxWidth = w;
|
|
514
|
-
maxWidthPoint1 = p1;
|
|
515
|
-
maxWidthPoint2 = p2;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
521
|
-
finally {
|
|
522
|
-
try {
|
|
523
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
524
|
-
}
|
|
525
|
-
finally { if (e_8) throw e_8.error; }
|
|
526
|
-
}
|
|
527
|
-
if (!maxWidthPoint1 || !maxWidthPoint2 || !maxHeightPoint) {
|
|
528
|
-
continue;
|
|
529
|
-
}
|
|
530
|
-
var widthLine = maxWidthPoint1.findLine(maxWidthPoint2);
|
|
531
|
-
var perpendicular1 = widthLine.findPerpendicular(maxWidthPoint1);
|
|
532
|
-
var perpendicular2 = widthLine.findPerpendicular(maxWidthPoint2);
|
|
533
|
-
var tempPolygon = new DPolygon([
|
|
534
|
-
maxWidthPoint1,
|
|
535
|
-
maxWidthPoint2,
|
|
536
|
-
perpendicular2.findPoint(perpendicular2.findPerpendicular(maxHeightPoint)),
|
|
537
|
-
perpendicular1.findPoint(perpendicular1.findPerpendicular(maxHeightPoint))
|
|
538
|
-
]).close();
|
|
539
|
-
if (tempPolygon.area < resultArea) {
|
|
540
|
-
resultPolygon = tempPolygon;
|
|
541
|
-
resultArea = tempPolygon.area;
|
|
276
|
+
for (let j = i; j < p.length - 1; j++) {
|
|
277
|
+
const p2 = l.findPoint(l.findPerpendicular(p.at(j)));
|
|
278
|
+
const w = p1.distance(p2);
|
|
279
|
+
if (w >= maxWidth) {
|
|
280
|
+
maxWidth = w;
|
|
281
|
+
maxWidthPoint1 = p1;
|
|
282
|
+
maxWidthPoint2 = p2;
|
|
542
283
|
}
|
|
543
284
|
}
|
|
544
285
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
try {
|
|
548
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
549
|
-
}
|
|
550
|
-
finally { if (e_7) throw e_7.error; }
|
|
286
|
+
if (!maxWidthPoint1 || !maxWidthPoint2 || !maxHeightPoint) {
|
|
287
|
+
continue;
|
|
551
288
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
if (
|
|
562
|
-
|
|
289
|
+
const widthLine = maxWidthPoint1.findLine(maxWidthPoint2);
|
|
290
|
+
const perpendicular1 = widthLine.findPerpendicular(maxWidthPoint1);
|
|
291
|
+
const perpendicular2 = widthLine.findPerpendicular(maxWidthPoint2);
|
|
292
|
+
const tempPolygon = new DPolygon([
|
|
293
|
+
maxWidthPoint1,
|
|
294
|
+
maxWidthPoint2,
|
|
295
|
+
perpendicular2.findPoint(perpendicular2.findPerpendicular(maxHeightPoint)),
|
|
296
|
+
perpendicular1.findPoint(perpendicular1.findPerpendicular(maxHeightPoint))
|
|
297
|
+
]).close();
|
|
298
|
+
if (tempPolygon.area < resultArea) {
|
|
299
|
+
resultPolygon = tempPolygon;
|
|
300
|
+
resultArea = tempPolygon.area;
|
|
563
301
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
p.
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
p
|
|
581
|
-
l = p.length;
|
|
582
|
-
for (var i = 1; i < p.length - 1; i++) {
|
|
583
|
-
var p1 = p.at(i - 1);
|
|
584
|
-
var p2 = p.at(i);
|
|
585
|
-
var p3 = p.at(i + 1);
|
|
586
|
-
var d = p2.findInnerAngle(p1, p3);
|
|
587
|
-
if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
|
|
588
|
-
p.removePart(--i, 1);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
iteration++;
|
|
592
|
-
} while (p.length !== l && iteration < MAX_CONVEX_ITERATIONS);
|
|
593
|
-
if (!isClockwise) {
|
|
594
|
-
p.reverse();
|
|
595
|
-
}
|
|
596
|
-
return p;
|
|
597
|
-
},
|
|
598
|
-
enumerable: false,
|
|
599
|
-
configurable: true
|
|
600
|
-
});
|
|
601
|
-
Object.defineProperty(DPolygon.prototype, "isClockwise", {
|
|
602
|
-
get: function () {
|
|
603
|
-
var e_9, _a;
|
|
604
|
-
var sum = 0;
|
|
605
|
-
try {
|
|
606
|
-
for (var _b = __values(this.clone().close()
|
|
607
|
-
.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
608
|
-
var _d = __read(_c.value, 2), _e = _d[0], x = _e.x, y = _e.y, _f = _d[1], a = _f.x, b = _f.y;
|
|
609
|
-
sum += (a - x) * (b + y);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
613
|
-
finally {
|
|
614
|
-
try {
|
|
615
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
616
|
-
}
|
|
617
|
-
finally { if (e_9) throw e_9.error; }
|
|
302
|
+
}
|
|
303
|
+
return resultPolygon;
|
|
304
|
+
}
|
|
305
|
+
get convex() {
|
|
306
|
+
let p = this.clone().open();
|
|
307
|
+
const { isClockwise } = p;
|
|
308
|
+
if (!isClockwise) {
|
|
309
|
+
p.reverse();
|
|
310
|
+
}
|
|
311
|
+
let l = 0;
|
|
312
|
+
do {
|
|
313
|
+
const p1 = p.last;
|
|
314
|
+
const p2 = p.first;
|
|
315
|
+
const p3 = p.second;
|
|
316
|
+
const d = p2.findInnerAngle(p1, p3);
|
|
317
|
+
if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
|
|
318
|
+
p.removePart(-1, 1);
|
|
618
319
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
enumerable: false,
|
|
622
|
-
configurable: true
|
|
623
|
-
});
|
|
624
|
-
Object.defineProperty(DPolygon.prototype, "clockWise", {
|
|
625
|
-
get: function () {
|
|
626
|
-
if (this.isClockwise) {
|
|
627
|
-
return this.clone();
|
|
320
|
+
else {
|
|
321
|
+
break;
|
|
628
322
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
});
|
|
643
|
-
DPolygon.prototype.reduce = function (f, v) {
|
|
644
|
-
return this.pPoints.reduce(f, v);
|
|
645
|
-
};
|
|
646
|
-
DPolygon.prototype.intersection = function (l, includeOnly) {
|
|
647
|
-
var e_10, _a;
|
|
648
|
-
if (includeOnly === void 0) { includeOnly = false; }
|
|
649
|
-
var res = [];
|
|
650
|
-
try {
|
|
651
|
-
for (var _b = __values(this.loopPointsGenerator(true)()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
652
|
-
var _d = __read(_c.value, 3), line = _d[2];
|
|
653
|
-
var intersect = line.intersection(l, 0, includeOnly);
|
|
654
|
-
if (intersect) {
|
|
655
|
-
res.push(intersect);
|
|
323
|
+
} while (p.length);
|
|
324
|
+
p.close();
|
|
325
|
+
let iteration = 0;
|
|
326
|
+
do {
|
|
327
|
+
p = p.deintersection;
|
|
328
|
+
l = p.length;
|
|
329
|
+
for (let i = 1; i < p.length - 1; i++) {
|
|
330
|
+
const p1 = p.at(i - 1);
|
|
331
|
+
const p2 = p.at(i);
|
|
332
|
+
const p3 = p.at(i + 1);
|
|
333
|
+
const d = p2.findInnerAngle(p1, p3);
|
|
334
|
+
if (d > Math.PI || DNumbers_1.DNumbers.likeZero(DNumbers_1.DNumbers.rad2Deg(d)) || DNumbers_1.DNumbers.likePI(d) || DNumbers_1.DNumbers.like2PI(d)) {
|
|
335
|
+
p.removePart(--i, 1);
|
|
656
336
|
}
|
|
657
337
|
}
|
|
338
|
+
iteration++;
|
|
339
|
+
} while (p.length !== l && iteration < MAX_CONVEX_ITERATIONS);
|
|
340
|
+
if (!isClockwise) {
|
|
341
|
+
p.reverse();
|
|
342
|
+
}
|
|
343
|
+
return p;
|
|
344
|
+
}
|
|
345
|
+
get isClockwise() {
|
|
346
|
+
let sum = 0;
|
|
347
|
+
for (const [{ x, y }, { x: a, y: b }] of this.clone().close()
|
|
348
|
+
.loopPointsGenerator()()) {
|
|
349
|
+
sum += (a - x) * (b + y);
|
|
350
|
+
}
|
|
351
|
+
return sum < 0;
|
|
352
|
+
}
|
|
353
|
+
get clockWise() {
|
|
354
|
+
if (this.isClockwise) {
|
|
355
|
+
return this.clone();
|
|
658
356
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
357
|
+
return this.clone().reverse();
|
|
358
|
+
}
|
|
359
|
+
get noHoles() {
|
|
360
|
+
const res = this.clone();
|
|
361
|
+
res.holes = [];
|
|
362
|
+
return res;
|
|
363
|
+
}
|
|
364
|
+
reduce(f, v) {
|
|
365
|
+
return this.pPoints.reduce(f, v);
|
|
366
|
+
}
|
|
367
|
+
intersection(l, includeOnly = false) {
|
|
368
|
+
const res = [];
|
|
369
|
+
for (const [, , line] of this.loopPointsGenerator(true)()) {
|
|
370
|
+
const intersect = line.intersection(l, 0, includeOnly);
|
|
371
|
+
if (intersect) {
|
|
372
|
+
res.push(intersect);
|
|
663
373
|
}
|
|
664
|
-
finally { if (e_10) throw e_10.error; }
|
|
665
374
|
}
|
|
666
375
|
return res;
|
|
667
|
-
}
|
|
668
|
-
|
|
376
|
+
}
|
|
377
|
+
setCenter(newCenter) {
|
|
669
378
|
return this.loop()
|
|
670
379
|
.move(newCenter.clone().move(this.center.minus()))
|
|
671
380
|
.run();
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
if (type === void 0) { type = DPolygon.WKT_POLYGON; }
|
|
675
|
-
if (withZ === void 0) { withZ = false; }
|
|
381
|
+
}
|
|
382
|
+
toWKT(type = DPolygon.WKT_POLYGON, withZ = false) {
|
|
676
383
|
if (type === DPolygon.WKT_POLYGON) {
|
|
677
|
-
|
|
384
|
+
let h = '';
|
|
678
385
|
if (this.holes && this.holes.length) {
|
|
679
|
-
h =
|
|
680
|
-
.join(', ')
|
|
386
|
+
h = `, ${this.holes.map((hole) => hole.toString())
|
|
387
|
+
.join(', ')}`;
|
|
681
388
|
}
|
|
682
|
-
return
|
|
683
|
-
.join(', ')
|
|
389
|
+
return `POLYGON ((${this.deintersection.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
390
|
+
.join(', ')})${h})`;
|
|
684
391
|
}
|
|
685
|
-
return
|
|
686
|
-
.join(', ')
|
|
687
|
-
}
|
|
688
|
-
|
|
392
|
+
return `LINESTRING (${this.mapArray((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
|
|
393
|
+
.join(', ')})`;
|
|
394
|
+
}
|
|
395
|
+
filter(f) {
|
|
689
396
|
this.pPoints = this.pPoints.filter(f);
|
|
690
397
|
return this;
|
|
691
|
-
}
|
|
692
|
-
|
|
398
|
+
}
|
|
399
|
+
map(f) {
|
|
693
400
|
this.pPoints = this.mapArray(f);
|
|
694
|
-
this.holes = this.holes.map(
|
|
401
|
+
this.holes = this.holes.map((h) => h.map(f));
|
|
695
402
|
return this;
|
|
696
|
-
}
|
|
697
|
-
|
|
403
|
+
}
|
|
404
|
+
mapArray(f) {
|
|
698
405
|
return this.pPoints.map(f);
|
|
699
|
-
}
|
|
700
|
-
|
|
406
|
+
}
|
|
407
|
+
sort(f) {
|
|
701
408
|
this.points.sort(f);
|
|
702
409
|
return this;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
|
|
410
|
+
}
|
|
411
|
+
at(index) {
|
|
412
|
+
const { length } = this;
|
|
706
413
|
return this.points[(index % length + length) % length];
|
|
707
|
-
}
|
|
708
|
-
|
|
414
|
+
}
|
|
415
|
+
pop() {
|
|
709
416
|
return this.pPoints.pop();
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
args[_i] = arguments[_i];
|
|
716
|
-
}
|
|
717
|
-
return (_a = this.pPoints).push.apply(_a, __spreadArray([], __read(args), false));
|
|
718
|
-
};
|
|
719
|
-
DPolygon.prototype.shift = function () {
|
|
417
|
+
}
|
|
418
|
+
push(...args) {
|
|
419
|
+
return this.pPoints.push(...args);
|
|
420
|
+
}
|
|
421
|
+
shift() {
|
|
720
422
|
return this.pPoints.shift();
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
args[_i] = arguments[_i];
|
|
727
|
-
}
|
|
728
|
-
return (_a = this.pPoints).unshift.apply(_a, __spreadArray([], __read(args), false));
|
|
729
|
-
};
|
|
730
|
-
DPolygon.prototype.reverse = function () {
|
|
423
|
+
}
|
|
424
|
+
unshift(...args) {
|
|
425
|
+
return this.pPoints.unshift(...args);
|
|
426
|
+
}
|
|
427
|
+
reverse() {
|
|
731
428
|
this.pPoints = this.pPoints.reverse();
|
|
732
|
-
this.holes = this.holes.map(
|
|
429
|
+
this.holes = this.holes.map((h) => h.reverse());
|
|
733
430
|
return this;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
return (this.pPoints.map(
|
|
737
|
-
.reduce(
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
return
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
|
|
431
|
+
}
|
|
432
|
+
getValue() {
|
|
433
|
+
return (this.pPoints.map((r) => r.getValue()) + this.holes
|
|
434
|
+
.reduce((a, h) => a + h.getValue(), ''));
|
|
435
|
+
}
|
|
436
|
+
toString() {
|
|
437
|
+
return `(${this.mapArray((r) => r.toString()).join(', ')})`;
|
|
438
|
+
}
|
|
439
|
+
close() {
|
|
440
|
+
const p0 = this.first;
|
|
744
441
|
if (p0 && !this.closed) {
|
|
745
442
|
this.push(p0.clone());
|
|
746
443
|
}
|
|
747
444
|
return this;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
|
|
445
|
+
}
|
|
446
|
+
open() {
|
|
447
|
+
const p = this.first;
|
|
751
448
|
if (this.length > 2 && p && this.closed) {
|
|
752
449
|
this.pop();
|
|
753
450
|
}
|
|
754
451
|
return this;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
res.holes =
|
|
452
|
+
}
|
|
453
|
+
add(poly) {
|
|
454
|
+
const res = new DPolygon([...this.points, ...poly.points]).close();
|
|
455
|
+
res.holes = [...this.holes, ...poly.holes].map((h) => h.clone());
|
|
759
456
|
return res;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
return this.pPoints.some(
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
res.holes = this.holes.map(
|
|
457
|
+
}
|
|
458
|
+
has(p) {
|
|
459
|
+
return this.pPoints.some((q) => q.equal(p));
|
|
460
|
+
}
|
|
461
|
+
clone() {
|
|
462
|
+
const res = new DPolygon(this.points.map((r) => r.clone()));
|
|
463
|
+
res.holes = this.holes.map((h) => h.clone());
|
|
767
464
|
res.properties = this.properties;
|
|
768
465
|
return res;
|
|
769
|
-
}
|
|
770
|
-
|
|
466
|
+
}
|
|
467
|
+
equal(p) {
|
|
771
468
|
if (!(p instanceof DPolygon)) {
|
|
772
469
|
return false;
|
|
773
470
|
}
|
|
@@ -775,14 +472,14 @@ var DPolygon = (function () {
|
|
|
775
472
|
return false;
|
|
776
473
|
}
|
|
777
474
|
return (this.same(p) &&
|
|
778
|
-
this.holes.reduce(
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
475
|
+
this.holes.reduce((a, hole) => a && p.holes.some((pHoles) => pHoles.same(hole)), true));
|
|
476
|
+
}
|
|
477
|
+
same(p) {
|
|
478
|
+
const pClone = p.clone().close();
|
|
479
|
+
const thisAsString = this.clone()
|
|
783
480
|
.close()
|
|
784
481
|
.toString();
|
|
785
|
-
for (
|
|
482
|
+
for (let i = 0; i < pClone.length; i++) {
|
|
786
483
|
if (thisAsString === pClone.toString() || thisAsString === pClone.clone().reverse()
|
|
787
484
|
.toString()) {
|
|
788
485
|
return true;
|
|
@@ -790,45 +487,37 @@ var DPolygon = (function () {
|
|
|
790
487
|
pClone.nextStart();
|
|
791
488
|
}
|
|
792
489
|
return false;
|
|
793
|
-
}
|
|
794
|
-
|
|
490
|
+
}
|
|
491
|
+
findIndex(a) {
|
|
795
492
|
if (a instanceof DPoint_1.DPoint) {
|
|
796
|
-
return this.points.findIndex(
|
|
493
|
+
return this.points.findIndex((t) => t.equal(a));
|
|
797
494
|
}
|
|
798
495
|
return this.points.findIndex(a);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
if (e === void 0) { e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE; }
|
|
496
|
+
}
|
|
497
|
+
approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
|
|
802
498
|
return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
points[_i - 1] = arguments[_i];
|
|
809
|
-
}
|
|
810
|
-
(_a = this.pPoints).splice.apply(_a, __spreadArray([index + 1, 0], __read(points), false));
|
|
811
|
-
};
|
|
812
|
-
DPolygon.prototype.removePart = function (index, count) {
|
|
499
|
+
}
|
|
500
|
+
insertAfter(index, ...points) {
|
|
501
|
+
this.pPoints.splice(index + 1, 0, ...points);
|
|
502
|
+
}
|
|
503
|
+
removePart(index, count) {
|
|
813
504
|
return this.pPoints.splice(index + 1, count);
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
505
|
+
}
|
|
506
|
+
hasSimpleIntersection(p) {
|
|
507
|
+
const extend1 = this.extend;
|
|
508
|
+
const extend2 = p.extend;
|
|
509
|
+
const extend1points = extend1.points;
|
|
510
|
+
const extend2points = extend2.points;
|
|
511
|
+
const in1 = extend1points.some((t) => extend2.simpleInclude(t));
|
|
512
|
+
const in2 = extend2points.some((t) => extend1.simpleInclude(t));
|
|
822
513
|
return in1 || in2;
|
|
823
|
-
}
|
|
824
|
-
|
|
514
|
+
}
|
|
515
|
+
simpleInclude(p) {
|
|
825
516
|
return this.simpleIncludeX(p) && this.simpleIncludeY(p);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
if (lineWidth === void 0) { lineWidth = 1; }
|
|
829
|
-
if (steps === void 0) { steps = this.length - 1; }
|
|
517
|
+
}
|
|
518
|
+
drawPolygonOnCanvas(canvas, fillColor, strokeColor, shadowColor, lineWidth = 1, steps = this.length - 1) {
|
|
830
519
|
if (this.length > 1) {
|
|
831
|
-
|
|
520
|
+
const ctx = canvas.getContext('2d');
|
|
832
521
|
if (fillColor) {
|
|
833
522
|
ctx.fillStyle = fillColor;
|
|
834
523
|
}
|
|
@@ -857,51 +546,39 @@ var DPolygon = (function () {
|
|
|
857
546
|
}
|
|
858
547
|
}
|
|
859
548
|
return this;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
549
|
+
}
|
|
550
|
+
clearPolygonOnCanvas(canvas) {
|
|
551
|
+
const ctx = canvas.getContext('2d');
|
|
552
|
+
const old = ctx.globalCompositeOperation;
|
|
864
553
|
ctx.globalCompositeOperation = 'destination-out';
|
|
865
554
|
this.goByPath(ctx);
|
|
866
555
|
ctx.fill();
|
|
867
556
|
ctx.globalCompositeOperation = old;
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
if (isBorderInside === void 0) { isBorderInside = false; }
|
|
872
|
-
var simpleInclude = this.simpleInclude(p);
|
|
557
|
+
}
|
|
558
|
+
contain(p, isBorderInside = false) {
|
|
559
|
+
const simpleInclude = this.simpleInclude(p);
|
|
873
560
|
if (!simpleInclude) {
|
|
874
561
|
return false;
|
|
875
562
|
}
|
|
876
|
-
|
|
563
|
+
const onBorder = this.onBorder(p);
|
|
877
564
|
if (onBorder) {
|
|
878
565
|
return isBorderInside;
|
|
879
566
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
if (line1.vectorProduct(line2).c > 0) {
|
|
889
|
-
totalFi += fiDif;
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
totalFi -= fiDif;
|
|
893
|
-
}
|
|
567
|
+
const poly = this.deintersection;
|
|
568
|
+
let totalFi = 0;
|
|
569
|
+
for (const [{ x, y }, { x: a, y: b }] of poly.loopPointsGenerator()()) {
|
|
570
|
+
const line1 = new DLine_1.DLine(x - p.x, y - p.y, 0);
|
|
571
|
+
const line2 = new DLine_1.DLine(a - p.x, b - p.y, 0);
|
|
572
|
+
const fiDif = line1.findFi(line2);
|
|
573
|
+
if (line1.vectorProduct(line2).c > 0) {
|
|
574
|
+
totalFi += fiDif;
|
|
894
575
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
finally {
|
|
898
|
-
try {
|
|
899
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
576
|
+
else {
|
|
577
|
+
totalFi -= fiDif;
|
|
900
578
|
}
|
|
901
|
-
finally { if (e_11) throw e_11.error; }
|
|
902
579
|
}
|
|
903
|
-
|
|
904
|
-
|
|
580
|
+
const eps = Math.PI / 10000;
|
|
581
|
+
const absTotalFi = Math.abs(totalFi);
|
|
905
582
|
if (absTotalFi < eps) {
|
|
906
583
|
return false;
|
|
907
584
|
}
|
|
@@ -909,123 +586,89 @@ var DPolygon = (function () {
|
|
|
909
586
|
return true;
|
|
910
587
|
}
|
|
911
588
|
throw new Error('contains2 faild');
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
var simpleInclude = this.simpleInclude(p);
|
|
589
|
+
}
|
|
590
|
+
onBorder(p) {
|
|
591
|
+
const simpleInclude = this.simpleInclude(p);
|
|
916
592
|
if (simpleInclude) {
|
|
917
|
-
|
|
918
|
-
|
|
593
|
+
const poly = this.deintersection;
|
|
594
|
+
const hasSamePoint = this.points.some((point) => point.equal(p));
|
|
919
595
|
if (hasSamePoint) {
|
|
920
596
|
return true;
|
|
921
597
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
if (onBorder) {
|
|
927
|
-
return true;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
932
|
-
finally {
|
|
933
|
-
try {
|
|
934
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
598
|
+
for (const [, , polygonLine] of poly.loopPointsGenerator(true)()) {
|
|
599
|
+
const onBorder = polygonLine.x(p).equal(p) && polygonLine.inRange(p);
|
|
600
|
+
if (onBorder) {
|
|
601
|
+
return true;
|
|
935
602
|
}
|
|
936
|
-
finally { if (e_12) throw e_12.error; }
|
|
937
603
|
}
|
|
938
604
|
}
|
|
939
605
|
return false;
|
|
940
|
-
}
|
|
941
|
-
|
|
606
|
+
}
|
|
607
|
+
nextStart() {
|
|
942
608
|
this.open();
|
|
943
609
|
this.push(this.shift());
|
|
944
610
|
this.close();
|
|
945
611
|
return this;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
for (
|
|
949
|
-
|
|
950
|
-
|
|
612
|
+
}
|
|
613
|
+
removeDuplicates() {
|
|
614
|
+
for (let i = 0; i < this.length - 1; i++) {
|
|
615
|
+
const p1 = this.at(i);
|
|
616
|
+
const p2 = this.at(i + 1);
|
|
951
617
|
if (p1.equal(p2)) {
|
|
952
618
|
this.removePart(i, 1);
|
|
953
619
|
i--;
|
|
954
620
|
}
|
|
955
621
|
}
|
|
956
622
|
return this;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
return new DPolygon(a.map(
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
return this.mapArray(
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
var d = p1.distance(p2);
|
|
623
|
+
}
|
|
624
|
+
static parse(a) {
|
|
625
|
+
return new DPolygon(a.map((r) => DPoint_1.DPoint.parse(r)));
|
|
626
|
+
}
|
|
627
|
+
toArrayOfCoords() {
|
|
628
|
+
return this.mapArray((r) => r.toCoords());
|
|
629
|
+
}
|
|
630
|
+
divideToPieces(piecesCount, withAltitude = false) {
|
|
631
|
+
const { fullLength } = this;
|
|
632
|
+
const pieceLength = fullLength / piecesCount;
|
|
633
|
+
let currentPieceLength = pieceLength;
|
|
634
|
+
for (const [p1, p2, , i] of this.loopPointsGenerator()()) {
|
|
635
|
+
const d = p1.distance(p2);
|
|
971
636
|
if (d === currentPieceLength) {
|
|
972
637
|
p2.properties.pieceBorder = true;
|
|
973
638
|
currentPieceLength = pieceLength;
|
|
974
639
|
}
|
|
975
640
|
else if (d - currentPieceLength > 0) {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
.filter(
|
|
641
|
+
const circle = new DCircle_1.DCircle(p1, currentPieceLength);
|
|
642
|
+
const line = p1.findLine(p2);
|
|
643
|
+
const intersectionPoint = line.intersectionWithCircle(circle)
|
|
644
|
+
.filter((p) => line.inRange(p, CLOSE_TO_INTERSECTION_DISTANCE))[0];
|
|
980
645
|
intersectionPoint.properties.pieceBorder = true;
|
|
981
|
-
|
|
646
|
+
this.insertAfter(i, intersectionPoint);
|
|
647
|
+
if (withAltitude) {
|
|
648
|
+
const p1z = p1.z;
|
|
649
|
+
intersectionPoint.z = p1z - (p1z - p2.z) * (p1.distance(intersectionPoint) / d);
|
|
650
|
+
}
|
|
982
651
|
currentPieceLength = pieceLength;
|
|
983
652
|
}
|
|
984
653
|
else {
|
|
985
654
|
currentPieceLength -= d;
|
|
986
655
|
}
|
|
987
|
-
};
|
|
988
|
-
var this_1 = this;
|
|
989
|
-
try {
|
|
990
|
-
for (var _b = __values(this.loopPointsGenerator()()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
991
|
-
var _d = __read(_c.value, 4), p1 = _d[0], p2 = _d[1], i = _d[3];
|
|
992
|
-
_loop_3(p1, p2, i);
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
996
|
-
finally {
|
|
997
|
-
try {
|
|
998
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
999
|
-
}
|
|
1000
|
-
finally { if (e_13) throw e_13.error; }
|
|
1001
656
|
}
|
|
1002
657
|
return this;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
var e_14, _a;
|
|
658
|
+
}
|
|
659
|
+
prepareToFastSearch() {
|
|
1006
660
|
this.searchStore = {};
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
if (!this.searchStore[x]) {
|
|
1011
|
-
this.searchStore[x] = {};
|
|
1012
|
-
}
|
|
1013
|
-
if (!this.searchStore[x][y]) {
|
|
1014
|
-
this.searchStore[x][y] = {};
|
|
1015
|
-
}
|
|
1016
|
-
this.searchStore[x][y][z || 'undefined'] = true;
|
|
661
|
+
for (const { x, y, z } of this.points) {
|
|
662
|
+
if (!this.searchStore[x]) {
|
|
663
|
+
this.searchStore[x] = {};
|
|
1017
664
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
finally {
|
|
1021
|
-
try {
|
|
1022
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
665
|
+
if (!this.searchStore[x][y]) {
|
|
666
|
+
this.searchStore[x][y] = {};
|
|
1023
667
|
}
|
|
1024
|
-
|
|
668
|
+
this.searchStore[x][y][z || 'undefined'] = true;
|
|
1025
669
|
}
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
var x = _a.x, y = _a.y, z = _a.z;
|
|
670
|
+
}
|
|
671
|
+
fastHas({ x, y, z }) {
|
|
1029
672
|
if (!this.searchStore[x]) {
|
|
1030
673
|
return false;
|
|
1031
674
|
}
|
|
@@ -1036,56 +679,23 @@ var DPolygon = (function () {
|
|
|
1036
679
|
return false;
|
|
1037
680
|
}
|
|
1038
681
|
return this.searchStore[x][y][z || 'undefined'];
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
_d.label = 2;
|
|
1055
|
-
case 2:
|
|
1056
|
-
if (!!_b.done) return [3, 5];
|
|
1057
|
-
p = _b.value;
|
|
1058
|
-
r.push(p);
|
|
1059
|
-
if (!p.properties.pieceBorder) return [3, 4];
|
|
1060
|
-
return [4, r.clone()];
|
|
1061
|
-
case 3:
|
|
1062
|
-
_d.sent();
|
|
1063
|
-
_d.label = 4;
|
|
1064
|
-
case 4:
|
|
1065
|
-
_b = _a.next();
|
|
1066
|
-
return [3, 2];
|
|
1067
|
-
case 5: return [3, 8];
|
|
1068
|
-
case 6:
|
|
1069
|
-
e_15_1 = _d.sent();
|
|
1070
|
-
e_15 = { error: e_15_1 };
|
|
1071
|
-
return [3, 8];
|
|
1072
|
-
case 7:
|
|
1073
|
-
try {
|
|
1074
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1075
|
-
}
|
|
1076
|
-
finally { if (e_15) throw e_15.error; }
|
|
1077
|
-
return [7];
|
|
1078
|
-
case 8: return [2, r.clone()];
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
};
|
|
1082
|
-
},
|
|
1083
|
-
enumerable: false,
|
|
1084
|
-
configurable: true
|
|
1085
|
-
});
|
|
1086
|
-
DPolygon.prototype.simpleUnion = function (p) {
|
|
682
|
+
}
|
|
683
|
+
get growingPiecesGenerator() {
|
|
684
|
+
const polygon = this;
|
|
685
|
+
return function* () {
|
|
686
|
+
const r = new DPolygon();
|
|
687
|
+
for (const p of polygon.pPoints) {
|
|
688
|
+
r.push(p);
|
|
689
|
+
if (p.properties.pieceBorder) {
|
|
690
|
+
yield r.clone();
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return r.clone();
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
simpleUnion(p) {
|
|
1087
697
|
try {
|
|
1088
|
-
|
|
698
|
+
const res = this.simpleLogicFunction(p, true, true);
|
|
1089
699
|
if (res === null) {
|
|
1090
700
|
return null;
|
|
1091
701
|
}
|
|
@@ -1097,77 +707,49 @@ var DPolygon = (function () {
|
|
|
1097
707
|
catch (ex) {
|
|
1098
708
|
return null;
|
|
1099
709
|
}
|
|
1100
|
-
}
|
|
1101
|
-
|
|
710
|
+
}
|
|
711
|
+
simpleIntersection(p) {
|
|
1102
712
|
return this.simpleLogicFunction(p, false, false);
|
|
1103
|
-
}
|
|
1104
|
-
|
|
713
|
+
}
|
|
714
|
+
simpleDifference(p) {
|
|
1105
715
|
return this.simpleLogicFunction(p, true, false);
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
var res = this.clone().simpleUnion(p);
|
|
716
|
+
}
|
|
717
|
+
smartUnion(p) {
|
|
718
|
+
const res = this.clone().simpleUnion(p);
|
|
1110
719
|
if (res) {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
var _loop_5 = function (b) {
|
|
720
|
+
let allHoles = [...this.holes, ...p.holes, ...res.holes].map((h) => h.clone());
|
|
721
|
+
for (const a of allHoles) {
|
|
722
|
+
for (const b of allHoles) {
|
|
1115
723
|
if (a.equal(b)) {
|
|
1116
|
-
|
|
724
|
+
continue;
|
|
1117
725
|
}
|
|
1118
|
-
|
|
726
|
+
const r = a.simpleUnion(b);
|
|
1119
727
|
if (r) {
|
|
1120
|
-
allHoles = allHoles.filter(
|
|
728
|
+
allHoles = allHoles.filter((v) => !v.equal(a) && !v.equal(b));
|
|
1121
729
|
allHoles.push(r);
|
|
1122
730
|
}
|
|
1123
|
-
};
|
|
1124
|
-
try {
|
|
1125
|
-
for (var allHoles_2 = (e_17 = void 0, __values(allHoles)), allHoles_2_1 = allHoles_2.next(); !allHoles_2_1.done; allHoles_2_1 = allHoles_2.next()) {
|
|
1126
|
-
var b = allHoles_2_1.value;
|
|
1127
|
-
_loop_5(b);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
1131
|
-
finally {
|
|
1132
|
-
try {
|
|
1133
|
-
if (allHoles_2_1 && !allHoles_2_1.done && (_b = allHoles_2.return)) _b.call(allHoles_2);
|
|
1134
|
-
}
|
|
1135
|
-
finally { if (e_17) throw e_17.error; }
|
|
1136
|
-
}
|
|
1137
|
-
};
|
|
1138
|
-
try {
|
|
1139
|
-
for (var allHoles_1 = __values(allHoles), allHoles_1_1 = allHoles_1.next(); !allHoles_1_1.done; allHoles_1_1 = allHoles_1.next()) {
|
|
1140
|
-
var a = allHoles_1_1.value;
|
|
1141
|
-
_loop_4(a);
|
|
1142
731
|
}
|
|
1143
732
|
}
|
|
1144
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
1145
|
-
finally {
|
|
1146
|
-
try {
|
|
1147
|
-
if (allHoles_1_1 && !allHoles_1_1.done && (_a = allHoles_1.return)) _a.call(allHoles_1);
|
|
1148
|
-
}
|
|
1149
|
-
finally { if (e_16) throw e_16.error; }
|
|
1150
|
-
}
|
|
1151
733
|
res.holes = allHoles;
|
|
1152
734
|
}
|
|
1153
735
|
return res;
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
.intersection(l, true).length)
|
|
736
|
+
}
|
|
737
|
+
toTriangles() {
|
|
738
|
+
const innerAndNotIntersect = (poly, p1, p2) => {
|
|
739
|
+
const l = p1.findLine(p2);
|
|
740
|
+
const { center } = l;
|
|
741
|
+
const intersections = poly.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
|
|
742
|
+
.intersection(l, true).length), Boolean(poly.clone().close()
|
|
1161
743
|
.intersection(l, true).length));
|
|
1162
|
-
|
|
1163
|
-
.contain(center)
|
|
744
|
+
const contain = poly.holes.reduce((a, hole) => a && !hole
|
|
745
|
+
.contain(center), poly.contain(center));
|
|
1164
746
|
return !intersections && contain;
|
|
1165
747
|
};
|
|
1166
|
-
|
|
1167
|
-
for (
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
748
|
+
const getTriangle = (poly) => {
|
|
749
|
+
for (let i = 0; i < poly.length; i++) {
|
|
750
|
+
const p0 = poly.at(0);
|
|
751
|
+
const p1 = poly.at(1);
|
|
752
|
+
const p2 = poly.at(2);
|
|
1171
753
|
if (innerAndNotIntersect(poly, p0, p2)) {
|
|
1172
754
|
poly.removePart(0, 1);
|
|
1173
755
|
return new DPolygon([
|
|
@@ -1180,47 +762,47 @@ var DPolygon = (function () {
|
|
|
1180
762
|
}
|
|
1181
763
|
return undefined;
|
|
1182
764
|
};
|
|
1183
|
-
|
|
765
|
+
const p = this.clone().clockWise.open();
|
|
1184
766
|
while (p.holes.length) {
|
|
1185
|
-
|
|
767
|
+
const h = p.holes.shift()
|
|
1186
768
|
.clone()
|
|
1187
769
|
.clockWise
|
|
1188
770
|
.reverse()
|
|
1189
771
|
.close();
|
|
1190
|
-
for (
|
|
772
|
+
for (let i = 0; i < p.length; i++) {
|
|
1191
773
|
if (innerAndNotIntersect(p, p.first, h.first)) {
|
|
1192
|
-
p.insertAfter
|
|
774
|
+
p.insertAfter(0, ...h.points, p.first);
|
|
1193
775
|
break;
|
|
1194
776
|
}
|
|
1195
777
|
p.push(p.shift());
|
|
1196
778
|
}
|
|
1197
779
|
}
|
|
1198
|
-
|
|
780
|
+
const res = [];
|
|
1199
781
|
while (p.length > 3) {
|
|
1200
|
-
|
|
782
|
+
const triangle = getTriangle(p);
|
|
1201
783
|
if (triangle) {
|
|
1202
784
|
res.push(triangle);
|
|
1203
785
|
}
|
|
1204
786
|
}
|
|
1205
787
|
res.push(p);
|
|
1206
788
|
return res;
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
.intersection(l, true).length)
|
|
789
|
+
}
|
|
790
|
+
getTrianglesPointIndexes() {
|
|
791
|
+
const innerAndNotIntersect = (poly, p1, p2) => {
|
|
792
|
+
const l = p1.findLine(p2);
|
|
793
|
+
const { center } = l;
|
|
794
|
+
const intersections = poly.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
|
|
795
|
+
.intersection(l, true).length), Boolean(poly.clone().close()
|
|
1214
796
|
.intersection(l, true).length));
|
|
1215
|
-
|
|
1216
|
-
.contain(center)
|
|
797
|
+
const contain = poly.holes.reduce((a, hole) => a && !hole
|
|
798
|
+
.contain(center), poly.contain(center));
|
|
1217
799
|
return !intersections && contain;
|
|
1218
800
|
};
|
|
1219
|
-
|
|
1220
|
-
for (
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
801
|
+
const getTriangle = (poly) => {
|
|
802
|
+
for (let i = 0; i < poly.length; i++) {
|
|
803
|
+
const p0 = poly.at(0);
|
|
804
|
+
const p1 = poly.at(1);
|
|
805
|
+
const p2 = poly.at(2);
|
|
1224
806
|
if (innerAndNotIntersect(poly, p0, p2)) {
|
|
1225
807
|
poly.removePart(0, 1);
|
|
1226
808
|
return [
|
|
@@ -1233,186 +815,147 @@ var DPolygon = (function () {
|
|
|
1233
815
|
}
|
|
1234
816
|
return undefined;
|
|
1235
817
|
};
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
p.points.forEach(
|
|
818
|
+
let p = this.clone();
|
|
819
|
+
let index = 0;
|
|
820
|
+
p.points.forEach((f) => {
|
|
1239
821
|
f.properties.index = index++;
|
|
1240
822
|
});
|
|
1241
|
-
p.holes.forEach(
|
|
1242
|
-
h.pPoints.forEach(
|
|
823
|
+
p.holes.forEach((h) => {
|
|
824
|
+
h.pPoints.forEach((f) => {
|
|
1243
825
|
f.properties.index = index++;
|
|
1244
826
|
});
|
|
1245
827
|
});
|
|
1246
828
|
p = p.clockWise.open();
|
|
1247
829
|
while (p.holes.length) {
|
|
1248
|
-
|
|
830
|
+
const h = p.holes.shift()
|
|
1249
831
|
.clone()
|
|
1250
832
|
.clockWise
|
|
1251
833
|
.reverse()
|
|
1252
834
|
.close();
|
|
1253
|
-
for (
|
|
835
|
+
for (let i = 0; i < p.length; i++) {
|
|
1254
836
|
if (innerAndNotIntersect(p, p.first, h.first)) {
|
|
1255
|
-
p.insertAfter
|
|
837
|
+
p.insertAfter(0, ...h.points, p.first);
|
|
1256
838
|
break;
|
|
1257
839
|
}
|
|
1258
840
|
p.push(p.shift());
|
|
1259
841
|
}
|
|
1260
842
|
}
|
|
1261
|
-
|
|
843
|
+
const res = [];
|
|
1262
844
|
while (p.length > 3) {
|
|
1263
|
-
|
|
845
|
+
const triangle = getTriangle(p);
|
|
1264
846
|
if (triangle) {
|
|
1265
|
-
res.push
|
|
847
|
+
res.push(...triangle);
|
|
1266
848
|
}
|
|
1267
849
|
}
|
|
1268
|
-
res.push
|
|
850
|
+
res.push(...p.points.map((f) => f.properties.index));
|
|
1269
851
|
return res;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
DPolygon.prototype.buffer = function (v, quadrantSegments, type) {
|
|
1279
|
-
if (quadrantSegments === void 0) { quadrantSegments = 64; }
|
|
1280
|
-
if (type === void 0) { type = DPolygon.CAP_ROUND; }
|
|
1281
|
-
var reader = new jsts_1.io.WKTReader();
|
|
1282
|
-
var _a = this, noHoles = _a.noHoles, closed = _a.closed;
|
|
1283
|
-
var points = reader
|
|
852
|
+
}
|
|
853
|
+
get closed() {
|
|
854
|
+
return this.first.equal(this.last);
|
|
855
|
+
}
|
|
856
|
+
buffer(v, quadrantSegments = 64, type = DPolygon.CAP_ROUND) {
|
|
857
|
+
const reader = new jsts_1.io.WKTReader();
|
|
858
|
+
const { noHoles, closed } = this;
|
|
859
|
+
const points = reader
|
|
1284
860
|
.read(noHoles.toWKT(closed ? DPolygon.WKT_POLYGON : DPolygon.WKT_LINESTRING))
|
|
1285
861
|
.buffer(v, quadrantSegments, type)
|
|
1286
862
|
.getCoordinates();
|
|
1287
|
-
return new DPolygon(points.map(
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
var _c = __read(last.sortByDistance(buffer).points.map(function (r) { return r.properties.index; }), 2), end0 = _c[0], end1 = _c[1];
|
|
1298
|
-
var fromPoint = Math.min(Math.max(start0, start1), Math.max(end0, end1));
|
|
1299
|
-
var toPoint = Math.max(Math.min(start0, start1), Math.min(end0, end1));
|
|
1300
|
-
var linePart = new DPolygon(buffer.removePart(fromPoint - 1, toPoint - fromPoint + 1));
|
|
863
|
+
return new DPolygon(points.map(({ x, y }) => new DPoint_1.DPoint(x, y)));
|
|
864
|
+
}
|
|
865
|
+
sideBuffers(v, quadrantSegments = 64) {
|
|
866
|
+
const { first, last } = this;
|
|
867
|
+
const buffer = this.buffer(v, quadrantSegments, DPolygon.CAP_FLAT).open();
|
|
868
|
+
const [start0, start1] = first.sortByDistance(buffer).points.map((r) => r.properties.index);
|
|
869
|
+
const [end0, end1] = last.sortByDistance(buffer).points.map((r) => r.properties.index);
|
|
870
|
+
const fromPoint = Math.min(Math.max(start0, start1), Math.max(end0, end1));
|
|
871
|
+
const toPoint = Math.max(Math.min(start0, start1), Math.min(end0, end1));
|
|
872
|
+
const linePart = new DPolygon(buffer.removePart(fromPoint - 1, toPoint - fromPoint + 1));
|
|
1301
873
|
buffer.unshift(buffer.pop());
|
|
1302
874
|
return [linePart.reverse(), buffer];
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
for (var i = 0; i < 1; i += step) {
|
|
875
|
+
}
|
|
876
|
+
bezier(step = 0.1) {
|
|
877
|
+
const res = new DPolygon();
|
|
878
|
+
for (let i = 0; i < 1; i += step) {
|
|
1308
879
|
res.push(this.clone().getBezierPoint(i));
|
|
1309
880
|
}
|
|
1310
881
|
return res;
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
882
|
+
}
|
|
883
|
+
setGrowingHeight(from, to) {
|
|
884
|
+
const { fullLength } = this;
|
|
885
|
+
let { first: prevPoint } = this;
|
|
886
|
+
const d = to - from;
|
|
887
|
+
let currentDistance = 0;
|
|
1317
888
|
this.loop()
|
|
1318
|
-
.setZ(
|
|
889
|
+
.setZ((p) => {
|
|
1319
890
|
currentDistance += prevPoint.distance(p);
|
|
1320
891
|
prevPoint = p;
|
|
1321
892
|
return from + currentDistance / fullLength * d;
|
|
1322
893
|
})
|
|
1323
894
|
.run();
|
|
1324
895
|
return this;
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
i = 0;
|
|
1335
|
-
_a.label = 1;
|
|
1336
|
-
case 1:
|
|
1337
|
-
if (!(i < that.length - 1)) return [3, 4];
|
|
1338
|
-
p1 = that.at(i);
|
|
1339
|
-
p2 = that.at(i + 1);
|
|
1340
|
-
return [4, [p1, p2, withLine ? p1.findLine(p2) : undefined, i]];
|
|
1341
|
-
case 2:
|
|
1342
|
-
_a.sent();
|
|
1343
|
-
_a.label = 3;
|
|
1344
|
-
case 3:
|
|
1345
|
-
i++;
|
|
1346
|
-
return [3, 1];
|
|
1347
|
-
case 4: return [2];
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
896
|
+
}
|
|
897
|
+
loopPointsGenerator(withLine = false) {
|
|
898
|
+
const that = this;
|
|
899
|
+
return function* () {
|
|
900
|
+
for (let i = 0; i < that.length - 1; i++) {
|
|
901
|
+
const p1 = that.at(i);
|
|
902
|
+
const p2 = that.at(i + 1);
|
|
903
|
+
yield [p1, p2, withLine ? p1.findLine(p2) : undefined, i];
|
|
904
|
+
}
|
|
1350
905
|
};
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
var e_18, _a;
|
|
906
|
+
}
|
|
907
|
+
getBezierPoint(v) {
|
|
1354
908
|
if (this.length === 1) {
|
|
1355
909
|
return this.first;
|
|
1356
910
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
p1.move(p2.clone().move(p1.clone().minus())
|
|
1361
|
-
.scale(v));
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
1365
|
-
finally {
|
|
1366
|
-
try {
|
|
1367
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1368
|
-
}
|
|
1369
|
-
finally { if (e_18) throw e_18.error; }
|
|
911
|
+
for (const [p1, p2] of this.loopPointsGenerator()()) {
|
|
912
|
+
p1.move(p2.clone().move(p1.clone().minus())
|
|
913
|
+
.scale(v));
|
|
1370
914
|
}
|
|
1371
915
|
this.pop();
|
|
1372
916
|
return this.getBezierPoint(v);
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
|
|
917
|
+
}
|
|
918
|
+
simpleIncludeX(p) {
|
|
919
|
+
const { x } = p;
|
|
1376
920
|
return this.minX <= x && this.maxX >= x;
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
|
|
921
|
+
}
|
|
922
|
+
simpleIncludeY(p) {
|
|
923
|
+
const { y } = p;
|
|
1380
924
|
return this.minY <= y && this.maxY >= y;
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
for (
|
|
1388
|
-
|
|
925
|
+
}
|
|
926
|
+
douglasPeucker(points, e) {
|
|
927
|
+
let dMax = 0;
|
|
928
|
+
let index = 0;
|
|
929
|
+
const end = points.length - 1;
|
|
930
|
+
const line = points[0].findLine(points[end]);
|
|
931
|
+
for (let i = 1; i < end; i++) {
|
|
932
|
+
const d = line.perpendicularDistance(points[i]);
|
|
1389
933
|
if (d > dMax) {
|
|
1390
934
|
index = i;
|
|
1391
935
|
dMax = d;
|
|
1392
936
|
}
|
|
1393
937
|
}
|
|
1394
938
|
if (dMax >= e) {
|
|
1395
|
-
|
|
1396
|
-
|
|
939
|
+
const recResult1 = this.douglasPeucker(points.slice(0, index + 1), e);
|
|
940
|
+
const recResult2 = this.douglasPeucker(points.slice(index), e);
|
|
1397
941
|
recResult1.pop();
|
|
1398
|
-
return
|
|
942
|
+
return [...recResult1, ...recResult2];
|
|
1399
943
|
}
|
|
1400
944
|
return [points[0], points[end]];
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
var start = this.first;
|
|
945
|
+
}
|
|
946
|
+
goByPath(ctx, steps = this.length - 1) {
|
|
947
|
+
const start = this.first;
|
|
1405
948
|
ctx.moveTo(start.x, start.y);
|
|
1406
|
-
for (
|
|
1407
|
-
|
|
949
|
+
for (let i = 1; i <= (steps % this.length); i++) {
|
|
950
|
+
const { x, y } = this.at(i);
|
|
1408
951
|
ctx.lineTo(x, y);
|
|
1409
952
|
}
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
953
|
+
}
|
|
954
|
+
getJSTSGeometry(p, unionThis, unionThat) {
|
|
955
|
+
const unionOrIntersection = unionThat === unionThis;
|
|
956
|
+
const reader = new jsts_1.io.WKTReader();
|
|
957
|
+
const a = reader.read(this.noHoles.toWKT());
|
|
958
|
+
const b = reader.read(p.noHoles.toWKT());
|
|
1416
959
|
if (!unionOrIntersection) {
|
|
1417
960
|
return a.difference(b);
|
|
1418
961
|
}
|
|
@@ -1423,21 +966,19 @@ var DPolygon = (function () {
|
|
|
1423
966
|
return a.intersection(b);
|
|
1424
967
|
}
|
|
1425
968
|
return undefined;
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
var c = this.getJSTSGeometry(p, unionThis, unionThat);
|
|
969
|
+
}
|
|
970
|
+
simpleLogicFunction(p, unionThis, unionThat) {
|
|
971
|
+
const c = this.getJSTSGeometry(p, unionThis, unionThat);
|
|
1430
972
|
if (c) {
|
|
1431
|
-
|
|
1432
|
-
if (
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
var first = ak[lastIndex].first;
|
|
973
|
+
const coordinates = c.getCoordinates();
|
|
974
|
+
if (coordinates.length) {
|
|
975
|
+
let result = coordinates.reduce((ak, { x, y }, index) => {
|
|
976
|
+
const lastIndex = ak.length - 1;
|
|
977
|
+
const t = new DPoint_1.DPoint(x, y);
|
|
978
|
+
const { first } = ak[lastIndex];
|
|
1438
979
|
if (t.equal(first)) {
|
|
1439
|
-
if (
|
|
1440
|
-
|
|
980
|
+
if (coordinates[index + 1]) {
|
|
981
|
+
const nextPoint = new DPoint_1.DPoint(coordinates[index + 1].x, coordinates[index + 1].y);
|
|
1441
982
|
if (ak[lastIndex].length > 1) {
|
|
1442
983
|
ak.push(new DPolygon([nextPoint]));
|
|
1443
984
|
}
|
|
@@ -1447,92 +988,41 @@ var DPolygon = (function () {
|
|
|
1447
988
|
ak[lastIndex].push(t);
|
|
1448
989
|
}
|
|
1449
990
|
return ak;
|
|
1450
|
-
}, [new DPolygon([new DPoint_1.DPoint(
|
|
991
|
+
}, [new DPolygon([new DPoint_1.DPoint(coordinates[0].x, coordinates[0].y)])]);
|
|
1451
992
|
if (unionThat && unionThis && result.length > 1) {
|
|
1452
|
-
|
|
1453
|
-
for (
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
(_e = q.points).splice.apply(_e, __spreadArray([index, 0], __read(r.points), false));
|
|
1460
|
-
result = result.filter(function (h) { return !h.equal(r); });
|
|
1461
|
-
return "continue";
|
|
1462
|
-
}
|
|
1463
|
-
if (result.length < 2) {
|
|
1464
|
-
return "break";
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
try {
|
|
1468
|
-
for (var result_2 = (e_20 = void 0, __values(result)), result_2_1 = result_2.next(); !result_2_1.done; result_2_1 = result_2.next()) {
|
|
1469
|
-
var r = result_2_1.value;
|
|
1470
|
-
var state_1 = _loop_6(r);
|
|
1471
|
-
if (state_1 === "break")
|
|
1472
|
-
break;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
1476
|
-
finally {
|
|
1477
|
-
try {
|
|
1478
|
-
if (result_2_1 && !result_2_1.done && (_b = result_2.return)) _b.call(result_2);
|
|
1479
|
-
}
|
|
1480
|
-
finally { if (e_20) throw e_20.error; }
|
|
993
|
+
for (const q of result) {
|
|
994
|
+
for (const r of result) {
|
|
995
|
+
if (q.has(r.first) && !q.equal(r)) {
|
|
996
|
+
const index = q.findIndex(r.first);
|
|
997
|
+
q.points.splice(index, 0, ...r.points);
|
|
998
|
+
result = result.filter((h) => !h.equal(r));
|
|
999
|
+
continue;
|
|
1481
1000
|
}
|
|
1482
1001
|
if (result.length < 2) {
|
|
1483
1002
|
break;
|
|
1484
1003
|
}
|
|
1485
1004
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
finally {
|
|
1489
|
-
try {
|
|
1490
|
-
if (result_1_1 && !result_1_1.done && (_a = result_1.return)) _a.call(result_1);
|
|
1005
|
+
if (result.length < 2) {
|
|
1006
|
+
break;
|
|
1491
1007
|
}
|
|
1492
|
-
finally { if (e_19) throw e_19.error; }
|
|
1493
1008
|
}
|
|
1494
1009
|
}
|
|
1495
|
-
result = result.filter(
|
|
1496
|
-
|
|
1497
|
-
for (
|
|
1498
|
-
var q = result_3_1.value;
|
|
1499
|
-
var _loop_7 = function (r) {
|
|
1500
|
-
if (result.length < 2) {
|
|
1501
|
-
return "break";
|
|
1502
|
-
}
|
|
1503
|
-
if (!q.equal(r)) {
|
|
1504
|
-
if (q.contain(r.first, true)) {
|
|
1505
|
-
q.holes.push(r);
|
|
1506
|
-
result = result.filter(function (h) { return !h.equal(r); });
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
};
|
|
1510
|
-
try {
|
|
1511
|
-
for (var result_4 = (e_22 = void 0, __values(result)), result_4_1 = result_4.next(); !result_4_1.done; result_4_1 = result_4.next()) {
|
|
1512
|
-
var r = result_4_1.value;
|
|
1513
|
-
var state_2 = _loop_7(r);
|
|
1514
|
-
if (state_2 === "break")
|
|
1515
|
-
break;
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
1519
|
-
finally {
|
|
1520
|
-
try {
|
|
1521
|
-
if (result_4_1 && !result_4_1.done && (_d = result_4.return)) _d.call(result_4);
|
|
1522
|
-
}
|
|
1523
|
-
finally { if (e_22) throw e_22.error; }
|
|
1524
|
-
}
|
|
1010
|
+
result = result.filter((h) => h.length > 2).map((h) => h.close());
|
|
1011
|
+
for (const q of result) {
|
|
1012
|
+
for (const r of result) {
|
|
1525
1013
|
if (result.length < 2) {
|
|
1526
1014
|
break;
|
|
1527
1015
|
}
|
|
1016
|
+
if (!q.equal(r)) {
|
|
1017
|
+
if (q.contain(r.first, true)) {
|
|
1018
|
+
q.holes.push(r);
|
|
1019
|
+
result = result.filter((h) => !h.equal(r));
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1528
1022
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
finally {
|
|
1532
|
-
try {
|
|
1533
|
-
if (result_3_1 && !result_3_1.done && (_c = result_3.return)) _c.call(result_3);
|
|
1023
|
+
if (result.length < 2) {
|
|
1024
|
+
break;
|
|
1534
1025
|
}
|
|
1535
|
-
finally { if (e_21) throw e_21.error; }
|
|
1536
1026
|
}
|
|
1537
1027
|
if (result.length === 0) {
|
|
1538
1028
|
return null;
|
|
@@ -1540,16 +1030,15 @@ var DPolygon = (function () {
|
|
|
1540
1030
|
if (result.length === 1) {
|
|
1541
1031
|
return result[0].close();
|
|
1542
1032
|
}
|
|
1543
|
-
return result.map(
|
|
1033
|
+
return result.map((g) => g.close());
|
|
1544
1034
|
}
|
|
1545
1035
|
}
|
|
1546
1036
|
return null;
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
DPolygon.CAP_FLAT = CAP_FLAT;
|
|
1550
|
-
DPolygon.CAP_SQUARE = CAP_SQUARE;
|
|
1551
|
-
DPolygon.WKT_LINESTRING = 'LINESTRING';
|
|
1552
|
-
DPolygon.WKT_POLYGON = 'POLYGON';
|
|
1553
|
-
return DPolygon;
|
|
1554
|
-
}());
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1555
1039
|
exports.DPolygon = DPolygon;
|
|
1040
|
+
DPolygon.CAP_ROUND = CAP_ROUND;
|
|
1041
|
+
DPolygon.CAP_FLAT = CAP_FLAT;
|
|
1042
|
+
DPolygon.CAP_SQUARE = CAP_SQUARE;
|
|
1043
|
+
DPolygon.WKT_LINESTRING = 'LINESTRING';
|
|
1044
|
+
DPolygon.WKT_POLYGON = 'POLYGON';
|