dgeoutils 2.2.13 → 2.2.17
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 +2 -0
- package/dist/DPoint.js +27 -0
- package/dist/DPolygon.d.ts +1 -0
- package/dist/DPolygon.js +18 -3
- package/dist/utils.d.ts +18 -9
- package/dist/utils.js +19 -12
- 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
|
@@ -37,6 +37,7 @@ export declare class DPoint {
|
|
|
37
37
|
height(z: number): DPoint;
|
|
38
38
|
toWKT(): string;
|
|
39
39
|
distance(p: DPoint): number;
|
|
40
|
+
distance3d(p: DPoint): number;
|
|
40
41
|
setX(x: number): DPoint;
|
|
41
42
|
setX(f: SetterFunction): DPoint;
|
|
42
43
|
setZ(z: number): DPoint;
|
|
@@ -101,4 +102,5 @@ export declare class DPoint {
|
|
|
101
102
|
setIfLessThan(p: DPoint): DPoint;
|
|
102
103
|
minus(): DPoint;
|
|
103
104
|
orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
|
|
105
|
+
findCloserPoint(p: DPolygon): DPoint;
|
|
104
106
|
}
|
package/dist/DPoint.js
CHANGED
|
@@ -128,6 +128,21 @@ class DPoint {
|
|
|
128
128
|
const dy = p.y - this.y;
|
|
129
129
|
return Math.sqrt(dx * dx + dy * dy);
|
|
130
130
|
}
|
|
131
|
+
distance3d(p) {
|
|
132
|
+
(0, utils_1.checkFunction)('distance3d')
|
|
133
|
+
.checkArgument('this')
|
|
134
|
+
.shouldBeMeters(this)
|
|
135
|
+
.checkArgument('p')
|
|
136
|
+
.shouldBeMeters(p)
|
|
137
|
+
.checkArgument('this.z')
|
|
138
|
+
.shouldExist(this.z)
|
|
139
|
+
.checkArgument('p.z')
|
|
140
|
+
.shouldExist(p.z);
|
|
141
|
+
const dx = p.x - this.x;
|
|
142
|
+
const dy = p.y - this.y;
|
|
143
|
+
const dz = p.z - this.z;
|
|
144
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
145
|
+
}
|
|
131
146
|
setX(x) {
|
|
132
147
|
this.x = typeof x === 'number' ? x : x(this);
|
|
133
148
|
return this;
|
|
@@ -447,5 +462,17 @@ class DPoint {
|
|
|
447
462
|
return new DPoint(x, y).radiansToDegrees();
|
|
448
463
|
}));
|
|
449
464
|
}
|
|
465
|
+
findCloserPoint(p) {
|
|
466
|
+
let d = Infinity;
|
|
467
|
+
let res = DPoint.zero();
|
|
468
|
+
for (const t of p.points) {
|
|
469
|
+
const td = this.distance(t);
|
|
470
|
+
if (td < d) {
|
|
471
|
+
d = td;
|
|
472
|
+
res = t.clone();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return res;
|
|
476
|
+
}
|
|
450
477
|
}
|
|
451
478
|
exports.DPoint = DPoint;
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -102,6 +102,7 @@ export declare class DPolygon {
|
|
|
102
102
|
get closed(): boolean;
|
|
103
103
|
buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
|
|
104
104
|
bezier(step?: number): DPolygon;
|
|
105
|
+
setGrowingHeight(from: number, to: number): DPolygon;
|
|
105
106
|
private getBezierPoint;
|
|
106
107
|
private simpleIncludeX;
|
|
107
108
|
private simpleIncludeY;
|
package/dist/DPolygon.js
CHANGED
|
@@ -7,6 +7,7 @@ const DCircle_1 = require("./DCircle");
|
|
|
7
7
|
const DNumbers_1 = require("./DNumbers");
|
|
8
8
|
const jsts_1 = require("jsts");
|
|
9
9
|
const DPolygonLoop_1 = require("./DPolygonLoop");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
10
11
|
const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = jsts_1.operation;
|
|
11
12
|
exports.MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
12
13
|
const APPROXIMATION_VALUE = 0.1;
|
|
@@ -19,11 +20,11 @@ class DPolygon {
|
|
|
19
20
|
this.holes = [];
|
|
20
21
|
this.searchStore = {};
|
|
21
22
|
}
|
|
22
|
-
static arrayOfTrianglesToVertices(triangles, height
|
|
23
|
-
return triangles.map((v) => v
|
|
23
|
+
static arrayOfTrianglesToVertices(triangles, height) {
|
|
24
|
+
return triangles.map((v) => ((0, utils_1.isDefAndNotNull)(height) ? v
|
|
24
25
|
.loop()
|
|
25
26
|
.height(height)
|
|
26
|
-
.run()
|
|
27
|
+
.run() : v)
|
|
27
28
|
.toArrayOfCoords())
|
|
28
29
|
.flat(2);
|
|
29
30
|
}
|
|
@@ -814,6 +815,20 @@ class DPolygon {
|
|
|
814
815
|
}
|
|
815
816
|
return res;
|
|
816
817
|
}
|
|
818
|
+
setGrowingHeight(from, to) {
|
|
819
|
+
const { fullLength } = this;
|
|
820
|
+
let { first: prevPoint } = this;
|
|
821
|
+
const d = to - from;
|
|
822
|
+
let currentDistance = 0;
|
|
823
|
+
this.loop()
|
|
824
|
+
.setZ((p) => {
|
|
825
|
+
currentDistance += prevPoint.distance(p);
|
|
826
|
+
prevPoint = p;
|
|
827
|
+
return from + currentDistance / fullLength * d;
|
|
828
|
+
})
|
|
829
|
+
.run();
|
|
830
|
+
return this;
|
|
831
|
+
}
|
|
817
832
|
getBezierPoint(v) {
|
|
818
833
|
if (this.length === 1) {
|
|
819
834
|
return this.first;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/// <reference types="offscreencanvas" />
|
|
2
2
|
import { DPoint } from './DPoint';
|
|
3
3
|
export declare const warn: (...args: any[]) => void;
|
|
4
|
+
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
4
5
|
declare type CheckFunc = (p: DPoint) => CheckFunction;
|
|
6
|
+
declare type CheckFunc2 = (p: any) => CheckFunction;
|
|
5
7
|
interface CheckArgument {
|
|
6
8
|
shouldBeDegree: CheckFunc;
|
|
7
9
|
shouldBeMeters: CheckFunc;
|
|
8
10
|
shouldBeInt: CheckFunc;
|
|
9
11
|
shouldBeUInt: CheckFunc;
|
|
10
12
|
shouldBeRadians: CheckFunc;
|
|
13
|
+
shouldExist: CheckFunc2;
|
|
11
14
|
}
|
|
12
15
|
interface CheckFunction {
|
|
13
16
|
checkArgument: (argName: string) => CheckArgument;
|
|
@@ -15,12 +18,18 @@ interface CheckFunction {
|
|
|
15
18
|
export declare const checkFunction: (funcName: string) => CheckFunction;
|
|
16
19
|
export declare const createArray: (v: number, fillSymbol?: any) => number[];
|
|
17
20
|
export declare const createMatrix: ({ h, w }: DPoint, fillSymbol?: any) => number[][];
|
|
18
|
-
export declare const gaussianElimination:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
declare
|
|
23
|
-
declare
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
export declare const gaussianElimination: {
|
|
22
|
+
(matrix: number[][]): number[];
|
|
23
|
+
MIN: number;
|
|
24
|
+
};
|
|
25
|
+
declare type True = true;
|
|
26
|
+
export declare const createCanvas: {
|
|
27
|
+
(size: number): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
28
|
+
(size: number, offscreen: True): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
29
|
+
(w: number, h: number): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
30
|
+
(w: number, h: number, offscreen: True): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
31
|
+
(size: DPoint): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
32
|
+
(size: DPoint, offscreen: True): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
33
|
+
document?: Document;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCanvas = exports.
|
|
3
|
+
exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
const DPoint_1 = require("./DPoint");
|
|
6
6
|
const warn = (...args) => {
|
|
@@ -9,6 +9,8 @@ const warn = (...args) => {
|
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
exports.warn = warn;
|
|
12
|
+
const isDefAndNotNull = (a) => a != undefined;
|
|
13
|
+
exports.isDefAndNotNull = isDefAndNotNull;
|
|
12
14
|
const hook = (scope) => () => scope;
|
|
13
15
|
const shouldBeInt = (scope, funcName, argName) => (p) => {
|
|
14
16
|
if (!p.clone().round()
|
|
@@ -36,6 +38,12 @@ const shouldBeRadians = (scope, funcName, argName) => (p) => {
|
|
|
36
38
|
}
|
|
37
39
|
return scope;
|
|
38
40
|
};
|
|
41
|
+
const shouldExist = (scope, funcName, argName) => (p) => {
|
|
42
|
+
if (!(0, exports.isDefAndNotNull)(p)) {
|
|
43
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should exist!`);
|
|
44
|
+
}
|
|
45
|
+
return scope;
|
|
46
|
+
};
|
|
39
47
|
const shouldBeMeters = (scope, funcName, argName) => (p) => {
|
|
40
48
|
if (!p.likePseudoMercator) {
|
|
41
49
|
(0, exports.warn)(`"${funcName}" -> "${argName}" should be meters!`);
|
|
@@ -50,7 +58,8 @@ const checkFunction = (funcName) => ({
|
|
|
50
58
|
shouldBeMeters: hook(this),
|
|
51
59
|
shouldBeInt: hook(this),
|
|
52
60
|
shouldBeUInt: hook(this),
|
|
53
|
-
shouldBeRadians: hook(this)
|
|
61
|
+
shouldBeRadians: hook(this),
|
|
62
|
+
shouldExist: hook(this)
|
|
54
63
|
};
|
|
55
64
|
}
|
|
56
65
|
return {
|
|
@@ -58,7 +67,8 @@ const checkFunction = (funcName) => ({
|
|
|
58
67
|
shouldBeMeters: shouldBeMeters(this, funcName, argName),
|
|
59
68
|
shouldBeInt: shouldBeInt(this, funcName, argName),
|
|
60
69
|
shouldBeUInt: shouldBeUInt(this, funcName, argName),
|
|
61
|
-
shouldBeRadians: shouldBeRadians(this, funcName, argName)
|
|
70
|
+
shouldBeRadians: shouldBeRadians(this, funcName, argName),
|
|
71
|
+
shouldExist: shouldExist(this, funcName, argName)
|
|
62
72
|
};
|
|
63
73
|
}
|
|
64
74
|
});
|
|
@@ -68,13 +78,12 @@ exports.createArray = createArray;
|
|
|
68
78
|
const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
|
|
69
79
|
.map(() => (0, exports.createArray)(w, fillSymbol));
|
|
70
80
|
exports.createMatrix = createMatrix;
|
|
71
|
-
const GAUSSIAN_ELIMINATION_MIN = 1e-10;
|
|
72
81
|
const gaussianElimination = (matrix) => {
|
|
73
82
|
const n = matrix.length;
|
|
74
83
|
const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
|
|
75
84
|
for (let i = 0; i < n; i++) {
|
|
76
85
|
for (let j = 0; j < n + 1; j++) {
|
|
77
|
-
matrix[i][j] = matrix[i][j] === 0 ?
|
|
86
|
+
matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
|
|
78
87
|
matrixClone[i][j] = matrix[i][j];
|
|
79
88
|
}
|
|
80
89
|
}
|
|
@@ -112,9 +121,8 @@ const gaussianElimination = (matrix) => {
|
|
|
112
121
|
return answer;
|
|
113
122
|
};
|
|
114
123
|
exports.gaussianElimination = gaussianElimination;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
function createCanvas(a, b, c) {
|
|
124
|
+
exports.gaussianElimination.MIN = 1e-10;
|
|
125
|
+
const createCanvas = (a, b, c) => {
|
|
118
126
|
var _a;
|
|
119
127
|
let w = 0;
|
|
120
128
|
let h = 0;
|
|
@@ -137,12 +145,11 @@ function createCanvas(a, b, c) {
|
|
|
137
145
|
if (typeof c === 'boolean') {
|
|
138
146
|
offscreen = c;
|
|
139
147
|
}
|
|
140
|
-
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
148
|
+
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
141
149
|
if (!offscreen) {
|
|
142
150
|
canvas.width = w;
|
|
143
151
|
canvas.height = h;
|
|
144
152
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
153
|
+
return [canvas, canvas.getContext('2d')];
|
|
154
|
+
};
|
|
148
155
|
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.17",
|
|
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",
|