dgeoutils 2.4.1 → 2.4.2

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.
Files changed (34) hide show
  1. package/dist/{cjs/DCircle.d.ts → DCircle.d.ts} +0 -0
  2. package/dist/{cjs/DCircle.js → DCircle.js} +0 -0
  3. package/dist/{cjs/DLine.d.ts → DLine.d.ts} +0 -0
  4. package/dist/{cjs/DLine.js → DLine.js} +0 -0
  5. package/dist/{cjs/DNumbers.d.ts → DNumbers.d.ts} +0 -0
  6. package/dist/{cjs/DNumbers.js → DNumbers.js} +0 -0
  7. package/dist/{cjs/DPlane.d.ts → DPlane.d.ts} +0 -0
  8. package/dist/{cjs/DPlane.js → DPlane.js} +0 -0
  9. package/dist/{cjs/DPoint.d.ts → DPoint.d.ts} +0 -0
  10. package/dist/{cjs/DPoint.js → DPoint.js} +0 -0
  11. package/dist/{cjs/DPolygon.d.ts → DPolygon.d.ts} +0 -0
  12. package/dist/{cjs/DPolygon.js → DPolygon.js} +0 -0
  13. package/dist/{cjs/DPolygonLoop.d.ts → DPolygonLoop.d.ts} +0 -0
  14. package/dist/{cjs/DPolygonLoop.js → DPolygonLoop.js} +0 -0
  15. package/dist/{cjs/FastSearch.d.ts → FastSearch.d.ts} +0 -0
  16. package/dist/{cjs/FastSearch.js → FastSearch.js} +0 -0
  17. package/dist/{cjs/TraceMatrix.d.ts → TraceMatrix.d.ts} +0 -0
  18. package/dist/{cjs/TraceMatrix.js → TraceMatrix.js} +0 -0
  19. package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  20. package/dist/{cjs/index.js → index.js} +0 -0
  21. package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
  22. package/dist/{cjs/utils.js → utils.js} +0 -0
  23. package/package.json +5 -6
  24. package/dist/es2015/DCircle.js +0 -87
  25. package/dist/es2015/DLine.js +0 -257
  26. package/dist/es2015/DNumbers.js +0 -22
  27. package/dist/es2015/DPlane.js +0 -105
  28. package/dist/es2015/DPoint.js +0 -472
  29. package/dist/es2015/DPolygon.js +0 -1040
  30. package/dist/es2015/DPolygonLoop.js +0 -392
  31. package/dist/es2015/FastSearch.js +0 -25
  32. package/dist/es2015/TraceMatrix.js +0 -200
  33. package/dist/es2015/index.js +0 -10
  34. package/dist/es2015/utils.js +0 -162
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "dgeoutils",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "Geometries utils for my projects",
5
5
  "scripts": {
6
- "build": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
7
- "build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015",
6
+ "build": "npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
8
7
  "build:esm": "tsc --module es2015 --target es5 --downlevelIteration --outDir dist/esm",
9
- "build:cjs": "tsc --module commonjs --target es2015 --declaration --downlevelIteration --outDir dist/cjs",
8
+ "build:cjs": "tsc",
10
9
  "build:umd": "rollup dist/esm/index.js --format umd -e \"jsts\" -g \"jsts:jsts\" --name \"DGeoUtils\" -m inline --file dist/umd/dgeoutils.js",
11
10
  "build:umd:min": "cd dist/umd && uglifyjs --compress --mangle --source-map --comments -o dgeoutils.min.js -- dgeoutils.js",
12
11
  "prepublishOnly": "npm run lint:report && npm run test && npm run test:badges && npm run doc && npm run build",
@@ -21,8 +20,8 @@
21
20
  },
22
21
  "author": "Efim Dejin <efim@dej.in.ua>",
23
22
  "license": "MIT",
24
- "main": "dist/cjs/index.js",
25
- "types": "dist/cjs/index.d.ts",
23
+ "main": "dist/index.js",
24
+ "types": "dist/index.d.ts",
26
25
  "files": [
27
26
  "/dist"
28
27
  ],
@@ -1,87 +0,0 @@
1
- import { DPoint, EARTH_RADIUS_IN_METERS } from './DPoint';
2
- import { DPolygon } from './DPolygon';
3
- import { checkFunction } from './utils';
4
- export class DCircle {
5
- constructor(center = DPoint.zero(), r = 0) {
6
- this.center = center;
7
- this.r = r;
8
- }
9
- toString() {
10
- return `(${this.center.toString()}, ${this.r})`;
11
- }
12
- getValue() {
13
- return { center: this.center, r: this.r };
14
- }
15
- clone() {
16
- return new DCircle(this.center, this.r);
17
- }
18
- findPoints(c) {
19
- if (this.equal(c)) {
20
- return Infinity;
21
- }
22
- const { center: { x: x0, y: y0 }, r: r0 } = this;
23
- const { center: { x: x1, y: y1 }, r: r1 } = c;
24
- const r02 = r0 * r0;
25
- const d = this.center.distance(c.center);
26
- const a = (r02 - r1 * r1 + d * d) / (2 * d);
27
- const h = Math.sqrt(r02 - a * a);
28
- const ad = a / d;
29
- const dy = y1 - y0;
30
- const dx = x1 - x0;
31
- const hd = h / d;
32
- const x2 = x0 + ad * (x1 - x0);
33
- const y2 = y0 + ad * (y1 - y0);
34
- const x31 = x2 + hd * dy;
35
- const y31 = y2 - hd * dx;
36
- const x32 = x2 - hd * dy;
37
- const y32 = y2 + hd * dx;
38
- const res = [];
39
- if (!isNaN(x31) && !isNaN(y31)) {
40
- res.push(new DPoint(x31, y31));
41
- }
42
- if (!isNaN(x32) && !isNaN(y32) && !(x31 === x32 && y31 === y32)) {
43
- res.push(new DPoint(x32, y32));
44
- }
45
- return res;
46
- }
47
- equal({ center, r }) {
48
- return this.center.equal(center) && this.r === r;
49
- }
50
- findPolygonInside(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
51
- const step = 2 * Math.PI / pointCount;
52
- const points = [];
53
- let angle = startAngle;
54
- while (angle < stopAngle - step) {
55
- points.push(new DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
56
- .move(this.center));
57
- angle += step;
58
- }
59
- const x = this.r * Math.cos(stopAngle) + this.center.x;
60
- const y = this.r * Math.sin(stopAngle) + this.center.y;
61
- points.push(new DPoint(x, y));
62
- return new DPolygon(points);
63
- }
64
- findPolygonInsideOnSphere(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
65
- checkFunction('findPolygonInsideOnSphere')
66
- .checkArgument('center')
67
- .shouldBeDegree(this.center);
68
- const step = 2 * Math.PI / pointCount;
69
- const points = [];
70
- let angle = startAngle;
71
- while (angle < stopAngle - step) {
72
- points.push(this.sphereOffset(angle));
73
- angle += step;
74
- }
75
- points.push(this.sphereOffset(stopAngle));
76
- return new DPolygon(points);
77
- }
78
- sphereOffset(bearing, earthRadius = EARTH_RADIUS_IN_METERS) {
79
- const { x: lon1, y: lat1 } = this.center.clone().degreeToRadians();
80
- const dByR = this.r / earthRadius;
81
- const lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
82
- Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
83
- const lon = lon1 +
84
- Math.atan2(Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
85
- return new DPoint(lon, lat).radiansToDegrees();
86
- }
87
- }
@@ -1,257 +0,0 @@
1
- import { DPoint } from './DPoint';
2
- import { checkFunction } from './utils';
3
- import { DNumbers } from './DNumbers';
4
- export class DLine {
5
- constructor(a, b, c, begin = DPoint.zero(), end = DPoint.zero()) {
6
- this.a = a;
7
- this.b = b;
8
- this.c = c;
9
- this.begin = begin;
10
- this.end = end;
11
- }
12
- clone() {
13
- return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
14
- }
15
- findPerpendicular(p) {
16
- checkFunction('findPerpendicular')
17
- .checkArgument('this.begin')
18
- .shouldBeMeters(this.begin)
19
- .checkArgument('this.end')
20
- .shouldBeMeters(this.end)
21
- .checkArgument('p')
22
- .shouldBeMeters(p);
23
- return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
24
- }
25
- perpendicularDistance(p) {
26
- checkFunction('perpendicularDistance')
27
- .checkArgument('this.begin')
28
- .shouldBeMeters(this.begin)
29
- .checkArgument('this.end')
30
- .shouldBeMeters(this.end)
31
- .checkArgument('p')
32
- .shouldBeMeters(p);
33
- const perpendicularLine = this.findPerpendicular(p);
34
- const targetPoint = perpendicularLine.findPoint(this);
35
- return targetPoint.distance(p);
36
- }
37
- intersection(l, d = 0, includeOnly = false) {
38
- const p = this.findPoint(l);
39
- if (p) {
40
- if (includeOnly) {
41
- return this.insideRange(p, d) && l.insideRange(p, d) ? p : null;
42
- }
43
- return this.inRange(p, d) && l.inRange(p, d) ? p : null;
44
- }
45
- return null;
46
- }
47
- intersectionWithCircle(circle) {
48
- const { center, r } = circle;
49
- const per = this.findPerpendicular(center);
50
- const t = this.findPoint(per);
51
- let distance = t.distance(center);
52
- if (this.begin.equal(center)) {
53
- distance = 0;
54
- }
55
- if (this.end.equal(center)) {
56
- distance = 0;
57
- }
58
- if (distance < r) {
59
- const { a, b, c } = this;
60
- if (this.isParallel) {
61
- const ct = center.distance(t);
62
- const move = Math.sqrt(r * r - ct * ct);
63
- if (this.isParallelY) {
64
- t.x = this.begin.x;
65
- const r1 = t.clone().move(0, -move);
66
- const r2 = t.clone().move(0, move);
67
- return [r1, r2];
68
- }
69
- if (this.isParallelX) {
70
- t.y = this.begin.y;
71
- const r1 = t.clone().move(move, 0);
72
- const r2 = t.clone().move(-move, 0);
73
- return [r1, r2];
74
- }
75
- }
76
- if (this.begin.like(center)) {
77
- const p = this.begin.clone();
78
- return [this.movePoint(p, r), this.movePoint(p, -r)];
79
- }
80
- if (this.end.like(center)) {
81
- const p = this.end.clone();
82
- return [this.movePoint(p, r), this.movePoint(p, -r)];
83
- }
84
- const s = a * a + b * b;
85
- const d = r * r - c * c / s;
86
- const mult = Math.sqrt(d / s);
87
- const r1 = t.clone().move(b * mult, -a * mult);
88
- const r2 = t.clone().move(-b * mult, a * mult);
89
- return [r1, r2];
90
- }
91
- if (distance === r) {
92
- return t;
93
- }
94
- return null;
95
- }
96
- inRange(p, d = 0) {
97
- const { minX, minY, maxX, maxY } = this;
98
- const { x, y } = p;
99
- const isInX = x >= minX - d && x <= maxX + d;
100
- const isInY = y >= minY - d && y <= maxY + d;
101
- return isInX && isInY;
102
- }
103
- insideRange(p, d = 0) {
104
- const { begin, end } = this;
105
- return this.inRange(p, d) && !begin.like(p, 0.00001) && !end.like(p, 0.00001);
106
- }
107
- get center() {
108
- return this.begin
109
- .clone()
110
- .setIfLessThan(this.end)
111
- .move(this.end
112
- .clone()
113
- .move(this.begin
114
- .clone()
115
- .minus())
116
- .abs()
117
- .minus()
118
- .divide(2));
119
- }
120
- get minX() {
121
- return Math.min(this.begin.x, this.end.x);
122
- }
123
- get minY() {
124
- return Math.min(this.begin.y, this.end.y);
125
- }
126
- get maxX() {
127
- return Math.max(this.begin.x, this.end.x);
128
- }
129
- get maxY() {
130
- return Math.max(this.begin.y, this.end.y);
131
- }
132
- toString() {
133
- return `(${this.a}, ${this.b}, ${this.c})`;
134
- }
135
- getValue() {
136
- return [this.a, this.b, this.c];
137
- }
138
- x(p) {
139
- if (this.isParallelY) {
140
- return new DPoint(-this.c / this.a, p.y);
141
- }
142
- if (this.isParallelX) {
143
- return new DPoint(p.x, -this.c / this.b);
144
- }
145
- return new DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
146
- }
147
- y(p) {
148
- if (this.isParallelY) {
149
- return new DPoint(-this.c / this.a, p.y);
150
- }
151
- if (this.isParallelX) {
152
- return new DPoint(p.x, -this.c / this.b);
153
- }
154
- return new DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
155
- }
156
- findPoint(l) {
157
- if (this.isParallelY && l.isParallelY) {
158
- return null;
159
- }
160
- if (this.isParallelX && l.isParallelX) {
161
- return null;
162
- }
163
- if (this.isParallelX && l.isParallelY) {
164
- return new DPoint(-l.c / l.a, -this.c / this.b);
165
- }
166
- if (this.isParallelY && l.isParallelX) {
167
- return new DPoint(-this.c / this.a, -l.c / l.b);
168
- }
169
- if (this.isParallelY) {
170
- const x = -this.c / this.a;
171
- return l.y(new DPoint(x));
172
- }
173
- if (this.isParallelX) {
174
- const y = -this.c / this.b;
175
- return l.x(new DPoint(0, y));
176
- }
177
- if (l.isParallelY) {
178
- const x = -l.c / l.a;
179
- return this.y(new DPoint(x));
180
- }
181
- if (l.isParallelX) {
182
- const y = -l.c / l.b;
183
- return this.x(new DPoint(0, y));
184
- }
185
- const res = this.y(new DPoint((l.c / l.b - this.c / this.b) / (this.a / this.b - l.a / l.b)));
186
- if (!isFinite(res.x) && !isFinite(res.y)) {
187
- return null;
188
- }
189
- return res;
190
- }
191
- get isParallel() {
192
- return this.isParallelX || this.isParallelY;
193
- }
194
- get isParallelY() {
195
- return Math.abs(this.b) < 0.001;
196
- }
197
- get isParallelX() {
198
- return Math.abs(this.a) < 0.001;
199
- }
200
- get points() {
201
- return [this.begin, this.end];
202
- }
203
- getFi() {
204
- checkFunction('getFi')
205
- .checkArgument('this.begin')
206
- .shouldBeMeters(this.begin)
207
- .checkArgument('this.end')
208
- .shouldBeMeters(this.end);
209
- const { x, y } = this.end.clone().move(this.begin.clone().minus());
210
- let v = Math.atan2(y, x) - Math.PI;
211
- if (v > 0) {
212
- v = Math.PI - v;
213
- }
214
- return (Math.PI - v) % (Math.PI * 2);
215
- }
216
- toWKT() {
217
- const { begin: { x: x1, y: y1 }, end: { x: x2, y: y2 } } = this;
218
- return `LINESTRING (${x1} ${y1}, ${x2} ${y2})`;
219
- }
220
- movePoint(i, k) {
221
- const isArray = Array.isArray(i);
222
- const p = isArray ? i : [i];
223
- const d = (isArray ? k : [k]);
224
- const fi = this.findFi(new DLine(1, 0, 0));
225
- const td = this.x(new DPoint(1, 1)).distance(this.x(new DPoint(2, 2))) / 2;
226
- const sinCos = new DPoint(Math.sin(fi), Math.cos(fi));
227
- const dt = sinCos.clone().scale(td);
228
- const p1T = p[0].clone().move(dt.clone().minus());
229
- const p2T = p[0].clone().move(dt);
230
- let res = [];
231
- if (DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers.like(this.y(p2T).y, p2T.y)) {
232
- res = p.map((t, index) => t.clone()
233
- .move(sinCos.clone().scale(d[index])));
234
- }
235
- else {
236
- res = p.map((t, index) => t.clone()
237
- .move(sinCos.clone().scale(d[index])
238
- .setX(({ x }) => -x)));
239
- }
240
- return isArray ? res : res[0];
241
- }
242
- findFi({ a, b }, delta = 1.0001) {
243
- const { a: q, b: w } = this;
244
- let val = (q * a + w * b) / (Math.sqrt(q * q + w * w) * Math.sqrt(a * a + b * b));
245
- if (val > 1 && val < delta) {
246
- val = 1;
247
- }
248
- else if (val < -1 && val > -delta) {
249
- val = -1;
250
- }
251
- return Math.acos(val);
252
- }
253
- vectorProduct({ a, b, c }) {
254
- const { a: q, b: w, c: e } = this;
255
- return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
256
- }
257
- }
@@ -1,22 +0,0 @@
1
- import { DEGREE_TO_PI, DOUBLE_PI_IN_DEGREE, PI_IN_DEGREE, PI_TO_DEGREE } from './DPoint';
2
- const delta = 0.001;
3
- export class DNumbers {
4
- static like(v, s, d = delta) {
5
- return Math.abs(v - s) < d;
6
- }
7
- static likeZero(v) {
8
- return DNumbers.like(v, 0);
9
- }
10
- static like2PI(v) {
11
- return DNumbers.like(DNumbers.rad2Deg(v), DOUBLE_PI_IN_DEGREE);
12
- }
13
- static likePI(v) {
14
- return DNumbers.like(DNumbers.rad2Deg(v), PI_IN_DEGREE);
15
- }
16
- static rad2Deg(v) {
17
- return v * DEGREE_TO_PI;
18
- }
19
- static deg2Rad(v) {
20
- return v * PI_TO_DEGREE;
21
- }
22
- }
@@ -1,105 +0,0 @@
1
- import { DPoint } from './DPoint';
2
- import { gaussianElimination } from './utils';
3
- import { DNumbers } from './DNumbers';
4
- export class DPlane {
5
- constructor(a, b, c, d, p1 = DPoint.zero(), p2 = DPoint.zero(), p3 = DPoint.zero()) {
6
- this.a = a;
7
- this.b = b;
8
- this.c = c;
9
- this.d = d;
10
- this.p1 = p1;
11
- this.p2 = p2;
12
- this.p3 = p3;
13
- }
14
- static find(p1, p2, p3) {
15
- if (p1.x === p2.x && p2.x === p3.x) {
16
- return new DPlane(1, 0, 0, -p1.x, p1, p2, p3);
17
- }
18
- if (p1.y === p2.y && p2.y === p3.y) {
19
- return new DPlane(0, 1, 0, -p1.y, p1, p2, p3);
20
- }
21
- if (p1.z === p2.z && p2.z === p3.z) {
22
- return new DPlane(0, 0, 1, -p1.z, p1, p2, p3);
23
- }
24
- const d = 1;
25
- const [a, b, c] = gaussianElimination([
26
- [p1.x, p1.y, p1.z, -d],
27
- [p2.x, p2.y, p2.z, -d],
28
- [p3.x, p3.y, p3.z, -d]
29
- ]);
30
- return new DPlane(a, b, c, d, p1, p2, p3);
31
- }
32
- x(p) {
33
- if (p instanceof DPoint) {
34
- const { a, b, c, d } = this;
35
- const { y, z } = p;
36
- p.x = -(b * y + c * z + d) / a;
37
- return p;
38
- }
39
- return p.map((t) => this.x(t));
40
- }
41
- y(p) {
42
- if (p instanceof DPoint) {
43
- const { a, b, c, d } = this;
44
- const { x, z } = p;
45
- p.y = -(a * x + c * z + d) / b;
46
- return p;
47
- }
48
- return p.map((t) => this.y(t));
49
- }
50
- z(p) {
51
- if (p instanceof DPoint) {
52
- const { a, b, c, d } = this;
53
- const { x, y } = p;
54
- p.z = -(a * x + b * y + d) / c;
55
- return p;
56
- }
57
- return p.map((t) => this.z(t));
58
- }
59
- clone() {
60
- const { a, b, c, d, p1, p2, p3 } = this;
61
- return new DPlane(a, b, c, d, p1, p2, p3);
62
- }
63
- distance(p) {
64
- if (p instanceof DPoint) {
65
- const { x, y, z } = p;
66
- const { a, b, c, d } = this;
67
- return Math.abs(a * x + b * y + c * z + d) / Math.sqrt(a * a + b * b + c * c);
68
- }
69
- const { a, b, c, d } = p;
70
- const { d: r } = this;
71
- return Math.abs(d - r) / Math.sqrt(a * a + b * b + c * c);
72
- }
73
- equal(p) {
74
- const { a, b, c, d } = p;
75
- const { a: q, b: w, c: e, d: r } = this;
76
- return DNumbers.like(a, q) &&
77
- DNumbers.like(b, w) &&
78
- DNumbers.like(c, e) &&
79
- DNumbers.like(d, r);
80
- }
81
- same(p) {
82
- const { a, b, c, d } = p;
83
- const { a: q, b: w, c: e, d: r } = this;
84
- const t = a / q;
85
- const y = b / w;
86
- const u = c / e;
87
- const i = d / r;
88
- return DNumbers.like(t, y) &&
89
- DNumbers.like(t, u) &&
90
- DNumbers.like(t, c) &&
91
- DNumbers.like(t, i);
92
- }
93
- parallel(p) {
94
- const { a, b, c, d } = p;
95
- const { a: q, b: w, c: e, d: r } = this;
96
- const t = a / q;
97
- const y = b / w;
98
- const u = c / e;
99
- const i = d / r;
100
- return DNumbers.like(t, y) &&
101
- DNumbers.like(t, u) &&
102
- DNumbers.like(t, c) &&
103
- !DNumbers.like(t, i);
104
- }
105
- }