dgeoutils 2.2.13 → 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 +2 -0
- package/dist/DCircle.d.ts +2 -2
- package/dist/DCircle.js +22 -17
- package/dist/DPoint.d.ts +1 -0
- package/dist/DPoint.js +12 -0
- package/dist/utils.d.ts +15 -8
- package/dist/utils.js +6 -7
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
[](https://edejin.github.io/DGeoUtils/media/lcov-report/index.html)
|
|
14
14
|
[](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
|
|
53
|
+
findPolygonInside(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
|
|
54
|
+
const step = 2 * Math.PI / pointCount;
|
|
56
55
|
const points = [];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
88
|
+
return new DPoint_1.DPoint(lon, lat).radiansToDegrees();
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
exports.DCircle = DCircle;
|
package/dist/DPoint.d.ts
CHANGED
package/dist/DPoint.js
CHANGED
|
@@ -447,5 +447,17 @@ class DPoint {
|
|
|
447
447
|
return new DPoint(x, y).radiansToDegrees();
|
|
448
448
|
}));
|
|
449
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
|
+
}
|
|
450
462
|
}
|
|
451
463
|
exports.DPoint = DPoint;
|
package/dist/utils.d.ts
CHANGED
|
@@ -15,12 +15,19 @@ interface CheckFunction {
|
|
|
15
15
|
export declare const checkFunction: (funcName: string) => CheckFunction;
|
|
16
16
|
export declare const createArray: (v: number, fillSymbol?: any) => number[];
|
|
17
17
|
export declare const createMatrix: ({ h, w }: DPoint, fillSymbol?: any) => number[][];
|
|
18
|
-
export declare const gaussianElimination:
|
|
18
|
+
export declare const gaussianElimination: {
|
|
19
|
+
(matrix: number[][]): number[];
|
|
20
|
+
MIN: number;
|
|
21
|
+
};
|
|
19
22
|
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
20
|
-
declare
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
};
|
|
33
|
+
export {};
|
package/dist/utils.js
CHANGED
|
@@ -68,13 +68,12 @@ exports.createArray = createArray;
|
|
|
68
68
|
const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
|
|
69
69
|
.map(() => (0, exports.createArray)(w, fillSymbol));
|
|
70
70
|
exports.createMatrix = createMatrix;
|
|
71
|
-
const GAUSSIAN_ELIMINATION_MIN = 1e-10;
|
|
72
71
|
const gaussianElimination = (matrix) => {
|
|
73
72
|
const n = matrix.length;
|
|
74
73
|
const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
|
|
75
74
|
for (let i = 0; i < n; i++) {
|
|
76
75
|
for (let j = 0; j < n + 1; j++) {
|
|
77
|
-
matrix[i][j] = matrix[i][j] === 0 ?
|
|
76
|
+
matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
|
|
78
77
|
matrixClone[i][j] = matrix[i][j];
|
|
79
78
|
}
|
|
80
79
|
}
|
|
@@ -112,9 +111,10 @@ const gaussianElimination = (matrix) => {
|
|
|
112
111
|
return answer;
|
|
113
112
|
};
|
|
114
113
|
exports.gaussianElimination = gaussianElimination;
|
|
114
|
+
exports.gaussianElimination.MIN = 1e-10;
|
|
115
115
|
const isDefAndNotNull = (a) => a != undefined;
|
|
116
116
|
exports.isDefAndNotNull = isDefAndNotNull;
|
|
117
|
-
|
|
117
|
+
const createCanvas = (a, b, c) => {
|
|
118
118
|
var _a;
|
|
119
119
|
let w = 0;
|
|
120
120
|
let h = 0;
|
|
@@ -137,12 +137,11 @@ function createCanvas(a, b, c) {
|
|
|
137
137
|
if (typeof c === 'boolean') {
|
|
138
138
|
offscreen = c;
|
|
139
139
|
}
|
|
140
|
-
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
140
|
+
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
141
141
|
if (!offscreen) {
|
|
142
142
|
canvas.width = w;
|
|
143
143
|
canvas.height = h;
|
|
144
144
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
145
|
+
return [canvas, canvas.getContext('2d')];
|
|
146
|
+
};
|
|
148
147
|
exports.createCanvas = createCanvas;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dgeoutils",
|
|
3
|
-
"version": "2.2.
|
|
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",
|