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,820 @@
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.distanceLatLon = function (p) {
270
+ (0, utils_1.checkFunction)('distance')
271
+ .checkArgument('this')
272
+ .shouldBeDegree(this)
273
+ .checkArgument('p')
274
+ .shouldBeDegree(p);
275
+ var d = p.clone().move(this.clone().minus())
276
+ .degreeToRadians();
277
+ var t1 = this.clone().degreeToRadians();
278
+ var t2 = p.clone().degreeToRadians();
279
+ var a = Math.pow(Math.sin(d.lat / 2), 2) +
280
+ Math.cos(t1.lat) *
281
+ Math.cos(t2.lat) *
282
+ (Math.pow((Math.sin(d.lon / 2)), 2));
283
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
284
+ return exports.EARTH_RADIUS_IN_METERS * c;
285
+ };
286
+ DPoint.prototype.distance3d = function (p) {
287
+ (0, utils_1.checkFunction)('distance3d')
288
+ .checkArgument('this')
289
+ .shouldBeMeters(this)
290
+ .checkArgument('p')
291
+ .shouldBeMeters(p)
292
+ .checkArgument('this.z')
293
+ .shouldExist(this.z)
294
+ .checkArgument('p.z')
295
+ .shouldExist(p.z);
296
+ var dx = p.x - this.x;
297
+ var dy = p.y - this.y;
298
+ var dz = p.z - this.z;
299
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
300
+ };
301
+ DPoint.prototype.setX = function (x) {
302
+ this.x = typeof x === 'number' ? x : x(this);
303
+ return this;
304
+ };
305
+ DPoint.prototype.setZ = function (z) {
306
+ this.z = typeof z === 'number' ? z : z(this);
307
+ return this;
308
+ };
309
+ DPoint.prototype.setY = function (y) {
310
+ this.y = typeof y === 'number' ? y : y(this);
311
+ return this;
312
+ };
313
+ DPoint.prototype.setProperties = function (v) {
314
+ this.properties = typeof v === 'object' ? v : v(this);
315
+ return this;
316
+ };
317
+ DPoint.prototype.clone = function () {
318
+ var p = new DPoint(this.x, this.y, this.z);
319
+ p.properties = __assign({}, this.properties);
320
+ return p;
321
+ };
322
+ DPoint.prototype.gt = function (p) {
323
+ return this.x > p.x && this.y > p.y;
324
+ };
325
+ DPoint.prototype.lt = function (p) {
326
+ return this.x < p.x && this.y < p.y;
327
+ };
328
+ DPoint.prototype.gtOrEqual = function (p) {
329
+ return this.gt(p) || this.equal(p);
330
+ };
331
+ DPoint.prototype.ltOrEqual = function (p) {
332
+ return this.lt(p) || this.equal(p);
333
+ };
334
+ DPoint.prototype.rotate = function (a) {
335
+ var x = this.x * Math.cos(a) - this.y * Math.sin(a);
336
+ var y = this.x * Math.sin(a) + this.y * Math.cos(a);
337
+ this.x = x;
338
+ this.y = y;
339
+ return this;
340
+ };
341
+ DPoint.prototype.rotate3dX = function (a) {
342
+ var _a = this, y = _a.y, z = _a.z;
343
+ this.y = y * Math.cos(a) + z * Math.sin(a);
344
+ this.z = -y * Math.sin(a) + z * Math.cos(a);
345
+ return this;
346
+ };
347
+ DPoint.prototype.rotate3dY = function (a) {
348
+ var _a = this, x = _a.x, z = _a.z;
349
+ this.x = x * Math.cos(a) + z * Math.sin(a);
350
+ this.z = -x * Math.sin(a) + z * Math.cos(a);
351
+ return this;
352
+ };
353
+ DPoint.prototype.rotate3dZ = function (a) {
354
+ var _a = this, x = _a.x, y = _a.y;
355
+ this.x = x * Math.cos(a) - y * Math.sin(a);
356
+ this.y = -x * Math.sin(a) + y * Math.cos(a);
357
+ return this;
358
+ };
359
+ DPoint.prototype.move = function (x, y, z) {
360
+ if (y === void 0) { y = x; }
361
+ var xV = 0;
362
+ var yV = 0;
363
+ var zV = undefined;
364
+ if (x instanceof DPoint) {
365
+ xV = this.x + x.x;
366
+ yV = this.y + x.y;
367
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
368
+ zV = this.z + x.z;
369
+ }
370
+ }
371
+ else {
372
+ xV = this.x + x;
373
+ yV = this.y + y;
374
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
375
+ zV = this.z + z;
376
+ }
377
+ }
378
+ this.x = xV;
379
+ this.y = yV;
380
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
381
+ this.z = zV;
382
+ }
383
+ return this;
384
+ };
385
+ DPoint.prototype.degreeToMeters = function () {
386
+ (0, utils_1.checkFunction)('degreeToMeters')
387
+ .checkArgument('this')
388
+ .shouldBeDegree(this);
389
+ var x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * METERS_IN_ONE_DEGREE;
390
+ var y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) *
391
+ (Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * METERS_IN_ONE_DEGREE;
392
+ this.x = x;
393
+ this.y = y;
394
+ return this;
395
+ };
396
+ DPoint.prototype.metersToDegree = function () {
397
+ (0, utils_1.checkFunction)('metersToDegree')
398
+ .checkArgument('this')
399
+ .shouldBeMeters(this);
400
+ var lon = this.x * DEGREES_IN_ONE_METER;
401
+ var lat = Math.atan(Math.pow(Math.E, ((this.y / METERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) *
402
+ (exports.DOUBLE_PI_IN_DEGREE / Math.PI) - exports.HALF_PI_IN_DEGREE;
403
+ this.x = lon;
404
+ this.y = lat;
405
+ return this;
406
+ };
407
+ DPoint.prototype.degreeToRadians = function () {
408
+ (0, utils_1.checkFunction)('degreeToRadians')
409
+ .checkArgument('this')
410
+ .shouldBeDegree(this);
411
+ return this.scale(exports.PI_TO_DEGREE);
412
+ };
413
+ DPoint.prototype.radiansToDegrees = function () {
414
+ (0, utils_1.checkFunction)('radiansToDegrees')
415
+ .checkArgument('this')
416
+ .shouldBeRadians(this);
417
+ return this.scale(exports.DEGREE_TO_PI);
418
+ };
419
+ DPoint.prototype.radiansToMeters = function () {
420
+ (0, utils_1.checkFunction)('radiansToMeters')
421
+ .checkArgument('this')
422
+ .shouldBeRadians(this);
423
+ return this.radiansToDegrees().degreeToMeters();
424
+ };
425
+ DPoint.prototype.metersToRadians = function () {
426
+ (0, utils_1.checkFunction)('metersToRadians')
427
+ .checkArgument('this')
428
+ .shouldBeMeters(this);
429
+ return this.metersToDegree().degreeToRadians();
430
+ };
431
+ DPoint.prototype.round = function () {
432
+ this.x = Math.round(this.x);
433
+ this.y = Math.round(this.y);
434
+ return this;
435
+ };
436
+ DPoint.prototype.ceil = function () {
437
+ this.x = Math.ceil(this.x);
438
+ this.y = Math.ceil(this.y);
439
+ return this;
440
+ };
441
+ DPoint.prototype.floor = function () {
442
+ this.x = Math.floor(this.x);
443
+ this.y = Math.floor(this.y);
444
+ return this;
445
+ };
446
+ DPoint.prototype.toFixed = function (n) {
447
+ if (n === void 0) { n = 2; }
448
+ this.x = parseFloat(this.x.toFixed(n));
449
+ this.y = parseFloat(this.y.toFixed(n));
450
+ return this;
451
+ };
452
+ DPoint.prototype.abs = function () {
453
+ this.x = Math.abs(this.x);
454
+ this.y = Math.abs(this.y);
455
+ return this;
456
+ };
457
+ DPoint.prototype.scale = function (x, y, z) {
458
+ if (y === void 0) { y = x; }
459
+ var xV = 0;
460
+ var yV = 0;
461
+ var zV = undefined;
462
+ if (x instanceof DPoint) {
463
+ xV = this.x * x.x;
464
+ yV = this.y * x.y;
465
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
466
+ zV = this.z * x.z;
467
+ }
468
+ }
469
+ else {
470
+ xV = this.x * x;
471
+ yV = this.y * y;
472
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
473
+ zV = this.z * z;
474
+ }
475
+ }
476
+ this.x = xV;
477
+ this.y = yV;
478
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
479
+ this.z = zV;
480
+ }
481
+ return this;
482
+ };
483
+ DPoint.prototype.divide = function (x, y, z) {
484
+ if (y === void 0) { y = x; }
485
+ var xV = 0;
486
+ var yV = 0;
487
+ var zV = undefined;
488
+ if (x instanceof DPoint) {
489
+ xV = this.x / x.x;
490
+ yV = this.y / x.y;
491
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
492
+ zV = this.z / x.z;
493
+ }
494
+ }
495
+ else {
496
+ xV = this.x / x;
497
+ yV = this.y / y;
498
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
499
+ zV = this.z / z;
500
+ }
501
+ }
502
+ this.x = xV;
503
+ this.y = yV;
504
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
505
+ this.z = zV;
506
+ }
507
+ return this;
508
+ };
509
+ DPoint.prototype.mod = function (x, y, z) {
510
+ if (y === void 0) { y = x; }
511
+ var xV = 0;
512
+ var yV = 0;
513
+ var zV = undefined;
514
+ if (x instanceof DPoint) {
515
+ xV = this.x % x.x;
516
+ yV = this.y % x.y;
517
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
518
+ zV = this.z % x.z;
519
+ }
520
+ }
521
+ else {
522
+ xV = this.x % x;
523
+ yV = this.y % y;
524
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
525
+ zV = this.z % z;
526
+ }
527
+ }
528
+ this.x = xV;
529
+ this.y = yV;
530
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
531
+ this.z = zV;
532
+ }
533
+ return this;
534
+ };
535
+ DPoint.prototype.div = function (x, y, z) {
536
+ if (y === void 0) { y = x; }
537
+ var xV = 0;
538
+ var yV = 0;
539
+ var zV = undefined;
540
+ if (x instanceof DPoint) {
541
+ xV = (0, utils_1.div)(this.x, x.x);
542
+ yV = (0, utils_1.div)(this.y, x.y);
543
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
544
+ zV = (0, utils_1.div)(this.z, x.z);
545
+ }
546
+ }
547
+ else {
548
+ xV = (0, utils_1.div)(this.x, x);
549
+ yV = (0, utils_1.div)(this.y, y);
550
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
551
+ zV = (0, utils_1.div)(this.z, z);
552
+ }
553
+ }
554
+ this.x = xV;
555
+ this.y = yV;
556
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
557
+ this.z = zV;
558
+ }
559
+ return this;
560
+ };
561
+ DPoint.prototype.equal = function (p) {
562
+ return this.x === p.x && this.y === p.y && this.z === p.z;
563
+ };
564
+ DPoint.prototype.like = function (p, d) {
565
+ var _a, _b, _c, _d;
566
+ if (d === void 0) { d = 0.001; }
567
+ if (this.equal(p)) {
568
+ return true;
569
+ }
570
+ var likeX = Math.abs(this.x - p.x) < d;
571
+ var likeY = Math.abs(this.y - p.y) < d;
572
+ 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;
573
+ return likeX && likeY && likeZ;
574
+ };
575
+ DPoint.prototype.flipVertically = function (size) {
576
+ var v = size;
577
+ if (size instanceof DPoint) {
578
+ v = size.y;
579
+ }
580
+ this.y = v - this.y;
581
+ return this;
582
+ };
583
+ Object.defineProperty(DPoint.prototype, "likeRadians", {
584
+ get: function () {
585
+ if (radiansPolygon.length === 0) {
586
+ radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2));
587
+ }
588
+ return radiansPolygon.simpleInclude(this);
589
+ },
590
+ enumerable: false,
591
+ configurable: true
592
+ });
593
+ Object.defineProperty(DPoint.prototype, "likeWorldGeodeticSystem", {
594
+ get: function () {
595
+ if (worldGeodeticPolygon.length === 0) {
596
+ worldGeodeticPolygon.push(new DPoint(-180, -90), new DPoint(180, 90));
597
+ }
598
+ return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this);
599
+ },
600
+ enumerable: false,
601
+ configurable: true
602
+ });
603
+ Object.defineProperty(DPoint.prototype, "likePseudoMercator", {
604
+ get: function () {
605
+ if (pseudoMercatorPolygon.length === 0) {
606
+ pseudoMercatorPolygon.push(new DPoint(-20026376.39, -20048966.10), new DPoint(20026376.39, 20048966.10));
607
+ }
608
+ return !this.likeRadians && !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this);
609
+ },
610
+ enumerable: false,
611
+ configurable: true
612
+ });
613
+ Object.defineProperty(DPoint.prototype, "w", {
614
+ get: function () {
615
+ return this.x;
616
+ },
617
+ set: function (x) {
618
+ this.x = x;
619
+ },
620
+ enumerable: false,
621
+ configurable: true
622
+ });
623
+ Object.defineProperty(DPoint.prototype, "h", {
624
+ get: function () {
625
+ return this.y;
626
+ },
627
+ set: function (y) {
628
+ this.y = y;
629
+ },
630
+ enumerable: false,
631
+ configurable: true
632
+ });
633
+ Object.defineProperty(DPoint.prototype, "area", {
634
+ get: function () {
635
+ (0, utils_1.checkFunction)('area')
636
+ .checkArgument('this')
637
+ .shouldBeMeters(this);
638
+ return this.w * this.h;
639
+ },
640
+ enumerable: false,
641
+ configurable: true
642
+ });
643
+ Object.defineProperty(DPoint.prototype, "hip", {
644
+ get: function () {
645
+ (0, utils_1.checkFunction)('hip')
646
+ .checkArgument('this')
647
+ .shouldBeMeters(this);
648
+ return Math.sqrt(this.w * this.w + this.h * this.h);
649
+ },
650
+ enumerable: false,
651
+ configurable: true
652
+ });
653
+ Object.defineProperty(DPoint.prototype, "min", {
654
+ get: function () {
655
+ return Math.min(this.x, this.y);
656
+ },
657
+ enumerable: false,
658
+ configurable: true
659
+ });
660
+ Object.defineProperty(DPoint.prototype, "max", {
661
+ get: function () {
662
+ return Math.max(this.x, this.y);
663
+ },
664
+ enumerable: false,
665
+ configurable: true
666
+ });
667
+ Object.defineProperty(DPoint.prototype, "hipPoint", {
668
+ get: function () {
669
+ var hip = this.hip;
670
+ return new DPoint(hip, hip);
671
+ },
672
+ enumerable: false,
673
+ configurable: true
674
+ });
675
+ Object.defineProperty(DPoint.prototype, "xPoint", {
676
+ get: function () {
677
+ var x = this.x;
678
+ return new DPoint(x, x);
679
+ },
680
+ enumerable: false,
681
+ configurable: true
682
+ });
683
+ Object.defineProperty(DPoint.prototype, "yPoint", {
684
+ get: function () {
685
+ var y = this.y;
686
+ return new DPoint(y, y);
687
+ },
688
+ enumerable: false,
689
+ configurable: true
690
+ });
691
+ Object.defineProperty(DPoint.prototype, "wPoint", {
692
+ get: function () {
693
+ return this.xPoint;
694
+ },
695
+ enumerable: false,
696
+ configurable: true
697
+ });
698
+ Object.defineProperty(DPoint.prototype, "hPoint", {
699
+ get: function () {
700
+ return this.yPoint;
701
+ },
702
+ enumerable: false,
703
+ configurable: true
704
+ });
705
+ Object.defineProperty(DPoint.prototype, "lat", {
706
+ get: function () {
707
+ return this.y;
708
+ },
709
+ set: function (v) {
710
+ this.y = v;
711
+ },
712
+ enumerable: false,
713
+ configurable: true
714
+ });
715
+ Object.defineProperty(DPoint.prototype, "lng", {
716
+ get: function () {
717
+ return this.x;
718
+ },
719
+ set: function (v) {
720
+ this.x = v;
721
+ },
722
+ enumerable: false,
723
+ configurable: true
724
+ });
725
+ Object.defineProperty(DPoint.prototype, "lon", {
726
+ get: function () {
727
+ return this.x;
728
+ },
729
+ set: function (v) {
730
+ this.x = v;
731
+ },
732
+ enumerable: false,
733
+ configurable: true
734
+ });
735
+ Object.defineProperty(DPoint.prototype, "alt", {
736
+ get: function () {
737
+ return this.z;
738
+ },
739
+ set: function (v) {
740
+ this.z = v;
741
+ },
742
+ enumerable: false,
743
+ configurable: true
744
+ });
745
+ DPoint.prototype.simple = function (xKey, yKey, zKey) {
746
+ var _a, _b;
747
+ if (xKey === void 0) { xKey = 'x'; }
748
+ if (yKey === void 0) { yKey = 'y'; }
749
+ if (zKey === void 0) { zKey = 'z'; }
750
+ return __assign((_a = {}, _a[xKey] = this.x, _a[yKey] = this.y, _a), ((0, utils_1.isDefAndNotNull)(this.z) ? (_b = {},
751
+ _b[zKey] = this.z,
752
+ _b) : {}));
753
+ };
754
+ DPoint.prototype.setIfLessThan = function (p) {
755
+ this.x = Math.max(this.x, p.x);
756
+ this.y = Math.max(this.y, p.y);
757
+ return this;
758
+ };
759
+ DPoint.prototype.setIfMoreThan = function (p) {
760
+ this.x = Math.min(this.x, p.x);
761
+ this.y = Math.min(this.y, p.y);
762
+ return this;
763
+ };
764
+ DPoint.prototype.minus = function () {
765
+ return this.scale(-1);
766
+ };
767
+ DPoint.prototype.orthodromicPath = function (point, pointsCount) {
768
+ if (pointsCount === void 0) { pointsCount = 360; }
769
+ (0, utils_1.checkFunction)('orthodromicPath')
770
+ .checkArgument('this')
771
+ .shouldBeDegree(this)
772
+ .checkArgument('point')
773
+ .shouldBeDegree(point);
774
+ var t = this.clone().degreeToRadians();
775
+ var p = point.clone().degreeToRadians();
776
+ var d = Math.sin(p.x - t.x);
777
+ var step = (p.x - t.x) / (pointsCount - 1);
778
+ return new DPolygon_1.DPolygon((0, utils_1.createArray)(pointsCount)
779
+ .map(function (v, i) {
780
+ var x = t.x + step * i;
781
+ var y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
782
+ (Math.tan(p.y) * Math.sin(x - t.x)) / d);
783
+ return new DPoint(x, y).radiansToDegrees();
784
+ }));
785
+ };
786
+ DPoint.prototype.sortByDistance = function (p) {
787
+ var _this = this;
788
+ return p
789
+ .clone()
790
+ .map(function (d, index) {
791
+ d.properties.distance = d.distance(_this);
792
+ d.properties.index = index;
793
+ return d;
794
+ })
795
+ .sort(function (a, b) { return a.properties.distance - b.properties.distance; });
796
+ };
797
+ DPoint.prototype.calculateAltitudeByDistanceBetweenPoints = function (p1, p2) {
798
+ var _a, _b, _c, _d, _e;
799
+ if (p1.alt === p2.alt) {
800
+ this.alt = p1.alt;
801
+ }
802
+ else {
803
+ var minAlt = Math.min((_a = p1.alt) !== null && _a !== void 0 ? _a : 0, (_b = p2.alt) !== null && _b !== void 0 ? _b : 0);
804
+ var maxAlt = Math.max((_c = p1.alt) !== null && _c !== void 0 ? _c : 0, (_d = p2.alt) !== null && _d !== void 0 ? _d : 0);
805
+ var dAlt = maxAlt - minAlt;
806
+ var distance1 = this.distance(p1);
807
+ var distance2 = this.distance(p2);
808
+ var totalDistance = distance1 + distance2;
809
+ if (((_e = p1.alt) !== null && _e !== void 0 ? _e : 0) === minAlt) {
810
+ this.alt = minAlt + distance1 / totalDistance * dAlt;
811
+ }
812
+ else {
813
+ this.alt = minAlt + distance2 / totalDistance * dAlt;
814
+ }
815
+ }
816
+ return this;
817
+ };
818
+ return DPoint;
819
+ }());
820
+ exports.DPoint = DPoint;