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.
@@ -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
- var DLine_1 = require("./DLine");
32
- var DPolygon_1 = require("./DPolygon");
33
- var utils_1 = require("./utils");
34
- var diff = 0;
35
- var radiansPolygon = new DPolygon_1.DPolygon();
36
- var pseudoMercatorPolygon = new DPolygon_1.DPolygon();
37
- var worldGeodeticPolygon = new DPolygon_1.DPolygon();
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
- var EARTH_IN_MITERS = 20037508.34;
40
- var DEGREES_IN_EARTH = 180;
41
- var MITERS_IN_ONE_DEGREE = EARTH_IN_MITERS / DEGREES_IN_EARTH;
42
- var DEGREES_IN_ONE_MITER = DEGREES_IN_EARTH / EARTH_IN_MITERS;
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
- var DPoint = (function () {
49
- function DPoint(x, y, z) {
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
- DPoint.zero = function () {
28
+ static zero() {
58
29
  return new DPoint();
59
- };
60
- DPoint.parse = function (c) {
61
- var _a = c, lat = _a.lat, lng = _a.lng;
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
- var _b = __read(c, 3), x = _b[0], y = _b[1], z = _b[2];
36
+ const [x, y, z] = c;
66
37
  return new DPoint(x, y, z);
67
- };
68
- DPoint.parseFromWKT = function (wkt) {
69
- var regexp = /POINT \((?<data>(?:(?!\)).)*?)\)$/miu;
70
- var data = wkt.trim().toUpperCase();
71
- var res = regexp.exec(data);
72
- var _a = __read(res.groups.data.split(' ').map(Number), 3), x = _a[0], y = _a[1], z = _a[2];
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
- DPoint.random = function () {
45
+ }
46
+ static random() {
76
47
  return new DPoint(Math.random(), Math.random());
77
- };
78
- DPoint.prototype.getTileFromCoords = function (zoom) {
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
- var x = Math.floor((this.x + exports.PI_IN_DEGREE) / exports.DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
84
- 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)));
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
- DPoint.prototype.getCoordsFromTile = function (zoom) {
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
- var n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom));
93
- var x = this.x / (Math.pow(2, zoom)) * exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE;
94
- var y = exports.PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
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
- DPoint.prototype.toCoords = function () {
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
- DPoint.prototype.findLine = function (p) {
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
- var a = this.y - p.y - diff;
113
- var b = p.x - this.x - diff;
114
- var c = this.x * p.y - p.x * this.y - diff;
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
- DPoint.prototype.findInnerAngle = function (p1, p3) {
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
- var a1 = this.findLine(p1).getFi();
132
- var a2 = this.findLine(p3).getFi();
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
- DPoint.prototype.toString = function () {
139
- return this.x + " " + this.y;
140
- };
141
- DPoint.prototype.getValue = function () {
106
+ }
107
+ toString() {
108
+ return `${this.x} ${this.y}`;
109
+ }
110
+ getValue() {
142
111
  return [this.x, this.y];
143
- };
144
- DPoint.prototype.height = function (z) {
112
+ }
113
+ height(z) {
145
114
  this.z = z;
146
115
  return this;
147
- };
148
- DPoint.prototype.toWKT = function () {
149
- var _a = this, x = _a.x, y = _a.y;
150
- return "POINT (" + x + " " + y + ")";
151
- };
152
- DPoint.prototype.distance = function (p) {
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
- var dx = p.x - this.x;
159
- var dy = p.y - this.y;
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
- DPoint.prototype.distance3d = function (p) {
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
- var dx = p.x - this.x;
173
- var dy = p.y - this.y;
174
- var dz = p.z - this.z;
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
- DPoint.prototype.setX = function (x) {
145
+ }
146
+ setX(x) {
178
147
  this.x = typeof x === 'number' ? x : x(this);
179
148
  return this;
180
- };
181
- DPoint.prototype.setZ = function (z) {
149
+ }
150
+ setZ(z) {
182
151
  this.z = typeof z === 'number' ? z : z(this);
183
152
  return this;
184
- };
185
- DPoint.prototype.setY = function (y) {
153
+ }
154
+ setY(y) {
186
155
  this.y = typeof y === 'number' ? y : y(this);
187
156
  return this;
188
- };
189
- DPoint.prototype.clone = function () {
190
- var p = new DPoint(this.x, this.y, this.z);
191
- p.properties = __assign({}, this.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
- DPoint.prototype.gt = function (p) {
162
+ }
163
+ gt(p) {
195
164
  return this.x > p.x && this.y > p.y;
196
- };
197
- DPoint.prototype.lt = function (p) {
165
+ }
166
+ lt(p) {
198
167
  return this.x < p.x && this.y < p.y;
199
- };
200
- DPoint.prototype.gtOrEqual = function (p) {
168
+ }
169
+ gtOrEqual(p) {
201
170
  return this.gt(p) || this.equal(p);
202
- };
203
- DPoint.prototype.ltOrEqual = function (p) {
171
+ }
172
+ ltOrEqual(p) {
204
173
  return this.lt(p) || this.equal(p);
205
- };
206
- DPoint.prototype.rotate = function (a) {
207
- var x = this.x * Math.cos(a) - this.y * Math.sin(a);
208
- var y = this.x * Math.sin(a) + this.y * Math.cos(a);
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
- DPoint.prototype.rotate3dX = function (a) {
214
- var _a = this, y = _a.y, z = _a.z;
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
- DPoint.prototype.rotate3dY = function (a) {
220
- var _a = this, x = _a.x, z = _a.z;
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
- DPoint.prototype.rotate3dZ = function (a) {
226
- var _a = this, x = _a.x, y = _a.y;
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
- DPoint.prototype.move = function (x, y, z) {
232
- if (y === void 0) { y = x; }
233
- var xV = 0;
234
- var yV = 0;
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
- DPoint.prototype.degreeToMeters = function () {
224
+ }
225
+ degreeToMeters() {
258
226
  (0, utils_1.checkFunction)('degreeToMeters')
259
227
  .checkArgument('this')
260
228
  .shouldBeDegree(this);
261
- var x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
262
- var y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) *
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
- DPoint.prototype.metersToDegree = function () {
235
+ }
236
+ metersToDegree() {
269
237
  (0, utils_1.checkFunction)('metersToDegree')
270
238
  .checkArgument('this')
271
239
  .shouldBeMeters(this);
272
- var lon = this.x * DEGREES_IN_ONE_MITER;
273
- var lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) *
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
- DPoint.prototype.degreeToRadians = function () {
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
- DPoint.prototype.radiansToDegrees = function () {
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
- DPoint.prototype.radiansToMeters = function () {
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
- DPoint.prototype.metersToRadians = function () {
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
- DPoint.prototype.round = function () {
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
- DPoint.prototype.ceil = function () {
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
- DPoint.prototype.floor = function () {
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
- DPoint.prototype.toFixed = function (n) {
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
- DPoint.prototype.abs = function () {
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
- DPoint.prototype.scale = function (x, y, z) {
330
- if (y === void 0) { y = x; }
331
- var xV = 0;
332
- var yV = 0;
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
- DPoint.prototype.divide = function (x, y, z) {
356
- if (y === void 0) { y = x; }
357
- var xV = 0;
358
- var yV = 0;
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
- DPoint.prototype.equal = function (p) {
345
+ }
346
+ equal(p) {
382
347
  return this.x === p.x && this.y === p.y && this.z === p.z;
383
- };
384
- DPoint.prototype.like = function (p, d) {
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
- var likeX = Math.abs(this.x - p.x) < d;
391
- var likeY = Math.abs(this.y - p.y) < d;
392
- 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;
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
- DPoint.prototype.flipVertically = function (size) {
396
- var v = size;
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
- Object.defineProperty(DPoint.prototype, "likeRadians", {
404
- get: function () {
405
- if (radiansPolygon.length === 0) {
406
- radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2));
407
- }
408
- return radiansPolygon.simpleInclude(this);
409
- },
410
- enumerable: false,
411
- configurable: true
412
- });
413
- Object.defineProperty(DPoint.prototype, "likeWorldGeodeticSystem", {
414
- get: function () {
415
- if (worldGeodeticPolygon.length === 0) {
416
- worldGeodeticPolygon.push(new DPoint(-180, -90), new DPoint(180, 90));
417
- }
418
- return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this);
419
- },
420
- enumerable: false,
421
- configurable: true
422
- });
423
- Object.defineProperty(DPoint.prototype, "likePseudoMercator", {
424
- get: function () {
425
- if (pseudoMercatorPolygon.length === 0) {
426
- pseudoMercatorPolygon.push(new DPoint(-20026376.39, -20048966.10), new DPoint(20026376.39, 20048966.10));
427
- }
428
- return !this.likeRadians && !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this);
429
- },
430
- enumerable: false,
431
- configurable: true
432
- });
433
- Object.defineProperty(DPoint.prototype, "w", {
434
- get: function () {
435
- return this.x;
436
- },
437
- set: function (x) {
438
- this.x = x;
439
- },
440
- enumerable: false,
441
- configurable: true
442
- });
443
- Object.defineProperty(DPoint.prototype, "h", {
444
- get: function () {
445
- return this.y;
446
- },
447
- set: function (y) {
448
- this.y = y;
449
- },
450
- enumerable: false,
451
- configurable: true
452
- });
453
- Object.defineProperty(DPoint.prototype, "area", {
454
- get: function () {
455
- (0, utils_1.checkFunction)('area')
456
- .checkArgument('this')
457
- .shouldBeMeters(this);
458
- return this.w * this.h;
459
- },
460
- enumerable: false,
461
- configurable: true
462
- });
463
- Object.defineProperty(DPoint.prototype, "hip", {
464
- get: function () {
465
- (0, utils_1.checkFunction)('hip')
466
- .checkArgument('this')
467
- .shouldBeMeters(this);
468
- return Math.sqrt(this.w * this.w + this.h * this.h);
469
- },
470
- enumerable: false,
471
- configurable: true
472
- });
473
- Object.defineProperty(DPoint.prototype, "min", {
474
- get: function () {
475
- return Math.min(this.x, this.y);
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
- DPoint.prototype.minus = function () {
443
+ }
444
+ minus() {
540
445
  return this.scale(-1);
541
- };
542
- DPoint.prototype.orthodromicPath = function (point, pointsCount) {
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
- var t = this.clone().degreeToRadians();
550
- var p = point.clone().degreeToRadians();
551
- var d = Math.sin(p.x - t.x);
552
- var step = (p.x - t.x) / (pointsCount - 1);
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(function (v, i) {
555
- var x = t.x + step * i;
556
- var y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
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
- DPoint.prototype.sortByDistance = function (p) {
562
- var _this = this;
464
+ }
465
+ sortByDistance(p) {
563
466
  return p
564
467
  .clone()
565
- .map(function (d, index) {
566
- d.properties.distance = d.distance(_this);
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(function (a, b) { return a.properties.distance - b.properties.distance; });
571
- };
572
- return DPoint;
573
- }());
473
+ .sort((a, b) => a.properties.distance - b.properties.distance);
474
+ }
475
+ }
574
476
  exports.DPoint = DPoint;