dgeoutils 2.2.4 → 2.2.8

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 CHANGED
@@ -3,10 +3,6 @@ import { DPolygon } from './DPolygon';
3
3
  export declare class DCircle {
4
4
  center: DPoint;
5
5
  r: number;
6
- /**
7
- * @param [center=(0,0)]
8
- * @param [r=0]
9
- */
10
6
  constructor(center?: DPoint, r?: number);
11
7
  toString(): string;
12
8
  getValue(): {
@@ -14,33 +10,9 @@ export declare class DCircle {
14
10
  r: number;
15
11
  };
16
12
  clone(): DCircle;
17
- /**
18
- * Find intersection points with other circle.
19
- *
20
- * ![Example](https://edejin.github.io/DGeoUtils/media/examples/findPoints.png)
21
- * @param c
22
- */
23
13
  findPoints(c: DCircle): DPoint[] | number;
24
14
  equal({ center, r }: DCircle): boolean;
25
- /**
26
- * Transform circle to polygon
27
- *
28
- * ![Example](https://edejin.github.io/DGeoUtils/media/examples/findPolygonInside.png)
29
- * @param [pointCount=64]
30
- */
31
15
  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
- * ![Example](https://edejin.github.io/DGeoUtils/media/examples/findPolygonInsideOnSphere.png)
42
- * @param [pointCount=64]
43
- */
44
16
  findPolygonInsideOnSphere(pointCount?: number): DPolygon;
45
17
  private sphereOffset;
46
18
  }
package/dist/DCircle.js CHANGED
@@ -5,13 +5,7 @@ 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
9
8
  class DCircle {
10
- /**
11
- * @param [center=(0,0)]
12
- * @param [r=0]
13
- */
14
- // eslint-disable-next-line no-useless-constructor,no-empty-function
15
9
  constructor(center = DPoint_1.DPoint.zero(), r = 0) {
16
10
  this.center = center;
17
11
  this.r = r;
@@ -25,12 +19,6 @@ class DCircle {
25
19
  clone() {
26
20
  return new DCircle(this.center, this.r);
27
21
  }
28
- /**
29
- * Find intersection points with other circle.
30
- *
31
- * ![Example](https://edejin.github.io/DGeoUtils/media/examples/findPoints.png)
32
- * @param c
33
- */
34
22
  findPoints(c) {
35
23
  if (this.equal(c)) {
36
24
  return Infinity;
@@ -63,12 +51,6 @@ class DCircle {
63
51
  equal({ center, r }) {
64
52
  return this.center.equal(center) && this.r === r;
65
53
  }
66
- /**
67
- * Transform circle to polygon
68
- *
69
- * ![Example](https://edejin.github.io/DGeoUtils/media/examples/findPolygonInside.png)
70
- * @param [pointCount=64]
71
- */
72
54
  findPolygonInside(pointCount = 64) {
73
55
  const preAngle = 2 * Math.PI / pointCount;
74
56
  const points = [];
@@ -80,18 +62,6 @@ class DCircle {
80
62
  }
81
63
  return new DPolygon_1.DPolygon([...points, points[0]]);
82
64
  }
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
- * ![Example](https://edejin.github.io/DGeoUtils/media/examples/findPolygonInsideOnSphere.png)
93
- * @param [pointCount=64]
94
- */
95
65
  findPolygonInsideOnSphere(pointCount = 64) {
96
66
  (0, utils_1.checkFunction)('findPolygonInsideOnSphere')
97
67
  .checkArgument('center')
package/dist/DLine.d.ts CHANGED
@@ -4,32 +4,15 @@ export declare class DLine {
4
4
  a: number;
5
5
  b: number;
6
6
  c: number;
7
- p1: DPoint;
8
- p2: DPoint;
9
- constructor(a?: number, b?: number, c?: number, p1?: DPoint, p2?: DPoint);
7
+ begin: DPoint;
8
+ end: DPoint;
9
+ constructor(a: number, b: number, c: number, begin?: DPoint, end?: DPoint);
10
10
  clone(): DLine;
11
11
  findPerpendicular(p: DPoint): DLine;
12
12
  perpendicularDistance(p: DPoint): number;
13
- /**
14
- * Find intersection of two lines segments.
15
- * For intersection of two lines use [[findPoint]]
16
- * @param l
17
- * @param [d=0]
18
- * @param [includeOnly=false]
19
- */
20
13
  intersection(l: DLine, d?: number, includeOnly?: boolean): DPoint | null;
21
14
  intersectionWithCircle(circle: DCircle): DPoint | [DPoint, DPoint] | null;
22
- /**
23
- * Check if point below to line segment
24
- * @param p
25
- * @param d
26
- */
27
15
  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
16
  insideRange(p: DPoint, d?: number): boolean;
34
17
  get center(): DPoint;
35
18
  get minX(): number;
@@ -38,52 +21,16 @@ export declare class DLine {
38
21
  get maxY(): number;
39
22
  toString(): string;
40
23
  getValue(): number[];
41
- /**
42
- * Find `x` from `y` value of point
43
- * @param p
44
- */
45
24
  x(p: DPoint): DPoint;
46
- /**
47
- * Find `y` from `x` value of point
48
- * @param p
49
- */
50
25
  y(p: DPoint): DPoint;
51
- /**
52
- * Find intersection of two lines.
53
- * For intersection of two lines segments use [[intersection]]
54
- * @param l
55
- */
56
26
  findPoint(l: DLine): DPoint | null;
57
- /**
58
- * Check if line parallel to `x` or `y` axis
59
- */
60
27
  get isParallel(): boolean;
61
28
  get isParallelY(): boolean;
62
29
  get isParallelX(): boolean;
63
- /**
64
- * Get lines segment start and end points as array
65
- */
66
30
  get points(): [DPoint, DPoint];
67
- /**
68
- * Get line segment direction (from start point to end point)
69
- */
70
31
  getFi(): number;
71
32
  toWKT(): string;
72
- /**
73
- * Move lines point to left or right
74
- * @param p
75
- * @param d
76
- */
77
33
  movePoint(p: DPoint, d: number): DPoint;
78
- /**
79
- * Find angle between current line and line in argument
80
- * @param l
81
- * @param delta
82
- */
83
- findFi(l: DLine, delta?: number): number;
84
- /**
85
- * [Cross product](https://en.wikipedia.org/wiki/Cross_product)
86
- * @param l
87
- */
88
- vectorProduct(l: DLine): DLine;
34
+ findFi({ a, b }: DLine, delta?: number): number;
35
+ vectorProduct({ a, b, c }: DLine): DLine;
89
36
  }
package/dist/DLine.js CHANGED
@@ -4,48 +4,38 @@ exports.DLine = void 0;
4
4
  const DPoint_1 = require("./DPoint");
5
5
  const utils_1 = require("./utils");
6
6
  class DLine {
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
- ) {
7
+ constructor(a, b, c, begin = DPoint_1.DPoint.zero(), end = DPoint_1.DPoint.zero()) {
11
8
  this.a = a;
12
9
  this.b = b;
13
10
  this.c = c;
14
- this.p1 = p1;
15
- this.p2 = p2;
11
+ this.begin = begin;
12
+ this.end = end;
16
13
  }
17
14
  clone() {
18
- return new DLine(this.a, this.b, this.c, this.p1.clone(), this.p2.clone());
15
+ return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
19
16
  }
20
17
  findPerpendicular(p) {
21
18
  (0, utils_1.checkFunction)('findPerpendicular')
22
- .checkArgument('this.p1')
23
- .shouldBeMeters(this.p1)
24
- .checkArgument('this.p2')
25
- .shouldBeMeters(this.p2)
19
+ .checkArgument('this.begin')
20
+ .shouldBeMeters(this.begin)
21
+ .checkArgument('this.end')
22
+ .shouldBeMeters(this.end)
26
23
  .checkArgument('p')
27
24
  .shouldBeMeters(p);
28
25
  return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
29
26
  }
30
27
  perpendicularDistance(p) {
31
28
  (0, utils_1.checkFunction)('perpendicularDistance')
32
- .checkArgument('this.p1')
33
- .shouldBeMeters(this.p1)
34
- .checkArgument('this.p2')
35
- .shouldBeMeters(this.p2)
29
+ .checkArgument('this.begin')
30
+ .shouldBeMeters(this.begin)
31
+ .checkArgument('this.end')
32
+ .shouldBeMeters(this.end)
36
33
  .checkArgument('p')
37
34
  .shouldBeMeters(p);
38
35
  const perpendicularLine = this.findPerpendicular(p);
39
36
  const targetPoint = perpendicularLine.findPoint(this);
40
37
  return targetPoint.distance(p);
41
38
  }
42
- /**
43
- * Find intersection of two lines segments.
44
- * For intersection of two lines use [[findPoint]]
45
- * @param l
46
- * @param [d=0]
47
- * @param [includeOnly=false]
48
- */
49
39
  intersection(l, d = 0, includeOnly = false) {
50
40
  const p = this.findPoint(l);
51
41
  if (p) {
@@ -61,10 +51,10 @@ class DLine {
61
51
  const per = this.findPerpendicular(center);
62
52
  const t = this.intersection(per, Infinity);
63
53
  let distance = t.distance(center);
64
- if (this.p1.equal(center)) {
54
+ if (this.begin.equal(center)) {
65
55
  distance = 0;
66
56
  }
67
- if (this.p2.equal(center)) {
57
+ if (this.end.equal(center)) {
68
58
  distance = 0;
69
59
  }
70
60
  if (distance < r) {
@@ -72,27 +62,25 @@ class DLine {
72
62
  if (this.isParallel) {
73
63
  const ct = center.distance(t);
74
64
  const move = Math.sqrt(r * r - ct * ct);
75
- // Mean "|" x = const
76
65
  if (this.isParallelY) {
77
- t.x = this.p1.x;
66
+ t.x = this.begin.x;
78
67
  const r1 = t.clone().move(0, -move);
79
68
  const r2 = t.clone().move(0, move);
80
69
  return [r1, r2];
81
70
  }
82
- // Mean "-" y = const
83
71
  if (this.isParallelX) {
84
- t.y = this.p1.y;
72
+ t.y = this.begin.y;
85
73
  const r1 = t.clone().move(move, 0);
86
74
  const r2 = t.clone().move(-move, 0);
87
75
  return [r1, r2];
88
76
  }
89
77
  }
90
- if (this.p1.like(center)) {
91
- const p = this.p1.clone();
78
+ if (this.begin.like(center)) {
79
+ const p = this.begin.clone();
92
80
  return [this.movePoint(p, r), this.movePoint(p, -r)];
93
81
  }
94
- if (this.p2.like(center)) {
95
- const p = this.p2.clone();
82
+ if (this.end.like(center)) {
83
+ const p = this.end.clone();
96
84
  return [this.movePoint(p, r), this.movePoint(p, -r)];
97
85
  }
98
86
  const s = a * a + b * b;
@@ -107,11 +95,6 @@ class DLine {
107
95
  }
108
96
  return null;
109
97
  }
110
- /**
111
- * Check if point below to line segment
112
- * @param p
113
- * @param d
114
- */
115
98
  inRange(p, d = 0) {
116
99
  const { minX, minY, maxX, maxY } = this;
117
100
  const { x, y } = p;
@@ -119,22 +102,17 @@ class DLine {
119
102
  const isInY = y >= minY - d && y <= maxY + d;
120
103
  return isInX && isInY;
121
104
  }
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
105
  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);
106
+ const { begin, end } = this;
107
+ return this.inRange(p, d) && !begin.like(p, 0.00001) && !end.like(p, 0.00001);
130
108
  }
131
109
  get center() {
132
- return this.p1
110
+ return this.begin
133
111
  .clone()
134
- .setIfLessThan(this.p2)
135
- .move(this.p2
112
+ .setIfLessThan(this.end)
113
+ .move(this.end
136
114
  .clone()
137
- .move(this.p1
115
+ .move(this.begin
138
116
  .clone()
139
117
  .minus())
140
118
  .abs()
@@ -142,16 +120,16 @@ class DLine {
142
120
  .divide(2));
143
121
  }
144
122
  get minX() {
145
- return Math.min(this.p1.x, this.p2.x);
123
+ return Math.min(this.begin.x, this.end.x);
146
124
  }
147
125
  get minY() {
148
- return Math.min(this.p1.y, this.p2.y);
126
+ return Math.min(this.begin.y, this.end.y);
149
127
  }
150
128
  get maxX() {
151
- return Math.max(this.p1.x, this.p2.x);
129
+ return Math.max(this.begin.x, this.end.x);
152
130
  }
153
131
  get maxY() {
154
- return Math.max(this.p1.y, this.p2.y);
132
+ return Math.max(this.begin.y, this.end.y);
155
133
  }
156
134
  toString() {
157
135
  return `(${this.a}, ${this.b}, ${this.c})`;
@@ -159,10 +137,6 @@ class DLine {
159
137
  getValue() {
160
138
  return [this.a, this.b, this.c];
161
139
  }
162
- /**
163
- * Find `x` from `y` value of point
164
- * @param p
165
- */
166
140
  x(p) {
167
141
  if (this.isParallelY) {
168
142
  return new DPoint_1.DPoint(-this.c / this.a, p.y);
@@ -172,10 +146,6 @@ class DLine {
172
146
  }
173
147
  return new DPoint_1.DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
174
148
  }
175
- /**
176
- * Find `y` from `x` value of point
177
- * @param p
178
- */
179
149
  y(p) {
180
150
  if (this.isParallelY) {
181
151
  return new DPoint_1.DPoint(-this.c / this.a, p.y);
@@ -185,11 +155,6 @@ class DLine {
185
155
  }
186
156
  return new DPoint_1.DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
187
157
  }
188
- /**
189
- * Find intersection of two lines.
190
- * For intersection of two lines segments use [[intersection]]
191
- * @param l
192
- */
193
158
  findPoint(l) {
194
159
  if (this.isParallelY && l.isParallelY) {
195
160
  return null;
@@ -225,9 +190,6 @@ class DLine {
225
190
  }
226
191
  return res;
227
192
  }
228
- /**
229
- * Check if line parallel to `x` or `y` axis
230
- */
231
193
  get isParallel() {
232
194
  return this.isParallelX || this.isParallelY;
233
195
  }
@@ -237,61 +199,29 @@ class DLine {
237
199
  get isParallelX() {
238
200
  return Math.abs(this.a) < 0.001;
239
201
  }
240
- /**
241
- * Get lines segment start and end points as array
242
- */
243
202
  get points() {
244
- return [this.p1, this.p2];
203
+ return [this.begin, this.end];
245
204
  }
246
- /**
247
- * Get line segment direction (from start point to end point)
248
- */
249
205
  getFi() {
250
206
  (0, utils_1.checkFunction)('getFi')
251
- .checkArgument('this.p1')
252
- .shouldBeMeters(this.p1)
253
- .checkArgument('this.p2')
254
- .shouldBeMeters(this.p2);
255
- const l = new DLine(0, 1, 0);
256
- const result = this.findFi(l);
257
- if (this.p1.x === this.p2.x) {
258
- if (this.p1.y === this.p2.y) {
259
- return 0;
260
- }
261
- else if (this.p1.y < this.p2.y) {
262
- return Math.PI + Math.PI / 2;
263
- }
264
- return Math.PI / 2;
265
- }
266
- else if (this.p1.x < this.p2.x) {
267
- if (this.p1.y === this.p2.y) {
268
- return 0;
269
- }
270
- else if (this.p1.y < this.p2.y) {
271
- return Math.PI - result + Math.PI;
272
- }
273
- return result;
274
- }
275
- if (this.p1.y === this.p2.y) {
276
- return Math.PI;
277
- }
278
- else if (this.p1.y < this.p2.y) {
279
- return Math.PI - result + Math.PI;
207
+ .checkArgument('this.begin')
208
+ .shouldBeMeters(this.begin)
209
+ .checkArgument('this.end')
210
+ .shouldBeMeters(this.end);
211
+ const { x, y } = this.end.clone().move(this.begin.clone().minus());
212
+ let v = Math.atan2(y, x) - Math.PI;
213
+ if (v > 0) {
214
+ v = Math.PI - v;
280
215
  }
281
- return result;
216
+ return (Math.PI - v) % (Math.PI * 2);
282
217
  }
283
218
  toWKT() {
284
- const { p1: { x: x1, y: y1 }, p2: { x: x2, y: y2 } } = this;
219
+ const { begin: { x: x1, y: y1 }, end: { x: x2, y: y2 } } = this;
285
220
  return `LINESTRING (${x1} ${y1}, ${x2} ${y2})`;
286
221
  }
287
- /**
288
- * Move lines point to left or right
289
- * @param p
290
- * @param d
291
- */
292
222
  movePoint(p, d) {
293
223
  const fi = this.findFi(new DLine(1, 0, 0));
294
- const td = this.p1.distance(this.p2) / 2;
224
+ const td = this.begin.distance(this.end) / 2;
295
225
  const dcosT = td * Math.cos(fi);
296
226
  const dsinT = td * Math.sin(fi);
297
227
  const p1T = new DPoint_1.DPoint(p.x - dsinT, p.y - dcosT);
@@ -305,13 +235,9 @@ class DLine {
305
235
  }
306
236
  return p3;
307
237
  }
308
- /**
309
- * Find angle between current line and line in argument
310
- * @param l
311
- * @param delta
312
- */
313
- findFi(l, delta = 1.0001) {
314
- let val = (this.a * l.a + this.b * l.b) / (Math.sqrt(this.a * this.a + this.b * this.b) * Math.sqrt(l.a * l.a + l.b * l.b));
238
+ findFi({ a, b }, delta = 1.0001) {
239
+ const { a: q, b: w } = this;
240
+ let val = (q * a + w * b) / (Math.sqrt(q * q + w * w) * Math.sqrt(a * a + b * b));
315
241
  if (val > 1 && val < delta) {
316
242
  val = 1;
317
243
  }
@@ -320,15 +246,9 @@ class DLine {
320
246
  }
321
247
  return Math.acos(val);
322
248
  }
323
- /**
324
- * [Cross product](https://en.wikipedia.org/wiki/Cross_product)
325
- * @param l
326
- */
327
- vectorProduct(l) {
328
- const i = this.b * l.c - this.c * l.b;
329
- const j = this.c * l.a - this.a * l.c;
330
- const k = this.a * l.b - this.b * l.a;
331
- return new DLine(i, j, k);
249
+ vectorProduct({ a, b, c }) {
250
+ const { a: q, b: w, c: e } = this;
251
+ return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
332
252
  }
333
253
  }
334
254
  exports.DLine = DLine;