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