dgeoutils 2.4.48 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cjs/DCircle.d.ts +18 -0
  2. package/dist/cjs/DCircle.js +102 -0
  3. package/dist/cjs/DLine.d.ts +39 -0
  4. package/dist/cjs/DLine.js +343 -0
  5. package/dist/cjs/DNumbers.d.ts +8 -0
  6. package/dist/cjs/DNumbers.js +30 -0
  7. package/dist/cjs/DPlane.d.ts +25 -0
  8. package/dist/cjs/DPlane.js +132 -0
  9. package/dist/cjs/DPoint.d.ts +139 -0
  10. package/dist/cjs/DPoint.js +820 -0
  11. package/dist/cjs/DPolygon.d.ts +139 -0
  12. package/dist/cjs/DPolygon.js +1774 -0
  13. package/dist/cjs/DPolygonLoop.d.ts +60 -0
  14. package/dist/cjs/DPolygonLoop.js +439 -0
  15. package/dist/cjs/FastSearch.d.ts +6 -0
  16. package/dist/cjs/FastSearch.js +53 -0
  17. package/dist/cjs/InterpolationMatrix.d.ts +24 -0
  18. package/dist/cjs/InterpolationMatrix.js +173 -0
  19. package/dist/cjs/TraceMatrix.d.ts +22 -0
  20. package/dist/cjs/TraceMatrix.js +285 -0
  21. package/dist/cjs/index.d.ts +11 -0
  22. package/dist/cjs/index.js +37 -0
  23. package/dist/cjs/utils.d.ts +49 -0
  24. package/dist/cjs/utils.js +281 -0
  25. package/dist/es2015/DCircle.js +87 -0
  26. package/dist/es2015/DLine.js +290 -0
  27. package/dist/es2015/DNumbers.js +22 -0
  28. package/dist/es2015/DPlane.js +105 -0
  29. package/dist/es2015/DPoint.js +693 -0
  30. package/dist/es2015/DPolygon.js +1203 -0
  31. package/dist/es2015/DPolygonLoop.js +430 -0
  32. package/dist/es2015/FastSearch.js +25 -0
  33. package/dist/es2015/InterpolationMatrix.js +128 -0
  34. package/dist/es2015/TraceMatrix.js +229 -0
  35. package/dist/es2015/index.js +11 -0
  36. package/dist/es2015/utils.js +208 -0
  37. package/dist/esm/DCircle.js +99 -0
  38. package/dist/esm/DLine.js +340 -0
  39. package/dist/esm/DNumbers.js +27 -0
  40. package/dist/esm/DPlane.js +129 -0
  41. package/dist/esm/DPoint.js +817 -0
  42. package/dist/esm/DPolygon.js +1771 -0
  43. package/dist/esm/DPolygonLoop.js +436 -0
  44. package/dist/esm/FastSearch.js +50 -0
  45. package/dist/esm/InterpolationMatrix.js +170 -0
  46. package/dist/esm/TraceMatrix.js +282 -0
  47. package/dist/esm/index.js +11 -0
  48. package/dist/esm/utils.js +266 -0
  49. package/dist/umd/dgeoutils.js +4394 -0
  50. package/dist/umd/dgeoutils.min.js +1 -0
  51. package/dist/umd/dgeoutils.min.js.map +1 -0
  52. package/package.json +9 -1
@@ -0,0 +1,817 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ var __read = (this && this.__read) || function (o, n) {
24
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
25
+ if (!m) return o;
26
+ var i = m.call(o), r, ar = [], e;
27
+ try {
28
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
+ }
30
+ catch (error) { e = { error: error }; }
31
+ finally {
32
+ try {
33
+ if (r && !r.done && (m = i["return"])) m.call(i);
34
+ }
35
+ finally { if (e) throw e.error; }
36
+ }
37
+ return ar;
38
+ };
39
+ import { DLine } from './DLine';
40
+ import { DPolygon } from './DPolygon';
41
+ import { checkFunction, createArray, DGeo, div, isDefAndNotNull, toDegreesMinutesSeconds } from './utils';
42
+ var diff = 0;
43
+ var radiansPolygon = new DPolygon();
44
+ var pseudoMercatorPolygon = new DPolygon();
45
+ var worldGeodeticPolygon = new DPolygon();
46
+ export var EARTH_RADIUS_IN_METERS = 6378137;
47
+ var EARTH_IN_METERS = 20037508.34;
48
+ var DEGREES_IN_EARTH = 180;
49
+ var METERS_IN_ONE_DEGREE = EARTH_IN_METERS / DEGREES_IN_EARTH;
50
+ var DEGREES_IN_ONE_METER = DEGREES_IN_EARTH / EARTH_IN_METERS;
51
+ export var HALF_PI_IN_DEGREE = 90;
52
+ export var PI_IN_DEGREE = 180;
53
+ export var DOUBLE_PI_IN_DEGREE = 360;
54
+ export var PI_TO_DEGREE = Math.PI / PI_IN_DEGREE;
55
+ export var DEGREE_TO_PI = PI_IN_DEGREE / Math.PI;
56
+ var DPoint = (function () {
57
+ function DPoint(x, y, z) {
58
+ if (x === void 0) { x = 0; }
59
+ if (y === void 0) { y = x; }
60
+ this.x = x;
61
+ this.y = y;
62
+ this.z = z;
63
+ this.properties = {};
64
+ }
65
+ DPoint.zero = function () {
66
+ return new DPoint();
67
+ };
68
+ DPoint.parse = function (c, format) {
69
+ if (format === void 0) { format = DGeo.parseFormat; }
70
+ var _a = c, lat = _a.lat, lon = _a.lon, _b = _a.lng, lng = _b === void 0 ? lon : _b, alt = _a.alt;
71
+ if (lat && lng) {
72
+ return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
73
+ }
74
+ var _c = c, x = _c.x, y = _c.y, z = _c.z, properties = __rest(_c, ["x", "y", "z"]);
75
+ if (isDefAndNotNull(x) && isDefAndNotNull(y)) {
76
+ return new DPoint(x, y, z).setProperties(properties);
77
+ }
78
+ var t = c;
79
+ if (c.type === 'Point') {
80
+ t = c.coordinates;
81
+ }
82
+ if (c.type === 'Feature') {
83
+ var f = DPoint.parse(c.geometry, format);
84
+ f.properties = __assign({}, c.properties);
85
+ return f;
86
+ }
87
+ return format.replace(/[^x-z]/gmiu, '')
88
+ .split('')
89
+ .reduce(function (a, k, index) {
90
+ var _a, _b;
91
+ switch (k) {
92
+ case 'x':
93
+ a.x = (_a = t[index]) !== null && _a !== void 0 ? _a : 0;
94
+ break;
95
+ case 'y':
96
+ a.y = (_b = t[index]) !== null && _b !== void 0 ? _b : 0;
97
+ break;
98
+ case 'z':
99
+ a.z = t[index];
100
+ break;
101
+ default:
102
+ }
103
+ return a;
104
+ }, new DPoint());
105
+ };
106
+ DPoint.parseFromWKT = function (wkt) {
107
+ var regexp = /POINT \((?<data>(?:(?!\)).)*?)\)$/miu;
108
+ var data = wkt.trim().toUpperCase();
109
+ var res = regexp.exec(data);
110
+ var _a = __read(res.groups.data.split(' ').map(Number), 3), x = _a[0], y = _a[1], z = _a[2];
111
+ return new DPoint(x, y, z);
112
+ };
113
+ DPoint.random = function () {
114
+ return new DPoint(Math.random(), Math.random());
115
+ };
116
+ DPoint.getTileFromQuadKey = function (quadKey) {
117
+ var p = new DPoint(0, 0, quadKey.length);
118
+ for (var i = p.z; i > 0; i--) {
119
+ var mask = 1 << (i - 1);
120
+ switch (quadKey[p.z - i]) {
121
+ case '0':
122
+ break;
123
+ case '1':
124
+ p.x |= mask;
125
+ break;
126
+ case '2':
127
+ p.y |= mask;
128
+ break;
129
+ case '3':
130
+ p.x |= mask;
131
+ p.y |= mask;
132
+ break;
133
+ default:
134
+ throw new Error('Invalid QuadKey digit sequence.');
135
+ }
136
+ }
137
+ return p;
138
+ };
139
+ DPoint.prototype.toDegreesMinutesSeconds = function () {
140
+ return {
141
+ x: toDegreesMinutesSeconds(this.x),
142
+ y: toDegreesMinutesSeconds(this.y)
143
+ };
144
+ };
145
+ DPoint.prototype.getTileFromCoords = function (zoom) {
146
+ if (zoom === void 0) { zoom = this.z; }
147
+ checkFunction('getTileFromCoords')
148
+ .checkArgument('this')
149
+ .shouldBeDegree(this);
150
+ var x = Math.floor((this.x + PI_IN_DEGREE) / DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
151
+ var y = Math.floor((1 - Math.log(Math.tan(this.y * PI_TO_DEGREE) + 1 / Math.cos(this.y * PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
152
+ return new DPoint(x, y, zoom);
153
+ };
154
+ DPoint.prototype.getQuadKeyFromTile = function (zoom) {
155
+ if (zoom === void 0) { zoom = this.z; }
156
+ var quadKey = [];
157
+ for (var i = zoom; i > 0; i--) {
158
+ var digit = 0;
159
+ var mask = 1 << (i - 1);
160
+ if ((this.x & mask) !== 0) {
161
+ digit++;
162
+ }
163
+ if ((this.y & mask) !== 0) {
164
+ digit++;
165
+ digit++;
166
+ }
167
+ quadKey.push(digit);
168
+ }
169
+ return quadKey.join('');
170
+ };
171
+ DPoint.prototype.getCoordsFromTile = function (zoom) {
172
+ if (zoom === void 0) { zoom = this.z; }
173
+ checkFunction('getCoordsFromTile')
174
+ .checkArgument('this')
175
+ .shouldBeUInt(this);
176
+ var n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom));
177
+ var x = this.x / (Math.pow(2, zoom)) * DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE;
178
+ var y = PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
179
+ return new DPoint(x, y, zoom);
180
+ };
181
+ DPoint.prototype.toCoords = function (format) {
182
+ var _this = this;
183
+ if (format === void 0) { format = DGeo.parseFormat; }
184
+ return format.replace(/[^x-z]/gmiu, '').split('')
185
+ .map(function (k) { return ({
186
+ x: _this.x,
187
+ y: _this.y,
188
+ z: _this.z
189
+ })[k]; })
190
+ .filter(function (r) { return r !== undefined; });
191
+ };
192
+ DPoint.prototype.toGeoJSON = function (format) {
193
+ if (format === void 0) { format = DGeo.parseFormat; }
194
+ return {
195
+ type: 'Point',
196
+ coordinates: this.toCoords(format)
197
+ };
198
+ };
199
+ DPoint.prototype.toGeoJSONFeature = function (format) {
200
+ if (format === void 0) { format = DGeo.parseFormat; }
201
+ return {
202
+ type: 'Feature',
203
+ properties: __assign({}, this.properties),
204
+ geometry: this.toGeoJSON(format)
205
+ };
206
+ };
207
+ DPoint.prototype.findLine = function (p) {
208
+ checkFunction('findLine')
209
+ .checkArgument('this')
210
+ .shouldBeMeters(this)
211
+ .checkArgument('p')
212
+ .shouldBeMeters(p);
213
+ if (this.equal(p)) {
214
+ return this.findLine(p.clone().move(0, 1));
215
+ }
216
+ var a = this.y - p.y - diff;
217
+ var b = p.x - this.x - diff;
218
+ var c = this.x * p.y - p.x * this.y - diff;
219
+ if (a === 0) {
220
+ return new DLine(0, 1, c / b, this, p);
221
+ }
222
+ if (b === 0) {
223
+ return new DLine(1, 0, c / a, this, p);
224
+ }
225
+ return new DLine(a, b, c, this, p);
226
+ };
227
+ DPoint.prototype.findInnerAngle = function (p1, p3) {
228
+ checkFunction('findInnerAngle')
229
+ .checkArgument('this')
230
+ .shouldBeMeters(this)
231
+ .checkArgument('p1')
232
+ .shouldBeMeters(p1)
233
+ .checkArgument('p3')
234
+ .shouldBeMeters(p3);
235
+ var a1 = this.findLine(p1).getFi();
236
+ var a2 = this.findLine(p3).getFi();
237
+ if (a2 >= a1) {
238
+ return a2 - a1;
239
+ }
240
+ return a2 + Math.PI * 2 - a1;
241
+ };
242
+ DPoint.prototype.toString = function () {
243
+ return "".concat(this.x, " ").concat(this.y);
244
+ };
245
+ DPoint.prototype.getValue = function () {
246
+ return [this.x, this.y];
247
+ };
248
+ DPoint.prototype.height = function (z) {
249
+ this.z = z;
250
+ return this;
251
+ };
252
+ DPoint.prototype.toWKT = function () {
253
+ var _a = this, x = _a.x, y = _a.y;
254
+ return "POINT (".concat(x, " ").concat(y, ")");
255
+ };
256
+ DPoint.prototype.distance = function (p) {
257
+ checkFunction('distance')
258
+ .checkArgument('this')
259
+ .shouldBeMeters(this)
260
+ .checkArgument('p')
261
+ .shouldBeMeters(p);
262
+ var dx = p.x - this.x;
263
+ var dy = p.y - this.y;
264
+ return Math.sqrt(dx * dx + dy * dy);
265
+ };
266
+ DPoint.prototype.distanceLatLon = function (p) {
267
+ checkFunction('distance')
268
+ .checkArgument('this')
269
+ .shouldBeDegree(this)
270
+ .checkArgument('p')
271
+ .shouldBeDegree(p);
272
+ var d = p.clone().move(this.clone().minus())
273
+ .degreeToRadians();
274
+ var t1 = this.clone().degreeToRadians();
275
+ var t2 = p.clone().degreeToRadians();
276
+ var a = Math.pow(Math.sin(d.lat / 2), 2) +
277
+ Math.cos(t1.lat) *
278
+ Math.cos(t2.lat) *
279
+ (Math.pow((Math.sin(d.lon / 2)), 2));
280
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
281
+ return EARTH_RADIUS_IN_METERS * c;
282
+ };
283
+ DPoint.prototype.distance3d = function (p) {
284
+ checkFunction('distance3d')
285
+ .checkArgument('this')
286
+ .shouldBeMeters(this)
287
+ .checkArgument('p')
288
+ .shouldBeMeters(p)
289
+ .checkArgument('this.z')
290
+ .shouldExist(this.z)
291
+ .checkArgument('p.z')
292
+ .shouldExist(p.z);
293
+ var dx = p.x - this.x;
294
+ var dy = p.y - this.y;
295
+ var dz = p.z - this.z;
296
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
297
+ };
298
+ DPoint.prototype.setX = function (x) {
299
+ this.x = typeof x === 'number' ? x : x(this);
300
+ return this;
301
+ };
302
+ DPoint.prototype.setZ = function (z) {
303
+ this.z = typeof z === 'number' ? z : z(this);
304
+ return this;
305
+ };
306
+ DPoint.prototype.setY = function (y) {
307
+ this.y = typeof y === 'number' ? y : y(this);
308
+ return this;
309
+ };
310
+ DPoint.prototype.setProperties = function (v) {
311
+ this.properties = typeof v === 'object' ? v : v(this);
312
+ return this;
313
+ };
314
+ DPoint.prototype.clone = function () {
315
+ var p = new DPoint(this.x, this.y, this.z);
316
+ p.properties = __assign({}, this.properties);
317
+ return p;
318
+ };
319
+ DPoint.prototype.gt = function (p) {
320
+ return this.x > p.x && this.y > p.y;
321
+ };
322
+ DPoint.prototype.lt = function (p) {
323
+ return this.x < p.x && this.y < p.y;
324
+ };
325
+ DPoint.prototype.gtOrEqual = function (p) {
326
+ return this.gt(p) || this.equal(p);
327
+ };
328
+ DPoint.prototype.ltOrEqual = function (p) {
329
+ return this.lt(p) || this.equal(p);
330
+ };
331
+ DPoint.prototype.rotate = function (a) {
332
+ var x = this.x * Math.cos(a) - this.y * Math.sin(a);
333
+ var y = this.x * Math.sin(a) + this.y * Math.cos(a);
334
+ this.x = x;
335
+ this.y = y;
336
+ return this;
337
+ };
338
+ DPoint.prototype.rotate3dX = function (a) {
339
+ var _a = this, y = _a.y, z = _a.z;
340
+ this.y = y * Math.cos(a) + z * Math.sin(a);
341
+ this.z = -y * Math.sin(a) + z * Math.cos(a);
342
+ return this;
343
+ };
344
+ DPoint.prototype.rotate3dY = function (a) {
345
+ var _a = this, x = _a.x, z = _a.z;
346
+ this.x = x * Math.cos(a) + z * Math.sin(a);
347
+ this.z = -x * Math.sin(a) + z * Math.cos(a);
348
+ return this;
349
+ };
350
+ DPoint.prototype.rotate3dZ = function (a) {
351
+ var _a = this, x = _a.x, y = _a.y;
352
+ this.x = x * Math.cos(a) - y * Math.sin(a);
353
+ this.y = -x * Math.sin(a) + y * Math.cos(a);
354
+ return this;
355
+ };
356
+ DPoint.prototype.move = function (x, y, z) {
357
+ if (y === void 0) { y = x; }
358
+ var xV = 0;
359
+ var yV = 0;
360
+ var zV = undefined;
361
+ if (x instanceof DPoint) {
362
+ xV = this.x + x.x;
363
+ yV = this.y + x.y;
364
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
365
+ zV = this.z + x.z;
366
+ }
367
+ }
368
+ else {
369
+ xV = this.x + x;
370
+ yV = this.y + y;
371
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
372
+ zV = this.z + z;
373
+ }
374
+ }
375
+ this.x = xV;
376
+ this.y = yV;
377
+ if (isDefAndNotNull(zV)) {
378
+ this.z = zV;
379
+ }
380
+ return this;
381
+ };
382
+ DPoint.prototype.degreeToMeters = function () {
383
+ checkFunction('degreeToMeters')
384
+ .checkArgument('this')
385
+ .shouldBeDegree(this);
386
+ var x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) * METERS_IN_ONE_DEGREE;
387
+ var y = (Math.log(Math.tan(((this.y + HALF_PI_IN_DEGREE) % PI_IN_DEGREE) *
388
+ (Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) * METERS_IN_ONE_DEGREE;
389
+ this.x = x;
390
+ this.y = y;
391
+ return this;
392
+ };
393
+ DPoint.prototype.metersToDegree = function () {
394
+ checkFunction('metersToDegree')
395
+ .checkArgument('this')
396
+ .shouldBeMeters(this);
397
+ var lon = this.x * DEGREES_IN_ONE_METER;
398
+ var lat = Math.atan(Math.pow(Math.E, ((this.y / METERS_IN_ONE_DEGREE) * PI_TO_DEGREE))) *
399
+ (DOUBLE_PI_IN_DEGREE / Math.PI) - HALF_PI_IN_DEGREE;
400
+ this.x = lon;
401
+ this.y = lat;
402
+ return this;
403
+ };
404
+ DPoint.prototype.degreeToRadians = function () {
405
+ checkFunction('degreeToRadians')
406
+ .checkArgument('this')
407
+ .shouldBeDegree(this);
408
+ return this.scale(PI_TO_DEGREE);
409
+ };
410
+ DPoint.prototype.radiansToDegrees = function () {
411
+ checkFunction('radiansToDegrees')
412
+ .checkArgument('this')
413
+ .shouldBeRadians(this);
414
+ return this.scale(DEGREE_TO_PI);
415
+ };
416
+ DPoint.prototype.radiansToMeters = function () {
417
+ checkFunction('radiansToMeters')
418
+ .checkArgument('this')
419
+ .shouldBeRadians(this);
420
+ return this.radiansToDegrees().degreeToMeters();
421
+ };
422
+ DPoint.prototype.metersToRadians = function () {
423
+ checkFunction('metersToRadians')
424
+ .checkArgument('this')
425
+ .shouldBeMeters(this);
426
+ return this.metersToDegree().degreeToRadians();
427
+ };
428
+ DPoint.prototype.round = function () {
429
+ this.x = Math.round(this.x);
430
+ this.y = Math.round(this.y);
431
+ return this;
432
+ };
433
+ DPoint.prototype.ceil = function () {
434
+ this.x = Math.ceil(this.x);
435
+ this.y = Math.ceil(this.y);
436
+ return this;
437
+ };
438
+ DPoint.prototype.floor = function () {
439
+ this.x = Math.floor(this.x);
440
+ this.y = Math.floor(this.y);
441
+ return this;
442
+ };
443
+ DPoint.prototype.toFixed = function (n) {
444
+ if (n === void 0) { n = 2; }
445
+ this.x = parseFloat(this.x.toFixed(n));
446
+ this.y = parseFloat(this.y.toFixed(n));
447
+ return this;
448
+ };
449
+ DPoint.prototype.abs = function () {
450
+ this.x = Math.abs(this.x);
451
+ this.y = Math.abs(this.y);
452
+ return this;
453
+ };
454
+ DPoint.prototype.scale = function (x, y, z) {
455
+ if (y === void 0) { y = x; }
456
+ var xV = 0;
457
+ var yV = 0;
458
+ var zV = undefined;
459
+ if (x instanceof DPoint) {
460
+ xV = this.x * x.x;
461
+ yV = this.y * x.y;
462
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
463
+ zV = this.z * x.z;
464
+ }
465
+ }
466
+ else {
467
+ xV = this.x * x;
468
+ yV = this.y * y;
469
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
470
+ zV = this.z * z;
471
+ }
472
+ }
473
+ this.x = xV;
474
+ this.y = yV;
475
+ if (isDefAndNotNull(zV)) {
476
+ this.z = zV;
477
+ }
478
+ return this;
479
+ };
480
+ DPoint.prototype.divide = function (x, y, z) {
481
+ if (y === void 0) { y = x; }
482
+ var xV = 0;
483
+ var yV = 0;
484
+ var zV = undefined;
485
+ if (x instanceof DPoint) {
486
+ xV = this.x / x.x;
487
+ yV = this.y / x.y;
488
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
489
+ zV = this.z / x.z;
490
+ }
491
+ }
492
+ else {
493
+ xV = this.x / x;
494
+ yV = this.y / y;
495
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
496
+ zV = this.z / z;
497
+ }
498
+ }
499
+ this.x = xV;
500
+ this.y = yV;
501
+ if (isDefAndNotNull(zV)) {
502
+ this.z = zV;
503
+ }
504
+ return this;
505
+ };
506
+ DPoint.prototype.mod = function (x, y, z) {
507
+ if (y === void 0) { y = x; }
508
+ var xV = 0;
509
+ var yV = 0;
510
+ var zV = undefined;
511
+ if (x instanceof DPoint) {
512
+ xV = this.x % x.x;
513
+ yV = this.y % x.y;
514
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
515
+ zV = this.z % x.z;
516
+ }
517
+ }
518
+ else {
519
+ xV = this.x % x;
520
+ yV = this.y % y;
521
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
522
+ zV = this.z % z;
523
+ }
524
+ }
525
+ this.x = xV;
526
+ this.y = yV;
527
+ if (isDefAndNotNull(zV)) {
528
+ this.z = zV;
529
+ }
530
+ return this;
531
+ };
532
+ DPoint.prototype.div = function (x, y, z) {
533
+ if (y === void 0) { y = x; }
534
+ var xV = 0;
535
+ var yV = 0;
536
+ var zV = undefined;
537
+ if (x instanceof DPoint) {
538
+ xV = div(this.x, x.x);
539
+ yV = div(this.y, x.y);
540
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
541
+ zV = div(this.z, x.z);
542
+ }
543
+ }
544
+ else {
545
+ xV = div(this.x, x);
546
+ yV = div(this.y, y);
547
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
548
+ zV = div(this.z, z);
549
+ }
550
+ }
551
+ this.x = xV;
552
+ this.y = yV;
553
+ if (isDefAndNotNull(zV)) {
554
+ this.z = zV;
555
+ }
556
+ return this;
557
+ };
558
+ DPoint.prototype.equal = function (p) {
559
+ return this.x === p.x && this.y === p.y && this.z === p.z;
560
+ };
561
+ DPoint.prototype.like = function (p, d) {
562
+ var _a, _b, _c, _d;
563
+ if (d === void 0) { d = 0.001; }
564
+ if (this.equal(p)) {
565
+ return true;
566
+ }
567
+ var likeX = Math.abs(this.x - p.x) < d;
568
+ var likeY = Math.abs(this.y - p.y) < d;
569
+ var 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;
570
+ return likeX && likeY && likeZ;
571
+ };
572
+ DPoint.prototype.flipVertically = function (size) {
573
+ var v = size;
574
+ if (size instanceof DPoint) {
575
+ v = size.y;
576
+ }
577
+ this.y = v - this.y;
578
+ return this;
579
+ };
580
+ Object.defineProperty(DPoint.prototype, "likeRadians", {
581
+ get: function () {
582
+ if (radiansPolygon.length === 0) {
583
+ radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2));
584
+ }
585
+ return radiansPolygon.simpleInclude(this);
586
+ },
587
+ enumerable: false,
588
+ configurable: true
589
+ });
590
+ Object.defineProperty(DPoint.prototype, "likeWorldGeodeticSystem", {
591
+ get: function () {
592
+ if (worldGeodeticPolygon.length === 0) {
593
+ worldGeodeticPolygon.push(new DPoint(-180, -90), new DPoint(180, 90));
594
+ }
595
+ return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this);
596
+ },
597
+ enumerable: false,
598
+ configurable: true
599
+ });
600
+ Object.defineProperty(DPoint.prototype, "likePseudoMercator", {
601
+ get: function () {
602
+ if (pseudoMercatorPolygon.length === 0) {
603
+ pseudoMercatorPolygon.push(new DPoint(-20026376.39, -20048966.10), new DPoint(20026376.39, 20048966.10));
604
+ }
605
+ return !this.likeRadians && !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this);
606
+ },
607
+ enumerable: false,
608
+ configurable: true
609
+ });
610
+ Object.defineProperty(DPoint.prototype, "w", {
611
+ get: function () {
612
+ return this.x;
613
+ },
614
+ set: function (x) {
615
+ this.x = x;
616
+ },
617
+ enumerable: false,
618
+ configurable: true
619
+ });
620
+ Object.defineProperty(DPoint.prototype, "h", {
621
+ get: function () {
622
+ return this.y;
623
+ },
624
+ set: function (y) {
625
+ this.y = y;
626
+ },
627
+ enumerable: false,
628
+ configurable: true
629
+ });
630
+ Object.defineProperty(DPoint.prototype, "area", {
631
+ get: function () {
632
+ checkFunction('area')
633
+ .checkArgument('this')
634
+ .shouldBeMeters(this);
635
+ return this.w * this.h;
636
+ },
637
+ enumerable: false,
638
+ configurable: true
639
+ });
640
+ Object.defineProperty(DPoint.prototype, "hip", {
641
+ get: function () {
642
+ checkFunction('hip')
643
+ .checkArgument('this')
644
+ .shouldBeMeters(this);
645
+ return Math.sqrt(this.w * this.w + this.h * this.h);
646
+ },
647
+ enumerable: false,
648
+ configurable: true
649
+ });
650
+ Object.defineProperty(DPoint.prototype, "min", {
651
+ get: function () {
652
+ return Math.min(this.x, this.y);
653
+ },
654
+ enumerable: false,
655
+ configurable: true
656
+ });
657
+ Object.defineProperty(DPoint.prototype, "max", {
658
+ get: function () {
659
+ return Math.max(this.x, this.y);
660
+ },
661
+ enumerable: false,
662
+ configurable: true
663
+ });
664
+ Object.defineProperty(DPoint.prototype, "hipPoint", {
665
+ get: function () {
666
+ var hip = this.hip;
667
+ return new DPoint(hip, hip);
668
+ },
669
+ enumerable: false,
670
+ configurable: true
671
+ });
672
+ Object.defineProperty(DPoint.prototype, "xPoint", {
673
+ get: function () {
674
+ var x = this.x;
675
+ return new DPoint(x, x);
676
+ },
677
+ enumerable: false,
678
+ configurable: true
679
+ });
680
+ Object.defineProperty(DPoint.prototype, "yPoint", {
681
+ get: function () {
682
+ var y = this.y;
683
+ return new DPoint(y, y);
684
+ },
685
+ enumerable: false,
686
+ configurable: true
687
+ });
688
+ Object.defineProperty(DPoint.prototype, "wPoint", {
689
+ get: function () {
690
+ return this.xPoint;
691
+ },
692
+ enumerable: false,
693
+ configurable: true
694
+ });
695
+ Object.defineProperty(DPoint.prototype, "hPoint", {
696
+ get: function () {
697
+ return this.yPoint;
698
+ },
699
+ enumerable: false,
700
+ configurable: true
701
+ });
702
+ Object.defineProperty(DPoint.prototype, "lat", {
703
+ get: function () {
704
+ return this.y;
705
+ },
706
+ set: function (v) {
707
+ this.y = v;
708
+ },
709
+ enumerable: false,
710
+ configurable: true
711
+ });
712
+ Object.defineProperty(DPoint.prototype, "lng", {
713
+ get: function () {
714
+ return this.x;
715
+ },
716
+ set: function (v) {
717
+ this.x = v;
718
+ },
719
+ enumerable: false,
720
+ configurable: true
721
+ });
722
+ Object.defineProperty(DPoint.prototype, "lon", {
723
+ get: function () {
724
+ return this.x;
725
+ },
726
+ set: function (v) {
727
+ this.x = v;
728
+ },
729
+ enumerable: false,
730
+ configurable: true
731
+ });
732
+ Object.defineProperty(DPoint.prototype, "alt", {
733
+ get: function () {
734
+ return this.z;
735
+ },
736
+ set: function (v) {
737
+ this.z = v;
738
+ },
739
+ enumerable: false,
740
+ configurable: true
741
+ });
742
+ DPoint.prototype.simple = function (xKey, yKey, zKey) {
743
+ var _a, _b;
744
+ if (xKey === void 0) { xKey = 'x'; }
745
+ if (yKey === void 0) { yKey = 'y'; }
746
+ if (zKey === void 0) { zKey = 'z'; }
747
+ return __assign((_a = {}, _a[xKey] = this.x, _a[yKey] = this.y, _a), (isDefAndNotNull(this.z) ? (_b = {},
748
+ _b[zKey] = this.z,
749
+ _b) : {}));
750
+ };
751
+ DPoint.prototype.setIfLessThan = function (p) {
752
+ this.x = Math.max(this.x, p.x);
753
+ this.y = Math.max(this.y, p.y);
754
+ return this;
755
+ };
756
+ DPoint.prototype.setIfMoreThan = function (p) {
757
+ this.x = Math.min(this.x, p.x);
758
+ this.y = Math.min(this.y, p.y);
759
+ return this;
760
+ };
761
+ DPoint.prototype.minus = function () {
762
+ return this.scale(-1);
763
+ };
764
+ DPoint.prototype.orthodromicPath = function (point, pointsCount) {
765
+ if (pointsCount === void 0) { pointsCount = 360; }
766
+ checkFunction('orthodromicPath')
767
+ .checkArgument('this')
768
+ .shouldBeDegree(this)
769
+ .checkArgument('point')
770
+ .shouldBeDegree(point);
771
+ var t = this.clone().degreeToRadians();
772
+ var p = point.clone().degreeToRadians();
773
+ var d = Math.sin(p.x - t.x);
774
+ var step = (p.x - t.x) / (pointsCount - 1);
775
+ return new DPolygon(createArray(pointsCount)
776
+ .map(function (v, i) {
777
+ var x = t.x + step * i;
778
+ var y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
779
+ (Math.tan(p.y) * Math.sin(x - t.x)) / d);
780
+ return new DPoint(x, y).radiansToDegrees();
781
+ }));
782
+ };
783
+ DPoint.prototype.sortByDistance = function (p) {
784
+ var _this = this;
785
+ return p
786
+ .clone()
787
+ .map(function (d, index) {
788
+ d.properties.distance = d.distance(_this);
789
+ d.properties.index = index;
790
+ return d;
791
+ })
792
+ .sort(function (a, b) { return a.properties.distance - b.properties.distance; });
793
+ };
794
+ DPoint.prototype.calculateAltitudeByDistanceBetweenPoints = function (p1, p2) {
795
+ var _a, _b, _c, _d, _e;
796
+ if (p1.alt === p2.alt) {
797
+ this.alt = p1.alt;
798
+ }
799
+ else {
800
+ var minAlt = Math.min((_a = p1.alt) !== null && _a !== void 0 ? _a : 0, (_b = p2.alt) !== null && _b !== void 0 ? _b : 0);
801
+ var maxAlt = Math.max((_c = p1.alt) !== null && _c !== void 0 ? _c : 0, (_d = p2.alt) !== null && _d !== void 0 ? _d : 0);
802
+ var dAlt = maxAlt - minAlt;
803
+ var distance1 = this.distance(p1);
804
+ var distance2 = this.distance(p2);
805
+ var totalDistance = distance1 + distance2;
806
+ if (((_e = p1.alt) !== null && _e !== void 0 ? _e : 0) === minAlt) {
807
+ this.alt = minAlt + distance1 / totalDistance * dAlt;
808
+ }
809
+ else {
810
+ this.alt = minAlt + distance2 / totalDistance * dAlt;
811
+ }
812
+ }
813
+ return this;
814
+ };
815
+ return DPoint;
816
+ }());
817
+ export { DPoint };