dgeoutils 2.2.2 → 2.2.6
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 +14 -7
- package/dist/DLine.js +61 -77
- package/dist/DPoint.d.ts +105 -12
- package/dist/DPoint.js +18 -21
- package/dist/DPolygon.d.ts +67 -76
- package/dist/DPolygon.js +151 -123
- package/dist/DPolygonLoop.d.ts +84 -6
- package/dist/DPolygonLoop.js +11 -4
- package/dist/TraceMatrix.d.ts +1 -1
- package/dist/TraceMatrix.js +4 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +4 -2
- package/package.json +2 -2
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
|
@@ -4,9 +4,16 @@ export declare class DLine {
|
|
|
4
4
|
a: number;
|
|
5
5
|
b: number;
|
|
6
6
|
c: number;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
begin: DPoint;
|
|
8
|
+
end: DPoint;
|
|
9
|
+
/**
|
|
10
|
+
* @param a
|
|
11
|
+
* @param b
|
|
12
|
+
* @param c
|
|
13
|
+
* @param [begin=DPoint.zero()]
|
|
14
|
+
* @param [end=DPoint.zero()]
|
|
15
|
+
*/
|
|
16
|
+
constructor(a: number, b: number, c: number, begin?: DPoint, end?: DPoint);
|
|
10
17
|
clone(): DLine;
|
|
11
18
|
findPerpendicular(p: DPoint): DLine;
|
|
12
19
|
perpendicularDistance(p: DPoint): number;
|
|
@@ -28,7 +35,7 @@ export declare class DLine {
|
|
|
28
35
|
/**
|
|
29
36
|
* Check if point below to line segment, but not equal star or end point.
|
|
30
37
|
* @param p
|
|
31
|
-
* @param d
|
|
38
|
+
* @param [d=0]
|
|
32
39
|
*/
|
|
33
40
|
insideRange(p: DPoint, d?: number): boolean;
|
|
34
41
|
get center(): DPoint;
|
|
@@ -80,10 +87,10 @@ export declare class DLine {
|
|
|
80
87
|
* @param l
|
|
81
88
|
* @param delta
|
|
82
89
|
*/
|
|
83
|
-
findFi(
|
|
90
|
+
findFi({ a, b }: DLine, delta?: number): number;
|
|
84
91
|
/**
|
|
85
92
|
* [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
86
|
-
* @param l
|
|
93
|
+
* @param l {DLine}
|
|
87
94
|
*/
|
|
88
|
-
vectorProduct(
|
|
95
|
+
vectorProduct({ a, b, c }: DLine): DLine;
|
|
89
96
|
}
|
package/dist/DLine.js
CHANGED
|
@@ -3,38 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DLine = void 0;
|
|
4
4
|
const DPoint_1 = require("./DPoint");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
+
// eslint-disable-next-line padded-blocks
|
|
6
7
|
class DLine {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @param a
|
|
10
|
+
* @param b
|
|
11
|
+
* @param c
|
|
12
|
+
* @param [begin=DPoint.zero()]
|
|
13
|
+
* @param [end=DPoint.zero()]
|
|
14
|
+
*/
|
|
15
|
+
// eslint-disable-next-line no-useless-constructor
|
|
16
|
+
constructor(a, b, c, begin = DPoint_1.DPoint.zero(), end = DPoint_1.DPoint.zero()
|
|
17
|
+
// eslint-disable-next-line no-empty-function
|
|
18
|
+
) {
|
|
13
19
|
this.a = a;
|
|
14
20
|
this.b = b;
|
|
15
21
|
this.c = c;
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
22
|
+
this.begin = begin;
|
|
23
|
+
this.end = end;
|
|
18
24
|
}
|
|
19
25
|
clone() {
|
|
20
|
-
return new DLine(this.a, this.b, this.c, this.
|
|
26
|
+
return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
|
|
21
27
|
}
|
|
22
28
|
findPerpendicular(p) {
|
|
23
29
|
(0, utils_1.checkFunction)('findPerpendicular')
|
|
24
|
-
.checkArgument('this.
|
|
25
|
-
.shouldBeMeters(this.
|
|
26
|
-
.checkArgument('this.
|
|
27
|
-
.shouldBeMeters(this.
|
|
30
|
+
.checkArgument('this.begin')
|
|
31
|
+
.shouldBeMeters(this.begin)
|
|
32
|
+
.checkArgument('this.end')
|
|
33
|
+
.shouldBeMeters(this.end)
|
|
28
34
|
.checkArgument('p')
|
|
29
35
|
.shouldBeMeters(p);
|
|
30
36
|
return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
|
|
31
37
|
}
|
|
32
38
|
perpendicularDistance(p) {
|
|
33
39
|
(0, utils_1.checkFunction)('perpendicularDistance')
|
|
34
|
-
.checkArgument('this.
|
|
35
|
-
.shouldBeMeters(this.
|
|
36
|
-
.checkArgument('this.
|
|
37
|
-
.shouldBeMeters(this.
|
|
40
|
+
.checkArgument('this.begin')
|
|
41
|
+
.shouldBeMeters(this.begin)
|
|
42
|
+
.checkArgument('this.end')
|
|
43
|
+
.shouldBeMeters(this.end)
|
|
38
44
|
.checkArgument('p')
|
|
39
45
|
.shouldBeMeters(p);
|
|
40
46
|
const perpendicularLine = this.findPerpendicular(p);
|
|
@@ -63,10 +69,10 @@ class DLine {
|
|
|
63
69
|
const per = this.findPerpendicular(center);
|
|
64
70
|
const t = this.intersection(per, Infinity);
|
|
65
71
|
let distance = t.distance(center);
|
|
66
|
-
if (this.
|
|
72
|
+
if (this.begin.equal(center)) {
|
|
67
73
|
distance = 0;
|
|
68
74
|
}
|
|
69
|
-
if (this.
|
|
75
|
+
if (this.end.equal(center)) {
|
|
70
76
|
distance = 0;
|
|
71
77
|
}
|
|
72
78
|
if (distance < r) {
|
|
@@ -76,25 +82,25 @@ class DLine {
|
|
|
76
82
|
const move = Math.sqrt(r * r - ct * ct);
|
|
77
83
|
// Mean "|" x = const
|
|
78
84
|
if (this.isParallelY) {
|
|
79
|
-
t.x = this.
|
|
85
|
+
t.x = this.begin.x;
|
|
80
86
|
const r1 = t.clone().move(0, -move);
|
|
81
87
|
const r2 = t.clone().move(0, move);
|
|
82
88
|
return [r1, r2];
|
|
83
89
|
}
|
|
84
90
|
// Mean "-" y = const
|
|
85
91
|
if (this.isParallelX) {
|
|
86
|
-
t.y = this.
|
|
92
|
+
t.y = this.begin.y;
|
|
87
93
|
const r1 = t.clone().move(move, 0);
|
|
88
94
|
const r2 = t.clone().move(-move, 0);
|
|
89
95
|
return [r1, r2];
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
|
-
if (this.
|
|
93
|
-
const p = this.
|
|
98
|
+
if (this.begin.like(center)) {
|
|
99
|
+
const p = this.begin.clone();
|
|
94
100
|
return [this.movePoint(p, r), this.movePoint(p, -r)];
|
|
95
101
|
}
|
|
96
|
-
if (this.
|
|
97
|
-
const p = this.
|
|
102
|
+
if (this.end.like(center)) {
|
|
103
|
+
const p = this.end.clone();
|
|
98
104
|
return [this.movePoint(p, r), this.movePoint(p, -r)];
|
|
99
105
|
}
|
|
100
106
|
const s = a * a + b * b;
|
|
@@ -124,19 +130,19 @@ class DLine {
|
|
|
124
130
|
/**
|
|
125
131
|
* Check if point below to line segment, but not equal star or end point.
|
|
126
132
|
* @param p
|
|
127
|
-
* @param d
|
|
133
|
+
* @param [d=0]
|
|
128
134
|
*/
|
|
129
135
|
insideRange(p, d = 0) {
|
|
130
|
-
const {
|
|
131
|
-
return this.inRange(p, d) && !
|
|
136
|
+
const { begin, end } = this;
|
|
137
|
+
return this.inRange(p, d) && !begin.like(p, 0.00001) && !end.like(p, 0.00001);
|
|
132
138
|
}
|
|
133
139
|
get center() {
|
|
134
|
-
return this.
|
|
140
|
+
return this.begin
|
|
135
141
|
.clone()
|
|
136
|
-
.setIfLessThan(this.
|
|
137
|
-
.move(this.
|
|
142
|
+
.setIfLessThan(this.end)
|
|
143
|
+
.move(this.end
|
|
138
144
|
.clone()
|
|
139
|
-
.move(this.
|
|
145
|
+
.move(this.begin
|
|
140
146
|
.clone()
|
|
141
147
|
.minus())
|
|
142
148
|
.abs()
|
|
@@ -144,16 +150,16 @@ class DLine {
|
|
|
144
150
|
.divide(2));
|
|
145
151
|
}
|
|
146
152
|
get minX() {
|
|
147
|
-
return Math.min(this.
|
|
153
|
+
return Math.min(this.begin.x, this.end.x);
|
|
148
154
|
}
|
|
149
155
|
get minY() {
|
|
150
|
-
return Math.min(this.
|
|
156
|
+
return Math.min(this.begin.y, this.end.y);
|
|
151
157
|
}
|
|
152
158
|
get maxX() {
|
|
153
|
-
return Math.max(this.
|
|
159
|
+
return Math.max(this.begin.x, this.end.x);
|
|
154
160
|
}
|
|
155
161
|
get maxY() {
|
|
156
|
-
return Math.max(this.
|
|
162
|
+
return Math.max(this.begin.y, this.end.y);
|
|
157
163
|
}
|
|
158
164
|
toString() {
|
|
159
165
|
return `(${this.a}, ${this.b}, ${this.c})`;
|
|
@@ -243,47 +249,26 @@ class DLine {
|
|
|
243
249
|
* Get lines segment start and end points as array
|
|
244
250
|
*/
|
|
245
251
|
get points() {
|
|
246
|
-
return [this.
|
|
252
|
+
return [this.begin, this.end];
|
|
247
253
|
}
|
|
248
254
|
/**
|
|
249
255
|
* Get line segment direction (from start point to end point)
|
|
250
256
|
*/
|
|
251
257
|
getFi() {
|
|
252
258
|
(0, utils_1.checkFunction)('getFi')
|
|
253
|
-
.checkArgument('this.
|
|
254
|
-
.shouldBeMeters(this.
|
|
255
|
-
.checkArgument('this.
|
|
256
|
-
.shouldBeMeters(this.
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
return 0;
|
|
262
|
-
}
|
|
263
|
-
else if (this.p1.y < this.p2.y) {
|
|
264
|
-
return Math.PI + Math.PI / 2;
|
|
265
|
-
}
|
|
266
|
-
return Math.PI / 2;
|
|
259
|
+
.checkArgument('this.begin')
|
|
260
|
+
.shouldBeMeters(this.begin)
|
|
261
|
+
.checkArgument('this.end')
|
|
262
|
+
.shouldBeMeters(this.end);
|
|
263
|
+
const { x, y } = this.end.clone().move(this.begin.clone().minus());
|
|
264
|
+
let v = Math.atan2(y, x) - Math.PI;
|
|
265
|
+
if (v > 0) {
|
|
266
|
+
v = Math.PI - v;
|
|
267
267
|
}
|
|
268
|
-
|
|
269
|
-
if (this.p1.y === this.p2.y) {
|
|
270
|
-
return 0;
|
|
271
|
-
}
|
|
272
|
-
else if (this.p1.y < this.p2.y) {
|
|
273
|
-
return Math.PI - result + Math.PI;
|
|
274
|
-
}
|
|
275
|
-
return result;
|
|
276
|
-
}
|
|
277
|
-
if (this.p1.y === this.p2.y) {
|
|
278
|
-
return Math.PI;
|
|
279
|
-
}
|
|
280
|
-
else if (this.p1.y < this.p2.y) {
|
|
281
|
-
return Math.PI - result + Math.PI;
|
|
282
|
-
}
|
|
283
|
-
return result;
|
|
268
|
+
return (Math.PI - v) % (Math.PI * 2);
|
|
284
269
|
}
|
|
285
270
|
toWKT() {
|
|
286
|
-
const {
|
|
271
|
+
const { begin: { x: x1, y: y1 }, end: { x: x2, y: y2 } } = this;
|
|
287
272
|
return `LINESTRING (${x1} ${y1}, ${x2} ${y2})`;
|
|
288
273
|
}
|
|
289
274
|
/**
|
|
@@ -293,7 +278,7 @@ class DLine {
|
|
|
293
278
|
*/
|
|
294
279
|
movePoint(p, d) {
|
|
295
280
|
const fi = this.findFi(new DLine(1, 0, 0));
|
|
296
|
-
const td = this.
|
|
281
|
+
const td = this.begin.distance(this.end) / 2;
|
|
297
282
|
const dcosT = td * Math.cos(fi);
|
|
298
283
|
const dsinT = td * Math.sin(fi);
|
|
299
284
|
const p1T = new DPoint_1.DPoint(p.x - dsinT, p.y - dcosT);
|
|
@@ -312,8 +297,9 @@ class DLine {
|
|
|
312
297
|
* @param l
|
|
313
298
|
* @param delta
|
|
314
299
|
*/
|
|
315
|
-
findFi(
|
|
316
|
-
|
|
300
|
+
findFi({ a, b }, delta = 1.0001) {
|
|
301
|
+
const { a: q, b: w } = this;
|
|
302
|
+
let val = (q * a + w * b) / (Math.sqrt(q * q + w * w) * Math.sqrt(a * a + b * b));
|
|
317
303
|
if (val > 1 && val < delta) {
|
|
318
304
|
val = 1;
|
|
319
305
|
}
|
|
@@ -324,13 +310,11 @@ class DLine {
|
|
|
324
310
|
}
|
|
325
311
|
/**
|
|
326
312
|
* [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
327
|
-
* @param l
|
|
313
|
+
* @param l {DLine}
|
|
328
314
|
*/
|
|
329
|
-
vectorProduct(
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
const k = this.a * l.b - this.b * l.a;
|
|
333
|
-
return new DLine(i, j, k);
|
|
315
|
+
vectorProduct({ a, b, c }) {
|
|
316
|
+
const { a: q, b: w, c: e } = this;
|
|
317
|
+
return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
|
|
334
318
|
}
|
|
335
319
|
}
|
|
336
320
|
exports.DLine = DLine;
|
package/dist/DPoint.d.ts
CHANGED
|
@@ -15,22 +15,36 @@ 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
|
+
* Create point
|
|
28
|
+
* @param xy - `x` and `y` value
|
|
29
|
+
*/
|
|
30
|
+
constructor(xy: number);
|
|
31
|
+
/**
|
|
32
|
+
* Create point
|
|
33
|
+
* @param x - lng, meters to East, radians to East or width
|
|
34
|
+
* @param y - lat, meters to North, radians to North or height
|
|
35
|
+
*/
|
|
36
|
+
constructor(x: number, y: number);
|
|
37
|
+
/**
|
|
38
|
+
* Create point
|
|
24
39
|
* @param x - lng, meters to East, radians to East or width
|
|
25
40
|
* @param y - lat, meters to North, radians to North or height
|
|
26
41
|
* @param z - height
|
|
27
42
|
*/
|
|
28
|
-
constructor(x
|
|
29
|
-
static
|
|
43
|
+
constructor(x: number, y: number, z?: number);
|
|
44
|
+
static zero(): DPoint;
|
|
30
45
|
static parse(c: LatLng | number[] | DCoord): DPoint;
|
|
31
|
-
static isPoint(p: unknown): boolean;
|
|
32
46
|
static parseFromWKT(wkt: string): DPoint;
|
|
33
|
-
static
|
|
47
|
+
static random(): DPoint;
|
|
34
48
|
/**
|
|
35
49
|
* @remark Point should be Lng/Lat.
|
|
36
50
|
*
|
|
@@ -59,8 +73,26 @@ export declare class DPoint {
|
|
|
59
73
|
height(z: number): DPoint;
|
|
60
74
|
toWKT(): string;
|
|
61
75
|
distance(p: DPoint): number;
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Set `x` value
|
|
78
|
+
* @param x
|
|
79
|
+
*/
|
|
80
|
+
setX(x: number): DPoint;
|
|
81
|
+
/**
|
|
82
|
+
* Transform `x` value by function
|
|
83
|
+
* @param f
|
|
84
|
+
*/
|
|
85
|
+
setX(f: SetterFunction): DPoint;
|
|
86
|
+
/**
|
|
87
|
+
* Set `y` value
|
|
88
|
+
* @param y
|
|
89
|
+
*/
|
|
90
|
+
setY(y: number): DPoint;
|
|
91
|
+
/**
|
|
92
|
+
* Transform `y` value by function
|
|
93
|
+
* @param f
|
|
94
|
+
*/
|
|
95
|
+
setY(f: SetterFunction): DPoint;
|
|
64
96
|
clone(): DPoint;
|
|
65
97
|
gt(p: DPoint): boolean;
|
|
66
98
|
lt(p: DPoint): boolean;
|
|
@@ -71,7 +103,22 @@ export declare class DPoint {
|
|
|
71
103
|
* @param a radians
|
|
72
104
|
*/
|
|
73
105
|
rotate(a: number): DPoint;
|
|
74
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Add `v` to `x` and `y`
|
|
108
|
+
* @param v
|
|
109
|
+
*/
|
|
110
|
+
move(v: number): DPoint;
|
|
111
|
+
/**
|
|
112
|
+
* Add `p.x` to `x` field and `p.y` to `y` field.
|
|
113
|
+
* @param p
|
|
114
|
+
*/
|
|
115
|
+
move(p: DPoint): DPoint;
|
|
116
|
+
/**
|
|
117
|
+
* Add `x` to `x` field and `y` to `y` field.
|
|
118
|
+
* @param x
|
|
119
|
+
* @param y
|
|
120
|
+
*/
|
|
121
|
+
move(x: number, y: number): DPoint;
|
|
75
122
|
degreeToMeters(): DPoint;
|
|
76
123
|
metersToDegree(): DPoint;
|
|
77
124
|
degreeToRadians(): DPoint;
|
|
@@ -81,13 +128,59 @@ export declare class DPoint {
|
|
|
81
128
|
round(): DPoint;
|
|
82
129
|
ceil(): DPoint;
|
|
83
130
|
floor(): DPoint;
|
|
131
|
+
/**
|
|
132
|
+
* @param [n=2]
|
|
133
|
+
*/
|
|
84
134
|
toFixed(n?: number): DPoint;
|
|
85
135
|
abs(): DPoint;
|
|
86
|
-
|
|
87
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Multiply `v` to `x` and `y`
|
|
138
|
+
* @param v
|
|
139
|
+
*/
|
|
140
|
+
scale(v: number): DPoint;
|
|
141
|
+
/**
|
|
142
|
+
* Multiply `p.x` to `x` field and `p.y` to `y` field.
|
|
143
|
+
* @param p
|
|
144
|
+
*/
|
|
145
|
+
scale(p: DPoint): DPoint;
|
|
146
|
+
/**
|
|
147
|
+
* Multiply `x` to `x` field and `y` to `y` field.
|
|
148
|
+
* @param x
|
|
149
|
+
* @param y
|
|
150
|
+
*/
|
|
151
|
+
scale(x: number, y: number): DPoint;
|
|
152
|
+
/**
|
|
153
|
+
* Divide `x` and `y` to `v`
|
|
154
|
+
* @param v
|
|
155
|
+
*/
|
|
156
|
+
divide(v: number): DPoint;
|
|
157
|
+
/**
|
|
158
|
+
* Divide `x` field to `p.x` and `y` field to `p.y`.
|
|
159
|
+
* @param p
|
|
160
|
+
*/
|
|
161
|
+
divide(p: DPoint): DPoint;
|
|
162
|
+
/**
|
|
163
|
+
* Divide `x` field to `x` and `y` field to `y`.
|
|
164
|
+
* @param x
|
|
165
|
+
* @param y
|
|
166
|
+
*/
|
|
167
|
+
divide(x: number, y: number): DPoint;
|
|
88
168
|
equal(p: DPoint): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* @param p
|
|
171
|
+
* @param [d=0.001]
|
|
172
|
+
*/
|
|
89
173
|
like(p: DPoint, d?: number): boolean;
|
|
90
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Flip vertically
|
|
176
|
+
* @param size canvas size
|
|
177
|
+
*/
|
|
178
|
+
flipVertically(size: DPoint): DPoint;
|
|
179
|
+
/**
|
|
180
|
+
* Flip vertically
|
|
181
|
+
* @param height canvas height
|
|
182
|
+
*/
|
|
183
|
+
flipVertically(height: number): DPoint;
|
|
91
184
|
/**
|
|
92
185
|
* Check if point looks like radians
|
|
93
186
|
*/
|
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 +
|