dgeoutils 2.4.41 → 2.4.44
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/package.json +1 -4
- package/dist/cjs/DCircle.d.ts +0 -18
- package/dist/cjs/DCircle.js +0 -102
- package/dist/cjs/DLine.d.ts +0 -39
- package/dist/cjs/DLine.js +0 -343
- package/dist/cjs/DNumbers.d.ts +0 -8
- package/dist/cjs/DNumbers.js +0 -30
- package/dist/cjs/DPlane.d.ts +0 -25
- package/dist/cjs/DPlane.js +0 -132
- package/dist/cjs/DPoint.d.ts +0 -138
- package/dist/cjs/DPoint.js +0 -803
- package/dist/cjs/DPolygon.d.ts +0 -137
- package/dist/cjs/DPolygon.js +0 -1745
- package/dist/cjs/DPolygonLoop.d.ts +0 -60
- package/dist/cjs/DPolygonLoop.js +0 -439
- package/dist/cjs/FastSearch.d.ts +0 -6
- package/dist/cjs/FastSearch.js +0 -53
- package/dist/cjs/InterpolationMatrix.d.ts +0 -24
- package/dist/cjs/InterpolationMatrix.js +0 -173
- package/dist/cjs/TraceMatrix.d.ts +0 -22
- package/dist/cjs/TraceMatrix.js +0 -285
- package/dist/cjs/index.d.ts +0 -11
- package/dist/cjs/index.js +0 -37
- package/dist/cjs/utils.d.ts +0 -49
- package/dist/cjs/utils.js +0 -280
- package/dist/es2015/DCircle.js +0 -87
- package/dist/es2015/DLine.js +0 -290
- package/dist/es2015/DNumbers.js +0 -22
- package/dist/es2015/DPlane.js +0 -105
- package/dist/es2015/DPoint.js +0 -676
- package/dist/es2015/DPolygon.js +0 -1193
- package/dist/es2015/DPolygonLoop.js +0 -430
- package/dist/es2015/FastSearch.js +0 -25
- package/dist/es2015/InterpolationMatrix.js +0 -128
- package/dist/es2015/TraceMatrix.js +0 -229
- package/dist/es2015/index.js +0 -11
- package/dist/es2015/utils.js +0 -207
- package/dist/esm/DCircle.js +0 -99
- package/dist/esm/DLine.js +0 -340
- package/dist/esm/DNumbers.js +0 -27
- package/dist/esm/DPlane.js +0 -129
- package/dist/esm/DPoint.js +0 -800
- package/dist/esm/DPolygon.js +0 -1742
- package/dist/esm/DPolygonLoop.js +0 -436
- package/dist/esm/FastSearch.js +0 -50
- package/dist/esm/InterpolationMatrix.js +0 -170
- package/dist/esm/TraceMatrix.js +0 -282
- package/dist/esm/index.js +0 -11
- package/dist/esm/utils.js +0 -265
- package/dist/umd/dgeoutils.js +0 -4347
- package/dist/umd/dgeoutils.min.js +0 -1
- package/dist/umd/dgeoutils.min.js.map +0 -1
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { DPoint } from './DPoint';
|
|
2
|
-
import { DPolygon, MIN_POINTS_IN_VALID_POLYGON } from './DPolygon';
|
|
3
|
-
import { FastSearch } from './FastSearch';
|
|
4
|
-
import { createArray } from './utils';
|
|
5
|
-
export var TraceMatrixValues;
|
|
6
|
-
(function (TraceMatrixValues) {
|
|
7
|
-
TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
|
|
8
|
-
TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
|
|
9
|
-
})(TraceMatrixValues || (TraceMatrixValues = {}));
|
|
10
|
-
const getByPosition = (m, p, defaultValue = TraceMatrixValues.f) => {
|
|
11
|
-
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
12
|
-
return defaultValue;
|
|
13
|
-
}
|
|
14
|
-
return m[p.y][p.x];
|
|
15
|
-
};
|
|
16
|
-
const setByPosition = (m, p, value) => {
|
|
17
|
-
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
m[p.y][p.x] = value;
|
|
21
|
-
return m[p.y][p.x];
|
|
22
|
-
};
|
|
23
|
-
export class TraceMatrix {
|
|
24
|
-
constructor(s, f) {
|
|
25
|
-
this.approximation = true;
|
|
26
|
-
this.findGroupByIndex = (m, s) => {
|
|
27
|
-
const res = new DPolygon();
|
|
28
|
-
if (s && getByPosition(m, s) === TraceMatrixValues.t) {
|
|
29
|
-
res.push(s);
|
|
30
|
-
let startIndex = 0;
|
|
31
|
-
const marked = TraceMatrix.createMatrix(this.size, () => TraceMatrixValues.f);
|
|
32
|
-
setByPosition(marked, s, TraceMatrixValues.t);
|
|
33
|
-
while (startIndex < res.length) {
|
|
34
|
-
const r = res.at(startIndex);
|
|
35
|
-
for (let i = -1; i < 2; i++) {
|
|
36
|
-
for (let j = -1; j < 2; j++) {
|
|
37
|
-
const t = new DPoint(r.x + i, r.y + j);
|
|
38
|
-
if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
|
|
39
|
-
getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
|
|
40
|
-
res.push(t);
|
|
41
|
-
setByPosition(marked, t, TraceMatrixValues.t);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
startIndex++;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return res;
|
|
49
|
-
};
|
|
50
|
-
this.findAllGroupsInMatrix = (m) => {
|
|
51
|
-
const firstMark = this.findMarked(m);
|
|
52
|
-
if (!firstMark) {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
const group = this.findGroupByIndex(m, firstMark);
|
|
56
|
-
const groups = [group];
|
|
57
|
-
let groupSum = group.length;
|
|
58
|
-
let allGroups = [...group.points];
|
|
59
|
-
const fs = new FastSearch();
|
|
60
|
-
fs.add(allGroups);
|
|
61
|
-
while (groupSum < this.totalCountInMatrix(m)) {
|
|
62
|
-
let mark = this.findMarked(m);
|
|
63
|
-
while (mark && fs.find(mark)) {
|
|
64
|
-
mark = this.findMarked(m, mark);
|
|
65
|
-
}
|
|
66
|
-
const nextGroup = this.findGroupByIndex(m, mark);
|
|
67
|
-
groupSum += nextGroup.length;
|
|
68
|
-
allGroups = [...allGroups, ...nextGroup.points];
|
|
69
|
-
fs.add(nextGroup.points);
|
|
70
|
-
groups.push(nextGroup);
|
|
71
|
-
}
|
|
72
|
-
return groups.filter((g) => g.length > 2);
|
|
73
|
-
};
|
|
74
|
-
this.traceGroup = (m, group) => {
|
|
75
|
-
const traceDirections = [
|
|
76
|
-
new DPoint(-1, -1),
|
|
77
|
-
new DPoint(-1, 0),
|
|
78
|
-
new DPoint(-1, 1),
|
|
79
|
-
new DPoint(0, 1),
|
|
80
|
-
new DPoint(1, 1),
|
|
81
|
-
new DPoint(1, 0),
|
|
82
|
-
new DPoint(1, -1),
|
|
83
|
-
new DPoint(0, -1)
|
|
84
|
-
];
|
|
85
|
-
const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
|
|
86
|
-
const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
|
|
87
|
-
if (group.length < 2) {
|
|
88
|
-
const t = group.at(0).clone();
|
|
89
|
-
return new DPolygon([t, t, t]);
|
|
90
|
-
}
|
|
91
|
-
const points = new DPolygon();
|
|
92
|
-
let direction = 0;
|
|
93
|
-
let prevDirection = Infinity;
|
|
94
|
-
let p = group.at(0);
|
|
95
|
-
while (!p.equal(group.at(0)) || points.length < 2) {
|
|
96
|
-
while (true) {
|
|
97
|
-
const nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
|
|
98
|
-
const nextNeighbourValue = getByPosition(m, p.clone().move(traceDirections[left(direction)]));
|
|
99
|
-
if (nextValue === TraceMatrixValues.t && nextNeighbourValue === TraceMatrixValues.f) {
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
direction = right(direction);
|
|
103
|
-
}
|
|
104
|
-
if (prevDirection !== direction) {
|
|
105
|
-
points.push(p);
|
|
106
|
-
prevDirection = direction;
|
|
107
|
-
}
|
|
108
|
-
p = p.clone().move(traceDirections[direction]);
|
|
109
|
-
direction = left(left(direction));
|
|
110
|
-
}
|
|
111
|
-
if (this.approximation) {
|
|
112
|
-
return points.approximation().close();
|
|
113
|
-
}
|
|
114
|
-
return points.clone().close();
|
|
115
|
-
};
|
|
116
|
-
this.createHoleMatrix = (group) => {
|
|
117
|
-
const fullTraceDirections = [
|
|
118
|
-
new DPoint(-1, 0),
|
|
119
|
-
new DPoint(0, 1),
|
|
120
|
-
new DPoint(1, 0),
|
|
121
|
-
new DPoint(0, -1)
|
|
122
|
-
];
|
|
123
|
-
group.prepareToFastSearch();
|
|
124
|
-
const tmpMatrix = TraceMatrix
|
|
125
|
-
.createMatrix(this.size, (p) => group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f);
|
|
126
|
-
const startCoords = new DPolygon();
|
|
127
|
-
for (let i = 0; i < this.size.w; i++) {
|
|
128
|
-
startCoords.push(new DPoint(i, -1));
|
|
129
|
-
startCoords.push(new DPoint(i, this.size.h));
|
|
130
|
-
}
|
|
131
|
-
for (let i = 0; i < this.size.h; i++) {
|
|
132
|
-
startCoords.push(new DPoint(-1, i));
|
|
133
|
-
startCoords.push(new DPoint(this.size.w, i));
|
|
134
|
-
}
|
|
135
|
-
while (startCoords.length) {
|
|
136
|
-
const point = startCoords.pop();
|
|
137
|
-
for (const direction of fullTraceDirections) {
|
|
138
|
-
const tmpPoint = point.clone().move(direction);
|
|
139
|
-
const value = getByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
140
|
-
if (value === TraceMatrixValues.f) {
|
|
141
|
-
setByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
142
|
-
startCoords.push(tmpPoint);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const t = this.reverseMatrix(tmpMatrix);
|
|
147
|
-
return this.totalCountInMatrix(t) ? t : null;
|
|
148
|
-
};
|
|
149
|
-
this.size = s.clone().scale(4);
|
|
150
|
-
const t = TraceMatrix.createMatrix(this.size, (p) => {
|
|
151
|
-
const { x, y } = p.clone().mod(4);
|
|
152
|
-
if ([1, 2].includes(x) && [1, 2].includes(y)) {
|
|
153
|
-
return f(p.clone().div(4));
|
|
154
|
-
}
|
|
155
|
-
return TraceMatrixValues.f;
|
|
156
|
-
});
|
|
157
|
-
this.m = TraceMatrix.createMatrix(this.size);
|
|
158
|
-
for (let i = 1; i < this.size.y - 1; i++) {
|
|
159
|
-
for (let j = 1; j < this.size.x - 1; j++) {
|
|
160
|
-
if (t[i][j] === TraceMatrixValues.t) {
|
|
161
|
-
this.m[i - 1][j - 1] = TraceMatrixValues.t;
|
|
162
|
-
this.m[i - 1][j] = TraceMatrixValues.t;
|
|
163
|
-
this.m[i - 1][j + 1] = TraceMatrixValues.t;
|
|
164
|
-
this.m[i][j - 1] = TraceMatrixValues.t;
|
|
165
|
-
this.m[i][j] = TraceMatrixValues.t;
|
|
166
|
-
this.m[i][j + 1] = TraceMatrixValues.t;
|
|
167
|
-
this.m[i + 1][j - 1] = TraceMatrixValues.t;
|
|
168
|
-
this.m[i + 1][j] = TraceMatrixValues.t;
|
|
169
|
-
this.m[i + 1][j + 1] = TraceMatrixValues.t;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
fullMatrixTrace() {
|
|
175
|
-
const groups = this.findAllGroupsInMatrix(this.m);
|
|
176
|
-
const paths = groups.map((g) => this.traceGroup(this.m, g));
|
|
177
|
-
const holeMatrixs = groups.map(this.createHoleMatrix);
|
|
178
|
-
const holesGroups = holeMatrixs.map((m) => m && this.findAllGroupsInMatrix(m));
|
|
179
|
-
const holesPaths = holesGroups.map((hg, index) => hg && hg.map((g) => this
|
|
180
|
-
.traceGroup(holeMatrixs[index], g)).filter((r) => r.length > MIN_POINTS_IN_VALID_POLYGON));
|
|
181
|
-
return groups.map((g, index) => {
|
|
182
|
-
const res = paths[index];
|
|
183
|
-
if (holesGroups[index] && holesGroups[index].length) {
|
|
184
|
-
res.holes = holesPaths[index];
|
|
185
|
-
}
|
|
186
|
-
return res.loop()
|
|
187
|
-
.divide(4)
|
|
188
|
-
.round()
|
|
189
|
-
.run();
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
reverseMatrix(m) {
|
|
193
|
-
return TraceMatrix.createMatrix(this.size, (p) => getByPosition(m, p) === TraceMatrixValues.f ? TraceMatrixValues.t : TraceMatrixValues.f);
|
|
194
|
-
}
|
|
195
|
-
findMarked(m, init) {
|
|
196
|
-
const s = this.size;
|
|
197
|
-
let ini = false;
|
|
198
|
-
for (let i = 0; i < s.w; i++) {
|
|
199
|
-
for (let j = 0; j < s.h; j++) {
|
|
200
|
-
if (!ini && init) {
|
|
201
|
-
i = init.x;
|
|
202
|
-
j = init.y;
|
|
203
|
-
ini = true;
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
if (getByPosition(m, new DPoint(i, j)) === TraceMatrixValues.t) {
|
|
207
|
-
return new DPoint(i, j);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
totalCountInMatrix(m) {
|
|
214
|
-
let res = 0;
|
|
215
|
-
const s = this.size;
|
|
216
|
-
for (let i = 0; i < s.w; i++) {
|
|
217
|
-
for (let j = 0; j < s.h; j++) {
|
|
218
|
-
if (getByPosition(m, new DPoint(i, j))) {
|
|
219
|
-
res++;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return res;
|
|
224
|
-
}
|
|
225
|
-
static createMatrix(size, f = () => TraceMatrixValues.f) {
|
|
226
|
-
return createArray(size.h)
|
|
227
|
-
.map((v, i) => createArray(size.w).map((v2, j) => f(new DPoint(j, i))));
|
|
228
|
-
}
|
|
229
|
-
}
|
package/dist/es2015/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './DCircle';
|
|
2
|
-
export * from './DLine';
|
|
3
|
-
export * from './DNumbers';
|
|
4
|
-
export * from './DPoint';
|
|
5
|
-
export * from './DPolygon';
|
|
6
|
-
export * from './FastSearch';
|
|
7
|
-
export * from './TraceMatrix';
|
|
8
|
-
export * from './InterpolationMatrix';
|
|
9
|
-
export * from './DPolygonLoop';
|
|
10
|
-
export * from './DPlane';
|
|
11
|
-
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, parseDegreesMinutesSeconds, DGeo } from './utils';
|
package/dist/es2015/utils.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { DPoint } from './DPoint';
|
|
2
|
-
export const DGeo = {
|
|
3
|
-
DEBUG: false,
|
|
4
|
-
parseFormat: 'xyz'
|
|
5
|
-
};
|
|
6
|
-
export const warn = (...args) => {
|
|
7
|
-
if (DGeo.DEBUG) {
|
|
8
|
-
console.warn(...args);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
export const isDefAndNotNull = (a) => a != undefined;
|
|
12
|
-
const hook = (scope) => () => scope;
|
|
13
|
-
const shouldBeInt = (scope, funcName, argName) => (p) => {
|
|
14
|
-
if (!p.clone().round()
|
|
15
|
-
.equal(p)) {
|
|
16
|
-
warn(`"${funcName}" -> "${argName}" should be Int!`);
|
|
17
|
-
}
|
|
18
|
-
return scope;
|
|
19
|
-
};
|
|
20
|
-
const shouldBeUInt = (scope, funcName, argName) => (p) => {
|
|
21
|
-
if (!p.clone().round()
|
|
22
|
-
.equal(p) || !p.gtOrEqual(DPoint.zero())) {
|
|
23
|
-
warn(`"${funcName}" -> "${argName}" should be UInt!`);
|
|
24
|
-
}
|
|
25
|
-
return scope;
|
|
26
|
-
};
|
|
27
|
-
const shouldBeDegree = (scope, funcName, argName) => (p) => {
|
|
28
|
-
if (!p.likeWorldGeodeticSystem) {
|
|
29
|
-
warn(`"${funcName}" -> "${argName}" should be degree!`);
|
|
30
|
-
}
|
|
31
|
-
return scope;
|
|
32
|
-
};
|
|
33
|
-
const shouldBeRadians = (scope, funcName, argName) => (p) => {
|
|
34
|
-
if (!p.likeRadians) {
|
|
35
|
-
warn(`"${funcName}" -> "${argName}" should be radians!`);
|
|
36
|
-
}
|
|
37
|
-
return scope;
|
|
38
|
-
};
|
|
39
|
-
const shouldExist = (scope, funcName, argName) => (p) => {
|
|
40
|
-
if (!isDefAndNotNull(p)) {
|
|
41
|
-
warn(`"${funcName}" -> "${argName}" should exist!`);
|
|
42
|
-
}
|
|
43
|
-
return scope;
|
|
44
|
-
};
|
|
45
|
-
const shouldBeMeters = (scope, funcName, argName) => (p) => {
|
|
46
|
-
if (!p.likePseudoMercator) {
|
|
47
|
-
warn(`"${funcName}" -> "${argName}" should be meters!`);
|
|
48
|
-
}
|
|
49
|
-
return scope;
|
|
50
|
-
};
|
|
51
|
-
export const checkFunction = (funcName) => ({
|
|
52
|
-
checkArgument: function (argName) {
|
|
53
|
-
if (!DGeo.DEBUG) {
|
|
54
|
-
return {
|
|
55
|
-
shouldBeDegree: hook(this),
|
|
56
|
-
shouldBeMeters: hook(this),
|
|
57
|
-
shouldBeInt: hook(this),
|
|
58
|
-
shouldBeUInt: hook(this),
|
|
59
|
-
shouldBeRadians: hook(this),
|
|
60
|
-
shouldExist: hook(this)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
shouldBeDegree: shouldBeDegree(this, funcName, argName),
|
|
65
|
-
shouldBeMeters: shouldBeMeters(this, funcName, argName),
|
|
66
|
-
shouldBeInt: shouldBeInt(this, funcName, argName),
|
|
67
|
-
shouldBeUInt: shouldBeUInt(this, funcName, argName),
|
|
68
|
-
shouldBeRadians: shouldBeRadians(this, funcName, argName),
|
|
69
|
-
shouldExist: shouldExist(this, funcName, argName)
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
export const createArray = (v, fillSymbol) => {
|
|
74
|
-
if (typeof fillSymbol === 'function') {
|
|
75
|
-
return new Array(v).fill(false)
|
|
76
|
-
.map((_, i) => fillSymbol(i));
|
|
77
|
-
}
|
|
78
|
-
return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
|
|
79
|
-
};
|
|
80
|
-
export const createMatrix = ({ h, w }, fillSymbol) => {
|
|
81
|
-
if (typeof fillSymbol === 'function') {
|
|
82
|
-
return createArray(h)
|
|
83
|
-
.map((_, y) => createArray(w, (x) => fillSymbol(x, y)));
|
|
84
|
-
}
|
|
85
|
-
return createArray(h)
|
|
86
|
-
.map(() => createArray(w, fillSymbol));
|
|
87
|
-
};
|
|
88
|
-
export const gaussianElimination = (matrix) => {
|
|
89
|
-
const n = matrix.length;
|
|
90
|
-
const matrixClone = createMatrix(new DPoint(n + 1, n));
|
|
91
|
-
for (let i = 0; i < n; i++) {
|
|
92
|
-
for (let j = 0; j < n + 1; j++) {
|
|
93
|
-
matrix[i][j] = matrix[i][j] === 0 ? gaussianElimination.MIN : matrix[i][j];
|
|
94
|
-
matrixClone[i][j] = matrix[i][j];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
for (let k = 0; k < n; k++) {
|
|
98
|
-
for (let i = 0; i < n + 1; i++) {
|
|
99
|
-
matrixClone[k][i] /= matrix[k][k];
|
|
100
|
-
}
|
|
101
|
-
for (let i = k + 1; i < n; i++) {
|
|
102
|
-
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
103
|
-
for (let j = 0; j < n + 1; j++) {
|
|
104
|
-
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
for (let i = 0; i < n; i++) {
|
|
108
|
-
for (let j = 0; j < n + 1; j++) {
|
|
109
|
-
matrix[i][j] = matrixClone[i][j];
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
for (let k = n - 1; k > -1; k--) {
|
|
114
|
-
for (let i = n; i > -1; i--) {
|
|
115
|
-
matrixClone[k][i] /= matrix[k][k];
|
|
116
|
-
}
|
|
117
|
-
for (let i = k - 1; i > -1; i--) {
|
|
118
|
-
const K = matrixClone[i][k] / matrixClone[k][k];
|
|
119
|
-
for (let j = n; j > -1; j--) {
|
|
120
|
-
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const answer = createArray(n);
|
|
125
|
-
for (let i = 0; i < n; i++) {
|
|
126
|
-
answer[i] = matrixClone[i][n];
|
|
127
|
-
}
|
|
128
|
-
return answer;
|
|
129
|
-
};
|
|
130
|
-
gaussianElimination.MIN = 1e-10;
|
|
131
|
-
export const createCanvas = (a, b, c) => {
|
|
132
|
-
var _a;
|
|
133
|
-
let w = 0;
|
|
134
|
-
let h = 0;
|
|
135
|
-
let offscreen = false;
|
|
136
|
-
if (a instanceof DPoint) {
|
|
137
|
-
const { x, y } = a;
|
|
138
|
-
w = x;
|
|
139
|
-
h = y;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
w = a;
|
|
143
|
-
h = a;
|
|
144
|
-
}
|
|
145
|
-
if (typeof b === 'boolean') {
|
|
146
|
-
offscreen = b;
|
|
147
|
-
}
|
|
148
|
-
else if (typeof b === 'number') {
|
|
149
|
-
h = b;
|
|
150
|
-
}
|
|
151
|
-
if (typeof c === 'boolean') {
|
|
152
|
-
offscreen = c;
|
|
153
|
-
}
|
|
154
|
-
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
155
|
-
if (!offscreen) {
|
|
156
|
-
canvas.width = w;
|
|
157
|
-
canvas.height = h;
|
|
158
|
-
}
|
|
159
|
-
return [canvas, canvas.getContext('2d')];
|
|
160
|
-
};
|
|
161
|
-
const f = (a, b) => [].concat(...a.map((c) => b.map((d) => [].concat(c, d))));
|
|
162
|
-
export const cartesianProduct = (a, b, ...c) => b ? cartesianProduct(f(a, b), ...c) : a;
|
|
163
|
-
export const getCombinations = (arr) => {
|
|
164
|
-
if (arr.length === 1) {
|
|
165
|
-
return arr[0];
|
|
166
|
-
}
|
|
167
|
-
const ans = [];
|
|
168
|
-
const otherCases = getCombinations(arr.slice(1));
|
|
169
|
-
for (let i = 0; i < otherCases.length; i++) {
|
|
170
|
-
for (let j = 0; j < arr[0].length; j++) {
|
|
171
|
-
ans.push([arr[0][j], ...otherCases[i]]);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return ans;
|
|
175
|
-
};
|
|
176
|
-
export const div = (a, b) => Math.floor(a / b);
|
|
177
|
-
export const toDegreesMinutesSeconds = (v) => {
|
|
178
|
-
const degrees = Math.floor(v);
|
|
179
|
-
const t = (v % 1) * 60;
|
|
180
|
-
const minutes = Math.floor(t);
|
|
181
|
-
const t2 = (t % 1) * 60;
|
|
182
|
-
const seconds = t2.toFixed(2);
|
|
183
|
-
return `${degrees}° ${minutes}' ${seconds}"`;
|
|
184
|
-
};
|
|
185
|
-
export const parseDegreesMinutesSeconds = (i) => {
|
|
186
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
187
|
-
const parts = i.matchAll(/(?<value>-?\d+(?<tail>\.\d{1,})?)(?<type>°|'|")/gmiu);
|
|
188
|
-
let d = 0;
|
|
189
|
-
let m = 0;
|
|
190
|
-
let s = 0;
|
|
191
|
-
for (const part of parts) {
|
|
192
|
-
switch ((_a = part === null || part === void 0 ? void 0 : part.groups) === null || _a === void 0 ? void 0 : _a.type) {
|
|
193
|
-
case '°':
|
|
194
|
-
d = Number((_c = (_b = part === null || part === void 0 ? void 0 : part.groups) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : '0');
|
|
195
|
-
break;
|
|
196
|
-
case '\'':
|
|
197
|
-
m = Number((_e = (_d = part === null || part === void 0 ? void 0 : part.groups) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : '0');
|
|
198
|
-
break;
|
|
199
|
-
case '"':
|
|
200
|
-
s = Number((_g = (_f = part === null || part === void 0 ? void 0 : part.groups) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : '0');
|
|
201
|
-
break;
|
|
202
|
-
default:
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
const h = d < 0 ? -1 : 1;
|
|
206
|
-
return d + h * m / 60 + h * s / 3600;
|
|
207
|
-
};
|
package/dist/esm/DCircle.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { DPoint, EARTH_RADIUS_IN_METERS } from './DPoint';
|
|
2
|
-
import { DPolygon } from './DPolygon';
|
|
3
|
-
import { checkFunction } from './utils';
|
|
4
|
-
var DCircle = (function () {
|
|
5
|
-
function DCircle(center, r) {
|
|
6
|
-
if (center === void 0) { center = DPoint.zero(); }
|
|
7
|
-
if (r === void 0) { r = 0; }
|
|
8
|
-
this.center = center;
|
|
9
|
-
this.r = r;
|
|
10
|
-
}
|
|
11
|
-
DCircle.prototype.toString = function () {
|
|
12
|
-
return "(".concat(this.center.toString(), ", ").concat(this.r, ")");
|
|
13
|
-
};
|
|
14
|
-
DCircle.prototype.getValue = function () {
|
|
15
|
-
return { center: this.center, r: this.r };
|
|
16
|
-
};
|
|
17
|
-
DCircle.prototype.clone = function () {
|
|
18
|
-
return new DCircle(this.center, this.r);
|
|
19
|
-
};
|
|
20
|
-
DCircle.prototype.findPoints = function (c) {
|
|
21
|
-
if (this.equal(c)) {
|
|
22
|
-
return Infinity;
|
|
23
|
-
}
|
|
24
|
-
var _a = this, _b = _a.center, x0 = _b.x, y0 = _b.y, r0 = _a.r;
|
|
25
|
-
var _c = c.center, x1 = _c.x, y1 = _c.y, r1 = c.r;
|
|
26
|
-
var r02 = r0 * r0;
|
|
27
|
-
var d = this.center.distance(c.center);
|
|
28
|
-
var a = (r02 - r1 * r1 + d * d) / (2 * d);
|
|
29
|
-
var h = Math.sqrt(r02 - a * a);
|
|
30
|
-
var ad = a / d;
|
|
31
|
-
var dy = y1 - y0;
|
|
32
|
-
var dx = x1 - x0;
|
|
33
|
-
var hd = h / d;
|
|
34
|
-
var x2 = x0 + ad * (x1 - x0);
|
|
35
|
-
var y2 = y0 + ad * (y1 - y0);
|
|
36
|
-
var x31 = x2 + hd * dy;
|
|
37
|
-
var y31 = y2 - hd * dx;
|
|
38
|
-
var x32 = x2 - hd * dy;
|
|
39
|
-
var y32 = y2 + hd * dx;
|
|
40
|
-
var res = [];
|
|
41
|
-
if (!isNaN(x31) && !isNaN(y31)) {
|
|
42
|
-
res.push(new DPoint(x31, y31));
|
|
43
|
-
}
|
|
44
|
-
if (!isNaN(x32) && !isNaN(y32) && !(x31 === x32 && y31 === y32)) {
|
|
45
|
-
res.push(new DPoint(x32, y32));
|
|
46
|
-
}
|
|
47
|
-
return res;
|
|
48
|
-
};
|
|
49
|
-
DCircle.prototype.equal = function (_a) {
|
|
50
|
-
var center = _a.center, r = _a.r;
|
|
51
|
-
return this.center.equal(center) && this.r === r;
|
|
52
|
-
};
|
|
53
|
-
DCircle.prototype.findPolygonInside = function (pointCount, startAngle, stopAngle) {
|
|
54
|
-
if (pointCount === void 0) { pointCount = 64; }
|
|
55
|
-
if (startAngle === void 0) { startAngle = 0; }
|
|
56
|
-
if (stopAngle === void 0) { stopAngle = 2 * Math.PI; }
|
|
57
|
-
var step = 2 * Math.PI / pointCount;
|
|
58
|
-
var points = [];
|
|
59
|
-
var angle = startAngle;
|
|
60
|
-
while (angle < stopAngle - step) {
|
|
61
|
-
points.push(new DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
|
|
62
|
-
.move(this.center));
|
|
63
|
-
angle += step;
|
|
64
|
-
}
|
|
65
|
-
var x = this.r * Math.cos(stopAngle) + this.center.x;
|
|
66
|
-
var y = this.r * Math.sin(stopAngle) + this.center.y;
|
|
67
|
-
points.push(new DPoint(x, y));
|
|
68
|
-
return new DPolygon(points);
|
|
69
|
-
};
|
|
70
|
-
DCircle.prototype.findPolygonInsideOnSphere = function (pointCount, startAngle, stopAngle) {
|
|
71
|
-
if (pointCount === void 0) { pointCount = 64; }
|
|
72
|
-
if (startAngle === void 0) { startAngle = 0; }
|
|
73
|
-
if (stopAngle === void 0) { stopAngle = 2 * Math.PI; }
|
|
74
|
-
checkFunction('findPolygonInsideOnSphere')
|
|
75
|
-
.checkArgument('center')
|
|
76
|
-
.shouldBeDegree(this.center);
|
|
77
|
-
var step = 2 * Math.PI / pointCount;
|
|
78
|
-
var points = [];
|
|
79
|
-
var angle = startAngle;
|
|
80
|
-
while (angle < stopAngle - step) {
|
|
81
|
-
points.push(this.sphereOffset(angle));
|
|
82
|
-
angle += step;
|
|
83
|
-
}
|
|
84
|
-
points.push(this.sphereOffset(stopAngle));
|
|
85
|
-
return new DPolygon(points);
|
|
86
|
-
};
|
|
87
|
-
DCircle.prototype.sphereOffset = function (bearing, earthRadius) {
|
|
88
|
-
if (earthRadius === void 0) { earthRadius = EARTH_RADIUS_IN_METERS; }
|
|
89
|
-
var _a = this.center.clone().degreeToRadians(), lon1 = _a.x, lat1 = _a.y;
|
|
90
|
-
var dByR = this.r / earthRadius;
|
|
91
|
-
var lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
|
|
92
|
-
Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
|
|
93
|
-
var lon = lon1 +
|
|
94
|
-
Math.atan2(Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
|
|
95
|
-
return new DPoint(lon, lat).radiansToDegrees();
|
|
96
|
-
};
|
|
97
|
-
return DCircle;
|
|
98
|
-
}());
|
|
99
|
-
export { DCircle };
|