dgeoutils 2.4.1 → 2.4.2

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 (34) hide show
  1. package/dist/{cjs/DCircle.d.ts → DCircle.d.ts} +0 -0
  2. package/dist/{cjs/DCircle.js → DCircle.js} +0 -0
  3. package/dist/{cjs/DLine.d.ts → DLine.d.ts} +0 -0
  4. package/dist/{cjs/DLine.js → DLine.js} +0 -0
  5. package/dist/{cjs/DNumbers.d.ts → DNumbers.d.ts} +0 -0
  6. package/dist/{cjs/DNumbers.js → DNumbers.js} +0 -0
  7. package/dist/{cjs/DPlane.d.ts → DPlane.d.ts} +0 -0
  8. package/dist/{cjs/DPlane.js → DPlane.js} +0 -0
  9. package/dist/{cjs/DPoint.d.ts → DPoint.d.ts} +0 -0
  10. package/dist/{cjs/DPoint.js → DPoint.js} +0 -0
  11. package/dist/{cjs/DPolygon.d.ts → DPolygon.d.ts} +0 -0
  12. package/dist/{cjs/DPolygon.js → DPolygon.js} +0 -0
  13. package/dist/{cjs/DPolygonLoop.d.ts → DPolygonLoop.d.ts} +0 -0
  14. package/dist/{cjs/DPolygonLoop.js → DPolygonLoop.js} +0 -0
  15. package/dist/{cjs/FastSearch.d.ts → FastSearch.d.ts} +0 -0
  16. package/dist/{cjs/FastSearch.js → FastSearch.js} +0 -0
  17. package/dist/{cjs/TraceMatrix.d.ts → TraceMatrix.d.ts} +0 -0
  18. package/dist/{cjs/TraceMatrix.js → TraceMatrix.js} +0 -0
  19. package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  20. package/dist/{cjs/index.js → index.js} +0 -0
  21. package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
  22. package/dist/{cjs/utils.js → utils.js} +0 -0
  23. package/package.json +5 -6
  24. package/dist/es2015/DCircle.js +0 -87
  25. package/dist/es2015/DLine.js +0 -257
  26. package/dist/es2015/DNumbers.js +0 -22
  27. package/dist/es2015/DPlane.js +0 -105
  28. package/dist/es2015/DPoint.js +0 -472
  29. package/dist/es2015/DPolygon.js +0 -1040
  30. package/dist/es2015/DPolygonLoop.js +0 -392
  31. package/dist/es2015/FastSearch.js +0 -25
  32. package/dist/es2015/TraceMatrix.js +0 -200
  33. package/dist/es2015/index.js +0 -10
  34. package/dist/es2015/utils.js +0 -162
@@ -1,472 +0,0 @@
1
- import { DLine } from './DLine';
2
- import { DPolygon } from './DPolygon';
3
- import { checkFunction, createArray, isDefAndNotNull } from './utils';
4
- const diff = 0;
5
- const radiansPolygon = new DPolygon();
6
- const pseudoMercatorPolygon = new DPolygon();
7
- const worldGeodeticPolygon = new DPolygon();
8
- export const EARTH_RADIUS_IN_METERS = 6371008.8;
9
- const EARTH_IN_MITERS = 20037508.34;
10
- const DEGREES_IN_EARTH = 180;
11
- const MITERS_IN_ONE_DEGREE = EARTH_IN_MITERS / DEGREES_IN_EARTH;
12
- const DEGREES_IN_ONE_MITER = DEGREES_IN_EARTH / EARTH_IN_MITERS;
13
- export const HALF_PI_IN_DEGREE = 90;
14
- export const PI_IN_DEGREE = 180;
15
- export const DOUBLE_PI_IN_DEGREE = 360;
16
- export const PI_TO_DEGREE = Math.PI / PI_IN_DEGREE;
17
- export const DEGREE_TO_PI = PI_IN_DEGREE / Math.PI;
18
- export class DPoint {
19
- constructor(x = 0, y = x, z) {
20
- this.x = x;
21
- this.y = y;
22
- this.z = z;
23
- this.properties = {};
24
- }
25
- static zero() {
26
- return new DPoint();
27
- }
28
- static parse(c) {
29
- const { lat, lng } = c;
30
- if (lat && lng) {
31
- return new DPoint(lat, lng, 0);
32
- }
33
- const [x, y, z] = c;
34
- return new DPoint(x, y, z);
35
- }
36
- static parseFromWKT(wkt) {
37
- const regexp = /POINT \((?<data>(?:(?!\)).)*?)\)$/miu;
38
- const data = wkt.trim().toUpperCase();
39
- const res = regexp.exec(data);
40
- const [x, y, z] = res.groups.data.split(' ').map(Number);
41
- return new DPoint(x, y, z);
42
- }
43
- static random() {
44
- return new DPoint(Math.random(), Math.random());
45
- }
46
- getTileFromCoords(zoom = this.z) {
47
- checkFunction('getTileFromCoords')
48
- .checkArgument('this')
49
- .shouldBeDegree(this);
50
- const x = Math.floor((this.x + PI_IN_DEGREE) / DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
51
- const 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)));
52
- return new DPoint(x, y, zoom);
53
- }
54
- getCoordsFromTile(zoom = this.z) {
55
- checkFunction('getCoordsFromTile')
56
- .checkArgument('this')
57
- .shouldBeUInt(this);
58
- const n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom));
59
- const x = this.x / (Math.pow(2, zoom)) * DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE;
60
- const y = PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
61
- return new DPoint(x, y, zoom);
62
- }
63
- toCoords() {
64
- if (this.z === undefined) {
65
- return [this.x, this.y];
66
- }
67
- return [this.x, this.y, this.z];
68
- }
69
- findLine(p) {
70
- checkFunction('findLine')
71
- .checkArgument('this')
72
- .shouldBeMeters(this)
73
- .checkArgument('p')
74
- .shouldBeMeters(p);
75
- if (this.equal(p)) {
76
- return this.findLine(p.clone().move(0, 1));
77
- }
78
- const a = this.y - p.y - diff;
79
- const b = p.x - this.x - diff;
80
- const c = this.x * p.y - p.x * this.y - diff;
81
- if (a === 0) {
82
- return new DLine(0, 1, c / b, this, p);
83
- }
84
- if (b === 0) {
85
- return new DLine(1, 0, c / a, this, p);
86
- }
87
- return new DLine(a, b, c, this, p);
88
- }
89
- findInnerAngle(p1, p3) {
90
- checkFunction('findInnerAngle')
91
- .checkArgument('this')
92
- .shouldBeMeters(this)
93
- .checkArgument('p1')
94
- .shouldBeMeters(p1)
95
- .checkArgument('p3')
96
- .shouldBeMeters(p3);
97
- const a1 = this.findLine(p1).getFi();
98
- const a2 = this.findLine(p3).getFi();
99
- if (a2 >= a1) {
100
- return a2 - a1;
101
- }
102
- return a2 + Math.PI * 2 - a1;
103
- }
104
- toString() {
105
- return `${this.x} ${this.y}`;
106
- }
107
- getValue() {
108
- return [this.x, this.y];
109
- }
110
- height(z) {
111
- this.z = z;
112
- return this;
113
- }
114
- toWKT() {
115
- const { x, y } = this;
116
- return `POINT (${x} ${y})`;
117
- }
118
- distance(p) {
119
- checkFunction('distance')
120
- .checkArgument('this')
121
- .shouldBeMeters(this)
122
- .checkArgument('p')
123
- .shouldBeMeters(p);
124
- const dx = p.x - this.x;
125
- const dy = p.y - this.y;
126
- return Math.sqrt(dx * dx + dy * dy);
127
- }
128
- distance3d(p) {
129
- checkFunction('distance3d')
130
- .checkArgument('this')
131
- .shouldBeMeters(this)
132
- .checkArgument('p')
133
- .shouldBeMeters(p)
134
- .checkArgument('this.z')
135
- .shouldExist(this.z)
136
- .checkArgument('p.z')
137
- .shouldExist(p.z);
138
- const dx = p.x - this.x;
139
- const dy = p.y - this.y;
140
- const dz = p.z - this.z;
141
- return Math.sqrt(dx * dx + dy * dy + dz * dz);
142
- }
143
- setX(x) {
144
- this.x = typeof x === 'number' ? x : x(this);
145
- return this;
146
- }
147
- setZ(z) {
148
- this.z = typeof z === 'number' ? z : z(this);
149
- return this;
150
- }
151
- setY(y) {
152
- this.y = typeof y === 'number' ? y : y(this);
153
- return this;
154
- }
155
- clone() {
156
- const p = new DPoint(this.x, this.y, this.z);
157
- p.properties = Object.assign({}, this.properties);
158
- return p;
159
- }
160
- gt(p) {
161
- return this.x > p.x && this.y > p.y;
162
- }
163
- lt(p) {
164
- return this.x < p.x && this.y < p.y;
165
- }
166
- gtOrEqual(p) {
167
- return this.gt(p) || this.equal(p);
168
- }
169
- ltOrEqual(p) {
170
- return this.lt(p) || this.equal(p);
171
- }
172
- rotate(a) {
173
- const x = this.x * Math.cos(a) - this.y * Math.sin(a);
174
- const y = this.x * Math.sin(a) + this.y * Math.cos(a);
175
- this.x = x;
176
- this.y = y;
177
- return this;
178
- }
179
- rotate3dX(a) {
180
- const { y, z } = this;
181
- this.y = y * Math.cos(a) + z * Math.sin(a);
182
- this.z = -y * Math.sin(a) + z * Math.cos(a);
183
- return this;
184
- }
185
- rotate3dY(a) {
186
- const { x, z } = this;
187
- this.x = x * Math.cos(a) + z * Math.sin(a);
188
- this.z = -x * Math.sin(a) + z * Math.cos(a);
189
- return this;
190
- }
191
- rotate3dZ(a) {
192
- const { x, y } = this;
193
- this.x = x * Math.cos(a) - y * Math.sin(a);
194
- this.y = -x * Math.sin(a) + y * Math.cos(a);
195
- return this;
196
- }
197
- move(x, y = x, z) {
198
- let xV = 0;
199
- let yV = 0;
200
- let zV = undefined;
201
- if (x instanceof DPoint) {
202
- xV = this.x + x.x;
203
- yV = this.y + x.y;
204
- if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
205
- zV = this.z + x.z;
206
- }
207
- }
208
- else {
209
- xV = this.x + x;
210
- yV = this.y + y;
211
- if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
212
- zV = this.z + z;
213
- }
214
- }
215
- this.x = xV;
216
- this.y = yV;
217
- if (isDefAndNotNull(zV)) {
218
- this.z = zV;
219
- }
220
- return this;
221
- }
222
- degreeToMeters() {
223
- checkFunction('degreeToMeters')
224
- .checkArgument('this')
225
- .shouldBeDegree(this);
226
- const x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
227
- const y = (Math.log(Math.tan(((this.y + HALF_PI_IN_DEGREE) % PI_IN_DEGREE) *
228
- (Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
229
- this.x = x;
230
- this.y = y;
231
- return this;
232
- }
233
- metersToDegree() {
234
- checkFunction('metersToDegree')
235
- .checkArgument('this')
236
- .shouldBeMeters(this);
237
- const lon = this.x * DEGREES_IN_ONE_MITER;
238
- const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * PI_TO_DEGREE))) *
239
- (DOUBLE_PI_IN_DEGREE / Math.PI) - HALF_PI_IN_DEGREE;
240
- this.x = lon;
241
- this.y = lat;
242
- return this;
243
- }
244
- degreeToRadians() {
245
- checkFunction('degreeToRadians')
246
- .checkArgument('this')
247
- .shouldBeDegree(this);
248
- return this.scale(PI_TO_DEGREE);
249
- }
250
- radiansToDegrees() {
251
- checkFunction('radiansToDegrees')
252
- .checkArgument('this')
253
- .shouldBeRadians(this);
254
- return this.scale(DEGREE_TO_PI);
255
- }
256
- radiansToMeters() {
257
- checkFunction('radiansToMeters')
258
- .checkArgument('this')
259
- .shouldBeRadians(this);
260
- return this.radiansToDegrees().degreeToMeters();
261
- }
262
- metersToRadians() {
263
- checkFunction('metersToRadians')
264
- .checkArgument('this')
265
- .shouldBeMeters(this);
266
- return this.metersToDegree().degreeToRadians();
267
- }
268
- round() {
269
- this.x = Math.round(this.x);
270
- this.y = Math.round(this.y);
271
- return this;
272
- }
273
- ceil() {
274
- this.x = Math.ceil(this.x);
275
- this.y = Math.ceil(this.y);
276
- return this;
277
- }
278
- floor() {
279
- this.x = Math.floor(this.x);
280
- this.y = Math.floor(this.y);
281
- return this;
282
- }
283
- toFixed(n = 2) {
284
- this.x = parseFloat(this.x.toFixed(n));
285
- this.y = parseFloat(this.y.toFixed(n));
286
- return this;
287
- }
288
- abs() {
289
- this.x = Math.abs(this.x);
290
- this.y = Math.abs(this.y);
291
- return this;
292
- }
293
- scale(x, y = x, z) {
294
- let xV = 0;
295
- let yV = 0;
296
- let zV = undefined;
297
- if (x instanceof DPoint) {
298
- xV = this.x * x.x;
299
- yV = this.y * x.y;
300
- if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
301
- zV = this.z * x.z;
302
- }
303
- }
304
- else {
305
- xV = this.x * x;
306
- yV = this.y * y;
307
- if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
308
- zV = this.z * z;
309
- }
310
- }
311
- this.x = xV;
312
- this.y = yV;
313
- if (isDefAndNotNull(zV)) {
314
- this.z = zV;
315
- }
316
- return this;
317
- }
318
- divide(x, y = x, z) {
319
- let xV = 0;
320
- let yV = 0;
321
- let zV = undefined;
322
- if (x instanceof DPoint) {
323
- xV = this.x / x.x;
324
- yV = this.y / x.y;
325
- if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
326
- zV = this.z / x.z;
327
- }
328
- }
329
- else {
330
- xV = this.x / x;
331
- yV = this.y / y;
332
- if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
333
- zV = this.z / z;
334
- }
335
- }
336
- this.x = xV;
337
- this.y = yV;
338
- if (isDefAndNotNull(zV)) {
339
- this.z = zV;
340
- }
341
- return this;
342
- }
343
- equal(p) {
344
- return this.x === p.x && this.y === p.y && this.z === p.z;
345
- }
346
- like(p, d = 0.001) {
347
- var _a, _b, _c, _d;
348
- if (this.equal(p)) {
349
- return true;
350
- }
351
- const likeX = Math.abs(this.x - p.x) < d;
352
- const likeY = Math.abs(this.y - p.y) < d;
353
- 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;
354
- return likeX && likeY && likeZ;
355
- }
356
- flipVertically(size) {
357
- let v = size;
358
- if (size instanceof DPoint) {
359
- v = size.y;
360
- }
361
- this.y = v - this.y;
362
- return this;
363
- }
364
- get likeRadians() {
365
- if (radiansPolygon.length === 0) {
366
- radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2));
367
- }
368
- return radiansPolygon.simpleInclude(this);
369
- }
370
- get likeWorldGeodeticSystem() {
371
- if (worldGeodeticPolygon.length === 0) {
372
- worldGeodeticPolygon.push(new DPoint(-180, -90), new DPoint(180, 90));
373
- }
374
- return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this);
375
- }
376
- get likePseudoMercator() {
377
- if (pseudoMercatorPolygon.length === 0) {
378
- pseudoMercatorPolygon.push(new DPoint(-20026376.39, -20048966.10), new DPoint(20026376.39, 20048966.10));
379
- }
380
- return !this.likeRadians && !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this);
381
- }
382
- get w() {
383
- return this.x;
384
- }
385
- set w(x) {
386
- this.x = x;
387
- }
388
- get h() {
389
- return this.y;
390
- }
391
- set h(y) {
392
- this.y = y;
393
- }
394
- get area() {
395
- checkFunction('area')
396
- .checkArgument('this')
397
- .shouldBeMeters(this);
398
- return this.w * this.h;
399
- }
400
- get hip() {
401
- checkFunction('hip')
402
- .checkArgument('this')
403
- .shouldBeMeters(this);
404
- return Math.sqrt(this.w * this.w + this.h * this.h);
405
- }
406
- get min() {
407
- return Math.min(this.x, this.y);
408
- }
409
- get max() {
410
- return Math.max(this.x, this.y);
411
- }
412
- get hipPoint() {
413
- const { hip } = this;
414
- return new DPoint(hip, hip);
415
- }
416
- get xPoint() {
417
- const { x } = this;
418
- return new DPoint(x, x);
419
- }
420
- get yPoint() {
421
- const { y } = this;
422
- return new DPoint(y, y);
423
- }
424
- get wPoint() {
425
- return this.xPoint;
426
- }
427
- get hPoint() {
428
- return this.yPoint;
429
- }
430
- simple(xKey = 'x', yKey = 'y') {
431
- return {
432
- [xKey]: this.x,
433
- [yKey]: this.y
434
- };
435
- }
436
- setIfLessThan(p) {
437
- this.x = Math.max(this.x, p.x);
438
- this.y = Math.max(this.y, p.y);
439
- return this;
440
- }
441
- minus() {
442
- return this.scale(-1);
443
- }
444
- orthodromicPath(point, pointsCount = 360) {
445
- checkFunction('orthodromicPath')
446
- .checkArgument('this')
447
- .shouldBeDegree(this)
448
- .checkArgument('point')
449
- .shouldBeDegree(point);
450
- const t = this.clone().degreeToRadians();
451
- const p = point.clone().degreeToRadians();
452
- const d = Math.sin(p.x - t.x);
453
- const step = (p.x - t.x) / (pointsCount - 1);
454
- return new DPolygon(createArray(pointsCount)
455
- .map((v, i) => {
456
- const x = t.x + step * i;
457
- const y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
458
- (Math.tan(p.y) * Math.sin(x - t.x)) / d);
459
- return new DPoint(x, y).radiansToDegrees();
460
- }));
461
- }
462
- sortByDistance(p) {
463
- return p
464
- .clone()
465
- .map((d, index) => {
466
- d.properties.distance = d.distance(this);
467
- d.properties.index = index;
468
- return d;
469
- })
470
- .sort((a, b) => a.properties.distance - b.properties.distance);
471
- }
472
- }