dgeoutils 2.2.23 → 2.3.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 (50) hide show
  1. package/README.md +7 -0
  2. package/dist/{DCircle.d.ts → cjs/DCircle.d.ts} +0 -0
  3. package/dist/cjs/DCircle.js +102 -0
  4. package/dist/{DLine.d.ts → cjs/DLine.d.ts} +0 -0
  5. package/dist/cjs/DLine.js +300 -0
  6. package/dist/{DNumbers.d.ts → cjs/DNumbers.d.ts} +0 -0
  7. package/dist/cjs/DNumbers.js +30 -0
  8. package/dist/{DPlane.d.ts → cjs/DPlane.d.ts} +0 -0
  9. package/dist/cjs/DPlane.js +132 -0
  10. package/dist/{DPoint.d.ts → cjs/DPoint.d.ts} +0 -0
  11. package/dist/cjs/DPoint.js +574 -0
  12. package/dist/{DPolygon.d.ts → cjs/DPolygon.d.ts} +7 -1
  13. package/dist/cjs/DPolygon.js +1555 -0
  14. package/dist/{DPolygonLoop.d.ts → cjs/DPolygonLoop.d.ts} +0 -0
  15. package/dist/cjs/DPolygonLoop.js +401 -0
  16. package/dist/{FastSearch.d.ts → cjs/FastSearch.d.ts} +0 -0
  17. package/dist/cjs/FastSearch.js +53 -0
  18. package/dist/{TraceMatrix.d.ts → cjs/TraceMatrix.d.ts} +0 -0
  19. package/dist/cjs/TraceMatrix.js +256 -0
  20. package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  21. package/dist/{index.js → cjs/index.js} +0 -0
  22. package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
  23. package/dist/cjs/utils.js +191 -0
  24. package/dist/{DCircle.js → es2015/DCircle.js} +14 -18
  25. package/dist/{DLine.js → es2015/DLine.js} +24 -28
  26. package/dist/es2015/DNumbers.js +22 -0
  27. package/dist/{DPlane.js → es2015/DPlane.js} +22 -26
  28. package/dist/{DPoint.js → es2015/DPoint.js} +52 -56
  29. package/dist/{DPolygon.js → es2015/DPolygon.js} +90 -86
  30. package/dist/{DPolygonLoop.js → es2015/DPolygonLoop.js} +1 -5
  31. package/dist/{FastSearch.js → es2015/FastSearch.js} +1 -5
  32. package/dist/{TraceMatrix.js → es2015/TraceMatrix.js} +35 -39
  33. package/dist/es2015/index.js +13 -0
  34. package/dist/{utils.js → es2015/utils.js} +26 -36
  35. package/dist/esm/DCircle.js +99 -0
  36. package/dist/esm/DLine.js +297 -0
  37. package/dist/esm/DNumbers.js +27 -0
  38. package/dist/esm/DPlane.js +129 -0
  39. package/dist/esm/DPoint.js +571 -0
  40. package/dist/esm/DPolygon.js +1552 -0
  41. package/dist/esm/DPolygonLoop.js +398 -0
  42. package/dist/esm/FastSearch.js +50 -0
  43. package/dist/esm/TraceMatrix.js +253 -0
  44. package/dist/esm/index.js +13 -0
  45. package/dist/esm/utils.js +181 -0
  46. package/dist/umd/dgeoutils.js +3569 -0
  47. package/dist/umd/dgeoutils.min.js +1 -0
  48. package/dist/umd/dgeoutils.min.js.map +1 -0
  49. package/package.json +17 -10
  50. package/dist/DNumbers.js +0 -26
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DPlane = void 0;
4
- const DPoint_1 = require("./DPoint");
5
- const utils_1 = require("./utils");
6
- const DNumbers_1 = require("./DNumbers");
7
- class DPlane {
8
- constructor(a, b, c, d, p1 = DPoint_1.DPoint.zero(), p2 = DPoint_1.DPoint.zero(), p3 = DPoint_1.DPoint.zero()) {
1
+ import { DPoint } from './DPoint';
2
+ import { gaussianElimination } from './utils';
3
+ import { DNumbers } from './DNumbers';
4
+ export class DPlane {
5
+ constructor(a, b, c, d, p1 = DPoint.zero(), p2 = DPoint.zero(), p3 = DPoint.zero()) {
9
6
  this.a = a;
10
7
  this.b = b;
11
8
  this.c = c;
@@ -25,7 +22,7 @@ class DPlane {
25
22
  return new DPlane(0, 0, 1, -p1.z, p1, p2, p3);
26
23
  }
27
24
  const d = 1;
28
- const [a, b, c] = (0, utils_1.gaussianElimination)([
25
+ const [a, b, c] = gaussianElimination([
29
26
  [p1.x, p1.y, p1.z, -d],
30
27
  [p2.x, p2.y, p2.z, -d],
31
28
  [p3.x, p3.y, p3.z, -d]
@@ -33,7 +30,7 @@ class DPlane {
33
30
  return new DPlane(a, b, c, d, p1, p2, p3);
34
31
  }
35
32
  x(p) {
36
- if (p instanceof DPoint_1.DPoint) {
33
+ if (p instanceof DPoint) {
37
34
  const { a, b, c, d } = this;
38
35
  const { y, z } = p;
39
36
  p.x = -(b * y + c * z + d) / a;
@@ -42,7 +39,7 @@ class DPlane {
42
39
  return p.map((t) => this.x(t));
43
40
  }
44
41
  y(p) {
45
- if (p instanceof DPoint_1.DPoint) {
42
+ if (p instanceof DPoint) {
46
43
  const { a, b, c, d } = this;
47
44
  const { x, z } = p;
48
45
  p.y = -(a * x + c * z + d) / b;
@@ -51,7 +48,7 @@ class DPlane {
51
48
  return p.map((t) => this.y(t));
52
49
  }
53
50
  z(p) {
54
- if (p instanceof DPoint_1.DPoint) {
51
+ if (p instanceof DPoint) {
55
52
  const { a, b, c, d } = this;
56
53
  const { x, y } = p;
57
54
  p.z = -(a * x + b * y + d) / c;
@@ -64,7 +61,7 @@ class DPlane {
64
61
  return new DPlane(a, b, c, d, p1, p2, p3);
65
62
  }
66
63
  distance(p) {
67
- if (p instanceof DPoint_1.DPoint) {
64
+ if (p instanceof DPoint) {
68
65
  const { x, y, z } = p;
69
66
  const { a, b, c, d } = this;
70
67
  return Math.abs(a * x + b * y + c * z + d) / Math.sqrt(a * a + b * b + c * c);
@@ -76,10 +73,10 @@ class DPlane {
76
73
  equal(p) {
77
74
  const { a, b, c, d } = p;
78
75
  const { a: q, b: w, c: e, d: r } = this;
79
- return DNumbers_1.DNumbers.like(a, q) &&
80
- DNumbers_1.DNumbers.like(b, w) &&
81
- DNumbers_1.DNumbers.like(c, e) &&
82
- DNumbers_1.DNumbers.like(d, r);
76
+ return DNumbers.like(a, q) &&
77
+ DNumbers.like(b, w) &&
78
+ DNumbers.like(c, e) &&
79
+ DNumbers.like(d, r);
83
80
  }
84
81
  same(p) {
85
82
  const { a, b, c, d } = p;
@@ -88,10 +85,10 @@ class DPlane {
88
85
  const y = b / w;
89
86
  const u = c / e;
90
87
  const i = d / r;
91
- return DNumbers_1.DNumbers.like(t, y) &&
92
- DNumbers_1.DNumbers.like(t, u) &&
93
- DNumbers_1.DNumbers.like(t, c) &&
94
- DNumbers_1.DNumbers.like(t, i);
88
+ return DNumbers.like(t, y) &&
89
+ DNumbers.like(t, u) &&
90
+ DNumbers.like(t, c) &&
91
+ DNumbers.like(t, i);
95
92
  }
96
93
  parallel(p) {
97
94
  const { a, b, c, d } = p;
@@ -100,10 +97,9 @@ class DPlane {
100
97
  const y = b / w;
101
98
  const u = c / e;
102
99
  const i = d / r;
103
- return DNumbers_1.DNumbers.like(t, y) &&
104
- DNumbers_1.DNumbers.like(t, u) &&
105
- DNumbers_1.DNumbers.like(t, c) &&
106
- !DNumbers_1.DNumbers.like(t, i);
100
+ return DNumbers.like(t, y) &&
101
+ DNumbers.like(t, u) &&
102
+ DNumbers.like(t, c) &&
103
+ !DNumbers.like(t, i);
107
104
  }
108
105
  }
109
- exports.DPlane = DPlane;
@@ -1,24 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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;
4
- const DLine_1 = require("./DLine");
5
- const DPolygon_1 = require("./DPolygon");
6
- const utils_1 = require("./utils");
1
+ import { DLine } from './DLine';
2
+ import { DPolygon } from './DPolygon';
3
+ import { checkFunction, createArray, isDefAndNotNull } from './utils';
7
4
  const diff = 0;
8
- const radiansPolygon = new DPolygon_1.DPolygon();
9
- const pseudoMercatorPolygon = new DPolygon_1.DPolygon();
10
- const worldGeodeticPolygon = new DPolygon_1.DPolygon();
11
- exports.EARTH_RADIUS_IN_METERS = 6371008.8;
5
+ const radiansPolygon = new DPolygon();
6
+ const pseudoMercatorPolygon = new DPolygon();
7
+ const worldGeodeticPolygon = new DPolygon();
8
+ export const EARTH_RADIUS_IN_METERS = 6371008.8;
12
9
  const EARTH_IN_MITERS = 20037508.34;
13
10
  const DEGREES_IN_EARTH = 180;
14
11
  const MITERS_IN_ONE_DEGREE = EARTH_IN_MITERS / DEGREES_IN_EARTH;
15
12
  const DEGREES_IN_ONE_MITER = DEGREES_IN_EARTH / EARTH_IN_MITERS;
16
- exports.HALF_PI_IN_DEGREE = 90;
17
- exports.PI_IN_DEGREE = 180;
18
- exports.DOUBLE_PI_IN_DEGREE = 360;
19
- exports.PI_TO_DEGREE = Math.PI / exports.PI_IN_DEGREE;
20
- exports.DEGREE_TO_PI = exports.PI_IN_DEGREE / Math.PI;
21
- class DPoint {
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 {
22
19
  constructor(x = 0, y = x, z) {
23
20
  this.x = x;
24
21
  this.y = y;
@@ -47,20 +44,20 @@ class DPoint {
47
44
  return new DPoint(Math.random(), Math.random());
48
45
  }
49
46
  getTileFromCoords(zoom = this.z) {
50
- (0, utils_1.checkFunction)('getTileFromCoords')
47
+ checkFunction('getTileFromCoords')
51
48
  .checkArgument('this')
52
49
  .shouldBeDegree(this);
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)));
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)));
55
52
  return new DPoint(x, y, zoom);
56
53
  }
57
54
  getCoordsFromTile(zoom = this.z) {
58
- (0, utils_1.checkFunction)('getCoordsFromTile')
55
+ checkFunction('getCoordsFromTile')
59
56
  .checkArgument('this')
60
57
  .shouldBeUInt(this);
61
58
  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);
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);
64
61
  return new DPoint(x, y, zoom);
65
62
  }
66
63
  toCoords() {
@@ -70,7 +67,7 @@ class DPoint {
70
67
  return [this.x, this.y, this.z];
71
68
  }
72
69
  findLine(p) {
73
- (0, utils_1.checkFunction)('findLine')
70
+ checkFunction('findLine')
74
71
  .checkArgument('this')
75
72
  .shouldBeMeters(this)
76
73
  .checkArgument('p')
@@ -82,15 +79,15 @@ class DPoint {
82
79
  const b = p.x - this.x - diff;
83
80
  const c = this.x * p.y - p.x * this.y - diff;
84
81
  if (a === 0) {
85
- return new DLine_1.DLine(0, 1, c / b, this, p);
82
+ return new DLine(0, 1, c / b, this, p);
86
83
  }
87
84
  if (b === 0) {
88
- return new DLine_1.DLine(1, 0, c / a, this, p);
85
+ return new DLine(1, 0, c / a, this, p);
89
86
  }
90
- return new DLine_1.DLine(a, b, c, this, p);
87
+ return new DLine(a, b, c, this, p);
91
88
  }
92
89
  findInnerAngle(p1, p3) {
93
- (0, utils_1.checkFunction)('findInnerAngle')
90
+ checkFunction('findInnerAngle')
94
91
  .checkArgument('this')
95
92
  .shouldBeMeters(this)
96
93
  .checkArgument('p1')
@@ -119,7 +116,7 @@ class DPoint {
119
116
  return `POINT (${x} ${y})`;
120
117
  }
121
118
  distance(p) {
122
- (0, utils_1.checkFunction)('distance')
119
+ checkFunction('distance')
123
120
  .checkArgument('this')
124
121
  .shouldBeMeters(this)
125
122
  .checkArgument('p')
@@ -129,7 +126,7 @@ class DPoint {
129
126
  return Math.sqrt(dx * dx + dy * dy);
130
127
  }
131
128
  distance3d(p) {
132
- (0, utils_1.checkFunction)('distance3d')
129
+ checkFunction('distance3d')
133
130
  .checkArgument('this')
134
131
  .shouldBeMeters(this)
135
132
  .checkArgument('p')
@@ -204,66 +201,66 @@ class DPoint {
204
201
  if (x instanceof DPoint) {
205
202
  xV = this.x + x.x;
206
203
  yV = this.y + x.y;
207
- if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
204
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
208
205
  zV = this.z + x.z;
209
206
  }
210
207
  }
211
208
  else {
212
209
  xV = this.x + x;
213
210
  yV = this.y + y;
214
- if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
211
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
215
212
  zV = this.z + z;
216
213
  }
217
214
  }
218
215
  this.x = xV;
219
216
  this.y = yV;
220
- if ((0, utils_1.isDefAndNotNull)(zV)) {
217
+ if (isDefAndNotNull(zV)) {
221
218
  this.z = zV;
222
219
  }
223
220
  return this;
224
221
  }
225
222
  degreeToMeters() {
226
- (0, utils_1.checkFunction)('degreeToMeters')
223
+ checkFunction('degreeToMeters')
227
224
  .checkArgument('this')
228
225
  .shouldBeDegree(this);
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) *
231
- (Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
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;
232
229
  this.x = x;
233
230
  this.y = y;
234
231
  return this;
235
232
  }
236
233
  metersToDegree() {
237
- (0, utils_1.checkFunction)('metersToDegree')
234
+ checkFunction('metersToDegree')
238
235
  .checkArgument('this')
239
236
  .shouldBeMeters(this);
240
237
  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))) *
242
- (exports.DOUBLE_PI_IN_DEGREE / Math.PI) - exports.HALF_PI_IN_DEGREE;
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;
243
240
  this.x = lon;
244
241
  this.y = lat;
245
242
  return this;
246
243
  }
247
244
  degreeToRadians() {
248
- (0, utils_1.checkFunction)('degreeToRadians')
245
+ checkFunction('degreeToRadians')
249
246
  .checkArgument('this')
250
247
  .shouldBeDegree(this);
251
- return this.scale(exports.PI_TO_DEGREE);
248
+ return this.scale(PI_TO_DEGREE);
252
249
  }
253
250
  radiansToDegrees() {
254
- (0, utils_1.checkFunction)('radiansToDegrees')
251
+ checkFunction('radiansToDegrees')
255
252
  .checkArgument('this')
256
253
  .shouldBeRadians(this);
257
- return this.scale(exports.DEGREE_TO_PI);
254
+ return this.scale(DEGREE_TO_PI);
258
255
  }
259
256
  radiansToMeters() {
260
- (0, utils_1.checkFunction)('radiansToMeters')
257
+ checkFunction('radiansToMeters')
261
258
  .checkArgument('this')
262
259
  .shouldBeRadians(this);
263
260
  return this.radiansToDegrees().degreeToMeters();
264
261
  }
265
262
  metersToRadians() {
266
- (0, utils_1.checkFunction)('metersToRadians')
263
+ checkFunction('metersToRadians')
267
264
  .checkArgument('this')
268
265
  .shouldBeMeters(this);
269
266
  return this.metersToDegree().degreeToRadians();
@@ -300,20 +297,20 @@ class DPoint {
300
297
  if (x instanceof DPoint) {
301
298
  xV = this.x * x.x;
302
299
  yV = this.y * x.y;
303
- if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
300
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
304
301
  zV = this.z * x.z;
305
302
  }
306
303
  }
307
304
  else {
308
305
  xV = this.x * x;
309
306
  yV = this.y * y;
310
- if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
307
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
311
308
  zV = this.z * z;
312
309
  }
313
310
  }
314
311
  this.x = xV;
315
312
  this.y = yV;
316
- if ((0, utils_1.isDefAndNotNull)(zV)) {
313
+ if (isDefAndNotNull(zV)) {
317
314
  this.z = zV;
318
315
  }
319
316
  return this;
@@ -325,20 +322,20 @@ class DPoint {
325
322
  if (x instanceof DPoint) {
326
323
  xV = this.x / x.x;
327
324
  yV = this.y / x.y;
328
- if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
325
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
329
326
  zV = this.z / x.z;
330
327
  }
331
328
  }
332
329
  else {
333
330
  xV = this.x / x;
334
331
  yV = this.y / y;
335
- if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
332
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
336
333
  zV = this.z / z;
337
334
  }
338
335
  }
339
336
  this.x = xV;
340
337
  this.y = yV;
341
- if ((0, utils_1.isDefAndNotNull)(zV)) {
338
+ if (isDefAndNotNull(zV)) {
342
339
  this.z = zV;
343
340
  }
344
341
  return this;
@@ -395,13 +392,13 @@ class DPoint {
395
392
  this.y = y;
396
393
  }
397
394
  get area() {
398
- (0, utils_1.checkFunction)('area')
395
+ checkFunction('area')
399
396
  .checkArgument('this')
400
397
  .shouldBeMeters(this);
401
398
  return this.w * this.h;
402
399
  }
403
400
  get hip() {
404
- (0, utils_1.checkFunction)('hip')
401
+ checkFunction('hip')
405
402
  .checkArgument('this')
406
403
  .shouldBeMeters(this);
407
404
  return Math.sqrt(this.w * this.w + this.h * this.h);
@@ -445,7 +442,7 @@ class DPoint {
445
442
  return this.scale(-1);
446
443
  }
447
444
  orthodromicPath(point, pointsCount = 360) {
448
- (0, utils_1.checkFunction)('orthodromicPath')
445
+ checkFunction('orthodromicPath')
449
446
  .checkArgument('this')
450
447
  .shouldBeDegree(this)
451
448
  .checkArgument('point')
@@ -454,7 +451,7 @@ class DPoint {
454
451
  const p = point.clone().degreeToRadians();
455
452
  const d = Math.sin(p.x - t.x);
456
453
  const step = (p.x - t.x) / (pointsCount - 1);
457
- return new DPolygon_1.DPolygon((0, utils_1.createArray)(pointsCount)
454
+ return new DPolygon(createArray(pointsCount)
458
455
  .map((v, i) => {
459
456
  const x = t.x + step * i;
460
457
  const y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
@@ -473,4 +470,3 @@ class DPoint {
473
470
  .sort((a, b) => a.properties.distance - b.properties.distance);
474
471
  }
475
472
  }
476
- exports.DPoint = DPoint;