dgeoutils 2.2.10 → 2.2.14

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/README.md CHANGED
@@ -13,6 +13,8 @@
13
13
  [![Coverage branches](https://edejin.github.io/DGeoUtils/media/badges/badge-branches.svg)](https://edejin.github.io/DGeoUtils/media/lcov-report/index.html)
14
14
  [![Coverage statements](https://edejin.github.io/DGeoUtils/media/badges/badge-statements.svg)](https://edejin.github.io/DGeoUtils/media/lcov-report/index.html)
15
15
 
16
+ [Test time report](https://edejin.github.io/DGeoUtils/media/time-report.html)
17
+
16
18
  [Docs](https://edejin.github.io/DGeoUtils/index.html)
17
19
 
18
20
  [ESLint Report](https://edejin.github.io/DGeoUtils/media/eslit.html)
package/dist/DCircle.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare class DCircle {
12
12
  clone(): DCircle;
13
13
  findPoints(c: DCircle): DPoint[] | number;
14
14
  equal({ center, r }: DCircle): boolean;
15
- findPolygonInside(pointCount?: number): DPolygon;
16
- findPolygonInsideOnSphere(pointCount?: number): DPolygon;
15
+ findPolygonInside(pointCount?: number, startAngle?: number, stopAngle?: number): DPolygon;
16
+ findPolygonInsideOnSphere(pointCount?: number, startAngle?: number, stopAngle?: number): DPolygon;
17
17
  private sphereOffset;
18
18
  }
package/dist/DCircle.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DCircle = void 0;
4
4
  const DPoint_1 = require("./DPoint");
5
5
  const DPolygon_1 = require("./DPolygon");
6
- const DNumbers_1 = require("./DNumbers");
7
6
  const utils_1 = require("./utils");
8
7
  class DCircle {
9
8
  constructor(center = DPoint_1.DPoint.zero(), r = 0) {
@@ -51,36 +50,42 @@ class DCircle {
51
50
  equal({ center, r }) {
52
51
  return this.center.equal(center) && this.r === r;
53
52
  }
54
- findPolygonInside(pointCount = 64) {
55
- const preAngle = 2 * Math.PI / pointCount;
53
+ findPolygonInside(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
54
+ const step = 2 * Math.PI / pointCount;
56
55
  const points = [];
57
- for (let i = 0; i < pointCount; i++) {
58
- const angle = preAngle * i;
59
- const x = this.r * Math.cos(angle) + this.center.x;
60
- const y = this.r * Math.sin(angle) + this.center.y;
61
- points.push(new DPoint_1.DPoint(x, y));
56
+ let angle = startAngle;
57
+ while (angle < stopAngle - step) {
58
+ points.push(new DPoint_1.DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
59
+ .move(this.center));
60
+ angle += step;
62
61
  }
63
- return new DPolygon_1.DPolygon([...points, points[0]]);
62
+ const x = this.r * Math.cos(stopAngle) + this.center.x;
63
+ const y = this.r * Math.sin(stopAngle) + this.center.y;
64
+ points.push(new DPoint_1.DPoint(x, y));
65
+ return new DPolygon_1.DPolygon(points);
64
66
  }
65
- findPolygonInsideOnSphere(pointCount = 64) {
67
+ findPolygonInsideOnSphere(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
66
68
  (0, utils_1.checkFunction)('findPolygonInsideOnSphere')
67
69
  .checkArgument('center')
68
70
  .shouldBeDegree(this.center);
69
- const res = new DPolygon_1.DPolygon();
70
- for (let i = 0; i < pointCount; i++) {
71
- res.push(this.sphereOffset(2 * Math.PI * i / pointCount));
71
+ const step = 2 * Math.PI / pointCount;
72
+ const points = [];
73
+ let angle = startAngle;
74
+ while (angle < stopAngle - step) {
75
+ points.push(this.sphereOffset(angle));
76
+ angle += step;
72
77
  }
73
- return res.close();
78
+ points.push(this.sphereOffset(stopAngle));
79
+ return new DPolygon_1.DPolygon(points);
74
80
  }
75
81
  sphereOffset(bearing, earthRadius = DPoint_1.EARTH_RADIUS_IN_METERS) {
76
- const lat1 = DNumbers_1.DNumbers.deg2Rad(this.center.y);
77
- const lon1 = DNumbers_1.DNumbers.deg2Rad(this.center.x);
82
+ const { x: lon1, y: lat1 } = this.center.clone().degreeToRadians();
78
83
  const dByR = this.r / earthRadius;
79
84
  const lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
80
85
  Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
81
86
  const lon = lon1 +
82
87
  Math.atan2(Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
83
- return new DPoint_1.DPoint(DNumbers_1.DNumbers.rad2Deg(lon), DNumbers_1.DNumbers.rad2Deg(lat));
88
+ return new DPoint_1.DPoint(lon, lat).radiansToDegrees();
84
89
  }
85
90
  }
86
91
  exports.DCircle = DCircle;
@@ -0,0 +1,25 @@
1
+ import { DPoint } from './DPoint';
2
+ import { DPolygon } from './DPolygon';
3
+ export declare class DPlane {
4
+ a: number;
5
+ b: number;
6
+ c: number;
7
+ d: number;
8
+ p1: DPoint;
9
+ p2: DPoint;
10
+ p3: DPoint;
11
+ constructor(a: number, b: number, c: number, d: number, p1?: DPoint, p2?: DPoint, p3?: DPoint);
12
+ static find(p1: DPoint, p2: DPoint, p3: DPoint): DPlane;
13
+ x(p: DPoint): DPoint;
14
+ x(p: DPolygon): DPolygon;
15
+ y(p: DPoint): DPoint;
16
+ y(p: DPolygon): DPolygon;
17
+ z(p: DPoint): DPoint;
18
+ z(p: DPolygon): DPolygon;
19
+ clone(): DPlane;
20
+ distance(p: DPoint): number;
21
+ distance(p: DPlane): number;
22
+ equal(p: DPlane): boolean;
23
+ same(p: DPlane): boolean;
24
+ parallel(p: DPlane): boolean;
25
+ }
package/dist/DPlane.js ADDED
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DPlane = void 0;
4
+ const DPoint_1 = require("./DPoint");
5
+ const utils_1 = require("./utils");
6
+ const DNumbers_1 = require("./DNumbers");
7
+ class DPlane {
8
+ constructor(a, b, c, d, p1 = DPoint_1.DPoint.zero(), p2 = DPoint_1.DPoint.zero(), p3 = DPoint_1.DPoint.zero()) {
9
+ this.a = a;
10
+ this.b = b;
11
+ this.c = c;
12
+ this.d = d;
13
+ this.p1 = p1;
14
+ this.p2 = p2;
15
+ this.p3 = p3;
16
+ }
17
+ static find(p1, p2, p3) {
18
+ if (p1.x === p2.x && p2.x === p3.x) {
19
+ return new DPlane(1, 0, 0, -p1.x, p1, p2, p3);
20
+ }
21
+ if (p1.y === p2.y && p2.y === p3.y) {
22
+ return new DPlane(0, 1, 0, -p1.y, p1, p2, p3);
23
+ }
24
+ if (p1.z === p2.z && p2.z === p3.z) {
25
+ return new DPlane(0, 0, 1, -p1.z, p1, p2, p3);
26
+ }
27
+ const d = 1;
28
+ const [a, b, c] = (0, utils_1.gaussianElimination)([
29
+ [p1.x, p1.y, p1.z, -d],
30
+ [p2.x, p2.y, p2.z, -d],
31
+ [p3.x, p3.y, p3.z, -d]
32
+ ]);
33
+ return new DPlane(a, b, c, d, p1, p2, p3);
34
+ }
35
+ x(p) {
36
+ if (p instanceof DPoint_1.DPoint) {
37
+ const { a, b, c, d } = this;
38
+ const { y, z } = p;
39
+ p.x = -(b * y + c * z + d) / a;
40
+ return p;
41
+ }
42
+ return p.map((t) => this.x(t));
43
+ }
44
+ y(p) {
45
+ if (p instanceof DPoint_1.DPoint) {
46
+ const { a, b, c, d } = this;
47
+ const { x, z } = p;
48
+ p.y = -(a * x + c * z + d) / b;
49
+ return p;
50
+ }
51
+ return p.map((t) => this.y(t));
52
+ }
53
+ z(p) {
54
+ if (p instanceof DPoint_1.DPoint) {
55
+ const { a, b, c, d } = this;
56
+ const { x, y } = p;
57
+ p.z = -(a * x + b * y + d) / c;
58
+ return p;
59
+ }
60
+ return p.map((t) => this.z(t));
61
+ }
62
+ clone() {
63
+ const { a, b, c, d, p1, p2, p3 } = this;
64
+ return new DPlane(a, b, c, d, p1, p2, p3);
65
+ }
66
+ distance(p) {
67
+ if (p instanceof DPoint_1.DPoint) {
68
+ const { x, y, z } = p;
69
+ const { a, b, c, d } = this;
70
+ return Math.abs(a * x + b * y + c * z + d) / Math.sqrt(a * a + b * b + c * c);
71
+ }
72
+ const { a, b, c, d } = p;
73
+ const { d: r } = this;
74
+ return Math.abs(d - r) / Math.sqrt(a * a + b * b + c * c);
75
+ }
76
+ equal(p) {
77
+ const { a, b, c, d } = p;
78
+ const { a: q, b: w, c: e, d: r } = this;
79
+ return DNumbers_1.DNumbers.like(a, q) &&
80
+ DNumbers_1.DNumbers.like(b, w) &&
81
+ DNumbers_1.DNumbers.like(c, e) &&
82
+ DNumbers_1.DNumbers.like(d, r);
83
+ }
84
+ same(p) {
85
+ const { a, b, c, d } = p;
86
+ const { a: q, b: w, c: e, d: r } = this;
87
+ const t = a / q;
88
+ const y = b / w;
89
+ const u = c / e;
90
+ const i = d / r;
91
+ return DNumbers_1.DNumbers.like(t, y) &&
92
+ DNumbers_1.DNumbers.like(t, u) &&
93
+ DNumbers_1.DNumbers.like(t, c) &&
94
+ DNumbers_1.DNumbers.like(t, i);
95
+ }
96
+ parallel(p) {
97
+ const { a, b, c, d } = p;
98
+ const { a: q, b: w, c: e, d: r } = this;
99
+ const t = a / q;
100
+ const y = b / w;
101
+ const u = c / e;
102
+ const i = d / r;
103
+ return DNumbers_1.DNumbers.like(t, y) &&
104
+ DNumbers_1.DNumbers.like(t, u) &&
105
+ DNumbers_1.DNumbers.like(t, c) &&
106
+ !DNumbers_1.DNumbers.like(t, i);
107
+ }
108
+ }
109
+ exports.DPlane = DPlane;
package/dist/DPoint.d.ts CHANGED
@@ -49,9 +49,13 @@ export declare class DPoint {
49
49
  gtOrEqual(p: DPoint): boolean;
50
50
  ltOrEqual(p: DPoint): boolean;
51
51
  rotate(a: number): DPoint;
52
+ rotate3dX(a: number): DPoint;
53
+ rotate3dY(a: number): DPoint;
54
+ rotate3dZ(a: number): DPoint;
52
55
  move(v: number): DPoint;
53
56
  move(p: DPoint): DPoint;
54
57
  move(x: number, y: number): DPoint;
58
+ move(x: number, y: number, z: number): DPoint;
55
59
  degreeToMeters(): DPoint;
56
60
  metersToDegree(): DPoint;
57
61
  degreeToRadians(): DPoint;
@@ -66,9 +70,11 @@ export declare class DPoint {
66
70
  scale(v: number): DPoint;
67
71
  scale(p: DPoint): DPoint;
68
72
  scale(x: number, y: number): DPoint;
73
+ scale(x: number, y: number, z: number): DPoint;
69
74
  divide(v: number): DPoint;
70
75
  divide(p: DPoint): DPoint;
71
76
  divide(x: number, y: number): DPoint;
77
+ divide(x: number, y: number, z: number): DPoint;
72
78
  equal(p: DPoint): boolean;
73
79
  like(p: DPoint, d?: number): boolean;
74
80
  flipVertically(size: DPoint): DPoint;
@@ -95,4 +101,5 @@ export declare class DPoint {
95
101
  setIfLessThan(p: DPoint): DPoint;
96
102
  minus(): DPoint;
97
103
  orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
104
+ findCloserPoint(p: DPolygon): DPoint;
98
105
  }
package/dist/DPoint.js CHANGED
@@ -164,19 +164,47 @@ class DPoint {
164
164
  this.y = y;
165
165
  return this;
166
166
  }
167
- move(x, y = x) {
167
+ rotate3dX(a) {
168
+ const { y, z } = this;
169
+ this.y = y * Math.cos(a) + z * Math.sin(a);
170
+ this.z = -y * Math.sin(a) + z * Math.cos(a);
171
+ return this;
172
+ }
173
+ rotate3dY(a) {
174
+ const { x, z } = this;
175
+ this.x = x * Math.cos(a) + z * Math.sin(a);
176
+ this.z = -x * Math.sin(a) + z * Math.cos(a);
177
+ return this;
178
+ }
179
+ rotate3dZ(a) {
180
+ const { x, y } = this;
181
+ this.x = x * Math.cos(a) - y * Math.sin(a);
182
+ this.y = -x * Math.sin(a) + y * Math.cos(a);
183
+ return this;
184
+ }
185
+ move(x, y = x, z) {
168
186
  let xV = 0;
169
187
  let yV = 0;
188
+ let zV = undefined;
170
189
  if (x instanceof DPoint) {
171
190
  xV = this.x + x.x;
172
191
  yV = this.y + x.y;
192
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
193
+ zV = this.z + x.z;
194
+ }
173
195
  }
174
196
  else {
175
197
  xV = this.x + x;
176
198
  yV = this.y + y;
199
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
200
+ zV = this.z + z;
201
+ }
177
202
  }
178
203
  this.x = xV;
179
204
  this.y = yV;
205
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
206
+ this.z = zV;
207
+ }
180
208
  return this;
181
209
  }
182
210
  degreeToMeters() {
@@ -250,34 +278,54 @@ class DPoint {
250
278
  this.y = Math.abs(this.y);
251
279
  return this;
252
280
  }
253
- scale(x, y = x) {
281
+ scale(x, y = x, z) {
254
282
  let xV = 0;
255
283
  let yV = 0;
284
+ let zV = undefined;
256
285
  if (x instanceof DPoint) {
257
286
  xV = this.x * x.x;
258
287
  yV = this.y * x.y;
288
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
289
+ zV = this.z * x.z;
290
+ }
259
291
  }
260
292
  else {
261
293
  xV = this.x * x;
262
294
  yV = this.y * y;
295
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
296
+ zV = this.z * z;
297
+ }
263
298
  }
264
299
  this.x = xV;
265
300
  this.y = yV;
301
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
302
+ this.z = zV;
303
+ }
266
304
  return this;
267
305
  }
268
- divide(x, y = x) {
306
+ divide(x, y = x, z) {
269
307
  let xV = 0;
270
308
  let yV = 0;
309
+ let zV = undefined;
271
310
  if (x instanceof DPoint) {
272
311
  xV = this.x / x.x;
273
312
  yV = this.y / x.y;
313
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
314
+ zV = this.z / x.z;
315
+ }
274
316
  }
275
317
  else {
276
318
  xV = this.x / x;
277
319
  yV = this.y / y;
320
+ if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
321
+ zV = this.z / z;
322
+ }
278
323
  }
279
324
  this.x = xV;
280
325
  this.y = yV;
326
+ if ((0, utils_1.isDefAndNotNull)(zV)) {
327
+ this.z = zV;
328
+ }
281
329
  return this;
282
330
  }
283
331
  equal(p) {
@@ -379,7 +427,7 @@ class DPoint {
379
427
  return this;
380
428
  }
381
429
  minus() {
382
- return this.clone().scale(-1);
430
+ return this.scale(-1);
383
431
  }
384
432
  orthodromicPath(point, pointsCount = 360) {
385
433
  (0, utils_1.checkFunction)('orthodromicPath')
@@ -399,5 +447,17 @@ class DPoint {
399
447
  return new DPoint(x, y).radiansToDegrees();
400
448
  }));
401
449
  }
450
+ findCloserPoint(p) {
451
+ let d = Infinity;
452
+ let res = DPoint.zero();
453
+ for (const t of p.points) {
454
+ const td = this.distance(t);
455
+ if (td < d) {
456
+ d = td;
457
+ res = t.clone();
458
+ }
459
+ }
460
+ return res;
461
+ }
402
462
  }
403
463
  exports.DPoint = DPoint;
@@ -54,7 +54,7 @@ export declare class DPolygon {
54
54
  setCenter(newCenter: DPoint): DPolygon;
55
55
  static WKT_LINESTRING: string;
56
56
  static WKT_POLYGON: string;
57
- toWKT(type?: string): string;
57
+ toWKT(type?: string, withZ?: boolean): string;
58
58
  filter(f: (p: DPoint) => boolean): DPolygon;
59
59
  map(f: (r: DPoint) => DPoint): DPolygon;
60
60
  map(f: (r: DPoint, index: number) => DPoint): DPolygon;
@@ -101,6 +101,8 @@ export declare class DPolygon {
101
101
  getTrianglesPointIndexes(): number[];
102
102
  get closed(): boolean;
103
103
  buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
104
+ bezier(step?: number): DPolygon;
105
+ private getBezierPoint;
104
106
  private simpleIncludeX;
105
107
  private simpleIncludeY;
106
108
  private douglasPeucker;
package/dist/DPolygon.js CHANGED
@@ -326,17 +326,17 @@ class DPolygon {
326
326
  .move(newCenter.clone().move(this.center.minus()))
327
327
  .run();
328
328
  }
329
- toWKT(type = DPolygon.WKT_POLYGON) {
329
+ toWKT(type = DPolygon.WKT_POLYGON, withZ = false) {
330
330
  if (type === DPolygon.WKT_POLYGON) {
331
331
  let h = '';
332
332
  if (this.holes && this.holes.length) {
333
333
  h = `, ${this.holes.map((hole) => hole.toString())
334
334
  .join(', ')}`;
335
335
  }
336
- return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}`)
336
+ return `POLYGON ((${this.deintersection.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
337
337
  .join(', ')})${h})`;
338
338
  }
339
- return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}`)
339
+ return `LINESTRING (${this.pPoints.map((r) => `${r.x} ${r.y}${withZ ? ` ${r.z}` : ''}`)
340
340
  .join(', ')})`;
341
341
  }
342
342
  filter(f) {
@@ -807,6 +807,26 @@ class DPolygon {
807
807
  .getCoordinates();
808
808
  return new DPolygon(points.map(({ x, y }) => new DPoint_1.DPoint(x, y)));
809
809
  }
810
+ bezier(step = 0.1) {
811
+ const res = new DPolygon();
812
+ for (let i = 0; i < 1; i += step) {
813
+ res.push(this.clone().getBezierPoint(i));
814
+ }
815
+ return res;
816
+ }
817
+ getBezierPoint(v) {
818
+ if (this.length === 1) {
819
+ return this.first;
820
+ }
821
+ for (let i = 0; i < this.length - 1; i++) {
822
+ const p1 = this.at(i);
823
+ const p2 = this.at(i + 1);
824
+ p1.move(p2.clone().move(p1.clone().minus())
825
+ .scale(v));
826
+ }
827
+ this.pop();
828
+ return this.getBezierPoint(v);
829
+ }
810
830
  simpleIncludeX(p) {
811
831
  const { x } = p;
812
832
  return this.minX <= x && this.maxX >= x;
@@ -17,6 +17,9 @@ export declare class DPolygonLoop {
17
17
  setZ(z: number): DPolygonLoop;
18
18
  setZ(f: SetterFunction): DPolygonLoop;
19
19
  rotate(a: number): DPolygonLoop;
20
+ rotate3dX(a: number): DPolygonLoop;
21
+ rotate3dY(a: number): DPolygonLoop;
22
+ rotate3dZ(a: number): DPolygonLoop;
20
23
  move(v: number): DPolygonLoop;
21
24
  move(p: DPoint): DPolygonLoop;
22
25
  move(x: number, y: number): DPolygonLoop;
@@ -10,28 +10,31 @@ var LoopFunctions;
10
10
  LoopFunctions[LoopFunctions["setY"] = 4] = "setY";
11
11
  LoopFunctions[LoopFunctions["setZ"] = 5] = "setZ";
12
12
  LoopFunctions[LoopFunctions["rotate"] = 6] = "rotate";
13
- LoopFunctions[LoopFunctions["move"] = 7] = "move";
14
- LoopFunctions[LoopFunctions["round"] = 8] = "round";
15
- LoopFunctions[LoopFunctions["ceil"] = 9] = "ceil";
16
- LoopFunctions[LoopFunctions["floor"] = 10] = "floor";
17
- LoopFunctions[LoopFunctions["toFixed"] = 11] = "toFixed";
18
- LoopFunctions[LoopFunctions["abs"] = 12] = "abs";
19
- LoopFunctions[LoopFunctions["scale"] = 13] = "scale";
20
- LoopFunctions[LoopFunctions["divide"] = 14] = "divide";
21
- LoopFunctions[LoopFunctions["degreeToRadians"] = 15] = "degreeToRadians";
22
- LoopFunctions[LoopFunctions["radiansToDegrees"] = 16] = "radiansToDegrees";
23
- LoopFunctions[LoopFunctions["radiansToMeters"] = 17] = "radiansToMeters";
24
- LoopFunctions[LoopFunctions["metersToRadians"] = 18] = "metersToRadians";
25
- LoopFunctions[LoopFunctions["hipPoint"] = 19] = "hipPoint";
26
- LoopFunctions[LoopFunctions["xPoint"] = 20] = "xPoint";
27
- LoopFunctions[LoopFunctions["yPoint"] = 21] = "yPoint";
28
- LoopFunctions[LoopFunctions["wPoint"] = 22] = "wPoint";
29
- LoopFunctions[LoopFunctions["hPoint"] = 23] = "hPoint";
30
- LoopFunctions[LoopFunctions["setIfLessThan"] = 24] = "setIfLessThan";
31
- LoopFunctions[LoopFunctions["minus"] = 25] = "minus";
32
- LoopFunctions[LoopFunctions["degreeToMeters"] = 26] = "degreeToMeters";
33
- LoopFunctions[LoopFunctions["metersToDegree"] = 27] = "metersToDegree";
34
- LoopFunctions[LoopFunctions["flipVertically"] = 28] = "flipVertically";
13
+ LoopFunctions[LoopFunctions["rotate3dX"] = 7] = "rotate3dX";
14
+ LoopFunctions[LoopFunctions["rotate3dY"] = 8] = "rotate3dY";
15
+ LoopFunctions[LoopFunctions["rotate3dZ"] = 9] = "rotate3dZ";
16
+ LoopFunctions[LoopFunctions["move"] = 10] = "move";
17
+ LoopFunctions[LoopFunctions["round"] = 11] = "round";
18
+ LoopFunctions[LoopFunctions["ceil"] = 12] = "ceil";
19
+ LoopFunctions[LoopFunctions["floor"] = 13] = "floor";
20
+ LoopFunctions[LoopFunctions["toFixed"] = 14] = "toFixed";
21
+ LoopFunctions[LoopFunctions["abs"] = 15] = "abs";
22
+ LoopFunctions[LoopFunctions["scale"] = 16] = "scale";
23
+ LoopFunctions[LoopFunctions["divide"] = 17] = "divide";
24
+ LoopFunctions[LoopFunctions["degreeToRadians"] = 18] = "degreeToRadians";
25
+ LoopFunctions[LoopFunctions["radiansToDegrees"] = 19] = "radiansToDegrees";
26
+ LoopFunctions[LoopFunctions["radiansToMeters"] = 20] = "radiansToMeters";
27
+ LoopFunctions[LoopFunctions["metersToRadians"] = 21] = "metersToRadians";
28
+ LoopFunctions[LoopFunctions["hipPoint"] = 22] = "hipPoint";
29
+ LoopFunctions[LoopFunctions["xPoint"] = 23] = "xPoint";
30
+ LoopFunctions[LoopFunctions["yPoint"] = 24] = "yPoint";
31
+ LoopFunctions[LoopFunctions["wPoint"] = 25] = "wPoint";
32
+ LoopFunctions[LoopFunctions["hPoint"] = 26] = "hPoint";
33
+ LoopFunctions[LoopFunctions["setIfLessThan"] = 27] = "setIfLessThan";
34
+ LoopFunctions[LoopFunctions["minus"] = 28] = "minus";
35
+ LoopFunctions[LoopFunctions["degreeToMeters"] = 29] = "degreeToMeters";
36
+ LoopFunctions[LoopFunctions["metersToDegree"] = 30] = "metersToDegree";
37
+ LoopFunctions[LoopFunctions["flipVertically"] = 31] = "flipVertically";
35
38
  })(LoopFunctions || (LoopFunctions = {}));
36
39
  const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg, setterArg }) => {
37
40
  let res = a;
@@ -64,6 +67,18 @@ const decodePoolRecord = (a, { functionName, pointArg, numberPointArg, numberArg
64
67
  res = (k) => a(k)
65
68
  .rotate(numberArg);
66
69
  break;
70
+ case LoopFunctions.rotate3dX:
71
+ res = (k) => a(k)
72
+ .rotate3dX(numberArg);
73
+ break;
74
+ case LoopFunctions.rotate3dY:
75
+ res = (k) => a(k)
76
+ .rotate3dY(numberArg);
77
+ break;
78
+ case LoopFunctions.rotate3dZ:
79
+ res = (k) => a(k)
80
+ .rotate3dZ(numberArg);
81
+ break;
67
82
  case LoopFunctions.move:
68
83
  res = (k) => a(k)
69
84
  .move(numberPointArg, numberArg);
@@ -215,6 +230,27 @@ class DPolygonLoop {
215
230
  });
216
231
  return this;
217
232
  }
233
+ rotate3dX(a) {
234
+ this.pool.push({
235
+ functionName: LoopFunctions.rotate3dX,
236
+ numberArg: a
237
+ });
238
+ return this;
239
+ }
240
+ rotate3dY(a) {
241
+ this.pool.push({
242
+ functionName: LoopFunctions.rotate3dY,
243
+ numberArg: a
244
+ });
245
+ return this;
246
+ }
247
+ rotate3dZ(a) {
248
+ this.pool.push({
249
+ functionName: LoopFunctions.rotate3dZ,
250
+ numberArg: a
251
+ });
252
+ return this;
253
+ }
218
254
  move(x, y = x) {
219
255
  this.pool.push({
220
256
  functionName: LoopFunctions.move,
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ export * from './DPolygon';
6
6
  export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
8
  export * from './DPolygonLoop';
9
+ export * from './DPlane';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull } from './utils';
9
11
  export declare const DGeo: {
10
12
  DEBUG: boolean;
11
13
  };
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.DGeo = void 0;
13
+ exports.DGeo = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
14
14
  __exportStar(require("./DCircle"), exports);
15
15
  __exportStar(require("./DLine"), exports);
16
16
  __exportStar(require("./DNumbers"), exports);
@@ -19,6 +19,13 @@ __exportStar(require("./DPolygon"), exports);
19
19
  __exportStar(require("./FastSearch"), exports);
20
20
  __exportStar(require("./TraceMatrix"), exports);
21
21
  __exportStar(require("./DPolygonLoop"), exports);
22
+ __exportStar(require("./DPlane"), exports);
23
+ var utils_1 = require("./utils");
24
+ Object.defineProperty(exports, "gaussianElimination", { enumerable: true, get: function () { return utils_1.gaussianElimination; } });
25
+ Object.defineProperty(exports, "createCanvas", { enumerable: true, get: function () { return utils_1.createCanvas; } });
26
+ Object.defineProperty(exports, "createArray", { enumerable: true, get: function () { return utils_1.createArray; } });
27
+ Object.defineProperty(exports, "createMatrix", { enumerable: true, get: function () { return utils_1.createMatrix; } });
28
+ Object.defineProperty(exports, "isDefAndNotNull", { enumerable: true, get: function () { return utils_1.isDefAndNotNull; } });
22
29
  exports.DGeo = {
23
30
  DEBUG: false
24
31
  };
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="offscreencanvas" />
1
2
  import { DPoint } from './DPoint';
2
3
  export declare const warn: (...args: any[]) => void;
3
4
  declare type CheckFunc = (p: DPoint) => CheckFunction;
@@ -12,5 +13,21 @@ interface CheckFunction {
12
13
  checkArgument: (argName: string) => CheckArgument;
13
14
  }
14
15
  export declare const checkFunction: (funcName: string) => CheckFunction;
15
- export declare const createArray: (v: number) => number[];
16
+ export declare const createArray: (v: number, fillSymbol?: any) => number[];
17
+ export declare const createMatrix: ({ h, w }: DPoint, fillSymbol?: any) => number[][];
18
+ export declare const gaussianElimination: {
19
+ (matrix: number[][]): number[];
20
+ MIN: number;
21
+ };
22
+ export declare const isDefAndNotNull: (a: any) => boolean;
23
+ declare type True = true;
24
+ export declare const createCanvas: {
25
+ (size: number): [HTMLCanvasElement, CanvasRenderingContext2D];
26
+ (size: number, offscreen: True): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
27
+ (w: number, h: number): [HTMLCanvasElement, CanvasRenderingContext2D];
28
+ (w: number, h: number, offscreen: True): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
29
+ (size: DPoint): [HTMLCanvasElement, CanvasRenderingContext2D];
30
+ (size: DPoint, offscreen: True): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
31
+ document?: Document;
32
+ };
16
33
  export {};
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createArray = exports.checkFunction = exports.warn = void 0;
3
+ exports.createCanvas = exports.isDefAndNotNull = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.warn = void 0;
4
4
  const index_1 = require("./index");
5
5
  const DPoint_1 = require("./DPoint");
6
6
  const warn = (...args) => {
@@ -63,5 +63,85 @@ const checkFunction = (funcName) => ({
63
63
  }
64
64
  });
65
65
  exports.checkFunction = checkFunction;
66
- const createArray = (v) => new Array(v).fill(0);
66
+ const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
67
67
  exports.createArray = createArray;
68
+ const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
69
+ .map(() => (0, exports.createArray)(w, fillSymbol));
70
+ exports.createMatrix = createMatrix;
71
+ const gaussianElimination = (matrix) => {
72
+ const n = matrix.length;
73
+ const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
74
+ for (let i = 0; i < n; i++) {
75
+ for (let j = 0; j < n + 1; j++) {
76
+ matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
77
+ matrixClone[i][j] = matrix[i][j];
78
+ }
79
+ }
80
+ for (let k = 0; k < n; k++) {
81
+ for (let i = 0; i < n + 1; i++) {
82
+ matrixClone[k][i] /= matrix[k][k];
83
+ }
84
+ for (let i = k + 1; i < n; i++) {
85
+ const K = matrixClone[i][k] / matrixClone[k][k];
86
+ for (let j = 0; j < n + 1; j++) {
87
+ matrixClone[i][j] -= matrixClone[k][j] * K;
88
+ }
89
+ }
90
+ for (let i = 0; i < n; i++) {
91
+ for (let j = 0; j < n + 1; j++) {
92
+ matrix[i][j] = matrixClone[i][j];
93
+ }
94
+ }
95
+ }
96
+ for (let k = n - 1; k > -1; k--) {
97
+ for (let i = n; i > -1; i--) {
98
+ matrixClone[k][i] /= matrix[k][k];
99
+ }
100
+ for (let i = k - 1; i > -1; i--) {
101
+ const K = matrixClone[i][k] / matrixClone[k][k];
102
+ for (let j = n; j > -1; j--) {
103
+ matrixClone[i][j] -= matrixClone[k][j] * K;
104
+ }
105
+ }
106
+ }
107
+ const answer = (0, exports.createArray)(n);
108
+ for (let i = 0; i < n; i++) {
109
+ answer[i] = matrixClone[i][n];
110
+ }
111
+ return answer;
112
+ };
113
+ exports.gaussianElimination = gaussianElimination;
114
+ exports.gaussianElimination.MIN = 1e-10;
115
+ const isDefAndNotNull = (a) => a != undefined;
116
+ exports.isDefAndNotNull = isDefAndNotNull;
117
+ const createCanvas = (a, b, c) => {
118
+ var _a;
119
+ let w = 0;
120
+ let h = 0;
121
+ let offscreen = false;
122
+ if (a instanceof DPoint_1.DPoint) {
123
+ const { x, y } = a;
124
+ w = x;
125
+ h = y;
126
+ }
127
+ else {
128
+ w = a;
129
+ h = a;
130
+ }
131
+ if (typeof b === 'boolean') {
132
+ offscreen = b;
133
+ }
134
+ else if (typeof b === 'number') {
135
+ h = b;
136
+ }
137
+ if (typeof c === 'boolean') {
138
+ offscreen = c;
139
+ }
140
+ const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
141
+ if (!offscreen) {
142
+ canvas.width = w;
143
+ canvas.height = h;
144
+ }
145
+ return [canvas, canvas.getContext('2d')];
146
+ };
147
+ exports.createCanvas = createCanvas;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgeoutils",
3
- "version": "2.2.10",
3
+ "version": "2.2.14",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "node_modules/.bin/tsc",
@@ -42,6 +42,7 @@
42
42
  "jest": "^27.0.6",
43
43
  "jest-canvas-mock": "^2.3.1",
44
44
  "jest-coverage-badges": "^1.1.2",
45
+ "jest-html-reporter": "^3.4.2",
45
46
  "jsdom": "^17.0.0",
46
47
  "ts-jest": "^27.0.4",
47
48
  "typedoc": "^0.21.9",