dgeoutils 2.4.10 → 2.4.13

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,7 +1,7 @@
1
1
  import { DLine } from './DLine';
2
2
  import { DPolygon } from './DPolygon';
3
3
  import { Point } from 'geojson';
4
- export declare const EARTH_RADIUS_IN_METERS = 6371008.8;
4
+ export declare const EARTH_RADIUS_IN_METERS = 6378137;
5
5
  export declare type DCoord = [number, number] | [number, number, number];
6
6
  export interface LatLng {
7
7
  lat: number;
@@ -14,7 +14,7 @@ export declare const PI_IN_DEGREE = 180;
14
14
  export declare const DOUBLE_PI_IN_DEGREE = 360;
15
15
  export declare const PI_TO_DEGREE: number;
16
16
  export declare const DEGREE_TO_PI: number;
17
- export declare type SetterFunction = (t: DPoint) => number;
17
+ declare type SetterFunction<T> = (t: DPoint) => T;
18
18
  export declare class DPoint {
19
19
  x: number;
20
20
  y: number;
@@ -45,11 +45,12 @@ export declare class DPoint {
45
45
  distance(p: DPoint): number;
46
46
  distance3d(p: DPoint): number;
47
47
  setX(x: number): DPoint;
48
- setX(f: SetterFunction): DPoint;
48
+ setX(f: SetterFunction<number>): DPoint;
49
49
  setZ(z: number): DPoint;
50
- setZ(f: SetterFunction): DPoint;
50
+ setZ(f: SetterFunction<number>): DPoint;
51
51
  setY(y: number): DPoint;
52
- setY(f: SetterFunction): DPoint;
52
+ setY(f: SetterFunction<number>): DPoint;
53
+ setProperties(v: SetterFunction<Record<string, any>> | Record<string, any>): DPoint;
53
54
  clone(): DPoint;
54
55
  gt(p: DPoint): boolean;
55
56
  lt(p: DPoint): boolean;
@@ -82,6 +83,14 @@ export declare class DPoint {
82
83
  divide(p: DPoint): DPoint;
83
84
  divide(x: number, y: number): DPoint;
84
85
  divide(x: number, y: number, z: number): DPoint;
86
+ mod(v: number): DPoint;
87
+ mod(p: DPoint): DPoint;
88
+ mod(x: number, y: number): DPoint;
89
+ mod(x: number, y: number, z: number): DPoint;
90
+ div(v: number): DPoint;
91
+ div(p: DPoint): DPoint;
92
+ div(x: number, y: number): DPoint;
93
+ div(x: number, y: number, z: number): DPoint;
85
94
  equal(p: DPoint): boolean;
86
95
  like(p: DPoint, d?: number): boolean;
87
96
  flipVertically(size: DPoint): DPoint;
@@ -117,4 +126,6 @@ export declare class DPoint {
117
126
  minus(): DPoint;
118
127
  orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
119
128
  sortByDistance(p: DPolygon): DPolygon;
129
+ calculateAltitudeByDistanceBetweenPoints(p1: DPoint, p2: DPoint): DPoint;
120
130
  }
131
+ export {};
@@ -35,11 +35,11 @@ var diff = 0;
35
35
  var radiansPolygon = new DPolygon_1.DPolygon();
36
36
  var pseudoMercatorPolygon = new DPolygon_1.DPolygon();
37
37
  var worldGeodeticPolygon = new DPolygon_1.DPolygon();
38
- exports.EARTH_RADIUS_IN_METERS = 6371008.8;
39
- var EARTH_IN_MITERS = 20037508.34;
38
+ exports.EARTH_RADIUS_IN_METERS = 6378137;
39
+ var EARTH_IN_METERS = 20037508.34;
40
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;
41
+ var METERS_IN_ONE_DEGREE = EARTH_IN_METERS / DEGREES_IN_EARTH;
42
+ var DEGREES_IN_ONE_METER = DEGREES_IN_EARTH / EARTH_IN_METERS;
43
43
  exports.HALF_PI_IN_DEGREE = 90;
44
44
  exports.PI_IN_DEGREE = 180;
45
45
  exports.DOUBLE_PI_IN_DEGREE = 360;
@@ -259,6 +259,10 @@ var DPoint = (function () {
259
259
  this.y = typeof y === 'number' ? y : y(this);
260
260
  return this;
261
261
  };
262
+ DPoint.prototype.setProperties = function (v) {
263
+ this.properties = typeof v === 'object' ? v : v(this);
264
+ return this;
265
+ };
262
266
  DPoint.prototype.clone = function () {
263
267
  var p = new DPoint(this.x, this.y, this.z);
264
268
  p.properties = __assign({}, this.properties);
@@ -331,9 +335,9 @@ var DPoint = (function () {
331
335
  (0, utils_1.checkFunction)('degreeToMeters')
332
336
  .checkArgument('this')
333
337
  .shouldBeDegree(this);
334
- var x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
338
+ var x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * METERS_IN_ONE_DEGREE;
335
339
  var y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) *
336
- (Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
340
+ (Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * METERS_IN_ONE_DEGREE;
337
341
  this.x = x;
338
342
  this.y = y;
339
343
  return this;
@@ -342,8 +346,8 @@ var DPoint = (function () {
342
346
  (0, utils_1.checkFunction)('metersToDegree')
343
347
  .checkArgument('this')
344
348
  .shouldBeMeters(this);
345
- var lon = this.x * DEGREES_IN_ONE_MITER;
346
- var lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) *
349
+ var lon = this.x * DEGREES_IN_ONE_METER;
350
+ var lat = Math.atan(Math.pow(Math.E, ((this.y / METERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) *
347
351
  (exports.DOUBLE_PI_IN_DEGREE / Math.PI) - exports.HALF_PI_IN_DEGREE;
348
352
  this.x = lon;
349
353
  this.y = lat;
@@ -451,6 +455,58 @@ var DPoint = (function () {
451
455
  }
452
456
  return this;
453
457
  };
458
+ DPoint.prototype.mod = function (x, y, z) {
459
+ if (y === void 0) { y = x; }
460
+ var xV = 0;
461
+ var yV = 0;
462
+ var zV = undefined;
463
+ if (x instanceof DPoint) {
464
+ xV = this.x % x.x;
465
+ yV = this.y % x.y;
466
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
467
+ zV = this.z % x.z;
468
+ }
469
+ }
470
+ else {
471
+ xV = this.x % x;
472
+ yV = this.y % y;
473
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
474
+ zV = this.z % z;
475
+ }
476
+ }
477
+ this.x = xV;
478
+ this.y = yV;
479
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
480
+ this.z = zV;
481
+ }
482
+ return this;
483
+ };
484
+ DPoint.prototype.div = function (x, y, z) {
485
+ if (y === void 0) { y = x; }
486
+ var xV = 0;
487
+ var yV = 0;
488
+ var zV = undefined;
489
+ if (x instanceof DPoint) {
490
+ xV = (0, utils_1.div)(this.x, x.x);
491
+ yV = (0, utils_1.div)(this.y, x.y);
492
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
493
+ zV = (0, utils_1.div)(this.z, x.z);
494
+ }
495
+ }
496
+ else {
497
+ xV = (0, utils_1.div)(this.x, x);
498
+ yV = (0, utils_1.div)(this.y, y);
499
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
500
+ zV = (0, utils_1.div)(this.z, z);
501
+ }
502
+ }
503
+ this.x = xV;
504
+ this.y = yV;
505
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
506
+ this.z = zV;
507
+ }
508
+ return this;
509
+ };
454
510
  DPoint.prototype.equal = function (p) {
455
511
  return this.x === p.x && this.y === p.y && this.z === p.z;
456
512
  };
@@ -682,6 +738,27 @@ var DPoint = (function () {
682
738
  })
683
739
  .sort(function (a, b) { return a.properties.distance - b.properties.distance; });
684
740
  };
741
+ DPoint.prototype.calculateAltitudeByDistanceBetweenPoints = function (p1, p2) {
742
+ var _a, _b, _c, _d;
743
+ if (p1.alt === p2.alt) {
744
+ this.alt = p1.alt;
745
+ }
746
+ else {
747
+ var minAlt = Math.min((_a = p1.alt) !== null && _a !== void 0 ? _a : 0, (_b = p2.alt) !== null && _b !== void 0 ? _b : 0);
748
+ var maxAlt = Math.max((_c = p1.alt) !== null && _c !== void 0 ? _c : 0, (_d = p2.alt) !== null && _d !== void 0 ? _d : 0);
749
+ var dAlt = maxAlt - minAlt;
750
+ var distance1 = this.distance(p1);
751
+ var distance2 = this.distance(p2);
752
+ var totalDistance = distance1 + distance2;
753
+ if (p1.alt === minAlt) {
754
+ this.alt = minAlt + distance1 / totalDistance * dAlt;
755
+ }
756
+ else {
757
+ this.alt = minAlt + distance2 / totalDistance * dAlt;
758
+ }
759
+ }
760
+ return this;
761
+ };
685
762
  return DPoint;
686
763
  }());
687
764
  exports.DPoint = DPoint;
@@ -1,6 +1,7 @@
1
1
  import { DPolygon } from './DPolygon';
2
- import { DPoint, SetterFunction } from './DPoint';
3
- export declare type LoopFunction = (k: DPoint) => DPoint;
2
+ import { DPoint } from './DPoint';
3
+ export declare type SetterFunction<T> = (t: DPoint, index: number) => T;
4
+ export declare type LoopFunction = (k: DPoint, index: number) => DPoint;
4
5
  export declare class DPolygonLoop {
5
6
  private readonly parent;
6
7
  private pool;
@@ -11,11 +12,12 @@ export declare class DPolygonLoop {
11
12
  getCoordsFromTile(zoom?: number): DPolygonLoop;
12
13
  height(z: number): DPolygonLoop;
13
14
  setX(x: number): DPolygonLoop;
14
- setX(f: SetterFunction): DPolygonLoop;
15
+ setX(f: SetterFunction<number>): DPolygonLoop;
16
+ setProperties(setterArgByObject: SetterFunction<Record<string, any>> | Record<string, any>): DPolygonLoop;
15
17
  setY(y: number): DPolygonLoop;
16
- setY(f: SetterFunction): DPolygonLoop;
18
+ setY(f: SetterFunction<number>): DPolygonLoop;
17
19
  setZ(z: number): DPolygonLoop;
18
- setZ(f: SetterFunction): DPolygonLoop;
20
+ setZ(f: SetterFunction<number>): DPolygonLoop;
19
21
  rotate(a: number): DPolygonLoop;
20
22
  rotate3dX(a: number): DPolygonLoop;
21
23
  rotate3dY(a: number): DPolygonLoop;
@@ -34,6 +36,12 @@ export declare class DPolygonLoop {
34
36
  divide(v: number): DPolygonLoop;
35
37
  divide(p: DPoint): DPolygonLoop;
36
38
  divide(x: number, y: number): DPolygonLoop;
39
+ div(v: number): DPolygonLoop;
40
+ div(p: DPoint): DPolygonLoop;
41
+ div(x: number, y: number): DPolygonLoop;
42
+ mod(v: number): DPolygonLoop;
43
+ mod(p: DPoint): DPolygonLoop;
44
+ mod(x: number, y: number): DPolygonLoop;
37
45
  degreeToRadians(): DPolygonLoop;
38
46
  radiansToDegrees(): DPolygonLoop;
39
47
  radiansToMeters(): DPolygonLoop;
@@ -35,139 +35,154 @@ var LoopFunctions;
35
35
  LoopFunctions[LoopFunctions["degreeToMeters"] = 29] = "degreeToMeters";
36
36
  LoopFunctions[LoopFunctions["metersToDegree"] = 30] = "metersToDegree";
37
37
  LoopFunctions[LoopFunctions["flipVertically"] = 31] = "flipVertically";
38
+ LoopFunctions[LoopFunctions["setProperties"] = 32] = "setProperties";
39
+ LoopFunctions[LoopFunctions["div"] = 33] = "div";
40
+ LoopFunctions[LoopFunctions["mod"] = 34] = "mod";
38
41
  })(LoopFunctions || (LoopFunctions = {}));
39
42
  var decodePoolRecord = function (a, _a) {
40
- var functionName = _a.functionName, pointArg = _a.pointArg, numberPointArg = _a.numberPointArg, numberArg = _a.numberArg, setterArg = _a.setterArg;
43
+ var functionName = _a.functionName, pointArg = _a.pointArg, numberPointArg = _a.numberPointArg, numberArg = _a.numberArg, setterArg = _a.setterArg, setterArgByObject = _a.setterArgByObject;
41
44
  var res = a;
42
45
  switch (functionName) {
43
46
  case LoopFunctions.getTileFromCoords:
44
- res = function (k) { return a(k)
47
+ res = function (k, index) { return a(k, index)
45
48
  .getTileFromCoords(numberArg); };
46
49
  break;
47
50
  case LoopFunctions.getCoordsFromTile:
48
- res = function (k) { return a(k)
51
+ res = function (k, index) { return a(k, index)
49
52
  .getCoordsFromTile(numberArg); };
50
53
  break;
51
54
  case LoopFunctions.height:
52
- res = function (k) { return a(k)
55
+ res = function (k, index) { return a(k, index)
53
56
  .height(numberArg); };
54
57
  break;
55
58
  case LoopFunctions.setX:
56
- res = function (k) { return a(k)
57
- .setX(setterArg); };
59
+ res = function (k, index) { return typeof setterArg === 'number' ? a(k, index)
60
+ .setX(setterArg) : a(k, index).setX(function (p) { return setterArg(p, index); }); };
58
61
  break;
59
62
  case LoopFunctions.setY:
60
- res = function (k) { return a(k)
61
- .setY(setterArg); };
63
+ res = function (k, index) { return typeof setterArg === 'number' ? a(k, index)
64
+ .setY(setterArg) : a(k, index).setY(function (p) { return setterArg(p, index); }); };
62
65
  break;
63
66
  case LoopFunctions.setZ:
64
- res = function (k) { return a(k)
65
- .setZ(setterArg); };
67
+ res = function (k, index) { return typeof setterArg === 'number' ? a(k, index)
68
+ .setZ(setterArg) : a(k, index).setZ(function (p) { return setterArg(p, index); }); };
66
69
  break;
67
70
  case LoopFunctions.rotate:
68
- res = function (k) { return a(k)
71
+ res = function (k, index) { return a(k, index)
69
72
  .rotate(numberArg); };
70
73
  break;
71
74
  case LoopFunctions.rotate3dX:
72
- res = function (k) { return a(k)
75
+ res = function (k, index) { return a(k, index)
73
76
  .rotate3dX(numberArg); };
74
77
  break;
75
78
  case LoopFunctions.rotate3dY:
76
- res = function (k) { return a(k)
79
+ res = function (k, index) { return a(k, index)
77
80
  .rotate3dY(numberArg); };
78
81
  break;
79
82
  case LoopFunctions.rotate3dZ:
80
- res = function (k) { return a(k)
83
+ res = function (k, index) { return a(k, index)
81
84
  .rotate3dZ(numberArg); };
82
85
  break;
83
86
  case LoopFunctions.move:
84
- res = function (k) { return a(k)
87
+ res = function (k, index) { return a(k, index)
85
88
  .move(numberPointArg, numberArg); };
86
89
  break;
87
90
  case LoopFunctions.round:
88
- res = function (k) { return a(k)
91
+ res = function (k, index) { return a(k, index)
89
92
  .round(); };
90
93
  break;
91
94
  case LoopFunctions.ceil:
92
- res = function (k) { return a(k)
95
+ res = function (k, index) { return a(k, index)
93
96
  .ceil(); };
94
97
  break;
95
98
  case LoopFunctions.floor:
96
- res = function (k) { return a(k)
99
+ res = function (k, index) { return a(k, index)
97
100
  .floor(); };
98
101
  break;
99
102
  case LoopFunctions.toFixed:
100
- res = function (k) { return a(k)
103
+ res = function (k, index) { return a(k, index)
101
104
  .toFixed(numberArg); };
102
105
  break;
103
106
  case LoopFunctions.abs:
104
- res = function (k) { return a(k)
107
+ res = function (k, index) { return a(k, index)
105
108
  .abs(); };
106
109
  break;
107
110
  case LoopFunctions.scale:
108
- res = function (k) { return a(k)
111
+ res = function (k, index) { return a(k, index)
109
112
  .scale(numberPointArg, numberArg); };
110
113
  break;
111
114
  case LoopFunctions.divide:
112
- res = function (k) { return a(k)
115
+ res = function (k, index) { return a(k, index)
113
116
  .divide(numberPointArg, numberArg); };
114
117
  break;
118
+ case LoopFunctions.div:
119
+ res = function (k, index) { return a(k, index)
120
+ .div(numberPointArg, numberArg); };
121
+ break;
122
+ case LoopFunctions.mod:
123
+ res = function (k, index) { return a(k, index)
124
+ .mod(numberPointArg, numberArg); };
125
+ break;
115
126
  case LoopFunctions.degreeToRadians:
116
- res = function (k) { return a(k)
127
+ res = function (k, index) { return a(k, index)
117
128
  .degreeToRadians(); };
118
129
  break;
119
130
  case LoopFunctions.radiansToDegrees:
120
- res = function (k) { return a(k)
131
+ res = function (k, index) { return a(k, index)
121
132
  .radiansToDegrees(); };
122
133
  break;
123
134
  case LoopFunctions.radiansToMeters:
124
- res = function (k) { return a(k)
135
+ res = function (k, index) { return a(k, index)
125
136
  .radiansToMeters(); };
126
137
  break;
127
138
  case LoopFunctions.metersToRadians:
128
- res = function (k) { return a(k)
139
+ res = function (k, index) { return a(k, index)
129
140
  .metersToRadians(); };
130
141
  break;
131
142
  case LoopFunctions.hipPoint:
132
- res = function (k) { return a(k)
143
+ res = function (k, index) { return a(k, index)
133
144
  .hipPoint; };
134
145
  break;
135
146
  case LoopFunctions.xPoint:
136
- res = function (k) { return a(k)
147
+ res = function (k, index) { return a(k, index)
137
148
  .xPoint; };
138
149
  break;
139
150
  case LoopFunctions.yPoint:
140
- res = function (k) { return a(k)
151
+ res = function (k, index) { return a(k, index)
141
152
  .yPoint; };
142
153
  break;
143
154
  case LoopFunctions.wPoint:
144
- res = function (k) { return a(k)
155
+ res = function (k, index) { return a(k, index)
145
156
  .wPoint; };
146
157
  break;
147
158
  case LoopFunctions.hPoint:
148
- res = function (k) { return a(k)
159
+ res = function (k, index) { return a(k, index)
149
160
  .hPoint; };
150
161
  break;
151
162
  case LoopFunctions.setIfLessThan:
152
- res = function (k) { return a(k)
163
+ res = function (k, index) { return a(k, index)
153
164
  .setIfLessThan(pointArg); };
154
165
  break;
155
166
  case LoopFunctions.minus:
156
- res = function (k) { return a(k)
167
+ res = function (k, index) { return a(k, index)
157
168
  .minus(); };
158
169
  break;
159
170
  case LoopFunctions.degreeToMeters:
160
- res = function (k) { return a(k)
171
+ res = function (k, index) { return a(k, index)
161
172
  .degreeToMeters(); };
162
173
  break;
163
174
  case LoopFunctions.metersToDegree:
164
- res = function (k) { return a(k)
175
+ res = function (k, index) { return a(k, index)
165
176
  .metersToDegree(); };
166
177
  break;
167
178
  case LoopFunctions.flipVertically:
168
- res = function (k) { return a(k)
179
+ res = function (k, index) { return a(k, index)
169
180
  .flipVertically(numberPointArg); };
170
181
  break;
182
+ case LoopFunctions.setProperties:
183
+ res = function (k, index) { return typeof setterArgByObject === 'object' ? a(k, index)
184
+ .setProperties(setterArgByObject) : a(k, index).setProperties(function (p) { return setterArgByObject(p, index); }); };
185
+ break;
171
186
  }
172
187
  return res;
173
188
  };
@@ -210,6 +225,13 @@ var DPolygonLoop = (function () {
210
225
  });
211
226
  return this;
212
227
  };
228
+ DPolygonLoop.prototype.setProperties = function (setterArgByObject) {
229
+ this.pool.push({
230
+ functionName: LoopFunctions.setProperties,
231
+ setterArgByObject: setterArgByObject
232
+ });
233
+ return this;
234
+ };
213
235
  DPolygonLoop.prototype.setY = function (y) {
214
236
  this.pool.push({
215
237
  functionName: LoopFunctions.setY,
@@ -310,6 +332,22 @@ var DPolygonLoop = (function () {
310
332
  });
311
333
  return this;
312
334
  };
335
+ DPolygonLoop.prototype.div = function (x, y) {
336
+ this.pool.push({
337
+ functionName: LoopFunctions.div,
338
+ numberPointArg: x,
339
+ numberArg: y
340
+ });
341
+ return this;
342
+ };
343
+ DPolygonLoop.prototype.mod = function (x, y) {
344
+ this.pool.push({
345
+ functionName: LoopFunctions.mod,
346
+ numberPointArg: x,
347
+ numberArg: y
348
+ });
349
+ return this;
350
+ };
313
351
  DPolygonLoop.prototype.degreeToRadians = function () {
314
352
  this.pool.push({
315
353
  functionName: LoopFunctions.degreeToRadians
@@ -39,4 +39,5 @@ export declare const cartesianProduct: {
39
39
  <T>(a: T[], ...b: T[][]): T[][];
40
40
  };
41
41
  export declare const getCombinations: <T>(arr: T[][]) => T[][];
42
+ export declare const div: (a: number, b: number) => number;
42
43
  export {};
package/dist/cjs/utils.js CHANGED
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25
25
  return to.concat(ar || Array.prototype.slice.call(from));
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
28
+ exports.div = exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
29
29
  var DPoint_1 = require("./DPoint");
30
30
  exports.DGeo = {
31
31
  DEBUG: false
@@ -214,3 +214,5 @@ var getCombinations = function (arr) {
214
214
  return ans;
215
215
  };
216
216
  exports.getCombinations = getCombinations;
217
+ var div = function (a, b) { return Math.floor(a / b); };
218
+ exports.div = div;
@@ -1,15 +1,15 @@
1
1
  import { DLine } from './DLine';
2
2
  import { DPolygon } from './DPolygon';
3
- import { checkFunction, createArray, isDefAndNotNull } from './utils';
3
+ import { checkFunction, createArray, div, isDefAndNotNull } from './utils';
4
4
  const diff = 0;
5
5
  const radiansPolygon = new DPolygon();
6
6
  const pseudoMercatorPolygon = new DPolygon();
7
7
  const worldGeodeticPolygon = new DPolygon();
8
- export const EARTH_RADIUS_IN_METERS = 6371008.8;
9
- const EARTH_IN_MITERS = 20037508.34;
8
+ export const EARTH_RADIUS_IN_METERS = 6378137;
9
+ const EARTH_IN_METERS = 20037508.34;
10
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;
11
+ const METERS_IN_ONE_DEGREE = EARTH_IN_METERS / DEGREES_IN_EARTH;
12
+ const DEGREES_IN_ONE_METER = DEGREES_IN_EARTH / EARTH_IN_METERS;
13
13
  export const HALF_PI_IN_DEGREE = 90;
14
14
  export const PI_IN_DEGREE = 180;
15
15
  export const DOUBLE_PI_IN_DEGREE = 360;
@@ -220,6 +220,10 @@ export class DPoint {
220
220
  this.y = typeof y === 'number' ? y : y(this);
221
221
  return this;
222
222
  }
223
+ setProperties(v) {
224
+ this.properties = typeof v === 'object' ? v : v(this);
225
+ return this;
226
+ }
223
227
  clone() {
224
228
  const p = new DPoint(this.x, this.y, this.z);
225
229
  p.properties = Object.assign({}, this.properties);
@@ -291,9 +295,9 @@ export class DPoint {
291
295
  checkFunction('degreeToMeters')
292
296
  .checkArgument('this')
293
297
  .shouldBeDegree(this);
294
- const x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
298
+ const x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) * METERS_IN_ONE_DEGREE;
295
299
  const y = (Math.log(Math.tan(((this.y + HALF_PI_IN_DEGREE) % PI_IN_DEGREE) *
296
- (Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
300
+ (Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) * METERS_IN_ONE_DEGREE;
297
301
  this.x = x;
298
302
  this.y = y;
299
303
  return this;
@@ -302,8 +306,8 @@ export class DPoint {
302
306
  checkFunction('metersToDegree')
303
307
  .checkArgument('this')
304
308
  .shouldBeMeters(this);
305
- const lon = this.x * DEGREES_IN_ONE_MITER;
306
- const lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * PI_TO_DEGREE))) *
309
+ const lon = this.x * DEGREES_IN_ONE_METER;
310
+ const lat = Math.atan(Math.pow(Math.E, ((this.y / METERS_IN_ONE_DEGREE) * PI_TO_DEGREE))) *
307
311
  (DOUBLE_PI_IN_DEGREE / Math.PI) - HALF_PI_IN_DEGREE;
308
312
  this.x = lon;
309
313
  this.y = lat;
@@ -408,6 +412,56 @@ export class DPoint {
408
412
  }
409
413
  return this;
410
414
  }
415
+ mod(x, y = x, z) {
416
+ let xV = 0;
417
+ let yV = 0;
418
+ let zV = undefined;
419
+ if (x instanceof DPoint) {
420
+ xV = this.x % x.x;
421
+ yV = this.y % x.y;
422
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
423
+ zV = this.z % x.z;
424
+ }
425
+ }
426
+ else {
427
+ xV = this.x % x;
428
+ yV = this.y % y;
429
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
430
+ zV = this.z % z;
431
+ }
432
+ }
433
+ this.x = xV;
434
+ this.y = yV;
435
+ if (isDefAndNotNull(zV)) {
436
+ this.z = zV;
437
+ }
438
+ return this;
439
+ }
440
+ div(x, y = x, z) {
441
+ let xV = 0;
442
+ let yV = 0;
443
+ let zV = undefined;
444
+ if (x instanceof DPoint) {
445
+ xV = div(this.x, x.x);
446
+ yV = div(this.y, x.y);
447
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(x.z)) {
448
+ zV = div(this.z, x.z);
449
+ }
450
+ }
451
+ else {
452
+ xV = div(this.x, x);
453
+ yV = div(this.y, y);
454
+ if (isDefAndNotNull(this.z) && isDefAndNotNull(z)) {
455
+ zV = div(this.z, z);
456
+ }
457
+ }
458
+ this.x = xV;
459
+ this.y = yV;
460
+ if (isDefAndNotNull(zV)) {
461
+ this.z = zV;
462
+ }
463
+ return this;
464
+ }
411
465
  equal(p) {
412
466
  return this.x === p.x && this.y === p.y && this.z === p.z;
413
467
  }
@@ -561,4 +615,25 @@ export class DPoint {
561
615
  })
562
616
  .sort((a, b) => a.properties.distance - b.properties.distance);
563
617
  }
618
+ calculateAltitudeByDistanceBetweenPoints(p1, p2) {
619
+ var _a, _b, _c, _d;
620
+ if (p1.alt === p2.alt) {
621
+ this.alt = p1.alt;
622
+ }
623
+ else {
624
+ const minAlt = Math.min((_a = p1.alt) !== null && _a !== void 0 ? _a : 0, (_b = p2.alt) !== null && _b !== void 0 ? _b : 0);
625
+ const maxAlt = Math.max((_c = p1.alt) !== null && _c !== void 0 ? _c : 0, (_d = p2.alt) !== null && _d !== void 0 ? _d : 0);
626
+ const dAlt = maxAlt - minAlt;
627
+ const distance1 = this.distance(p1);
628
+ const distance2 = this.distance(p2);
629
+ const totalDistance = distance1 + distance2;
630
+ if (p1.alt === minAlt) {
631
+ this.alt = minAlt + distance1 / totalDistance * dAlt;
632
+ }
633
+ else {
634
+ this.alt = minAlt + distance2 / totalDistance * dAlt;
635
+ }
636
+ }
637
+ return this;
638
+ }
564
639
  }