dgeoutils 2.1.0 → 2.2.3
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 +25 -1
- package/dist/DCircle.js +29 -5
- package/dist/DLine.d.ts +10 -2
- package/dist/DLine.js +32 -8
- package/dist/DPoint.d.ts +126 -12
- package/dist/DPoint.js +46 -22
- package/dist/DPolygon.d.ts +26 -32
- package/dist/DPolygon.js +114 -144
- package/dist/DPolygonLoop.d.ts +87 -8
- package/dist/DPolygonLoop.js +265 -62
- package/dist/TraceMatrix.js +7 -9
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +4 -2
- package/package.json +1 -1
package/dist/DCircle.d.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { DPolygon } from './DPolygon';
|
|
|
3
3
|
export declare class DCircle {
|
|
4
4
|
center: DPoint;
|
|
5
5
|
r: number;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param [center=(0,0)]
|
|
8
|
+
* @param [r=0]
|
|
9
|
+
*/
|
|
10
|
+
constructor(center?: DPoint, r?: number);
|
|
7
11
|
toString(): string;
|
|
8
12
|
getValue(): {
|
|
9
13
|
center: DPoint;
|
|
@@ -12,11 +16,31 @@ export declare class DCircle {
|
|
|
12
16
|
clone(): DCircle;
|
|
13
17
|
/**
|
|
14
18
|
* Find intersection points with other circle.
|
|
19
|
+
*
|
|
20
|
+
* 
|
|
15
21
|
* @param c
|
|
16
22
|
*/
|
|
17
23
|
findPoints(c: DCircle): DPoint[] | number;
|
|
18
24
|
equal({ center, r }: DCircle): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Transform circle to polygon
|
|
27
|
+
*
|
|
28
|
+
* 
|
|
29
|
+
* @param [pointCount=64]
|
|
30
|
+
*/
|
|
19
31
|
findPolygonInside(pointCount?: number): DPolygon;
|
|
32
|
+
/**
|
|
33
|
+
* Transform circle to polygon on sphere. It would be different for different latitude.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Center should be Lng/Lat.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Radius should be in meters.
|
|
40
|
+
*
|
|
41
|
+
* 
|
|
42
|
+
* @param [pointCount=64]
|
|
43
|
+
*/
|
|
20
44
|
findPolygonInsideOnSphere(pointCount?: number): DPolygon;
|
|
21
45
|
private sphereOffset;
|
|
22
46
|
}
|
package/dist/DCircle.js
CHANGED
|
@@ -5,12 +5,16 @@ const DPoint_1 = require("./DPoint");
|
|
|
5
5
|
const DPolygon_1 = require("./DPolygon");
|
|
6
6
|
const DNumbers_1 = require("./DNumbers");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
|
+
// eslint-disable-next-line padded-blocks
|
|
8
9
|
class DCircle {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param [center=(0,0)]
|
|
12
|
+
* @param [r=0]
|
|
13
|
+
*/
|
|
14
|
+
// eslint-disable-next-line no-useless-constructor,no-empty-function
|
|
15
|
+
constructor(center = DPoint_1.DPoint.zero(), r = 0) {
|
|
13
16
|
this.center = center;
|
|
17
|
+
this.r = r;
|
|
14
18
|
}
|
|
15
19
|
toString() {
|
|
16
20
|
return `(${this.center.toString()}, ${this.r})`;
|
|
@@ -23,6 +27,8 @@ class DCircle {
|
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
29
|
* Find intersection points with other circle.
|
|
30
|
+
*
|
|
31
|
+
* 
|
|
26
32
|
* @param c
|
|
27
33
|
*/
|
|
28
34
|
findPoints(c) {
|
|
@@ -57,6 +63,12 @@ class DCircle {
|
|
|
57
63
|
equal({ center, r }) {
|
|
58
64
|
return this.center.equal(center) && this.r === r;
|
|
59
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Transform circle to polygon
|
|
68
|
+
*
|
|
69
|
+
* 
|
|
70
|
+
* @param [pointCount=64]
|
|
71
|
+
*/
|
|
60
72
|
findPolygonInside(pointCount = 64) {
|
|
61
73
|
const preAngle = 2 * Math.PI / pointCount;
|
|
62
74
|
const points = [];
|
|
@@ -68,6 +80,18 @@ class DCircle {
|
|
|
68
80
|
}
|
|
69
81
|
return new DPolygon_1.DPolygon([...points, points[0]]);
|
|
70
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Transform circle to polygon on sphere. It would be different for different latitude.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* Center should be Lng/Lat.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* Radius should be in meters.
|
|
91
|
+
*
|
|
92
|
+
* 
|
|
93
|
+
* @param [pointCount=64]
|
|
94
|
+
*/
|
|
71
95
|
findPolygonInsideOnSphere(pointCount = 64) {
|
|
72
96
|
(0, utils_1.checkFunction)('findPolygonInsideOnSphere')
|
|
73
97
|
.checkArgument('center')
|
|
@@ -76,7 +100,7 @@ class DCircle {
|
|
|
76
100
|
for (let i = 0; i < pointCount; i++) {
|
|
77
101
|
res.push(this.sphereOffset(2 * Math.PI * i / pointCount));
|
|
78
102
|
}
|
|
79
|
-
return res;
|
|
103
|
+
return res.close();
|
|
80
104
|
}
|
|
81
105
|
sphereOffset(bearing, earthRadius = DPoint_1.EARTH_RADIUS_IN_METERS) {
|
|
82
106
|
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=0]
|
|
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
|
@@ -4,12 +4,10 @@ exports.DLine = void 0;
|
|
|
4
4
|
const DPoint_1 = require("./DPoint");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
class DLine {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.p1 = DPoint_1.DPoint.Zero();
|
|
12
|
-
this.p2 = DPoint_1.DPoint.Zero();
|
|
7
|
+
// eslint-disable-next-line no-useless-constructor
|
|
8
|
+
constructor(a = 0, b = 0, c = 0, p1 = DPoint_1.DPoint.zero(), p2 = DPoint_1.DPoint.zero()
|
|
9
|
+
// eslint-disable-next-line no-empty-function
|
|
10
|
+
) {
|
|
13
11
|
this.a = a;
|
|
14
12
|
this.b = b;
|
|
15
13
|
this.c = c;
|
|
@@ -45,11 +43,15 @@ class DLine {
|
|
|
45
43
|
* Find intersection of two lines segments.
|
|
46
44
|
* For intersection of two lines use [[findPoint]]
|
|
47
45
|
* @param l
|
|
48
|
-
* @param d
|
|
46
|
+
* @param [d=0]
|
|
47
|
+
* @param [includeOnly=false]
|
|
49
48
|
*/
|
|
50
|
-
intersection(l, d = 0) {
|
|
49
|
+
intersection(l, d = 0, includeOnly = false) {
|
|
51
50
|
const p = this.findPoint(l);
|
|
52
51
|
if (p) {
|
|
52
|
+
if (includeOnly) {
|
|
53
|
+
return this.insideRange(p, d) && l.insideRange(p, d) ? p : null;
|
|
54
|
+
}
|
|
53
55
|
return this.inRange(p, d) && l.inRange(p, d) ? p : null;
|
|
54
56
|
}
|
|
55
57
|
return null;
|
|
@@ -117,6 +119,28 @@ class DLine {
|
|
|
117
119
|
const isInY = y >= minY - d && y <= maxY + d;
|
|
118
120
|
return isInX && isInY;
|
|
119
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if point below to line segment, but not equal star or end point.
|
|
124
|
+
* @param p
|
|
125
|
+
* @param [d=0]
|
|
126
|
+
*/
|
|
127
|
+
insideRange(p, d = 0) {
|
|
128
|
+
const { p1, p2 } = this;
|
|
129
|
+
return this.inRange(p, d) && !p1.like(p, 0.00001) && !p2.like(p, 0.00001);
|
|
130
|
+
}
|
|
131
|
+
get center() {
|
|
132
|
+
return this.p1
|
|
133
|
+
.clone()
|
|
134
|
+
.setIfLessThan(this.p2)
|
|
135
|
+
.move(this.p2
|
|
136
|
+
.clone()
|
|
137
|
+
.move(this.p1
|
|
138
|
+
.clone()
|
|
139
|
+
.minus())
|
|
140
|
+
.abs()
|
|
141
|
+
.minus()
|
|
142
|
+
.divide(2));
|
|
143
|
+
}
|
|
120
144
|
get minX() {
|
|
121
145
|
return Math.min(this.p1.x, this.p2.x);
|
|
122
146
|
}
|
package/dist/DPoint.d.ts
CHANGED
|
@@ -15,23 +15,48 @@ export declare type SetterFunction = (t: DPoint) => number;
|
|
|
15
15
|
export declare class DPoint {
|
|
16
16
|
x: number;
|
|
17
17
|
y: number;
|
|
18
|
-
z?: number;
|
|
18
|
+
z?: number | undefined;
|
|
19
19
|
properties: {
|
|
20
20
|
[key: string]: any;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Create point with zero coords `(0, 0)`
|
|
24
|
+
*/
|
|
25
|
+
constructor();
|
|
26
|
+
/**
|
|
27
|
+
* @param xy - `x` and `y` value
|
|
28
|
+
*/
|
|
29
|
+
constructor(xy: number);
|
|
30
|
+
/**
|
|
31
|
+
* @param x - lng, meters to East, radians to East or width
|
|
32
|
+
* @param y - lat, meters to North, radians to North or height
|
|
33
|
+
*/
|
|
34
|
+
constructor(x: number, y: number);
|
|
35
|
+
/**
|
|
24
36
|
* @param x - lng, meters to East, radians to East or width
|
|
25
37
|
* @param y - lat, meters to North, radians to North or height
|
|
26
38
|
* @param z - height
|
|
27
39
|
*/
|
|
28
|
-
constructor(x
|
|
29
|
-
static
|
|
40
|
+
constructor(x: number, y: number, z?: number);
|
|
41
|
+
static zero(): DPoint;
|
|
30
42
|
static parse(c: LatLng | number[] | DCoord): DPoint;
|
|
31
|
-
static isPoint(p: unknown): boolean;
|
|
32
43
|
static parseFromWKT(wkt: string): DPoint;
|
|
33
|
-
static
|
|
44
|
+
static random(): DPoint;
|
|
45
|
+
/**
|
|
46
|
+
* @remark Point should be Lng/Lat.
|
|
47
|
+
*
|
|
48
|
+
* @remark `z` value default for `zoom` argument.
|
|
49
|
+
*
|
|
50
|
+
* @param [zoom=this.z]
|
|
51
|
+
*/
|
|
34
52
|
getTileFromCoords(zoom?: number): DPoint;
|
|
53
|
+
/**
|
|
54
|
+
* Result would be Lng/Lat.
|
|
55
|
+
*
|
|
56
|
+
* @remark `z` value default for `zoom` argument.
|
|
57
|
+
*
|
|
58
|
+
* @param [zoom=this.z]
|
|
59
|
+
*/
|
|
35
60
|
getCoordsFromTile(zoom?: number): DPoint;
|
|
36
61
|
toCoords(): DCoord;
|
|
37
62
|
/**
|
|
@@ -45,8 +70,26 @@ export declare class DPoint {
|
|
|
45
70
|
height(z: number): DPoint;
|
|
46
71
|
toWKT(): string;
|
|
47
72
|
distance(p: DPoint): number;
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Set `x` value
|
|
75
|
+
* @param x
|
|
76
|
+
*/
|
|
77
|
+
setX(x: number): DPoint;
|
|
78
|
+
/**
|
|
79
|
+
* Transform `x` value by function
|
|
80
|
+
* @param f
|
|
81
|
+
*/
|
|
82
|
+
setX(f: SetterFunction): DPoint;
|
|
83
|
+
/**
|
|
84
|
+
* Set `y` value
|
|
85
|
+
* @param y
|
|
86
|
+
*/
|
|
87
|
+
setY(y: number): DPoint;
|
|
88
|
+
/**
|
|
89
|
+
* Transform `y` value by function
|
|
90
|
+
* @param f
|
|
91
|
+
*/
|
|
92
|
+
setY(f: SetterFunction): DPoint;
|
|
50
93
|
clone(): DPoint;
|
|
51
94
|
gt(p: DPoint): boolean;
|
|
52
95
|
lt(p: DPoint): boolean;
|
|
@@ -57,7 +100,22 @@ export declare class DPoint {
|
|
|
57
100
|
* @param a radians
|
|
58
101
|
*/
|
|
59
102
|
rotate(a: number): DPoint;
|
|
60
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Add `v` to `x` and `y`
|
|
105
|
+
* @param v
|
|
106
|
+
*/
|
|
107
|
+
move(v: number): DPoint;
|
|
108
|
+
/**
|
|
109
|
+
* Add `p.x` to `x` field and `p.y` to `y` field.
|
|
110
|
+
* @param p
|
|
111
|
+
*/
|
|
112
|
+
move(p: DPoint): DPoint;
|
|
113
|
+
/**
|
|
114
|
+
* Add `x` to `x` field and `y` to `y` field.
|
|
115
|
+
* @param x
|
|
116
|
+
* @param y
|
|
117
|
+
*/
|
|
118
|
+
move(x: number, y: number): DPoint;
|
|
61
119
|
degreeToMeters(): DPoint;
|
|
62
120
|
metersToDegree(): DPoint;
|
|
63
121
|
degreeToRadians(): DPoint;
|
|
@@ -67,13 +125,59 @@ export declare class DPoint {
|
|
|
67
125
|
round(): DPoint;
|
|
68
126
|
ceil(): DPoint;
|
|
69
127
|
floor(): DPoint;
|
|
128
|
+
/**
|
|
129
|
+
* @param [n=2]
|
|
130
|
+
*/
|
|
70
131
|
toFixed(n?: number): DPoint;
|
|
71
132
|
abs(): DPoint;
|
|
72
|
-
|
|
73
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Multiply `v` to `x` and `y`
|
|
135
|
+
* @param v
|
|
136
|
+
*/
|
|
137
|
+
scale(v: number): DPoint;
|
|
138
|
+
/**
|
|
139
|
+
* Multiply `p.x` to `x` field and `p.y` to `y` field.
|
|
140
|
+
* @param p
|
|
141
|
+
*/
|
|
142
|
+
scale(p: DPoint): DPoint;
|
|
143
|
+
/**
|
|
144
|
+
* Multiply `x` to `x` field and `y` to `y` field.
|
|
145
|
+
* @param x
|
|
146
|
+
* @param y
|
|
147
|
+
*/
|
|
148
|
+
scale(x: number, y: number): DPoint;
|
|
149
|
+
/**
|
|
150
|
+
* Divide `x` and `y` to `v`
|
|
151
|
+
* @param v
|
|
152
|
+
*/
|
|
153
|
+
divide(v: number): DPoint;
|
|
154
|
+
/**
|
|
155
|
+
* Divide `x` field to `p.x` and `y` field to `p.y`.
|
|
156
|
+
* @param p
|
|
157
|
+
*/
|
|
158
|
+
divide(p: DPoint): DPoint;
|
|
159
|
+
/**
|
|
160
|
+
* Divide `x` field to `x` and `y` field to `y`.
|
|
161
|
+
* @param x
|
|
162
|
+
* @param y
|
|
163
|
+
*/
|
|
164
|
+
divide(x: number, y: number): DPoint;
|
|
74
165
|
equal(p: DPoint): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* @param p
|
|
168
|
+
* @param [d=0.001]
|
|
169
|
+
*/
|
|
75
170
|
like(p: DPoint, d?: number): boolean;
|
|
76
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Flip vertically
|
|
173
|
+
* @param size canvas size
|
|
174
|
+
*/
|
|
175
|
+
flipVertically(size: DPoint): DPoint;
|
|
176
|
+
/**
|
|
177
|
+
* Flip vertically
|
|
178
|
+
* @param height canvas height
|
|
179
|
+
*/
|
|
180
|
+
flipVertically(height: number): DPoint;
|
|
77
181
|
/**
|
|
78
182
|
* Check if point looks like radians
|
|
79
183
|
*/
|
|
@@ -104,5 +208,15 @@ export declare class DPoint {
|
|
|
104
208
|
};
|
|
105
209
|
setIfLessThan(p: DPoint): DPoint;
|
|
106
210
|
minus(): DPoint;
|
|
211
|
+
/**
|
|
212
|
+
* Find [orthodromic path](https://en.wikipedia.org/wiki/Great-circle_navigation) between to points.
|
|
213
|
+
*
|
|
214
|
+
* @remark Points should be Lng/Lat.
|
|
215
|
+
*
|
|
216
|
+
* 
|
|
217
|
+
*
|
|
218
|
+
* @param point
|
|
219
|
+
* @param [pointsCount=360]
|
|
220
|
+
*/
|
|
107
221
|
orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
|
|
108
222
|
}
|
package/dist/DPoint.js
CHANGED
|
@@ -19,23 +19,16 @@ exports.DOUBLE_PI_IN_DEGREE = 360;
|
|
|
19
19
|
exports.PI_TO_DEGREE = Math.PI / exports.PI_IN_DEGREE;
|
|
20
20
|
exports.DEGREE_TO_PI = exports.PI_IN_DEGREE / Math.PI;
|
|
21
21
|
class DPoint {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* @param x - lng, meters to East, radians to East or width
|
|
25
|
-
* @param y - lat, meters to North, radians to North or height
|
|
26
|
-
* @param z - height
|
|
27
|
-
*/
|
|
28
|
-
constructor(x = 0, y = 0, z) {
|
|
29
|
-
this.x = 0;
|
|
30
|
-
this.y = 0;
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
this.properties = {};
|
|
22
|
+
// eslint-disable-next-line no-empty-function,no-useless-constructor
|
|
23
|
+
constructor(x = 0, y = x, z) {
|
|
33
24
|
this.x = x;
|
|
34
25
|
this.y = y;
|
|
35
26
|
this.z = z;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
this.properties = {};
|
|
36
29
|
}
|
|
37
|
-
static
|
|
38
|
-
return new DPoint(
|
|
30
|
+
static zero() {
|
|
31
|
+
return new DPoint();
|
|
39
32
|
}
|
|
40
33
|
static parse(c) {
|
|
41
34
|
const { lat, lng } = c;
|
|
@@ -45,9 +38,6 @@ class DPoint {
|
|
|
45
38
|
const [x, y, z] = c;
|
|
46
39
|
return new DPoint(x, y, z);
|
|
47
40
|
}
|
|
48
|
-
static isPoint(p) {
|
|
49
|
-
return p instanceof DPoint;
|
|
50
|
-
}
|
|
51
41
|
static parseFromWKT(wkt) {
|
|
52
42
|
const regexp = /POINT \((?<data>(?:(?!\)).)*?)\)$/miu;
|
|
53
43
|
const data = wkt.trim().toUpperCase();
|
|
@@ -55,9 +45,16 @@ class DPoint {
|
|
|
55
45
|
const [x, y, z] = res.groups.data.split(' ').map(Number);
|
|
56
46
|
return new DPoint(x, y, z);
|
|
57
47
|
}
|
|
58
|
-
static
|
|
48
|
+
static random() {
|
|
59
49
|
return new DPoint(Math.random(), Math.random());
|
|
60
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* @remark Point should be Lng/Lat.
|
|
53
|
+
*
|
|
54
|
+
* @remark `z` value default for `zoom` argument.
|
|
55
|
+
*
|
|
56
|
+
* @param [zoom=this.z]
|
|
57
|
+
*/
|
|
61
58
|
getTileFromCoords(zoom = this.z) {
|
|
62
59
|
(0, utils_1.checkFunction)('getTileFromCoords')
|
|
63
60
|
.checkArgument('this')
|
|
@@ -66,6 +63,13 @@ class DPoint {
|
|
|
66
63
|
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
64
|
return new DPoint(x, y, zoom);
|
|
68
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Result would be Lng/Lat.
|
|
68
|
+
*
|
|
69
|
+
* @remark `z` value default for `zoom` argument.
|
|
70
|
+
*
|
|
71
|
+
* @param [zoom=this.z]
|
|
72
|
+
*/
|
|
69
73
|
getCoordsFromTile(zoom = this.z) {
|
|
70
74
|
(0, utils_1.checkFunction)('getCoordsFromTile')
|
|
71
75
|
.checkArgument('this')
|
|
@@ -180,7 +184,7 @@ class DPoint {
|
|
|
180
184
|
this.y = y;
|
|
181
185
|
return this;
|
|
182
186
|
}
|
|
183
|
-
move(x
|
|
187
|
+
move(x, y = x) {
|
|
184
188
|
let xV = 0;
|
|
185
189
|
let yV = 0;
|
|
186
190
|
if (x instanceof DPoint) {
|
|
@@ -256,6 +260,9 @@ class DPoint {
|
|
|
256
260
|
this.y = Math.floor(this.y);
|
|
257
261
|
return this;
|
|
258
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* @param [n=2]
|
|
265
|
+
*/
|
|
259
266
|
toFixed(n = 2) {
|
|
260
267
|
this.x = parseFloat(this.x.toFixed(n));
|
|
261
268
|
this.y = parseFloat(this.y.toFixed(n));
|
|
@@ -266,7 +273,7 @@ class DPoint {
|
|
|
266
273
|
this.y = Math.abs(this.y);
|
|
267
274
|
return this;
|
|
268
275
|
}
|
|
269
|
-
scale(x
|
|
276
|
+
scale(x, y = x) {
|
|
270
277
|
let xV = 0;
|
|
271
278
|
let yV = 0;
|
|
272
279
|
if (x instanceof DPoint) {
|
|
@@ -281,7 +288,7 @@ class DPoint {
|
|
|
281
288
|
this.y = yV;
|
|
282
289
|
return this;
|
|
283
290
|
}
|
|
284
|
-
divide(x
|
|
291
|
+
divide(x, y = x) {
|
|
285
292
|
let xV = 0;
|
|
286
293
|
let yV = 0;
|
|
287
294
|
if (x instanceof DPoint) {
|
|
@@ -299,10 +306,17 @@ class DPoint {
|
|
|
299
306
|
equal(p) {
|
|
300
307
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
301
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* @param p
|
|
311
|
+
* @param [d=0.001]
|
|
312
|
+
*/
|
|
302
313
|
like(p, d = 0.001) {
|
|
314
|
+
if (this.equal(p)) {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
303
317
|
const likeX = Math.abs(this.x - p.x) < d;
|
|
304
318
|
const likeY = Math.abs(this.y - p.y) < d;
|
|
305
|
-
const likeZ =
|
|
319
|
+
const likeZ = Math.abs((this.z || 0) - (p.z || 0)) < d;
|
|
306
320
|
return likeX && likeY && likeZ;
|
|
307
321
|
}
|
|
308
322
|
flipVertically(size) {
|
|
@@ -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')
|
|
@@ -412,7 +436,7 @@ class DPoint {
|
|
|
412
436
|
const p = point.clone().degreeToRadians();
|
|
413
437
|
const d = Math.sin(p.x - t.x);
|
|
414
438
|
const step = (p.x - t.x) / (pointsCount - 1);
|
|
415
|
-
return new DPolygon_1.DPolygon(
|
|
439
|
+
return new DPolygon_1.DPolygon((0, utils_1.createArray)(pointsCount)
|
|
416
440
|
.map((v, i) => {
|
|
417
441
|
const x = t.x + step * i;
|
|
418
442
|
const y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import { DLine } from './DLine';
|
|
|
4
4
|
import { DPolygonLoop } from './DPolygonLoop';
|
|
5
5
|
export declare const MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
6
6
|
export declare class DPolygon {
|
|
7
|
+
private pPoints;
|
|
7
8
|
properties: {
|
|
8
9
|
[key: string]: any;
|
|
9
10
|
};
|
|
10
11
|
holes: DPolygon[];
|
|
11
|
-
private pPoints;
|
|
12
12
|
private searchStore;
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(pPoints?: DPoint[]);
|
|
14
14
|
/**
|
|
15
15
|
* Get size of min area rectangle.
|
|
16
16
|
* @param poly should be `minAreaRectangle`
|
|
@@ -130,44 +130,28 @@ 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
|
|
138
139
|
*/
|
|
139
140
|
setCenter(newCenter: DPoint): DPolygon;
|
|
140
141
|
toWKT(): string;
|
|
141
|
-
/**
|
|
142
|
-
* Rotate polygon with center in point {0, 0}
|
|
143
|
-
* @param a Radians
|
|
144
|
-
*/
|
|
145
|
-
rotate(a: number): DPolygon;
|
|
146
142
|
/**
|
|
147
143
|
* Filter points
|
|
148
144
|
* @param f
|
|
149
145
|
*/
|
|
150
146
|
filter(f: (p: DPoint) => boolean): DPolygon;
|
|
151
|
-
move(x?: number | DPoint, y?: number): DPolygon;
|
|
152
|
-
scale(x?: number | DPoint, y?: number): DPolygon;
|
|
153
|
-
divide(x?: number | DPoint, y?: number): DPolygon;
|
|
154
|
-
round(): DPolygon;
|
|
155
|
-
floor(): DPolygon;
|
|
156
|
-
ceil(): DPolygon;
|
|
157
|
-
flipVertically(size: DPoint | number): DPolygon;
|
|
158
|
-
toFixed(n?: number): DPolygon;
|
|
159
147
|
map(f: (r: DPoint, index?: number) => DPoint): DPolygon;
|
|
160
|
-
|
|
148
|
+
at(index: number): DPoint;
|
|
161
149
|
pop(): DPoint;
|
|
162
150
|
push(...args: DPoint[]): number;
|
|
163
151
|
shift(): DPoint;
|
|
164
152
|
unshift(...args: DPoint[]): number;
|
|
165
153
|
reverse(): DPolygon;
|
|
166
154
|
getValue(): string;
|
|
167
|
-
degreeToMeters(): DPolygon;
|
|
168
|
-
metersToDegree(): DPolygon;
|
|
169
|
-
radiansToMeters(): DPolygon;
|
|
170
|
-
metersToRadians(): DPolygon;
|
|
171
155
|
toString(): string;
|
|
172
156
|
/**
|
|
173
157
|
* Add to the end of polygon point equal to first point if it not exist
|
|
@@ -177,11 +161,6 @@ export declare class DPolygon {
|
|
|
177
161
|
* Remove from the end of polygon point equal to first point if it exist
|
|
178
162
|
*/
|
|
179
163
|
open(): DPolygon;
|
|
180
|
-
/**
|
|
181
|
-
* Set `height` (`z`)
|
|
182
|
-
* @param z
|
|
183
|
-
*/
|
|
184
|
-
height(z: number): DPolygon;
|
|
185
164
|
add(poly: DPolygon): DPolygon;
|
|
186
165
|
/**
|
|
187
166
|
* Check if has point in list of points
|
|
@@ -203,7 +182,7 @@ export declare class DPolygon {
|
|
|
203
182
|
/**
|
|
204
183
|
* Get polygon approximation by
|
|
205
184
|
* [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)
|
|
206
|
-
* @param e
|
|
185
|
+
* @param [e=Math.sqrt(this.perimeter)*APPROXIMATION_VALUE]
|
|
207
186
|
*/
|
|
208
187
|
approximation(e?: number): DPolygon;
|
|
209
188
|
insertAfter(index: number, ...points: DPoint[]): void;
|
|
@@ -223,8 +202,8 @@ export declare class DPolygon {
|
|
|
223
202
|
/**
|
|
224
203
|
* Check if contain point
|
|
225
204
|
* @param p
|
|
226
|
-
* @param isBorderInside
|
|
227
|
-
* @param move Ignore this parameter
|
|
205
|
+
* @param [isBorderInside=false]
|
|
206
|
+
* @param [move=(0,0)] Ignore this parameter
|
|
228
207
|
*/
|
|
229
208
|
contain(p: DPoint, isBorderInside?: boolean, move?: DPoint): boolean;
|
|
230
209
|
/**
|
|
@@ -241,11 +220,20 @@ export declare class DPolygon {
|
|
|
241
220
|
*/
|
|
242
221
|
removeDuplicates(): DPolygon;
|
|
243
222
|
/**
|
|
244
|
-
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
245
|
-
*
|
|
223
|
+
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
224
|
+
* @param a
|
|
225
|
+
*/
|
|
226
|
+
static parse(a: LatLng[]): DPolygon;
|
|
227
|
+
/**
|
|
228
|
+
* Parse from [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) coordinates
|
|
246
229
|
* @param a
|
|
247
230
|
*/
|
|
248
|
-
static parse(a:
|
|
231
|
+
static parse(a: number[][]): DPolygon;
|
|
232
|
+
/**
|
|
233
|
+
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
234
|
+
* @param a
|
|
235
|
+
*/
|
|
236
|
+
static parse(a: DCoord[]): DPolygon;
|
|
249
237
|
/**
|
|
250
238
|
* Transform to array of coordinates for [OpenLayers](https://openlayers.org/) or
|
|
251
239
|
* [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON)
|
|
@@ -266,6 +254,12 @@ export declare class DPolygon {
|
|
|
266
254
|
simpleIntersection(p: DPolygon): DPolygon | null | DPolygon[];
|
|
267
255
|
simpleDifference(p: DPolygon): DPolygon | null | DPolygon[];
|
|
268
256
|
smartUnion(p: DPolygon): DPolygon | null;
|
|
257
|
+
/**
|
|
258
|
+
* Divide polygon to triangles
|
|
259
|
+
*
|
|
260
|
+
* 
|
|
261
|
+
*/
|
|
262
|
+
toTriangles(): DPolygon[];
|
|
269
263
|
private simpleIncludeX;
|
|
270
264
|
private simpleIncludeY;
|
|
271
265
|
private douglasPeucker;
|