dgeoutils 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/DCircle.js +52 -63
- package/dist/cjs/DLine.js +132 -181
- package/dist/cjs/DNumbers.js +16 -20
- package/dist/cjs/DPlane.js +56 -79
- package/dist/cjs/DPoint.js +240 -338
- package/dist/cjs/DPolygon.js +635 -1151
- package/dist/cjs/DPolygonLoop.js +138 -143
- package/dist/cjs/FastSearch.js +13 -37
- package/dist/cjs/TraceMatrix.js +87 -139
- package/dist/cjs/utils.js +61 -103
- package/package.json +2 -2
package/dist/cjs/DPoint.js
CHANGED
|
@@ -1,106 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
3
|
exports.DPoint = exports.DEGREE_TO_PI = exports.PI_TO_DEGREE = exports.DOUBLE_PI_IN_DEGREE = exports.PI_IN_DEGREE = exports.HALF_PI_IN_DEGREE = exports.EARTH_RADIUS_IN_METERS = void 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
4
|
+
const DLine_1 = require("./DLine");
|
|
5
|
+
const DPolygon_1 = require("./DPolygon");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const diff = 0;
|
|
8
|
+
const radiansPolygon = new DPolygon_1.DPolygon();
|
|
9
|
+
const pseudoMercatorPolygon = new DPolygon_1.DPolygon();
|
|
10
|
+
const worldGeodeticPolygon = new DPolygon_1.DPolygon();
|
|
38
11
|
exports.EARTH_RADIUS_IN_METERS = 6371008.8;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
12
|
+
const EARTH_IN_MITERS = 20037508.34;
|
|
13
|
+
const DEGREES_IN_EARTH = 180;
|
|
14
|
+
const MITERS_IN_ONE_DEGREE = EARTH_IN_MITERS / DEGREES_IN_EARTH;
|
|
15
|
+
const DEGREES_IN_ONE_MITER = DEGREES_IN_EARTH / EARTH_IN_MITERS;
|
|
43
16
|
exports.HALF_PI_IN_DEGREE = 90;
|
|
44
17
|
exports.PI_IN_DEGREE = 180;
|
|
45
18
|
exports.DOUBLE_PI_IN_DEGREE = 360;
|
|
46
19
|
exports.PI_TO_DEGREE = Math.PI / exports.PI_IN_DEGREE;
|
|
47
20
|
exports.DEGREE_TO_PI = exports.PI_IN_DEGREE / Math.PI;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (x === void 0) { x = 0; }
|
|
51
|
-
if (y === void 0) { y = x; }
|
|
21
|
+
class DPoint {
|
|
22
|
+
constructor(x = 0, y = x, z) {
|
|
52
23
|
this.x = x;
|
|
53
24
|
this.y = y;
|
|
54
25
|
this.z = z;
|
|
55
26
|
this.properties = {};
|
|
56
27
|
}
|
|
57
|
-
|
|
28
|
+
static zero() {
|
|
58
29
|
return new DPoint();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
}
|
|
31
|
+
static parse(c) {
|
|
32
|
+
const { lat, lng } = c;
|
|
62
33
|
if (lat && lng) {
|
|
63
34
|
return new DPoint(lat, lng, 0);
|
|
64
35
|
}
|
|
65
|
-
|
|
36
|
+
const [x, y, z] = c;
|
|
66
37
|
return new DPoint(x, y, z);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
38
|
+
}
|
|
39
|
+
static parseFromWKT(wkt) {
|
|
40
|
+
const regexp = /POINT \((?<data>(?:(?!\)).)*?)\)$/miu;
|
|
41
|
+
const data = wkt.trim().toUpperCase();
|
|
42
|
+
const res = regexp.exec(data);
|
|
43
|
+
const [x, y, z] = res.groups.data.split(' ').map(Number);
|
|
73
44
|
return new DPoint(x, y, z);
|
|
74
|
-
}
|
|
75
|
-
|
|
45
|
+
}
|
|
46
|
+
static random() {
|
|
76
47
|
return new DPoint(Math.random(), Math.random());
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (zoom === void 0) { zoom = this.z; }
|
|
48
|
+
}
|
|
49
|
+
getTileFromCoords(zoom = this.z) {
|
|
80
50
|
(0, utils_1.checkFunction)('getTileFromCoords')
|
|
81
51
|
.checkArgument('this')
|
|
82
52
|
.shouldBeDegree(this);
|
|
83
|
-
|
|
84
|
-
|
|
53
|
+
const x = Math.floor((this.x + exports.PI_IN_DEGREE) / exports.DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
|
|
54
|
+
const y = Math.floor((1 - Math.log(Math.tan(this.y * exports.PI_TO_DEGREE) + 1 / Math.cos(this.y * exports.PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
|
|
85
55
|
return new DPoint(x, y, zoom);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (zoom === void 0) { zoom = this.z; }
|
|
56
|
+
}
|
|
57
|
+
getCoordsFromTile(zoom = this.z) {
|
|
89
58
|
(0, utils_1.checkFunction)('getCoordsFromTile')
|
|
90
59
|
.checkArgument('this')
|
|
91
60
|
.shouldBeUInt(this);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
61
|
+
const n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom));
|
|
62
|
+
const x = this.x / (Math.pow(2, zoom)) * exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE;
|
|
63
|
+
const y = exports.PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
|
|
95
64
|
return new DPoint(x, y, zoom);
|
|
96
|
-
}
|
|
97
|
-
|
|
65
|
+
}
|
|
66
|
+
toCoords() {
|
|
98
67
|
if (this.z === undefined) {
|
|
99
68
|
return [this.x, this.y];
|
|
100
69
|
}
|
|
101
70
|
return [this.x, this.y, this.z];
|
|
102
|
-
}
|
|
103
|
-
|
|
71
|
+
}
|
|
72
|
+
findLine(p) {
|
|
104
73
|
(0, utils_1.checkFunction)('findLine')
|
|
105
74
|
.checkArgument('this')
|
|
106
75
|
.shouldBeMeters(this)
|
|
@@ -109,9 +78,9 @@ var DPoint = (function () {
|
|
|
109
78
|
if (this.equal(p)) {
|
|
110
79
|
return this.findLine(p.clone().move(0, 1));
|
|
111
80
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
81
|
+
const a = this.y - p.y - diff;
|
|
82
|
+
const b = p.x - this.x - diff;
|
|
83
|
+
const c = this.x * p.y - p.x * this.y - diff;
|
|
115
84
|
if (a === 0) {
|
|
116
85
|
return new DLine_1.DLine(0, 1, c / b, this, p);
|
|
117
86
|
}
|
|
@@ -119,8 +88,8 @@ var DPoint = (function () {
|
|
|
119
88
|
return new DLine_1.DLine(1, 0, c / a, this, p);
|
|
120
89
|
}
|
|
121
90
|
return new DLine_1.DLine(a, b, c, this, p);
|
|
122
|
-
}
|
|
123
|
-
|
|
91
|
+
}
|
|
92
|
+
findInnerAngle(p1, p3) {
|
|
124
93
|
(0, utils_1.checkFunction)('findInnerAngle')
|
|
125
94
|
.checkArgument('this')
|
|
126
95
|
.shouldBeMeters(this)
|
|
@@ -128,38 +97,38 @@ var DPoint = (function () {
|
|
|
128
97
|
.shouldBeMeters(p1)
|
|
129
98
|
.checkArgument('p3')
|
|
130
99
|
.shouldBeMeters(p3);
|
|
131
|
-
|
|
132
|
-
|
|
100
|
+
const a1 = this.findLine(p1).getFi();
|
|
101
|
+
const a2 = this.findLine(p3).getFi();
|
|
133
102
|
if (a2 >= a1) {
|
|
134
103
|
return a2 - a1;
|
|
135
104
|
}
|
|
136
105
|
return a2 + Math.PI * 2 - a1;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return this.x
|
|
140
|
-
}
|
|
141
|
-
|
|
106
|
+
}
|
|
107
|
+
toString() {
|
|
108
|
+
return `${this.x} ${this.y}`;
|
|
109
|
+
}
|
|
110
|
+
getValue() {
|
|
142
111
|
return [this.x, this.y];
|
|
143
|
-
}
|
|
144
|
-
|
|
112
|
+
}
|
|
113
|
+
height(z) {
|
|
145
114
|
this.z = z;
|
|
146
115
|
return this;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
|
|
116
|
+
}
|
|
117
|
+
toWKT() {
|
|
118
|
+
const { x, y } = this;
|
|
119
|
+
return `POINT (${x} ${y})`;
|
|
120
|
+
}
|
|
121
|
+
distance(p) {
|
|
153
122
|
(0, utils_1.checkFunction)('distance')
|
|
154
123
|
.checkArgument('this')
|
|
155
124
|
.shouldBeMeters(this)
|
|
156
125
|
.checkArgument('p')
|
|
157
126
|
.shouldBeMeters(p);
|
|
158
|
-
|
|
159
|
-
|
|
127
|
+
const dx = p.x - this.x;
|
|
128
|
+
const dy = p.y - this.y;
|
|
160
129
|
return Math.sqrt(dx * dx + dy * dy);
|
|
161
|
-
}
|
|
162
|
-
|
|
130
|
+
}
|
|
131
|
+
distance3d(p) {
|
|
163
132
|
(0, utils_1.checkFunction)('distance3d')
|
|
164
133
|
.checkArgument('this')
|
|
165
134
|
.shouldBeMeters(this)
|
|
@@ -169,70 +138,69 @@ var DPoint = (function () {
|
|
|
169
138
|
.shouldExist(this.z)
|
|
170
139
|
.checkArgument('p.z')
|
|
171
140
|
.shouldExist(p.z);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
141
|
+
const dx = p.x - this.x;
|
|
142
|
+
const dy = p.y - this.y;
|
|
143
|
+
const dz = p.z - this.z;
|
|
175
144
|
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
176
|
-
}
|
|
177
|
-
|
|
145
|
+
}
|
|
146
|
+
setX(x) {
|
|
178
147
|
this.x = typeof x === 'number' ? x : x(this);
|
|
179
148
|
return this;
|
|
180
|
-
}
|
|
181
|
-
|
|
149
|
+
}
|
|
150
|
+
setZ(z) {
|
|
182
151
|
this.z = typeof z === 'number' ? z : z(this);
|
|
183
152
|
return this;
|
|
184
|
-
}
|
|
185
|
-
|
|
153
|
+
}
|
|
154
|
+
setY(y) {
|
|
186
155
|
this.y = typeof y === 'number' ? y : y(this);
|
|
187
156
|
return this;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
p.properties =
|
|
157
|
+
}
|
|
158
|
+
clone() {
|
|
159
|
+
const p = new DPoint(this.x, this.y, this.z);
|
|
160
|
+
p.properties = Object.assign({}, this.properties);
|
|
192
161
|
return p;
|
|
193
|
-
}
|
|
194
|
-
|
|
162
|
+
}
|
|
163
|
+
gt(p) {
|
|
195
164
|
return this.x > p.x && this.y > p.y;
|
|
196
|
-
}
|
|
197
|
-
|
|
165
|
+
}
|
|
166
|
+
lt(p) {
|
|
198
167
|
return this.x < p.x && this.y < p.y;
|
|
199
|
-
}
|
|
200
|
-
|
|
168
|
+
}
|
|
169
|
+
gtOrEqual(p) {
|
|
201
170
|
return this.gt(p) || this.equal(p);
|
|
202
|
-
}
|
|
203
|
-
|
|
171
|
+
}
|
|
172
|
+
ltOrEqual(p) {
|
|
204
173
|
return this.lt(p) || this.equal(p);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
174
|
+
}
|
|
175
|
+
rotate(a) {
|
|
176
|
+
const x = this.x * Math.cos(a) - this.y * Math.sin(a);
|
|
177
|
+
const y = this.x * Math.sin(a) + this.y * Math.cos(a);
|
|
209
178
|
this.x = x;
|
|
210
179
|
this.y = y;
|
|
211
180
|
return this;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
181
|
+
}
|
|
182
|
+
rotate3dX(a) {
|
|
183
|
+
const { y, z } = this;
|
|
215
184
|
this.y = y * Math.cos(a) + z * Math.sin(a);
|
|
216
185
|
this.z = -y * Math.sin(a) + z * Math.cos(a);
|
|
217
186
|
return this;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
187
|
+
}
|
|
188
|
+
rotate3dY(a) {
|
|
189
|
+
const { x, z } = this;
|
|
221
190
|
this.x = x * Math.cos(a) + z * Math.sin(a);
|
|
222
191
|
this.z = -x * Math.sin(a) + z * Math.cos(a);
|
|
223
192
|
return this;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
193
|
+
}
|
|
194
|
+
rotate3dZ(a) {
|
|
195
|
+
const { x, y } = this;
|
|
227
196
|
this.x = x * Math.cos(a) - y * Math.sin(a);
|
|
228
197
|
this.y = -x * Math.sin(a) + y * Math.cos(a);
|
|
229
198
|
return this;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var zV = undefined;
|
|
199
|
+
}
|
|
200
|
+
move(x, y = x, z) {
|
|
201
|
+
let xV = 0;
|
|
202
|
+
let yV = 0;
|
|
203
|
+
let zV = undefined;
|
|
236
204
|
if (x instanceof DPoint) {
|
|
237
205
|
xV = this.x + x.x;
|
|
238
206
|
yV = this.y + x.y;
|
|
@@ -253,84 +221,82 @@ var DPoint = (function () {
|
|
|
253
221
|
this.z = zV;
|
|
254
222
|
}
|
|
255
223
|
return this;
|
|
256
|
-
}
|
|
257
|
-
|
|
224
|
+
}
|
|
225
|
+
degreeToMeters() {
|
|
258
226
|
(0, utils_1.checkFunction)('degreeToMeters')
|
|
259
227
|
.checkArgument('this')
|
|
260
228
|
.shouldBeDegree(this);
|
|
261
|
-
|
|
262
|
-
|
|
229
|
+
const x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
230
|
+
const y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) *
|
|
263
231
|
(Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
264
232
|
this.x = x;
|
|
265
233
|
this.y = y;
|
|
266
234
|
return this;
|
|
267
|
-
}
|
|
268
|
-
|
|
235
|
+
}
|
|
236
|
+
metersToDegree() {
|
|
269
237
|
(0, utils_1.checkFunction)('metersToDegree')
|
|
270
238
|
.checkArgument('this')
|
|
271
239
|
.shouldBeMeters(this);
|
|
272
|
-
|
|
273
|
-
|
|
240
|
+
const lon = this.x * DEGREES_IN_ONE_MITER;
|
|
241
|
+
const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) *
|
|
274
242
|
(exports.DOUBLE_PI_IN_DEGREE / Math.PI) - exports.HALF_PI_IN_DEGREE;
|
|
275
243
|
this.x = lon;
|
|
276
244
|
this.y = lat;
|
|
277
245
|
return this;
|
|
278
|
-
}
|
|
279
|
-
|
|
246
|
+
}
|
|
247
|
+
degreeToRadians() {
|
|
280
248
|
(0, utils_1.checkFunction)('degreeToRadians')
|
|
281
249
|
.checkArgument('this')
|
|
282
250
|
.shouldBeDegree(this);
|
|
283
251
|
return this.scale(exports.PI_TO_DEGREE);
|
|
284
|
-
}
|
|
285
|
-
|
|
252
|
+
}
|
|
253
|
+
radiansToDegrees() {
|
|
286
254
|
(0, utils_1.checkFunction)('radiansToDegrees')
|
|
287
255
|
.checkArgument('this')
|
|
288
256
|
.shouldBeRadians(this);
|
|
289
257
|
return this.scale(exports.DEGREE_TO_PI);
|
|
290
|
-
}
|
|
291
|
-
|
|
258
|
+
}
|
|
259
|
+
radiansToMeters() {
|
|
292
260
|
(0, utils_1.checkFunction)('radiansToMeters')
|
|
293
261
|
.checkArgument('this')
|
|
294
262
|
.shouldBeRadians(this);
|
|
295
263
|
return this.radiansToDegrees().degreeToMeters();
|
|
296
|
-
}
|
|
297
|
-
|
|
264
|
+
}
|
|
265
|
+
metersToRadians() {
|
|
298
266
|
(0, utils_1.checkFunction)('metersToRadians')
|
|
299
267
|
.checkArgument('this')
|
|
300
268
|
.shouldBeMeters(this);
|
|
301
269
|
return this.metersToDegree().degreeToRadians();
|
|
302
|
-
}
|
|
303
|
-
|
|
270
|
+
}
|
|
271
|
+
round() {
|
|
304
272
|
this.x = Math.round(this.x);
|
|
305
273
|
this.y = Math.round(this.y);
|
|
306
274
|
return this;
|
|
307
|
-
}
|
|
308
|
-
|
|
275
|
+
}
|
|
276
|
+
ceil() {
|
|
309
277
|
this.x = Math.ceil(this.x);
|
|
310
278
|
this.y = Math.ceil(this.y);
|
|
311
279
|
return this;
|
|
312
|
-
}
|
|
313
|
-
|
|
280
|
+
}
|
|
281
|
+
floor() {
|
|
314
282
|
this.x = Math.floor(this.x);
|
|
315
283
|
this.y = Math.floor(this.y);
|
|
316
284
|
return this;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (n === void 0) { n = 2; }
|
|
285
|
+
}
|
|
286
|
+
toFixed(n = 2) {
|
|
320
287
|
this.x = parseFloat(this.x.toFixed(n));
|
|
321
288
|
this.y = parseFloat(this.y.toFixed(n));
|
|
322
289
|
return this;
|
|
323
|
-
}
|
|
324
|
-
|
|
290
|
+
}
|
|
291
|
+
abs() {
|
|
325
292
|
this.x = Math.abs(this.x);
|
|
326
293
|
this.y = Math.abs(this.y);
|
|
327
294
|
return this;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
var zV = undefined;
|
|
295
|
+
}
|
|
296
|
+
scale(x, y = x, z) {
|
|
297
|
+
let xV = 0;
|
|
298
|
+
let yV = 0;
|
|
299
|
+
let zV = undefined;
|
|
334
300
|
if (x instanceof DPoint) {
|
|
335
301
|
xV = this.x * x.x;
|
|
336
302
|
yV = this.y * x.y;
|
|
@@ -351,12 +317,11 @@ var DPoint = (function () {
|
|
|
351
317
|
this.z = zV;
|
|
352
318
|
}
|
|
353
319
|
return this;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
var zV = undefined;
|
|
320
|
+
}
|
|
321
|
+
divide(x, y = x, z) {
|
|
322
|
+
let xV = 0;
|
|
323
|
+
let yV = 0;
|
|
324
|
+
let zV = undefined;
|
|
360
325
|
if (x instanceof DPoint) {
|
|
361
326
|
xV = this.x / x.x;
|
|
362
327
|
yV = this.y / x.y;
|
|
@@ -377,198 +342,135 @@ var DPoint = (function () {
|
|
|
377
342
|
this.z = zV;
|
|
378
343
|
}
|
|
379
344
|
return this;
|
|
380
|
-
}
|
|
381
|
-
|
|
345
|
+
}
|
|
346
|
+
equal(p) {
|
|
382
347
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
383
|
-
}
|
|
384
|
-
|
|
348
|
+
}
|
|
349
|
+
like(p, d = 0.001) {
|
|
385
350
|
var _a, _b, _c, _d;
|
|
386
|
-
if (d === void 0) { d = 0.001; }
|
|
387
351
|
if (this.equal(p)) {
|
|
388
352
|
return true;
|
|
389
353
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
354
|
+
const likeX = Math.abs(this.x - p.x) < d;
|
|
355
|
+
const likeY = Math.abs(this.y - p.y) < d;
|
|
356
|
+
const likeZ = Math.abs(((_b = (_a = this.z) !== null && _a !== void 0 ? _a : p.z) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = p.z) !== null && _c !== void 0 ? _c : this.z) !== null && _d !== void 0 ? _d : 0)) < d;
|
|
393
357
|
return likeX && likeY && likeZ;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
358
|
+
}
|
|
359
|
+
flipVertically(size) {
|
|
360
|
+
let v = size;
|
|
397
361
|
if (size instanceof DPoint) {
|
|
398
362
|
v = size.y;
|
|
399
363
|
}
|
|
400
364
|
this.y = v - this.y;
|
|
401
365
|
return this;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
},
|
|
477
|
-
enumerable: false,
|
|
478
|
-
configurable: true
|
|
479
|
-
});
|
|
480
|
-
Object.defineProperty(DPoint.prototype, "max", {
|
|
481
|
-
get: function () {
|
|
482
|
-
return Math.max(this.x, this.y);
|
|
483
|
-
},
|
|
484
|
-
enumerable: false,
|
|
485
|
-
configurable: true
|
|
486
|
-
});
|
|
487
|
-
Object.defineProperty(DPoint.prototype, "hipPoint", {
|
|
488
|
-
get: function () {
|
|
489
|
-
var hip = this.hip;
|
|
490
|
-
return new DPoint(hip, hip);
|
|
491
|
-
},
|
|
492
|
-
enumerable: false,
|
|
493
|
-
configurable: true
|
|
494
|
-
});
|
|
495
|
-
Object.defineProperty(DPoint.prototype, "xPoint", {
|
|
496
|
-
get: function () {
|
|
497
|
-
var x = this.x;
|
|
498
|
-
return new DPoint(x, x);
|
|
499
|
-
},
|
|
500
|
-
enumerable: false,
|
|
501
|
-
configurable: true
|
|
502
|
-
});
|
|
503
|
-
Object.defineProperty(DPoint.prototype, "yPoint", {
|
|
504
|
-
get: function () {
|
|
505
|
-
var y = this.y;
|
|
506
|
-
return new DPoint(y, y);
|
|
507
|
-
},
|
|
508
|
-
enumerable: false,
|
|
509
|
-
configurable: true
|
|
510
|
-
});
|
|
511
|
-
Object.defineProperty(DPoint.prototype, "wPoint", {
|
|
512
|
-
get: function () {
|
|
513
|
-
return this.xPoint;
|
|
514
|
-
},
|
|
515
|
-
enumerable: false,
|
|
516
|
-
configurable: true
|
|
517
|
-
});
|
|
518
|
-
Object.defineProperty(DPoint.prototype, "hPoint", {
|
|
519
|
-
get: function () {
|
|
520
|
-
return this.yPoint;
|
|
521
|
-
},
|
|
522
|
-
enumerable: false,
|
|
523
|
-
configurable: true
|
|
524
|
-
});
|
|
525
|
-
DPoint.prototype.simple = function (xKey, yKey) {
|
|
526
|
-
var _a;
|
|
527
|
-
if (xKey === void 0) { xKey = 'x'; }
|
|
528
|
-
if (yKey === void 0) { yKey = 'y'; }
|
|
529
|
-
return _a = {},
|
|
530
|
-
_a[xKey] = this.x,
|
|
531
|
-
_a[yKey] = this.y,
|
|
532
|
-
_a;
|
|
533
|
-
};
|
|
534
|
-
DPoint.prototype.setIfLessThan = function (p) {
|
|
366
|
+
}
|
|
367
|
+
get likeRadians() {
|
|
368
|
+
if (radiansPolygon.length === 0) {
|
|
369
|
+
radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2));
|
|
370
|
+
}
|
|
371
|
+
return radiansPolygon.simpleInclude(this);
|
|
372
|
+
}
|
|
373
|
+
get likeWorldGeodeticSystem() {
|
|
374
|
+
if (worldGeodeticPolygon.length === 0) {
|
|
375
|
+
worldGeodeticPolygon.push(new DPoint(-180, -90), new DPoint(180, 90));
|
|
376
|
+
}
|
|
377
|
+
return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this);
|
|
378
|
+
}
|
|
379
|
+
get likePseudoMercator() {
|
|
380
|
+
if (pseudoMercatorPolygon.length === 0) {
|
|
381
|
+
pseudoMercatorPolygon.push(new DPoint(-20026376.39, -20048966.10), new DPoint(20026376.39, 20048966.10));
|
|
382
|
+
}
|
|
383
|
+
return !this.likeRadians && !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this);
|
|
384
|
+
}
|
|
385
|
+
get w() {
|
|
386
|
+
return this.x;
|
|
387
|
+
}
|
|
388
|
+
set w(x) {
|
|
389
|
+
this.x = x;
|
|
390
|
+
}
|
|
391
|
+
get h() {
|
|
392
|
+
return this.y;
|
|
393
|
+
}
|
|
394
|
+
set h(y) {
|
|
395
|
+
this.y = y;
|
|
396
|
+
}
|
|
397
|
+
get area() {
|
|
398
|
+
(0, utils_1.checkFunction)('area')
|
|
399
|
+
.checkArgument('this')
|
|
400
|
+
.shouldBeMeters(this);
|
|
401
|
+
return this.w * this.h;
|
|
402
|
+
}
|
|
403
|
+
get hip() {
|
|
404
|
+
(0, utils_1.checkFunction)('hip')
|
|
405
|
+
.checkArgument('this')
|
|
406
|
+
.shouldBeMeters(this);
|
|
407
|
+
return Math.sqrt(this.w * this.w + this.h * this.h);
|
|
408
|
+
}
|
|
409
|
+
get min() {
|
|
410
|
+
return Math.min(this.x, this.y);
|
|
411
|
+
}
|
|
412
|
+
get max() {
|
|
413
|
+
return Math.max(this.x, this.y);
|
|
414
|
+
}
|
|
415
|
+
get hipPoint() {
|
|
416
|
+
const { hip } = this;
|
|
417
|
+
return new DPoint(hip, hip);
|
|
418
|
+
}
|
|
419
|
+
get xPoint() {
|
|
420
|
+
const { x } = this;
|
|
421
|
+
return new DPoint(x, x);
|
|
422
|
+
}
|
|
423
|
+
get yPoint() {
|
|
424
|
+
const { y } = this;
|
|
425
|
+
return new DPoint(y, y);
|
|
426
|
+
}
|
|
427
|
+
get wPoint() {
|
|
428
|
+
return this.xPoint;
|
|
429
|
+
}
|
|
430
|
+
get hPoint() {
|
|
431
|
+
return this.yPoint;
|
|
432
|
+
}
|
|
433
|
+
simple(xKey = 'x', yKey = 'y') {
|
|
434
|
+
return {
|
|
435
|
+
[xKey]: this.x,
|
|
436
|
+
[yKey]: this.y
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
setIfLessThan(p) {
|
|
535
440
|
this.x = Math.max(this.x, p.x);
|
|
536
441
|
this.y = Math.max(this.y, p.y);
|
|
537
442
|
return this;
|
|
538
|
-
}
|
|
539
|
-
|
|
443
|
+
}
|
|
444
|
+
minus() {
|
|
540
445
|
return this.scale(-1);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
if (pointsCount === void 0) { pointsCount = 360; }
|
|
446
|
+
}
|
|
447
|
+
orthodromicPath(point, pointsCount = 360) {
|
|
544
448
|
(0, utils_1.checkFunction)('orthodromicPath')
|
|
545
449
|
.checkArgument('this')
|
|
546
450
|
.shouldBeDegree(this)
|
|
547
451
|
.checkArgument('point')
|
|
548
452
|
.shouldBeDegree(point);
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
453
|
+
const t = this.clone().degreeToRadians();
|
|
454
|
+
const p = point.clone().degreeToRadians();
|
|
455
|
+
const d = Math.sin(p.x - t.x);
|
|
456
|
+
const step = (p.x - t.x) / (pointsCount - 1);
|
|
553
457
|
return new DPolygon_1.DPolygon((0, utils_1.createArray)(pointsCount)
|
|
554
|
-
.map(
|
|
555
|
-
|
|
556
|
-
|
|
458
|
+
.map((v, i) => {
|
|
459
|
+
const x = t.x + step * i;
|
|
460
|
+
const y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
|
|
557
461
|
(Math.tan(p.y) * Math.sin(x - t.x)) / d);
|
|
558
462
|
return new DPoint(x, y).radiansToDegrees();
|
|
559
463
|
}));
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
var _this = this;
|
|
464
|
+
}
|
|
465
|
+
sortByDistance(p) {
|
|
563
466
|
return p
|
|
564
467
|
.clone()
|
|
565
|
-
.map(
|
|
566
|
-
d.properties.distance = d.distance(
|
|
468
|
+
.map((d, index) => {
|
|
469
|
+
d.properties.distance = d.distance(this);
|
|
567
470
|
d.properties.index = index;
|
|
568
471
|
return d;
|
|
569
472
|
})
|
|
570
|
-
.sort(
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
}());
|
|
473
|
+
.sort((a, b) => a.properties.distance - b.properties.distance);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
574
476
|
exports.DPoint = DPoint;
|