dgeoutils 2.4.12 → 2.4.15
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.
- package/dist/cjs/DPoint.d.ts +11 -7
- package/dist/cjs/DPoint.js +71 -19
- package/dist/cjs/DPolygon.d.ts +2 -2
- package/dist/cjs/DPolygon.js +13 -6
- package/dist/cjs/DPolygonLoop.d.ts +6 -0
- package/dist/cjs/DPolygonLoop.js +26 -0
- package/dist/cjs/utils.d.ts +9 -4
- package/dist/cjs/utils.js +14 -5
- package/dist/es2015/DPoint.js +68 -19
- package/dist/es2015/DPolygon.js +14 -7
- package/dist/es2015/DPolygonLoop.js +26 -0
- package/dist/es2015/utils.js +18 -4
- package/dist/esm/DPoint.js +72 -20
- package/dist/esm/DPolygon.js +14 -7
- package/dist/esm/DPolygonLoop.js +26 -0
- package/dist/esm/utils.js +12 -4
- package/dist/umd/dgeoutils.js +123 -30
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/DPoint.d.ts
CHANGED
|
@@ -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 =
|
|
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;
|
|
@@ -19,9 +19,7 @@ export declare class DPoint {
|
|
|
19
19
|
x: number;
|
|
20
20
|
y: number;
|
|
21
21
|
z?: number | undefined;
|
|
22
|
-
properties:
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
};
|
|
22
|
+
properties: Record<string, any>;
|
|
25
23
|
constructor();
|
|
26
24
|
constructor(xy: number);
|
|
27
25
|
constructor(x: number, y: number);
|
|
@@ -83,6 +81,14 @@ export declare class DPoint {
|
|
|
83
81
|
divide(p: DPoint): DPoint;
|
|
84
82
|
divide(x: number, y: number): DPoint;
|
|
85
83
|
divide(x: number, y: number, z: number): DPoint;
|
|
84
|
+
mod(v: number): DPoint;
|
|
85
|
+
mod(p: DPoint): DPoint;
|
|
86
|
+
mod(x: number, y: number): DPoint;
|
|
87
|
+
mod(x: number, y: number, z: number): DPoint;
|
|
88
|
+
div(v: number): DPoint;
|
|
89
|
+
div(p: DPoint): DPoint;
|
|
90
|
+
div(x: number, y: number): DPoint;
|
|
91
|
+
div(x: number, y: number, z: number): DPoint;
|
|
86
92
|
equal(p: DPoint): boolean;
|
|
87
93
|
like(p: DPoint, d?: number): boolean;
|
|
88
94
|
flipVertically(size: DPoint): DPoint;
|
|
@@ -111,9 +117,7 @@ export declare class DPoint {
|
|
|
111
117
|
set lon(v: number);
|
|
112
118
|
get alt(): number | undefined;
|
|
113
119
|
set alt(v: number | undefined);
|
|
114
|
-
simple(xKey?: string, yKey?: string):
|
|
115
|
-
[key: string]: number;
|
|
116
|
-
};
|
|
120
|
+
simple<T extends Record<string, number>>(xKey?: string, yKey?: string, zKey?: string): T;
|
|
117
121
|
setIfLessThan(p: DPoint): DPoint;
|
|
118
122
|
minus(): DPoint;
|
|
119
123
|
orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
|
package/dist/cjs/DPoint.js
CHANGED
|
@@ -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 =
|
|
39
|
-
var
|
|
38
|
+
exports.EARTH_RADIUS_IN_METERS = 6378137;
|
|
39
|
+
var EARTH_IN_METERS = 20037508.34;
|
|
40
40
|
var DEGREES_IN_EARTH = 180;
|
|
41
|
-
var
|
|
42
|
-
var
|
|
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;
|
|
@@ -58,7 +58,7 @@ var DPoint = (function () {
|
|
|
58
58
|
return new DPoint();
|
|
59
59
|
};
|
|
60
60
|
DPoint.parse = function (c, format) {
|
|
61
|
-
if (format === void 0) { format =
|
|
61
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
62
62
|
var _a = c, lat = _a.lat, lon = _a.lon, _b = _a.lng, lng = _b === void 0 ? lon : _b, alt = _a.alt;
|
|
63
63
|
if (lat && lng) {
|
|
64
64
|
return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
|
|
@@ -157,7 +157,7 @@ var DPoint = (function () {
|
|
|
157
157
|
};
|
|
158
158
|
DPoint.prototype.toCoords = function (format) {
|
|
159
159
|
var _this = this;
|
|
160
|
-
if (format === void 0) { format =
|
|
160
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
161
161
|
return format.replace(/[^x-z]/gmiu, '').split('')
|
|
162
162
|
.map(function (k) { return ({
|
|
163
163
|
x: _this.x,
|
|
@@ -167,7 +167,7 @@ var DPoint = (function () {
|
|
|
167
167
|
.filter(function (r) { return r !== undefined; });
|
|
168
168
|
};
|
|
169
169
|
DPoint.prototype.toGeoJSON = function (format) {
|
|
170
|
-
if (format === void 0) { format =
|
|
170
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
171
171
|
return {
|
|
172
172
|
type: 'Point',
|
|
173
173
|
coordinates: this.toCoords(format)
|
|
@@ -335,9 +335,9 @@ var DPoint = (function () {
|
|
|
335
335
|
(0, utils_1.checkFunction)('degreeToMeters')
|
|
336
336
|
.checkArgument('this')
|
|
337
337
|
.shouldBeDegree(this);
|
|
338
|
-
var x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) *
|
|
338
|
+
var x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * METERS_IN_ONE_DEGREE;
|
|
339
339
|
var y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) *
|
|
340
|
-
(Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) *
|
|
340
|
+
(Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * METERS_IN_ONE_DEGREE;
|
|
341
341
|
this.x = x;
|
|
342
342
|
this.y = y;
|
|
343
343
|
return this;
|
|
@@ -346,8 +346,8 @@ var DPoint = (function () {
|
|
|
346
346
|
(0, utils_1.checkFunction)('metersToDegree')
|
|
347
347
|
.checkArgument('this')
|
|
348
348
|
.shouldBeMeters(this);
|
|
349
|
-
var lon = this.x *
|
|
350
|
-
var lat = Math.atan(Math.pow(Math.E, ((this.y /
|
|
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))) *
|
|
351
351
|
(exports.DOUBLE_PI_IN_DEGREE / Math.PI) - exports.HALF_PI_IN_DEGREE;
|
|
352
352
|
this.x = lon;
|
|
353
353
|
this.y = lat;
|
|
@@ -455,6 +455,58 @@ var DPoint = (function () {
|
|
|
455
455
|
}
|
|
456
456
|
return this;
|
|
457
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
|
+
};
|
|
458
510
|
DPoint.prototype.equal = function (p) {
|
|
459
511
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
460
512
|
};
|
|
@@ -639,14 +691,14 @@ var DPoint = (function () {
|
|
|
639
691
|
enumerable: false,
|
|
640
692
|
configurable: true
|
|
641
693
|
});
|
|
642
|
-
DPoint.prototype.simple = function (xKey, yKey) {
|
|
643
|
-
var _a;
|
|
694
|
+
DPoint.prototype.simple = function (xKey, yKey, zKey) {
|
|
695
|
+
var _a, _b;
|
|
644
696
|
if (xKey === void 0) { xKey = 'x'; }
|
|
645
697
|
if (yKey === void 0) { yKey = 'y'; }
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
698
|
+
if (zKey === void 0) { zKey = 'z'; }
|
|
699
|
+
return __assign((_a = {}, _a[xKey] = this.x, _a[yKey] = this.y, _a), ((0, utils_1.isDefAndNotNull)(this.z) ? (_b = {},
|
|
700
|
+
_b[zKey] = this.z,
|
|
701
|
+
_b) : {}));
|
|
650
702
|
};
|
|
651
703
|
DPoint.prototype.setIfLessThan = function (p) {
|
|
652
704
|
this.x = Math.max(this.x, p.x);
|
|
@@ -687,7 +739,7 @@ var DPoint = (function () {
|
|
|
687
739
|
.sort(function (a, b) { return a.properties.distance - b.properties.distance; });
|
|
688
740
|
};
|
|
689
741
|
DPoint.prototype.calculateAltitudeByDistanceBetweenPoints = function (p1, p2) {
|
|
690
|
-
var _a, _b, _c, _d;
|
|
742
|
+
var _a, _b, _c, _d, _e;
|
|
691
743
|
if (p1.alt === p2.alt) {
|
|
692
744
|
this.alt = p1.alt;
|
|
693
745
|
}
|
|
@@ -698,7 +750,7 @@ var DPoint = (function () {
|
|
|
698
750
|
var distance1 = this.distance(p1);
|
|
699
751
|
var distance2 = this.distance(p2);
|
|
700
752
|
var totalDistance = distance1 + distance2;
|
|
701
|
-
if (p1.alt === minAlt) {
|
|
753
|
+
if (((_e = p1.alt) !== null && _e !== void 0 ? _e : 0) === minAlt) {
|
|
702
754
|
this.alt = minAlt + distance1 / totalDistance * dAlt;
|
|
703
755
|
}
|
|
704
756
|
else {
|
package/dist/cjs/DPolygon.d.ts
CHANGED
|
@@ -94,13 +94,13 @@ export declare class DPolygon {
|
|
|
94
94
|
onBorder(p: DPoint): boolean;
|
|
95
95
|
nextStart(): DPolygon;
|
|
96
96
|
removeDuplicates(): DPolygon;
|
|
97
|
-
static toGeoJSONFeatureCollection(polygons: DPolygon[], format?: string): FeatureCollection<LineString | Polygon
|
|
97
|
+
static toGeoJSONFeatureCollection(polygons: DPolygon[], format?: string): FeatureCollection<LineString | Polygon>;
|
|
98
98
|
static parse(a: LatLng[], format?: string): DPolygon;
|
|
99
99
|
static parse(a: number[][], format?: string): DPolygon;
|
|
100
100
|
static parse(a: DCoord[], format?: string): DPolygon;
|
|
101
101
|
static parse(a: GeoJsonGeometry | Feature | FeatureCollection<LineString | Polygon>, format?: string): DPolygon | DeepArray<DPolygon>;
|
|
102
102
|
toArrayOfCoords(format?: string): DCoord[];
|
|
103
|
-
toGeoJSONFeature(format?: string): Feature<LineString | Polygon
|
|
103
|
+
toGeoJSONFeature(format?: string): Feature<LineString | Polygon>;
|
|
104
104
|
toGeoJSON(format?: string): LineString | Polygon;
|
|
105
105
|
divideToPieces(piecesCount: number, withAltitude?: boolean): DPolygon;
|
|
106
106
|
prepareToFastSearch(): void;
|
package/dist/cjs/DPolygon.js
CHANGED
|
@@ -967,14 +967,14 @@ var DPolygon = (function () {
|
|
|
967
967
|
return this;
|
|
968
968
|
};
|
|
969
969
|
DPolygon.toGeoJSONFeatureCollection = function (polygons, format) {
|
|
970
|
-
if (format === void 0) { format =
|
|
970
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
971
971
|
return {
|
|
972
972
|
type: 'FeatureCollection',
|
|
973
973
|
features: polygons.map(function (polygon) { return polygon.toGeoJSONFeature(format); })
|
|
974
974
|
};
|
|
975
975
|
};
|
|
976
976
|
DPolygon.parse = function (a, format) {
|
|
977
|
-
if (format === void 0) { format =
|
|
977
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
978
978
|
if (a.type) {
|
|
979
979
|
switch (a.type) {
|
|
980
980
|
case 'FeatureCollection':
|
|
@@ -990,7 +990,14 @@ var DPolygon = (function () {
|
|
|
990
990
|
}, []);
|
|
991
991
|
case 'Feature': {
|
|
992
992
|
var t = DPolygon.parse(a.geometry, format);
|
|
993
|
-
|
|
993
|
+
if (Array.isArray(t)) {
|
|
994
|
+
t.forEach(function (record) {
|
|
995
|
+
record.properties = __assign(__assign({}, a.properties), { id: a.id });
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
t.properties = __assign(__assign({}, a.properties), { id: a.id });
|
|
1000
|
+
}
|
|
994
1001
|
return t;
|
|
995
1002
|
}
|
|
996
1003
|
case 'LineString':
|
|
@@ -1031,11 +1038,11 @@ var DPolygon = (function () {
|
|
|
1031
1038
|
.map(function (r) { return DPoint_1.DPoint.parse(r, format); }));
|
|
1032
1039
|
};
|
|
1033
1040
|
DPolygon.prototype.toArrayOfCoords = function (format) {
|
|
1034
|
-
if (format === void 0) { format =
|
|
1041
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
1035
1042
|
return this.mapArray(function (r) { return r.toCoords(format); });
|
|
1036
1043
|
};
|
|
1037
1044
|
DPolygon.prototype.toGeoJSONFeature = function (format) {
|
|
1038
|
-
if (format === void 0) { format =
|
|
1045
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
1039
1046
|
return {
|
|
1040
1047
|
type: 'Feature',
|
|
1041
1048
|
properties: __assign({}, this.properties),
|
|
@@ -1043,7 +1050,7 @@ var DPolygon = (function () {
|
|
|
1043
1050
|
};
|
|
1044
1051
|
};
|
|
1045
1052
|
DPolygon.prototype.toGeoJSON = function (format) {
|
|
1046
|
-
if (format === void 0) { format =
|
|
1053
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
1047
1054
|
if (this.closed) {
|
|
1048
1055
|
return {
|
|
1049
1056
|
type: 'Polygon',
|
|
@@ -36,6 +36,12 @@ export declare class DPolygonLoop {
|
|
|
36
36
|
divide(v: number): DPolygonLoop;
|
|
37
37
|
divide(p: DPoint): DPolygonLoop;
|
|
38
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;
|
|
39
45
|
degreeToRadians(): DPolygonLoop;
|
|
40
46
|
radiansToDegrees(): DPolygonLoop;
|
|
41
47
|
radiansToMeters(): DPolygonLoop;
|
package/dist/cjs/DPolygonLoop.js
CHANGED
|
@@ -36,6 +36,8 @@ var LoopFunctions;
|
|
|
36
36
|
LoopFunctions[LoopFunctions["metersToDegree"] = 30] = "metersToDegree";
|
|
37
37
|
LoopFunctions[LoopFunctions["flipVertically"] = 31] = "flipVertically";
|
|
38
38
|
LoopFunctions[LoopFunctions["setProperties"] = 32] = "setProperties";
|
|
39
|
+
LoopFunctions[LoopFunctions["div"] = 33] = "div";
|
|
40
|
+
LoopFunctions[LoopFunctions["mod"] = 34] = "mod";
|
|
39
41
|
})(LoopFunctions || (LoopFunctions = {}));
|
|
40
42
|
var decodePoolRecord = function (a, _a) {
|
|
41
43
|
var functionName = _a.functionName, pointArg = _a.pointArg, numberPointArg = _a.numberPointArg, numberArg = _a.numberArg, setterArg = _a.setterArg, setterArgByObject = _a.setterArgByObject;
|
|
@@ -113,6 +115,14 @@ var decodePoolRecord = function (a, _a) {
|
|
|
113
115
|
res = function (k, index) { return a(k, index)
|
|
114
116
|
.divide(numberPointArg, numberArg); };
|
|
115
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;
|
|
116
126
|
case LoopFunctions.degreeToRadians:
|
|
117
127
|
res = function (k, index) { return a(k, index)
|
|
118
128
|
.degreeToRadians(); };
|
|
@@ -322,6 +332,22 @@ var DPolygonLoop = (function () {
|
|
|
322
332
|
});
|
|
323
333
|
return this;
|
|
324
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
|
+
};
|
|
325
351
|
DPolygonLoop.prototype.degreeToRadians = function () {
|
|
326
352
|
this.pool.push({
|
|
327
353
|
functionName: LoopFunctions.degreeToRadians
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="offscreencanvas" />
|
|
2
2
|
import { DPoint } from './DPoint';
|
|
3
|
-
|
|
3
|
+
interface DGeoInterface {
|
|
4
4
|
DEBUG: boolean;
|
|
5
|
-
|
|
5
|
+
parseFormat: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const DGeo: DGeoInterface;
|
|
6
8
|
export declare const warn: (...args: any[]) => void;
|
|
7
9
|
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
8
10
|
declare type CheckFunc = (p: DPoint) => CheckFunction;
|
|
@@ -19,8 +21,10 @@ interface CheckFunction {
|
|
|
19
21
|
checkArgument: (argName: string) => CheckArgument;
|
|
20
22
|
}
|
|
21
23
|
export declare const checkFunction: (funcName: string) => CheckFunction;
|
|
22
|
-
|
|
23
|
-
export declare const
|
|
24
|
+
declare type ArrayFillFunction<T> = (index: number) => T;
|
|
25
|
+
export declare const createArray: <T = number>(v: number, fillSymbol?: T | ArrayFillFunction<T> | undefined) => T[];
|
|
26
|
+
declare type MatrixFillFunction<T> = (x: number, y: number) => T;
|
|
27
|
+
export declare const createMatrix: <T>({ h, w }: DPoint, fillSymbol?: T | MatrixFillFunction<T> | undefined) => T[][];
|
|
24
28
|
export declare const gaussianElimination: {
|
|
25
29
|
(matrix: number[][]): number[];
|
|
26
30
|
MIN: number;
|
|
@@ -39,4 +43,5 @@ export declare const cartesianProduct: {
|
|
|
39
43
|
<T>(a: T[], ...b: T[][]): T[][];
|
|
40
44
|
};
|
|
41
45
|
export declare const getCombinations: <T>(arr: T[][]) => T[][];
|
|
46
|
+
export declare const div: (a: number, b: number) => number;
|
|
42
47
|
export {};
|
package/dist/cjs/utils.js
CHANGED
|
@@ -25,10 +25,11 @@ 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
|
-
DEBUG: false
|
|
31
|
+
DEBUG: false,
|
|
32
|
+
parseFormat: 'xyz'
|
|
32
33
|
};
|
|
33
34
|
var warn = function () {
|
|
34
35
|
var args = [];
|
|
@@ -105,13 +106,19 @@ var checkFunction = function (funcName) { return ({
|
|
|
105
106
|
}); };
|
|
106
107
|
exports.checkFunction = checkFunction;
|
|
107
108
|
var createArray = function (v, fillSymbol) {
|
|
108
|
-
if (fillSymbol ===
|
|
109
|
-
|
|
109
|
+
if (typeof fillSymbol === 'function') {
|
|
110
|
+
return new Array(v).fill(false)
|
|
111
|
+
.map(function (_, i) { return fillSymbol(i); });
|
|
112
|
+
}
|
|
113
|
+
return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
|
|
110
114
|
};
|
|
111
115
|
exports.createArray = createArray;
|
|
112
116
|
var createMatrix = function (_a, fillSymbol) {
|
|
113
117
|
var h = _a.h, w = _a.w;
|
|
114
|
-
if (fillSymbol ===
|
|
118
|
+
if (typeof fillSymbol === 'function') {
|
|
119
|
+
return (0, exports.createArray)(h)
|
|
120
|
+
.map(function (_, y) { return (0, exports.createArray)(w, function (x) { return fillSymbol(x, y); }); });
|
|
121
|
+
}
|
|
115
122
|
return (0, exports.createArray)(h)
|
|
116
123
|
.map(function () { return (0, exports.createArray)(w, fillSymbol); });
|
|
117
124
|
};
|
|
@@ -214,3 +221,5 @@ var getCombinations = function (arr) {
|
|
|
214
221
|
return ans;
|
|
215
222
|
};
|
|
216
223
|
exports.getCombinations = getCombinations;
|
|
224
|
+
var div = function (a, b) { return Math.floor(a / b); };
|
|
225
|
+
exports.div = div;
|
package/dist/es2015/DPoint.js
CHANGED
|
@@ -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, DGeo, 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 =
|
|
9
|
-
const
|
|
8
|
+
export const EARTH_RADIUS_IN_METERS = 6378137;
|
|
9
|
+
const EARTH_IN_METERS = 20037508.34;
|
|
10
10
|
const DEGREES_IN_EARTH = 180;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
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;
|
|
@@ -25,7 +25,7 @@ export class DPoint {
|
|
|
25
25
|
static zero() {
|
|
26
26
|
return new DPoint();
|
|
27
27
|
}
|
|
28
|
-
static parse(c, format =
|
|
28
|
+
static parse(c, format = DGeo.parseFormat) {
|
|
29
29
|
const { lat, lon, lng = lon, alt } = c;
|
|
30
30
|
if (lat && lng) {
|
|
31
31
|
return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
|
|
@@ -119,7 +119,7 @@ export class DPoint {
|
|
|
119
119
|
const y = PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
|
|
120
120
|
return new DPoint(x, y, zoom);
|
|
121
121
|
}
|
|
122
|
-
toCoords(format =
|
|
122
|
+
toCoords(format = DGeo.parseFormat) {
|
|
123
123
|
return format.replace(/[^x-z]/gmiu, '').split('')
|
|
124
124
|
.map((k) => ({
|
|
125
125
|
x: this.x,
|
|
@@ -128,7 +128,7 @@ export class DPoint {
|
|
|
128
128
|
})[k])
|
|
129
129
|
.filter((r) => r !== undefined);
|
|
130
130
|
}
|
|
131
|
-
toGeoJSON(format =
|
|
131
|
+
toGeoJSON(format = DGeo.parseFormat) {
|
|
132
132
|
return {
|
|
133
133
|
type: 'Point',
|
|
134
134
|
coordinates: this.toCoords(format)
|
|
@@ -295,9 +295,9 @@ export class DPoint {
|
|
|
295
295
|
checkFunction('degreeToMeters')
|
|
296
296
|
.checkArgument('this')
|
|
297
297
|
.shouldBeDegree(this);
|
|
298
|
-
const x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) *
|
|
298
|
+
const x = ((this.x + PI_IN_DEGREE) % DOUBLE_PI_IN_DEGREE - PI_IN_DEGREE) * METERS_IN_ONE_DEGREE;
|
|
299
299
|
const y = (Math.log(Math.tan(((this.y + HALF_PI_IN_DEGREE) % PI_IN_DEGREE) *
|
|
300
|
-
(Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) *
|
|
300
|
+
(Math.PI / DOUBLE_PI_IN_DEGREE))) / PI_TO_DEGREE) * METERS_IN_ONE_DEGREE;
|
|
301
301
|
this.x = x;
|
|
302
302
|
this.y = y;
|
|
303
303
|
return this;
|
|
@@ -306,8 +306,8 @@ export class DPoint {
|
|
|
306
306
|
checkFunction('metersToDegree')
|
|
307
307
|
.checkArgument('this')
|
|
308
308
|
.shouldBeMeters(this);
|
|
309
|
-
const lon = this.x *
|
|
310
|
-
const lat = Math.atan(Math.pow(Math.E, ((this.y /
|
|
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))) *
|
|
311
311
|
(DOUBLE_PI_IN_DEGREE / Math.PI) - HALF_PI_IN_DEGREE;
|
|
312
312
|
this.x = lon;
|
|
313
313
|
this.y = lat;
|
|
@@ -412,6 +412,56 @@ export class DPoint {
|
|
|
412
412
|
}
|
|
413
413
|
return this;
|
|
414
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
|
+
}
|
|
415
465
|
equal(p) {
|
|
416
466
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
417
467
|
}
|
|
@@ -523,11 +573,10 @@ export class DPoint {
|
|
|
523
573
|
set alt(v) {
|
|
524
574
|
this.z = v;
|
|
525
575
|
}
|
|
526
|
-
simple(xKey = 'x', yKey = 'y') {
|
|
527
|
-
return {
|
|
528
|
-
[
|
|
529
|
-
|
|
530
|
-
};
|
|
576
|
+
simple(xKey = 'x', yKey = 'y', zKey = 'z') {
|
|
577
|
+
return Object.assign({ [xKey]: this.x, [yKey]: this.y }, (isDefAndNotNull(this.z) ? {
|
|
578
|
+
[zKey]: this.z
|
|
579
|
+
} : {}));
|
|
531
580
|
}
|
|
532
581
|
setIfLessThan(p) {
|
|
533
582
|
this.x = Math.max(this.x, p.x);
|
|
@@ -566,7 +615,7 @@ export class DPoint {
|
|
|
566
615
|
.sort((a, b) => a.properties.distance - b.properties.distance);
|
|
567
616
|
}
|
|
568
617
|
calculateAltitudeByDistanceBetweenPoints(p1, p2) {
|
|
569
|
-
var _a, _b, _c, _d;
|
|
618
|
+
var _a, _b, _c, _d, _e;
|
|
570
619
|
if (p1.alt === p2.alt) {
|
|
571
620
|
this.alt = p1.alt;
|
|
572
621
|
}
|
|
@@ -577,7 +626,7 @@ export class DPoint {
|
|
|
577
626
|
const distance1 = this.distance(p1);
|
|
578
627
|
const distance2 = this.distance(p2);
|
|
579
628
|
const totalDistance = distance1 + distance2;
|
|
580
|
-
if (p1.alt === minAlt) {
|
|
629
|
+
if (((_e = p1.alt) !== null && _e !== void 0 ? _e : 0) === minAlt) {
|
|
581
630
|
this.alt = minAlt + distance1 / totalDistance * dAlt;
|
|
582
631
|
}
|
|
583
632
|
else {
|
package/dist/es2015/DPolygon.js
CHANGED
|
@@ -4,7 +4,7 @@ import { DCircle } from './DCircle';
|
|
|
4
4
|
import { DNumbers } from './DNumbers';
|
|
5
5
|
import { io as jstsIo, operation } from 'jsts';
|
|
6
6
|
import { DPolygonLoop } from './DPolygonLoop';
|
|
7
|
-
import { isDefAndNotNull } from './utils';
|
|
7
|
+
import { DGeo, isDefAndNotNull } from './utils';
|
|
8
8
|
const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = operation;
|
|
9
9
|
export const MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
10
10
|
const APPROXIMATION_VALUE = 0.1;
|
|
@@ -618,13 +618,13 @@ export class DPolygon {
|
|
|
618
618
|
}
|
|
619
619
|
return this;
|
|
620
620
|
}
|
|
621
|
-
static toGeoJSONFeatureCollection(polygons, format =
|
|
621
|
+
static toGeoJSONFeatureCollection(polygons, format = DGeo.parseFormat) {
|
|
622
622
|
return {
|
|
623
623
|
type: 'FeatureCollection',
|
|
624
624
|
features: polygons.map((polygon) => polygon.toGeoJSONFeature(format))
|
|
625
625
|
};
|
|
626
626
|
}
|
|
627
|
-
static parse(a, format =
|
|
627
|
+
static parse(a, format = DGeo.parseFormat) {
|
|
628
628
|
if (a.type) {
|
|
629
629
|
switch (a.type) {
|
|
630
630
|
case 'FeatureCollection':
|
|
@@ -640,7 +640,14 @@ export class DPolygon {
|
|
|
640
640
|
}, []);
|
|
641
641
|
case 'Feature': {
|
|
642
642
|
const t = DPolygon.parse(a.geometry, format);
|
|
643
|
-
|
|
643
|
+
if (Array.isArray(t)) {
|
|
644
|
+
t.forEach((record) => {
|
|
645
|
+
record.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
t.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
|
|
650
|
+
}
|
|
644
651
|
return t;
|
|
645
652
|
}
|
|
646
653
|
case 'LineString':
|
|
@@ -680,17 +687,17 @@ export class DPolygon {
|
|
|
680
687
|
return new DPolygon(a
|
|
681
688
|
.map((r) => DPoint.parse(r, format)));
|
|
682
689
|
}
|
|
683
|
-
toArrayOfCoords(format =
|
|
690
|
+
toArrayOfCoords(format = DGeo.parseFormat) {
|
|
684
691
|
return this.mapArray((r) => r.toCoords(format));
|
|
685
692
|
}
|
|
686
|
-
toGeoJSONFeature(format =
|
|
693
|
+
toGeoJSONFeature(format = DGeo.parseFormat) {
|
|
687
694
|
return {
|
|
688
695
|
type: 'Feature',
|
|
689
696
|
properties: Object.assign({}, this.properties),
|
|
690
697
|
geometry: this.toGeoJSON(format)
|
|
691
698
|
};
|
|
692
699
|
}
|
|
693
|
-
toGeoJSON(format =
|
|
700
|
+
toGeoJSON(format = DGeo.parseFormat) {
|
|
694
701
|
if (this.closed) {
|
|
695
702
|
return {
|
|
696
703
|
type: 'Polygon',
|