dgeoutils 2.2.0 → 2.2.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.
- package/dist/DCircle.d.ts +20 -0
- package/dist/DCircle.js +21 -1
- package/dist/DLine.d.ts +10 -2
- package/dist/DLine.js +32 -2
- package/dist/DPoint.d.ts +24 -0
- package/dist/DPoint.js +24 -0
- package/dist/DPolygon.d.ts +13 -1
- package/dist/DPolygon.js +65 -3
- package/package.json +1 -1
package/dist/DCircle.d.ts
CHANGED
|
@@ -12,11 +12,31 @@ export declare class DCircle {
|
|
|
12
12
|
clone(): DCircle;
|
|
13
13
|
/**
|
|
14
14
|
* Find intersection points with other circle.
|
|
15
|
+
*
|
|
16
|
+
* 
|
|
15
17
|
* @param c
|
|
16
18
|
*/
|
|
17
19
|
findPoints(c: DCircle): DPoint[] | number;
|
|
18
20
|
equal({ center, r }: DCircle): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Transform circle to polygon
|
|
23
|
+
*
|
|
24
|
+
* 
|
|
25
|
+
* @param [pointCount=64]
|
|
26
|
+
*/
|
|
19
27
|
findPolygonInside(pointCount?: number): DPolygon;
|
|
28
|
+
/**
|
|
29
|
+
* Transform circle to polygon on sphere. It would be different for different latitude.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Center should be Lng/Lat.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Radius should be in meters.
|
|
36
|
+
*
|
|
37
|
+
* 
|
|
38
|
+
* @param [pointCount=64]
|
|
39
|
+
*/
|
|
20
40
|
findPolygonInsideOnSphere(pointCount?: number): DPolygon;
|
|
21
41
|
private sphereOffset;
|
|
22
42
|
}
|
package/dist/DCircle.js
CHANGED
|
@@ -23,6 +23,8 @@ class DCircle {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Find intersection points with other circle.
|
|
26
|
+
*
|
|
27
|
+
* 
|
|
26
28
|
* @param c
|
|
27
29
|
*/
|
|
28
30
|
findPoints(c) {
|
|
@@ -57,6 +59,12 @@ class DCircle {
|
|
|
57
59
|
equal({ center, r }) {
|
|
58
60
|
return this.center.equal(center) && this.r === r;
|
|
59
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Transform circle to polygon
|
|
64
|
+
*
|
|
65
|
+
* 
|
|
66
|
+
* @param [pointCount=64]
|
|
67
|
+
*/
|
|
60
68
|
findPolygonInside(pointCount = 64) {
|
|
61
69
|
const preAngle = 2 * Math.PI / pointCount;
|
|
62
70
|
const points = [];
|
|
@@ -68,6 +76,18 @@ class DCircle {
|
|
|
68
76
|
}
|
|
69
77
|
return new DPolygon_1.DPolygon([...points, points[0]]);
|
|
70
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Transform circle to polygon on sphere. It would be different for different latitude.
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* Center should be Lng/Lat.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* Radius should be in meters.
|
|
87
|
+
*
|
|
88
|
+
* 
|
|
89
|
+
* @param [pointCount=64]
|
|
90
|
+
*/
|
|
71
91
|
findPolygonInsideOnSphere(pointCount = 64) {
|
|
72
92
|
(0, utils_1.checkFunction)('findPolygonInsideOnSphere')
|
|
73
93
|
.checkArgument('center')
|
|
@@ -76,7 +96,7 @@ class DCircle {
|
|
|
76
96
|
for (let i = 0; i < pointCount; i++) {
|
|
77
97
|
res.push(this.sphereOffset(2 * Math.PI * i / pointCount));
|
|
78
98
|
}
|
|
79
|
-
return res;
|
|
99
|
+
return res.close();
|
|
80
100
|
}
|
|
81
101
|
sphereOffset(bearing, earthRadius = DPoint_1.EARTH_RADIUS_IN_METERS) {
|
|
82
102
|
const lat1 = DNumbers_1.DNumbers.deg2Rad(this.center.y);
|
package/dist/DLine.d.ts
CHANGED
|
@@ -14,9 +14,10 @@ export declare class DLine {
|
|
|
14
14
|
* Find intersection of two lines segments.
|
|
15
15
|
* For intersection of two lines use [[findPoint]]
|
|
16
16
|
* @param l
|
|
17
|
-
* @param d
|
|
17
|
+
* @param [d=0]
|
|
18
|
+
* @param [includeOnly=false]
|
|
18
19
|
*/
|
|
19
|
-
intersection(l: DLine, d?: number): DPoint | null;
|
|
20
|
+
intersection(l: DLine, d?: number, includeOnly?: boolean): DPoint | null;
|
|
20
21
|
intersectionWithCircle(circle: DCircle): DPoint | [DPoint, DPoint] | null;
|
|
21
22
|
/**
|
|
22
23
|
* Check if point below to line segment
|
|
@@ -24,6 +25,13 @@ export declare class DLine {
|
|
|
24
25
|
* @param d
|
|
25
26
|
*/
|
|
26
27
|
inRange(p: DPoint, d?: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Check if point below to line segment, but not equal star or end point.
|
|
30
|
+
* @param p
|
|
31
|
+
* @param d
|
|
32
|
+
*/
|
|
33
|
+
insideRange(p: DPoint, d?: number): boolean;
|
|
34
|
+
get center(): DPoint;
|
|
27
35
|
get minX(): number;
|
|
28
36
|
get minY(): number;
|
|
29
37
|
get maxX(): number;
|
package/dist/DLine.js
CHANGED
|
@@ -45,11 +45,15 @@ class DLine {
|
|
|
45
45
|
* Find intersection of two lines segments.
|
|
46
46
|
* For intersection of two lines use [[findPoint]]
|
|
47
47
|
* @param l
|
|
48
|
-
* @param d
|
|
48
|
+
* @param [d=0]
|
|
49
|
+
* @param [includeOnly=false]
|
|
49
50
|
*/
|
|
50
|
-
intersection(l, d = 0) {
|
|
51
|
+
intersection(l, d = 0, includeOnly = false) {
|
|
51
52
|
const p = this.findPoint(l);
|
|
52
53
|
if (p) {
|
|
54
|
+
if (includeOnly) {
|
|
55
|
+
return this.insideRange(p, d) && l.insideRange(p, d) ? p : null;
|
|
56
|
+
}
|
|
53
57
|
return this.inRange(p, d) && l.inRange(p, d) ? p : null;
|
|
54
58
|
}
|
|
55
59
|
return null;
|
|
@@ -117,6 +121,32 @@ class DLine {
|
|
|
117
121
|
const isInY = y >= minY - d && y <= maxY + d;
|
|
118
122
|
return isInX && isInY;
|
|
119
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Check if point below to line segment, but not equal star or end point.
|
|
126
|
+
* @param p
|
|
127
|
+
* @param d
|
|
128
|
+
*/
|
|
129
|
+
insideRange(p, d = 0) {
|
|
130
|
+
const { minX, minY, maxX, maxY, p1, p2 } = this;
|
|
131
|
+
const { x, y } = p;
|
|
132
|
+
return this.inRange(p, d) && !p1.like(p, 0.00001) && !p2.like(p, 0.00001);
|
|
133
|
+
const isInX = x > minX - d && x < maxX + d;
|
|
134
|
+
const isInY = y > minY - d && y < maxY + d;
|
|
135
|
+
return isInX && isInY && !p1.like(p, 0.00001) && !p2.like(p, 0.00001);
|
|
136
|
+
}
|
|
137
|
+
get center() {
|
|
138
|
+
return this.p1
|
|
139
|
+
.clone()
|
|
140
|
+
.setIfLessThan(this.p2)
|
|
141
|
+
.move(this.p2
|
|
142
|
+
.clone()
|
|
143
|
+
.move(this.p1
|
|
144
|
+
.clone()
|
|
145
|
+
.minus())
|
|
146
|
+
.abs()
|
|
147
|
+
.minus()
|
|
148
|
+
.divide(2));
|
|
149
|
+
}
|
|
120
150
|
get minX() {
|
|
121
151
|
return Math.min(this.p1.x, this.p2.x);
|
|
122
152
|
}
|
package/dist/DPoint.d.ts
CHANGED
|
@@ -31,7 +31,21 @@ export declare class DPoint {
|
|
|
31
31
|
static isPoint(p: unknown): boolean;
|
|
32
32
|
static parseFromWKT(wkt: string): DPoint;
|
|
33
33
|
static Random(): DPoint;
|
|
34
|
+
/**
|
|
35
|
+
* @remark Point should be Lng/Lat.
|
|
36
|
+
*
|
|
37
|
+
* @remark `z` value default for `zoom` argument.
|
|
38
|
+
*
|
|
39
|
+
* @param [zoom=this.z]
|
|
40
|
+
*/
|
|
34
41
|
getTileFromCoords(zoom?: number): DPoint;
|
|
42
|
+
/**
|
|
43
|
+
* Result would be Lng/Lat.
|
|
44
|
+
*
|
|
45
|
+
* @remark `z` value default for `zoom` argument.
|
|
46
|
+
*
|
|
47
|
+
* @param [zoom=this.z]
|
|
48
|
+
*/
|
|
35
49
|
getCoordsFromTile(zoom?: number): DPoint;
|
|
36
50
|
toCoords(): DCoord;
|
|
37
51
|
/**
|
|
@@ -104,5 +118,15 @@ export declare class DPoint {
|
|
|
104
118
|
};
|
|
105
119
|
setIfLessThan(p: DPoint): DPoint;
|
|
106
120
|
minus(): DPoint;
|
|
121
|
+
/**
|
|
122
|
+
* Find [orthodromic path](https://en.wikipedia.org/wiki/Great-circle_navigation) between to points.
|
|
123
|
+
*
|
|
124
|
+
* @remark Points should be Lng/Lat.
|
|
125
|
+
*
|
|
126
|
+
* 
|
|
127
|
+
*
|
|
128
|
+
* @param point
|
|
129
|
+
* @param [pointsCount=360]
|
|
130
|
+
*/
|
|
107
131
|
orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
|
|
108
132
|
}
|
package/dist/DPoint.js
CHANGED
|
@@ -58,6 +58,13 @@ class DPoint {
|
|
|
58
58
|
static Random() {
|
|
59
59
|
return new DPoint(Math.random(), Math.random());
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* @remark Point should be Lng/Lat.
|
|
63
|
+
*
|
|
64
|
+
* @remark `z` value default for `zoom` argument.
|
|
65
|
+
*
|
|
66
|
+
* @param [zoom=this.z]
|
|
67
|
+
*/
|
|
61
68
|
getTileFromCoords(zoom = this.z) {
|
|
62
69
|
(0, utils_1.checkFunction)('getTileFromCoords')
|
|
63
70
|
.checkArgument('this')
|
|
@@ -66,6 +73,13 @@ class DPoint {
|
|
|
66
73
|
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)));
|
|
67
74
|
return new DPoint(x, y, zoom);
|
|
68
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Result would be Lng/Lat.
|
|
78
|
+
*
|
|
79
|
+
* @remark `z` value default for `zoom` argument.
|
|
80
|
+
*
|
|
81
|
+
* @param [zoom=this.z]
|
|
82
|
+
*/
|
|
69
83
|
getCoordsFromTile(zoom = this.z) {
|
|
70
84
|
(0, utils_1.checkFunction)('getCoordsFromTile')
|
|
71
85
|
.checkArgument('this')
|
|
@@ -402,6 +416,16 @@ class DPoint {
|
|
|
402
416
|
minus() {
|
|
403
417
|
return this.clone().scale(-1);
|
|
404
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Find [orthodromic path](https://en.wikipedia.org/wiki/Great-circle_navigation) between to points.
|
|
421
|
+
*
|
|
422
|
+
* @remark Points should be Lng/Lat.
|
|
423
|
+
*
|
|
424
|
+
* 
|
|
425
|
+
*
|
|
426
|
+
* @param point
|
|
427
|
+
* @param [pointsCount=360]
|
|
428
|
+
*/
|
|
405
429
|
orthodromicPath(point, pointsCount = 360) {
|
|
406
430
|
(0, utils_1.checkFunction)('orthodromicPath')
|
|
407
431
|
.checkArgument('this')
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -130,8 +130,9 @@ export declare class DPolygon {
|
|
|
130
130
|
/**
|
|
131
131
|
* Check polygon intersection with line
|
|
132
132
|
* @param l
|
|
133
|
+
* @param [includeOnly=false]
|
|
133
134
|
*/
|
|
134
|
-
intersection(l: DLine): DPoint[];
|
|
135
|
+
intersection(l: DLine, includeOnly?: boolean): DPoint[];
|
|
135
136
|
/**
|
|
136
137
|
* Set polygon center
|
|
137
138
|
* @param newCenter
|
|
@@ -266,6 +267,17 @@ export declare class DPolygon {
|
|
|
266
267
|
simpleIntersection(p: DPolygon): DPolygon | null | DPolygon[];
|
|
267
268
|
simpleDifference(p: DPolygon): DPolygon | null | DPolygon[];
|
|
268
269
|
smartUnion(p: DPolygon): DPolygon | null;
|
|
270
|
+
/**
|
|
271
|
+
* Divide polygon to triangles
|
|
272
|
+
*
|
|
273
|
+
* 
|
|
274
|
+
*/
|
|
275
|
+
toTriangles(): DPolygon[];
|
|
276
|
+
/**
|
|
277
|
+
* @internal
|
|
278
|
+
*/
|
|
279
|
+
getTriangle(): DPolygon | void;
|
|
280
|
+
private innerAndNotIntersect;
|
|
269
281
|
private simpleIncludeX;
|
|
270
282
|
private simpleIncludeY;
|
|
271
283
|
private douglasPeucker;
|
package/dist/DPolygon.js
CHANGED
|
@@ -386,14 +386,15 @@ class DPolygon {
|
|
|
386
386
|
/**
|
|
387
387
|
* Check polygon intersection with line
|
|
388
388
|
* @param l
|
|
389
|
+
* @param [includeOnly=false]
|
|
389
390
|
*/
|
|
390
|
-
intersection(l) {
|
|
391
|
+
intersection(l, includeOnly = false) {
|
|
391
392
|
const res = [];
|
|
392
393
|
for (let i = 0; i < this.pPoints.length - 1; i++) {
|
|
393
394
|
const p1 = this.pPoints[i];
|
|
394
395
|
const p2 = this.pPoints[i + 1];
|
|
395
396
|
const line = p1.findLine(p2);
|
|
396
|
-
const intersect = line.intersection(l);
|
|
397
|
+
const intersect = line.intersection(l, 0, includeOnly);
|
|
397
398
|
if (intersect) {
|
|
398
399
|
res.push(intersect);
|
|
399
400
|
}
|
|
@@ -662,7 +663,7 @@ class DPolygon {
|
|
|
662
663
|
if (lineWidth) {
|
|
663
664
|
ctx.lineWidth = lineWidth;
|
|
664
665
|
}
|
|
665
|
-
if (fillColor) {
|
|
666
|
+
if (fillColor || strokeColor) {
|
|
666
667
|
ctx.beginPath();
|
|
667
668
|
}
|
|
668
669
|
this.goByPath(ctx, steps % this.length);
|
|
@@ -902,6 +903,67 @@ class DPolygon {
|
|
|
902
903
|
}
|
|
903
904
|
return res;
|
|
904
905
|
}
|
|
906
|
+
/**
|
|
907
|
+
* Divide polygon to triangles
|
|
908
|
+
*
|
|
909
|
+
* 
|
|
910
|
+
*/
|
|
911
|
+
toTriangles() {
|
|
912
|
+
const p = this.clone().clockWise.open();
|
|
913
|
+
while (p.holes.length) {
|
|
914
|
+
const h = p.holes.shift()
|
|
915
|
+
.clone()
|
|
916
|
+
.clockWise
|
|
917
|
+
.reverse()
|
|
918
|
+
.close();
|
|
919
|
+
for (let i = 0; i < p.length; i++) {
|
|
920
|
+
if (p.innerAndNotIntersect(p.first, h.first)) {
|
|
921
|
+
p.insertAfter(0, ...h.points, p.first);
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
924
|
+
p.push(p.shift());
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
const res = [];
|
|
928
|
+
while (p.length > 3) {
|
|
929
|
+
const triangle = p.getTriangle();
|
|
930
|
+
if (triangle) {
|
|
931
|
+
res.push(triangle);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
res.push(p);
|
|
935
|
+
return res;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* @internal
|
|
939
|
+
*/
|
|
940
|
+
getTriangle() {
|
|
941
|
+
for (let i = 0; i < this.length; i++) {
|
|
942
|
+
const p0 = this.p(0);
|
|
943
|
+
const p1 = this.p(1);
|
|
944
|
+
const p2 = this.p(2);
|
|
945
|
+
if (this.innerAndNotIntersect(p0, p2)) {
|
|
946
|
+
this.removePart(0, 1);
|
|
947
|
+
return new DPolygon([
|
|
948
|
+
p0.clone(),
|
|
949
|
+
p1.clone(),
|
|
950
|
+
p2.clone()
|
|
951
|
+
]);
|
|
952
|
+
}
|
|
953
|
+
this.push(this.shift());
|
|
954
|
+
}
|
|
955
|
+
return undefined;
|
|
956
|
+
}
|
|
957
|
+
innerAndNotIntersect(p1, p2) {
|
|
958
|
+
const l = p1.findLine(p2);
|
|
959
|
+
const { center } = l;
|
|
960
|
+
const intersections = this.holes.reduce((a, hole) => a && Boolean(hole.clone().close()
|
|
961
|
+
.intersection(l, true).length), Boolean(this.clone().close()
|
|
962
|
+
.intersection(l, true).length));
|
|
963
|
+
const contain = this.holes.reduce((a, hole) => a && !hole
|
|
964
|
+
.contain(center), this.contain(center));
|
|
965
|
+
return !intersections && contain;
|
|
966
|
+
}
|
|
905
967
|
simpleIncludeX(p) {
|
|
906
968
|
const { x } = p;
|
|
907
969
|
return this.minX <= x && this.maxX >= x;
|