dgeoutils 2.4.47 → 2.4.52

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