dgeoutils 2.2.2 → 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 +5 -1
- package/dist/DCircle.js +8 -4
- package/dist/DLine.d.ts +1 -1
- package/dist/DLine.js +5 -7
- package/dist/DPoint.d.ts +102 -12
- package/dist/DPoint.js +18 -21
- package/dist/DPolygon.d.ts +17 -76
- package/dist/DPolygon.js +8 -109
- package/dist/DPolygonLoop.d.ts +84 -6
- package/dist/DPolygonLoop.js +9 -3
- package/dist/TraceMatrix.js +3 -5
- 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;
|
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})`;
|
package/dist/DLine.d.ts
CHANGED
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;
|
|
@@ -124,7 +122,7 @@ class DLine {
|
|
|
124
122
|
/**
|
|
125
123
|
* Check if point below to line segment, but not equal star or end point.
|
|
126
124
|
* @param p
|
|
127
|
-
* @param d
|
|
125
|
+
* @param [d=0]
|
|
128
126
|
*/
|
|
129
127
|
insideRange(p, d = 0) {
|
|
130
128
|
const { p1, p2 } = this;
|
package/dist/DPoint.d.ts
CHANGED
|
@@ -15,22 +15,33 @@ 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;
|
|
34
45
|
/**
|
|
35
46
|
* @remark Point should be Lng/Lat.
|
|
36
47
|
*
|
|
@@ -59,8 +70,26 @@ export declare class DPoint {
|
|
|
59
70
|
height(z: number): DPoint;
|
|
60
71
|
toWKT(): string;
|
|
61
72
|
distance(p: DPoint): number;
|
|
62
|
-
|
|
63
|
-
|
|
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;
|
|
64
93
|
clone(): DPoint;
|
|
65
94
|
gt(p: DPoint): boolean;
|
|
66
95
|
lt(p: DPoint): boolean;
|
|
@@ -71,7 +100,22 @@ export declare class DPoint {
|
|
|
71
100
|
* @param a radians
|
|
72
101
|
*/
|
|
73
102
|
rotate(a: number): DPoint;
|
|
74
|
-
|
|
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;
|
|
75
119
|
degreeToMeters(): DPoint;
|
|
76
120
|
metersToDegree(): DPoint;
|
|
77
121
|
degreeToRadians(): DPoint;
|
|
@@ -81,13 +125,59 @@ export declare class DPoint {
|
|
|
81
125
|
round(): DPoint;
|
|
82
126
|
ceil(): DPoint;
|
|
83
127
|
floor(): DPoint;
|
|
128
|
+
/**
|
|
129
|
+
* @param [n=2]
|
|
130
|
+
*/
|
|
84
131
|
toFixed(n?: number): DPoint;
|
|
85
132
|
abs(): DPoint;
|
|
86
|
-
|
|
87
|
-
|
|
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;
|
|
88
165
|
equal(p: DPoint): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* @param p
|
|
168
|
+
* @param [d=0.001]
|
|
169
|
+
*/
|
|
89
170
|
like(p: DPoint, d?: number): boolean;
|
|
90
|
-
|
|
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;
|
|
91
181
|
/**
|
|
92
182
|
* Check if point looks like radians
|
|
93
183
|
*/
|
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,7 +45,7 @@ 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
|
}
|
|
61
51
|
/**
|
|
@@ -194,7 +184,7 @@ class DPoint {
|
|
|
194
184
|
this.y = y;
|
|
195
185
|
return this;
|
|
196
186
|
}
|
|
197
|
-
move(x
|
|
187
|
+
move(x, y = x) {
|
|
198
188
|
let xV = 0;
|
|
199
189
|
let yV = 0;
|
|
200
190
|
if (x instanceof DPoint) {
|
|
@@ -270,6 +260,9 @@ class DPoint {
|
|
|
270
260
|
this.y = Math.floor(this.y);
|
|
271
261
|
return this;
|
|
272
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* @param [n=2]
|
|
265
|
+
*/
|
|
273
266
|
toFixed(n = 2) {
|
|
274
267
|
this.x = parseFloat(this.x.toFixed(n));
|
|
275
268
|
this.y = parseFloat(this.y.toFixed(n));
|
|
@@ -280,7 +273,7 @@ class DPoint {
|
|
|
280
273
|
this.y = Math.abs(this.y);
|
|
281
274
|
return this;
|
|
282
275
|
}
|
|
283
|
-
scale(x
|
|
276
|
+
scale(x, y = x) {
|
|
284
277
|
let xV = 0;
|
|
285
278
|
let yV = 0;
|
|
286
279
|
if (x instanceof DPoint) {
|
|
@@ -295,7 +288,7 @@ class DPoint {
|
|
|
295
288
|
this.y = yV;
|
|
296
289
|
return this;
|
|
297
290
|
}
|
|
298
|
-
divide(x
|
|
291
|
+
divide(x, y = x) {
|
|
299
292
|
let xV = 0;
|
|
300
293
|
let yV = 0;
|
|
301
294
|
if (x instanceof DPoint) {
|
|
@@ -313,6 +306,10 @@ class DPoint {
|
|
|
313
306
|
equal(p) {
|
|
314
307
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
315
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* @param p
|
|
311
|
+
* @param [d=0.001]
|
|
312
|
+
*/
|
|
316
313
|
like(p, d = 0.001) {
|
|
317
314
|
if (this.equal(p)) {
|
|
318
315
|
return true;
|
|
@@ -439,7 +436,7 @@ class DPoint {
|
|
|
439
436
|
const p = point.clone().degreeToRadians();
|
|
440
437
|
const d = Math.sin(p.x - t.x);
|
|
441
438
|
const step = (p.x - t.x) / (pointsCount - 1);
|
|
442
|
-
return new DPolygon_1.DPolygon(
|
|
439
|
+
return new DPolygon_1.DPolygon((0, utils_1.createArray)(pointsCount)
|
|
443
440
|
.map((v, i) => {
|
|
444
441
|
const x = t.x + step * i;
|
|
445
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`
|
|
@@ -139,57 +139,11 @@ export declare class DPolygon {
|
|
|
139
139
|
*/
|
|
140
140
|
setCenter(newCenter: DPoint): DPolygon;
|
|
141
141
|
toWKT(): string;
|
|
142
|
-
/**
|
|
143
|
-
* Rotate polygon with center in point {0, 0}
|
|
144
|
-
* @param a Radians
|
|
145
|
-
* @deprecated Better to use loop
|
|
146
|
-
*/
|
|
147
|
-
rotate(a: number): DPolygon;
|
|
148
142
|
/**
|
|
149
143
|
* Filter points
|
|
150
144
|
* @param f
|
|
151
145
|
*/
|
|
152
146
|
filter(f: (p: DPoint) => boolean): DPolygon;
|
|
153
|
-
/**
|
|
154
|
-
* @deprecated Better to use loop
|
|
155
|
-
* @param [x=0]
|
|
156
|
-
* @param [y=x]
|
|
157
|
-
*/
|
|
158
|
-
move(x?: number | DPoint, y?: number): DPolygon;
|
|
159
|
-
/**
|
|
160
|
-
* @deprecated Better to use loop
|
|
161
|
-
* @param [x=0]
|
|
162
|
-
* @param [y=x]
|
|
163
|
-
*/
|
|
164
|
-
scale(x?: number | DPoint, y?: number): DPolygon;
|
|
165
|
-
/**
|
|
166
|
-
* @deprecated Better to use loop
|
|
167
|
-
* @param [x=0]
|
|
168
|
-
* @param [y=x]
|
|
169
|
-
*/
|
|
170
|
-
divide(x?: number | DPoint, y?: number): DPolygon;
|
|
171
|
-
/**
|
|
172
|
-
* @deprecated Better to use loop
|
|
173
|
-
*/
|
|
174
|
-
round(): DPolygon;
|
|
175
|
-
/**
|
|
176
|
-
* @deprecated Better to use loop
|
|
177
|
-
*/
|
|
178
|
-
floor(): DPolygon;
|
|
179
|
-
/**
|
|
180
|
-
* @deprecated Better to use loop
|
|
181
|
-
*/
|
|
182
|
-
ceil(): DPolygon;
|
|
183
|
-
/**
|
|
184
|
-
* @deprecated Better to use loop
|
|
185
|
-
* @param size
|
|
186
|
-
*/
|
|
187
|
-
flipVertically(size: DPoint | number): DPolygon;
|
|
188
|
-
/**
|
|
189
|
-
* @deprecated Better to use loop
|
|
190
|
-
* @param [n=2]
|
|
191
|
-
*/
|
|
192
|
-
toFixed(n?: number): DPolygon;
|
|
193
147
|
map(f: (r: DPoint, index?: number) => DPoint): DPolygon;
|
|
194
148
|
at(index: number): DPoint;
|
|
195
149
|
pop(): DPoint;
|
|
@@ -198,22 +152,6 @@ export declare class DPolygon {
|
|
|
198
152
|
unshift(...args: DPoint[]): number;
|
|
199
153
|
reverse(): DPolygon;
|
|
200
154
|
getValue(): string;
|
|
201
|
-
/**
|
|
202
|
-
* @deprecated Better to use loop
|
|
203
|
-
*/
|
|
204
|
-
degreeToMeters(): DPolygon;
|
|
205
|
-
/**
|
|
206
|
-
* @deprecated Better to use loop
|
|
207
|
-
*/
|
|
208
|
-
metersToDegree(): DPolygon;
|
|
209
|
-
/**
|
|
210
|
-
* @deprecated Better to use loop
|
|
211
|
-
*/
|
|
212
|
-
radiansToMeters(): DPolygon;
|
|
213
|
-
/**
|
|
214
|
-
* @deprecated Better to use loop
|
|
215
|
-
*/
|
|
216
|
-
metersToRadians(): DPolygon;
|
|
217
155
|
toString(): string;
|
|
218
156
|
/**
|
|
219
157
|
* Add to the end of polygon point equal to first point if it not exist
|
|
@@ -223,12 +161,6 @@ export declare class DPolygon {
|
|
|
223
161
|
* Remove from the end of polygon point equal to first point if it exist
|
|
224
162
|
*/
|
|
225
163
|
open(): DPolygon;
|
|
226
|
-
/**
|
|
227
|
-
* Set `height` (`z`)
|
|
228
|
-
* @param z
|
|
229
|
-
* @deprecated Better to use loop
|
|
230
|
-
*/
|
|
231
|
-
height(z: number): DPolygon;
|
|
232
164
|
add(poly: DPolygon): DPolygon;
|
|
233
165
|
/**
|
|
234
166
|
* Check if has point in list of points
|
|
@@ -250,7 +182,7 @@ export declare class DPolygon {
|
|
|
250
182
|
/**
|
|
251
183
|
* Get polygon approximation by
|
|
252
184
|
* [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)
|
|
253
|
-
* @param e
|
|
185
|
+
* @param [e=Math.sqrt(this.perimeter)*APPROXIMATION_VALUE]
|
|
254
186
|
*/
|
|
255
187
|
approximation(e?: number): DPolygon;
|
|
256
188
|
insertAfter(index: number, ...points: DPoint[]): void;
|
|
@@ -270,8 +202,8 @@ export declare class DPolygon {
|
|
|
270
202
|
/**
|
|
271
203
|
* Check if contain point
|
|
272
204
|
* @param p
|
|
273
|
-
* @param isBorderInside
|
|
274
|
-
* @param move Ignore this parameter
|
|
205
|
+
* @param [isBorderInside=false]
|
|
206
|
+
* @param [move=(0,0)] Ignore this parameter
|
|
275
207
|
*/
|
|
276
208
|
contain(p: DPoint, isBorderInside?: boolean, move?: DPoint): boolean;
|
|
277
209
|
/**
|
|
@@ -288,11 +220,20 @@ export declare class DPolygon {
|
|
|
288
220
|
*/
|
|
289
221
|
removeDuplicates(): DPolygon;
|
|
290
222
|
/**
|
|
291
|
-
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
292
|
-
*
|
|
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
|
|
229
|
+
* @param a
|
|
230
|
+
*/
|
|
231
|
+
static parse(a: number[][]): DPolygon;
|
|
232
|
+
/**
|
|
233
|
+
* Parse from [OpenLayers](https://openlayers.org/) coordinates
|
|
293
234
|
* @param a
|
|
294
235
|
*/
|
|
295
|
-
static parse(a:
|
|
236
|
+
static parse(a: DCoord[]): DPolygon;
|
|
296
237
|
/**
|
|
297
238
|
* Transform to array of coordinates for [OpenLayers](https://openlayers.org/) or
|
|
298
239
|
* [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON)
|
package/dist/DPolygon.js
CHANGED
|
@@ -13,13 +13,13 @@ const APPROXIMATION_VALUE = 0.1;
|
|
|
13
13
|
const MAX_CONVEX_ITERATIONS = 100;
|
|
14
14
|
const CLOSE_TO_INTERSECTION_DISTANCE = 0.001;
|
|
15
15
|
class DPolygon {
|
|
16
|
-
|
|
16
|
+
// eslint-disable-next-line no-useless-constructor,no-empty-function
|
|
17
|
+
constructor(pPoints = []) {
|
|
18
|
+
this.pPoints = pPoints;
|
|
17
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
20
|
this.properties = {};
|
|
19
21
|
this.holes = [];
|
|
20
|
-
this.pPoints = [];
|
|
21
22
|
this.searchStore = {};
|
|
22
|
-
this.pPoints = points;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Get size of min area rectangle.
|
|
@@ -93,7 +93,7 @@ class DPolygon {
|
|
|
93
93
|
return res;
|
|
94
94
|
}
|
|
95
95
|
static createSquareBySize(size) {
|
|
96
|
-
return new DPolygon([DPoint_1.DPoint.
|
|
96
|
+
return new DPolygon([DPoint_1.DPoint.zero(), size.clone().setX(0), size.clone(), size.clone().setY(0)]).close();
|
|
97
97
|
}
|
|
98
98
|
loop() {
|
|
99
99
|
return new DPolygonLoop_1.DPolygonLoop(this);
|
|
@@ -417,14 +417,6 @@ class DPolygon {
|
|
|
417
417
|
}
|
|
418
418
|
return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}`).join(', ')})${h})`;
|
|
419
419
|
}
|
|
420
|
-
/**
|
|
421
|
-
* Rotate polygon with center in point {0, 0}
|
|
422
|
-
* @param a Radians
|
|
423
|
-
* @deprecated Better to use loop
|
|
424
|
-
*/
|
|
425
|
-
rotate(a) {
|
|
426
|
-
return this.map((h) => h.rotate(a));
|
|
427
|
-
}
|
|
428
420
|
/**
|
|
429
421
|
* Filter points
|
|
430
422
|
* @param f
|
|
@@ -433,62 +425,6 @@ class DPolygon {
|
|
|
433
425
|
this.pPoints = this.pPoints.filter(f);
|
|
434
426
|
return this;
|
|
435
427
|
}
|
|
436
|
-
/**
|
|
437
|
-
* @deprecated Better to use loop
|
|
438
|
-
* @param [x=0]
|
|
439
|
-
* @param [y=x]
|
|
440
|
-
*/
|
|
441
|
-
move(x = 0, y) {
|
|
442
|
-
return this.map((h) => h.move(x, y));
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* @deprecated Better to use loop
|
|
446
|
-
* @param [x=0]
|
|
447
|
-
* @param [y=x]
|
|
448
|
-
*/
|
|
449
|
-
scale(x = 0, y) {
|
|
450
|
-
return this.map((h) => h.scale(x, y));
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* @deprecated Better to use loop
|
|
454
|
-
* @param [x=0]
|
|
455
|
-
* @param [y=x]
|
|
456
|
-
*/
|
|
457
|
-
divide(x = 0, y) {
|
|
458
|
-
return this.map((h) => h.divide(x, y));
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* @deprecated Better to use loop
|
|
462
|
-
*/
|
|
463
|
-
round() {
|
|
464
|
-
return this.map((h) => h.round());
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* @deprecated Better to use loop
|
|
468
|
-
*/
|
|
469
|
-
floor() {
|
|
470
|
-
return this.map((h) => h.floor());
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* @deprecated Better to use loop
|
|
474
|
-
*/
|
|
475
|
-
ceil() {
|
|
476
|
-
return this.map((h) => h.ceil());
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* @deprecated Better to use loop
|
|
480
|
-
* @param size
|
|
481
|
-
*/
|
|
482
|
-
flipVertically(size) {
|
|
483
|
-
return this.map((h) => h.flipVertically(size));
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* @deprecated Better to use loop
|
|
487
|
-
* @param [n=2]
|
|
488
|
-
*/
|
|
489
|
-
toFixed(n = 2) {
|
|
490
|
-
return this.map((h) => h.toFixed(n));
|
|
491
|
-
}
|
|
492
428
|
map(f) {
|
|
493
429
|
this.pPoints = this.pPoints.map(f);
|
|
494
430
|
this.holes = this.holes.map((h) => h.map(f));
|
|
@@ -519,30 +455,6 @@ class DPolygon {
|
|
|
519
455
|
return (this.pPoints.map((r) => r.getValue()) + this.holes
|
|
520
456
|
.reduce((a, h) => a + h.getValue(), ''));
|
|
521
457
|
}
|
|
522
|
-
/**
|
|
523
|
-
* @deprecated Better to use loop
|
|
524
|
-
*/
|
|
525
|
-
degreeToMeters() {
|
|
526
|
-
return this.map((r) => r.degreeToMeters());
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* @deprecated Better to use loop
|
|
530
|
-
*/
|
|
531
|
-
metersToDegree() {
|
|
532
|
-
return this.map((r) => r.metersToDegree());
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* @deprecated Better to use loop
|
|
536
|
-
*/
|
|
537
|
-
radiansToMeters() {
|
|
538
|
-
return this.map((r) => r.radiansToMeters());
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* @deprecated Better to use loop
|
|
542
|
-
*/
|
|
543
|
-
metersToRadians() {
|
|
544
|
-
return this.map((r) => r.metersToRadians());
|
|
545
|
-
}
|
|
546
458
|
toString() {
|
|
547
459
|
return `(${this.pPoints.map((r) => r.toString()).join(', ')})`;
|
|
548
460
|
}
|
|
@@ -566,14 +478,6 @@ class DPolygon {
|
|
|
566
478
|
}
|
|
567
479
|
return this;
|
|
568
480
|
}
|
|
569
|
-
/**
|
|
570
|
-
* Set `height` (`z`)
|
|
571
|
-
* @param z
|
|
572
|
-
* @deprecated Better to use loop
|
|
573
|
-
*/
|
|
574
|
-
height(z) {
|
|
575
|
-
return this.map((p) => p.height(z));
|
|
576
|
-
}
|
|
577
481
|
add(poly) {
|
|
578
482
|
const res = new DPolygon([...this.points, ...poly.points]).close();
|
|
579
483
|
res.holes = [...this.holes, ...poly.holes].map((h) => h.clone());
|
|
@@ -630,7 +534,7 @@ class DPolygon {
|
|
|
630
534
|
/**
|
|
631
535
|
* Get polygon approximation by
|
|
632
536
|
* [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)
|
|
633
|
-
* @param e
|
|
537
|
+
* @param [e=Math.sqrt(this.perimeter)*APPROXIMATION_VALUE]
|
|
634
538
|
*/
|
|
635
539
|
approximation(e = Math.sqrt(this.perimeter) * APPROXIMATION_VALUE) {
|
|
636
540
|
return new DPolygon(this.clone().douglasPeucker(this.pPoints, e));
|
|
@@ -704,10 +608,10 @@ class DPolygon {
|
|
|
704
608
|
/**
|
|
705
609
|
* Check if contain point
|
|
706
610
|
* @param p
|
|
707
|
-
* @param isBorderInside
|
|
708
|
-
* @param move Ignore this parameter
|
|
611
|
+
* @param [isBorderInside=false]
|
|
612
|
+
* @param [move=(0,0)] Ignore this parameter
|
|
709
613
|
*/
|
|
710
|
-
contain(p, isBorderInside = false, move = DPoint_1.DPoint.
|
|
614
|
+
contain(p, isBorderInside = false, move = DPoint_1.DPoint.zero()) {
|
|
711
615
|
const simpleInclude = this.simpleInclude(p);
|
|
712
616
|
if (!simpleInclude) {
|
|
713
617
|
return false;
|
|
@@ -779,11 +683,6 @@ class DPolygon {
|
|
|
779
683
|
}
|
|
780
684
|
return this;
|
|
781
685
|
}
|
|
782
|
-
/**
|
|
783
|
-
* Parse from [OpenLayers](https://openlayers.org/) coordinates or
|
|
784
|
-
* [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) coordinates
|
|
785
|
-
* @param a
|
|
786
|
-
*/
|
|
787
686
|
static parse(a) {
|
|
788
687
|
return new DPolygon(a.map((r) => DPoint_1.DPoint.parse(r)));
|
|
789
688
|
}
|
package/dist/DPolygonLoop.d.ts
CHANGED
|
@@ -10,20 +10,89 @@ export declare class DPolygonLoop {
|
|
|
10
10
|
* Run loop
|
|
11
11
|
*/
|
|
12
12
|
run(): DPolygon;
|
|
13
|
+
/**
|
|
14
|
+
* @param zoom default value would be `z` of point
|
|
15
|
+
*/
|
|
13
16
|
getTileFromCoords(zoom?: number): DPolygonLoop;
|
|
17
|
+
/**
|
|
18
|
+
* @param zoom default value would be `z` of point
|
|
19
|
+
*/
|
|
14
20
|
getCoordsFromTile(zoom?: number): DPolygonLoop;
|
|
15
21
|
height(z: number): DPolygonLoop;
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Set `x` value
|
|
24
|
+
* @param x
|
|
25
|
+
*/
|
|
26
|
+
setX(x: number): DPolygonLoop;
|
|
27
|
+
/**
|
|
28
|
+
* Transform `x` value by function
|
|
29
|
+
* @param f
|
|
30
|
+
*/
|
|
31
|
+
setX(f: SetterFunction): DPolygonLoop;
|
|
32
|
+
/**
|
|
33
|
+
* Set `y` value
|
|
34
|
+
* @param y
|
|
35
|
+
*/
|
|
36
|
+
setY(y: number): DPolygonLoop;
|
|
37
|
+
/**
|
|
38
|
+
* Transform `y` value by function
|
|
39
|
+
* @param f
|
|
40
|
+
*/
|
|
41
|
+
setY(f: SetterFunction): DPolygonLoop;
|
|
18
42
|
rotate(a: number): DPolygonLoop;
|
|
19
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Add `v` to `x` and `y`
|
|
45
|
+
* @param v
|
|
46
|
+
*/
|
|
47
|
+
move(v: number): DPolygonLoop;
|
|
48
|
+
/**
|
|
49
|
+
* Add `p.x` to `x` field and `p.y` to `y` field.
|
|
50
|
+
* @param p
|
|
51
|
+
*/
|
|
52
|
+
move(p: DPoint): DPolygonLoop;
|
|
53
|
+
/**
|
|
54
|
+
* Add `x` to `x` field and `y` to `y` field.
|
|
55
|
+
* @param x
|
|
56
|
+
* @param y
|
|
57
|
+
*/
|
|
58
|
+
move(x: number, y: number): DPolygonLoop;
|
|
20
59
|
round(): DPolygonLoop;
|
|
21
60
|
ceil(): DPolygonLoop;
|
|
22
61
|
floor(): DPolygonLoop;
|
|
23
62
|
toFixed(n?: number): DPolygonLoop;
|
|
24
63
|
abs(): DPolygonLoop;
|
|
25
|
-
|
|
26
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Multiply `v` to `x` and `y`
|
|
66
|
+
* @param v
|
|
67
|
+
*/
|
|
68
|
+
scale(v: number): DPolygonLoop;
|
|
69
|
+
/**
|
|
70
|
+
* Multiply `p.x` to `x` field and `p.y` to `y` field.
|
|
71
|
+
* @param p
|
|
72
|
+
*/
|
|
73
|
+
scale(p: DPoint): DPolygonLoop;
|
|
74
|
+
/**
|
|
75
|
+
* Multiply `x` to `x` field and `y` to `y` field.
|
|
76
|
+
* @param x
|
|
77
|
+
* @param y
|
|
78
|
+
*/
|
|
79
|
+
scale(x: number, y: number): DPolygonLoop;
|
|
80
|
+
/**
|
|
81
|
+
* Divide `x` and `y` to `v`
|
|
82
|
+
* @param v
|
|
83
|
+
*/
|
|
84
|
+
divide(v: number): DPolygonLoop;
|
|
85
|
+
/**
|
|
86
|
+
* Divide `x` field to `p.x` and `y` field to `p.y`.
|
|
87
|
+
* @param p
|
|
88
|
+
*/
|
|
89
|
+
divide(p: DPoint): DPolygonLoop;
|
|
90
|
+
/**
|
|
91
|
+
* Divide `x` field to `x` and `y` field to `y`.
|
|
92
|
+
* @param x
|
|
93
|
+
* @param y
|
|
94
|
+
*/
|
|
95
|
+
divide(x: number, y: number): DPolygonLoop;
|
|
27
96
|
degreeToRadians(): DPolygonLoop;
|
|
28
97
|
radiansToDegrees(): DPolygonLoop;
|
|
29
98
|
radiansToMeters(): DPolygonLoop;
|
|
@@ -37,5 +106,14 @@ export declare class DPolygonLoop {
|
|
|
37
106
|
minus(): DPolygonLoop;
|
|
38
107
|
degreeToMeters(): DPolygonLoop;
|
|
39
108
|
metersToDegree(): DPolygonLoop;
|
|
40
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Flip vertically
|
|
111
|
+
* @param size canvas size
|
|
112
|
+
*/
|
|
113
|
+
flipVertically(size: DPoint): DPolygonLoop;
|
|
114
|
+
/**
|
|
115
|
+
* Flip vertically
|
|
116
|
+
* @param height canvas height
|
|
117
|
+
*/
|
|
118
|
+
flipVertically(height: number): DPolygonLoop;
|
|
41
119
|
}
|
package/dist/DPolygonLoop.js
CHANGED
|
@@ -166,6 +166,9 @@ class DPolygonLoop {
|
|
|
166
166
|
run() {
|
|
167
167
|
return this.parent.map(this.getLoopFunction());
|
|
168
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* @param zoom default value would be `z` of point
|
|
171
|
+
*/
|
|
169
172
|
getTileFromCoords(zoom) {
|
|
170
173
|
this.pool.push({
|
|
171
174
|
functionName: LoopFunctions.getTileFromCoords,
|
|
@@ -173,6 +176,9 @@ class DPolygonLoop {
|
|
|
173
176
|
});
|
|
174
177
|
return this;
|
|
175
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* @param zoom default value would be `z` of point
|
|
181
|
+
*/
|
|
176
182
|
getCoordsFromTile(zoom) {
|
|
177
183
|
this.pool.push({
|
|
178
184
|
functionName: LoopFunctions.getCoordsFromTile,
|
|
@@ -208,7 +214,7 @@ class DPolygonLoop {
|
|
|
208
214
|
});
|
|
209
215
|
return this;
|
|
210
216
|
}
|
|
211
|
-
move(x
|
|
217
|
+
move(x, y = x) {
|
|
212
218
|
this.pool.push({
|
|
213
219
|
functionName: LoopFunctions.move,
|
|
214
220
|
numberPointArg: x,
|
|
@@ -247,7 +253,7 @@ class DPolygonLoop {
|
|
|
247
253
|
});
|
|
248
254
|
return this;
|
|
249
255
|
}
|
|
250
|
-
scale(x
|
|
256
|
+
scale(x, y = x) {
|
|
251
257
|
this.pool.push({
|
|
252
258
|
functionName: LoopFunctions.scale,
|
|
253
259
|
numberPointArg: x,
|
|
@@ -255,7 +261,7 @@ class DPolygonLoop {
|
|
|
255
261
|
});
|
|
256
262
|
return this;
|
|
257
263
|
}
|
|
258
|
-
divide(x
|
|
264
|
+
divide(x, y) {
|
|
259
265
|
this.pool.push({
|
|
260
266
|
functionName: LoopFunctions.divide,
|
|
261
267
|
numberPointArg: x,
|
package/dist/TraceMatrix.js
CHANGED
|
@@ -4,10 +4,7 @@ exports.TraceMatrix = exports.TraceMatrixValues = void 0;
|
|
|
4
4
|
const DPoint_1 = require("./DPoint");
|
|
5
5
|
const DPolygon_1 = require("./DPolygon");
|
|
6
6
|
const FastSearch_1 = require("./FastSearch");
|
|
7
|
-
const
|
|
8
|
-
.join(' ')
|
|
9
|
-
.split('')
|
|
10
|
-
.map((r, i) => i);
|
|
7
|
+
const utils_1 = require("./utils");
|
|
11
8
|
var TraceMatrixValues;
|
|
12
9
|
(function (TraceMatrixValues) {
|
|
13
10
|
TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
|
|
@@ -201,7 +198,8 @@ class TraceMatrix {
|
|
|
201
198
|
return res;
|
|
202
199
|
}
|
|
203
200
|
static createMatrix(size, f = () => TraceMatrixValues.f) {
|
|
204
|
-
return
|
|
201
|
+
return (0, utils_1.createArray)(size.h)
|
|
202
|
+
.map((v, i) => (0, utils_1.createArray)(size.w).map((v2, j) => f(new DPoint_1.DPoint(j, i))));
|
|
205
203
|
}
|
|
206
204
|
}
|
|
207
205
|
exports.TraceMatrix = TraceMatrix;
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkFunction = exports.warn = void 0;
|
|
3
|
+
exports.createArray = exports.checkFunction = exports.warn = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
const DPoint_1 = require("./DPoint");
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -21,7 +21,7 @@ const shouldBeInt = (scope, funcName, argName) => (p) => {
|
|
|
21
21
|
};
|
|
22
22
|
const shouldBeUInt = (scope, funcName, argName) => (p) => {
|
|
23
23
|
if (!p.clone().round()
|
|
24
|
-
.equal(p) || !p.gtOrEqual(DPoint_1.DPoint.
|
|
24
|
+
.equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
|
|
25
25
|
(0, exports.warn)(`"${funcName}" -> "${argName}" should be UInt!`);
|
|
26
26
|
}
|
|
27
27
|
return scope;
|
|
@@ -66,3 +66,5 @@ const checkFunction = (funcName) => ({
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
exports.checkFunction = checkFunction;
|
|
69
|
+
const createArray = (v) => new Array(v).fill(0);
|
|
70
|
+
exports.createArray = createArray;
|