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