dgeoutils 2.4.2 → 2.4.5
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/dist/{DCircle.d.ts → cjs/DCircle.d.ts} +0 -0
- package/dist/cjs/DCircle.js +102 -0
- package/dist/{DLine.d.ts → cjs/DLine.d.ts} +0 -0
- package/dist/cjs/DLine.js +310 -0
- package/dist/{DNumbers.d.ts → cjs/DNumbers.d.ts} +0 -0
- package/dist/cjs/DNumbers.js +30 -0
- package/dist/{DPlane.d.ts → cjs/DPlane.d.ts} +0 -0
- package/dist/cjs/DPlane.js +132 -0
- package/dist/{DPoint.d.ts → cjs/DPoint.d.ts} +2 -0
- package/dist/cjs/DPoint.js +614 -0
- package/dist/{DPolygon.d.ts → cjs/DPolygon.d.ts} +0 -0
- package/dist/cjs/DPolygon.js +1560 -0
- package/dist/{DPolygonLoop.d.ts → cjs/DPolygonLoop.d.ts} +0 -0
- package/dist/cjs/DPolygonLoop.js +401 -0
- package/dist/{FastSearch.d.ts → cjs/FastSearch.d.ts} +0 -0
- package/dist/cjs/FastSearch.js +53 -0
- package/dist/{TraceMatrix.d.ts → cjs/TraceMatrix.d.ts} +0 -0
- package/dist/cjs/TraceMatrix.js +256 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- package/dist/{index.js → cjs/index.js} +5 -1
- package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
- package/dist/cjs/utils.js +216 -0
- package/dist/{DCircle.js → es2015/DCircle.js} +14 -18
- package/dist/{DLine.js → es2015/DLine.js} +24 -28
- package/dist/es2015/DNumbers.js +22 -0
- package/dist/{DPlane.js → es2015/DPlane.js} +22 -26
- package/dist/{DPoint.js → es2015/DPoint.js} +91 -56
- package/dist/{DPolygon.js → es2015/DPolygon.js} +41 -45
- package/dist/{DPolygonLoop.js → es2015/DPolygonLoop.js} +1 -5
- package/dist/{FastSearch.js → es2015/FastSearch.js} +1 -5
- package/dist/{TraceMatrix.js → es2015/TraceMatrix.js} +35 -39
- package/dist/es2015/index.js +10 -0
- package/dist/{utils.js → es2015/utils.js} +29 -41
- package/dist/esm/DCircle.js +1 -1
- package/dist/esm/DLine.js +2 -2
- package/dist/esm/DPoint.js +42 -2
- package/dist/esm/DPolygon.js +7 -7
- package/dist/esm/utils.js +6 -6
- package/dist/umd/dgeoutils.js +59 -19
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +9 -13
- package/dist/DNumbers.js +0 -26
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
var __values = (this && this.__values) || function(o) {
|
|
28
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
+
if (m) return m.call(o);
|
|
30
|
+
if (o && typeof o.length === "number") return {
|
|
31
|
+
next: function () {
|
|
32
|
+
if (o && i >= o.length) o = void 0;
|
|
33
|
+
return { value: o && o[i++], done: !o };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.TraceMatrix = exports.TraceMatrixValues = void 0;
|
|
40
|
+
var DPoint_1 = require("./DPoint");
|
|
41
|
+
var DPolygon_1 = require("./DPolygon");
|
|
42
|
+
var FastSearch_1 = require("./FastSearch");
|
|
43
|
+
var utils_1 = require("./utils");
|
|
44
|
+
var TraceMatrixValues;
|
|
45
|
+
(function (TraceMatrixValues) {
|
|
46
|
+
TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
|
|
47
|
+
TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
|
|
48
|
+
})(TraceMatrixValues = exports.TraceMatrixValues || (exports.TraceMatrixValues = {}));
|
|
49
|
+
var getByPosition = function (m, p, defaultValue) {
|
|
50
|
+
if (defaultValue === void 0) { defaultValue = TraceMatrixValues.f; }
|
|
51
|
+
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
52
|
+
return defaultValue;
|
|
53
|
+
}
|
|
54
|
+
return m[p.y][p.x];
|
|
55
|
+
};
|
|
56
|
+
var setByPosition = function (m, p, value) {
|
|
57
|
+
if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
m[p.y][p.x] = value;
|
|
61
|
+
return m[p.y][p.x];
|
|
62
|
+
};
|
|
63
|
+
var TraceMatrix = (function () {
|
|
64
|
+
function TraceMatrix(size, f) {
|
|
65
|
+
var _this = this;
|
|
66
|
+
this.size = size;
|
|
67
|
+
this.findGroupByIndex = function (m, s) {
|
|
68
|
+
var res = new DPolygon_1.DPolygon();
|
|
69
|
+
if (s && getByPosition(m, s) === TraceMatrixValues.t) {
|
|
70
|
+
res.push(s);
|
|
71
|
+
var startIndex = 0;
|
|
72
|
+
var marked = TraceMatrix.createMatrix(_this.size, function () { return TraceMatrixValues.f; });
|
|
73
|
+
setByPosition(marked, s, TraceMatrixValues.t);
|
|
74
|
+
while (startIndex < res.length) {
|
|
75
|
+
var r = res.at(startIndex);
|
|
76
|
+
for (var i = -1; i < 2; i++) {
|
|
77
|
+
for (var j = -1; j < 2; j++) {
|
|
78
|
+
var t = new DPoint_1.DPoint(r.x + i, r.y + j);
|
|
79
|
+
if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
|
|
80
|
+
getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
|
|
81
|
+
res.push(t);
|
|
82
|
+
setByPosition(marked, t, TraceMatrixValues.t);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
startIndex++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return res;
|
|
90
|
+
};
|
|
91
|
+
this.findAllGroupsInMatrix = function (m) {
|
|
92
|
+
var firstMark = _this.findMarked(m);
|
|
93
|
+
if (!firstMark) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
var group = _this.findGroupByIndex(m, firstMark);
|
|
97
|
+
var groups = [group];
|
|
98
|
+
var groupSum = group.length;
|
|
99
|
+
var allGroups = __spreadArray([], __read(group.points), false);
|
|
100
|
+
var fs = new FastSearch_1.FastSearch();
|
|
101
|
+
fs.add(allGroups);
|
|
102
|
+
while (groupSum < _this.totalCountInMatrix(m)) {
|
|
103
|
+
var mark = _this.findMarked(m);
|
|
104
|
+
while (mark && fs.find(mark)) {
|
|
105
|
+
mark = _this.findMarked(m, mark);
|
|
106
|
+
}
|
|
107
|
+
var nextGroup = _this.findGroupByIndex(m, mark);
|
|
108
|
+
groupSum += nextGroup.length;
|
|
109
|
+
allGroups = __spreadArray(__spreadArray([], __read(allGroups), false), __read(nextGroup.points), false);
|
|
110
|
+
fs.add(nextGroup.points);
|
|
111
|
+
groups.push(nextGroup);
|
|
112
|
+
}
|
|
113
|
+
return groups.filter(function (g) { return g.length > 2; });
|
|
114
|
+
};
|
|
115
|
+
this.traceGroup = function (m, group) {
|
|
116
|
+
var traceDirections = [
|
|
117
|
+
new DPoint_1.DPoint(-1, -1),
|
|
118
|
+
new DPoint_1.DPoint(-1, 0),
|
|
119
|
+
new DPoint_1.DPoint(-1, 1),
|
|
120
|
+
new DPoint_1.DPoint(0, 1),
|
|
121
|
+
new DPoint_1.DPoint(1, 1),
|
|
122
|
+
new DPoint_1.DPoint(1, 0),
|
|
123
|
+
new DPoint_1.DPoint(1, -1),
|
|
124
|
+
new DPoint_1.DPoint(0, -1)
|
|
125
|
+
];
|
|
126
|
+
var left = function (d) { return (d + traceDirections.length + 1) % traceDirections.length; };
|
|
127
|
+
var right = function (d) { return (d + traceDirections.length - 1) % traceDirections.length; };
|
|
128
|
+
if (group.length < 2) {
|
|
129
|
+
var t = group.at(0).clone();
|
|
130
|
+
return new DPolygon_1.DPolygon([t, t, t]);
|
|
131
|
+
}
|
|
132
|
+
var points = new DPolygon_1.DPolygon();
|
|
133
|
+
var direction = 0;
|
|
134
|
+
var prevDirection = Infinity;
|
|
135
|
+
var p = group.at(0);
|
|
136
|
+
while (!p.equal(group.at(0)) || points.length < 2) {
|
|
137
|
+
while (true) {
|
|
138
|
+
var nextValue = getByPosition(m, p.clone().move(traceDirections[direction]));
|
|
139
|
+
var nextNeighbourValue = getByPosition(m, p.clone().move(traceDirections[left(direction)]));
|
|
140
|
+
if (nextValue === TraceMatrixValues.t && nextNeighbourValue === TraceMatrixValues.f) {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
direction = right(direction);
|
|
144
|
+
}
|
|
145
|
+
if (prevDirection !== direction) {
|
|
146
|
+
points.push(p);
|
|
147
|
+
prevDirection = direction;
|
|
148
|
+
}
|
|
149
|
+
p = p.clone().move(traceDirections[direction]);
|
|
150
|
+
direction = left(left(direction));
|
|
151
|
+
}
|
|
152
|
+
return points.approximation().close();
|
|
153
|
+
};
|
|
154
|
+
this.createHoleMatrix = function (group) {
|
|
155
|
+
var e_1, _a;
|
|
156
|
+
var fullTraceDirections = [
|
|
157
|
+
new DPoint_1.DPoint(-1, 0),
|
|
158
|
+
new DPoint_1.DPoint(0, 1),
|
|
159
|
+
new DPoint_1.DPoint(1, 0),
|
|
160
|
+
new DPoint_1.DPoint(0, -1)
|
|
161
|
+
];
|
|
162
|
+
group.prepareToFastSearch();
|
|
163
|
+
var tmpMatrix = TraceMatrix
|
|
164
|
+
.createMatrix(_this.size, function (p) { return group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f; });
|
|
165
|
+
var startCoords = new DPolygon_1.DPolygon();
|
|
166
|
+
for (var i = 0; i < _this.size.w; i++) {
|
|
167
|
+
startCoords.push(new DPoint_1.DPoint(i, -1));
|
|
168
|
+
startCoords.push(new DPoint_1.DPoint(i, _this.size.h));
|
|
169
|
+
}
|
|
170
|
+
for (var i = 0; i < _this.size.h; i++) {
|
|
171
|
+
startCoords.push(new DPoint_1.DPoint(-1, i));
|
|
172
|
+
startCoords.push(new DPoint_1.DPoint(_this.size.w, i));
|
|
173
|
+
}
|
|
174
|
+
while (startCoords.length) {
|
|
175
|
+
var point = startCoords.pop();
|
|
176
|
+
try {
|
|
177
|
+
for (var fullTraceDirections_1 = (e_1 = void 0, __values(fullTraceDirections)), fullTraceDirections_1_1 = fullTraceDirections_1.next(); !fullTraceDirections_1_1.done; fullTraceDirections_1_1 = fullTraceDirections_1.next()) {
|
|
178
|
+
var direction = fullTraceDirections_1_1.value;
|
|
179
|
+
var tmpPoint = point.clone().move(direction);
|
|
180
|
+
var value = getByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
181
|
+
if (value === TraceMatrixValues.f) {
|
|
182
|
+
setByPosition(tmpMatrix, tmpPoint, TraceMatrixValues.t);
|
|
183
|
+
startCoords.push(tmpPoint);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
188
|
+
finally {
|
|
189
|
+
try {
|
|
190
|
+
if (fullTraceDirections_1_1 && !fullTraceDirections_1_1.done && (_a = fullTraceDirections_1.return)) _a.call(fullTraceDirections_1);
|
|
191
|
+
}
|
|
192
|
+
finally { if (e_1) throw e_1.error; }
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
var t = _this.reverseMatrix(tmpMatrix);
|
|
196
|
+
return _this.totalCountInMatrix(t) ? t : null;
|
|
197
|
+
};
|
|
198
|
+
this.m = TraceMatrix.createMatrix(this.size, f);
|
|
199
|
+
}
|
|
200
|
+
TraceMatrix.prototype.fullMatrixTrace = function () {
|
|
201
|
+
var _this = this;
|
|
202
|
+
var groups = this.findAllGroupsInMatrix(this.m);
|
|
203
|
+
var paths = groups.map(function (g) { return _this.traceGroup(_this.m, g); });
|
|
204
|
+
var holeMatrixs = groups.map(this.createHoleMatrix);
|
|
205
|
+
var holesGroups = holeMatrixs.map(function (m) { return m && _this.findAllGroupsInMatrix(m); });
|
|
206
|
+
var holesPaths = holesGroups.map(function (hg, index) { return hg && hg.map(function (g) { return _this
|
|
207
|
+
.traceGroup(holeMatrixs[index], g); }).filter(function (r) { return r.length > DPolygon_1.MIN_POINTS_IN_VALID_POLYGON; }); });
|
|
208
|
+
return groups.map(function (g, index) {
|
|
209
|
+
var res = paths[index];
|
|
210
|
+
if (holesGroups[index] && holesGroups[index].length) {
|
|
211
|
+
res.holes = holesPaths[index];
|
|
212
|
+
}
|
|
213
|
+
return res;
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
TraceMatrix.prototype.reverseMatrix = function (m) {
|
|
217
|
+
return TraceMatrix.createMatrix(this.size, function (p) { return getByPosition(m, p) === TraceMatrixValues.f ? TraceMatrixValues.t : TraceMatrixValues.f; });
|
|
218
|
+
};
|
|
219
|
+
TraceMatrix.prototype.findMarked = function (m, init) {
|
|
220
|
+
var s = this.size;
|
|
221
|
+
var ini = false;
|
|
222
|
+
for (var i = 0; i < s.w; i++) {
|
|
223
|
+
for (var j = 0; j < s.h; j++) {
|
|
224
|
+
if (!ini && init) {
|
|
225
|
+
i = init.x;
|
|
226
|
+
j = init.y;
|
|
227
|
+
ini = true;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (getByPosition(m, new DPoint_1.DPoint(i, j)) === TraceMatrixValues.t) {
|
|
231
|
+
return new DPoint_1.DPoint(i, j);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
};
|
|
237
|
+
TraceMatrix.prototype.totalCountInMatrix = function (m) {
|
|
238
|
+
var res = 0;
|
|
239
|
+
var s = this.size;
|
|
240
|
+
for (var i = 0; i < s.w; i++) {
|
|
241
|
+
for (var j = 0; j < s.h; j++) {
|
|
242
|
+
if (getByPosition(m, new DPoint_1.DPoint(i, j))) {
|
|
243
|
+
res++;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return res;
|
|
248
|
+
};
|
|
249
|
+
TraceMatrix.createMatrix = function (size, f) {
|
|
250
|
+
if (f === void 0) { f = function () { return TraceMatrixValues.f; }; }
|
|
251
|
+
return (0, utils_1.createArray)(size.h)
|
|
252
|
+
.map(function (v, i) { return (0, utils_1.createArray)(size.w).map(function (v2, j) { return f(new DPoint_1.DPoint(j, i)); }); });
|
|
253
|
+
};
|
|
254
|
+
return TraceMatrix;
|
|
255
|
+
}());
|
|
256
|
+
exports.TraceMatrix = TraceMatrix;
|
|
File without changes
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
File without changes
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
|
|
29
|
+
var DPoint_1 = require("./DPoint");
|
|
30
|
+
exports.DGeo = {
|
|
31
|
+
DEBUG: false
|
|
32
|
+
};
|
|
33
|
+
var warn = function () {
|
|
34
|
+
var args = [];
|
|
35
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
36
|
+
args[_i] = arguments[_i];
|
|
37
|
+
}
|
|
38
|
+
if (exports.DGeo.DEBUG) {
|
|
39
|
+
console.warn.apply(console, __spreadArray([], __read(args), false));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.warn = warn;
|
|
43
|
+
var isDefAndNotNull = function (a) { return a != undefined; };
|
|
44
|
+
exports.isDefAndNotNull = isDefAndNotNull;
|
|
45
|
+
var hook = function (scope) { return function () { return scope; }; };
|
|
46
|
+
var shouldBeInt = function (scope, funcName, argName) { return function (p) {
|
|
47
|
+
if (!p.clone().round()
|
|
48
|
+
.equal(p)) {
|
|
49
|
+
(0, exports.warn)("\"".concat(funcName, "\" -> \"").concat(argName, "\" should be Int!"));
|
|
50
|
+
}
|
|
51
|
+
return scope;
|
|
52
|
+
}; };
|
|
53
|
+
var shouldBeUInt = function (scope, funcName, argName) { return function (p) {
|
|
54
|
+
if (!p.clone().round()
|
|
55
|
+
.equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
|
|
56
|
+
(0, exports.warn)("\"".concat(funcName, "\" -> \"").concat(argName, "\" should be UInt!"));
|
|
57
|
+
}
|
|
58
|
+
return scope;
|
|
59
|
+
}; };
|
|
60
|
+
var shouldBeDegree = function (scope, funcName, argName) { return function (p) {
|
|
61
|
+
if (!p.likeWorldGeodeticSystem) {
|
|
62
|
+
(0, exports.warn)("\"".concat(funcName, "\" -> \"").concat(argName, "\" should be degree!"));
|
|
63
|
+
}
|
|
64
|
+
return scope;
|
|
65
|
+
}; };
|
|
66
|
+
var shouldBeRadians = function (scope, funcName, argName) { return function (p) {
|
|
67
|
+
if (!p.likeRadians) {
|
|
68
|
+
(0, exports.warn)("\"".concat(funcName, "\" -> \"").concat(argName, "\" should be radians!"));
|
|
69
|
+
}
|
|
70
|
+
return scope;
|
|
71
|
+
}; };
|
|
72
|
+
var shouldExist = function (scope, funcName, argName) { return function (p) {
|
|
73
|
+
if (!(0, exports.isDefAndNotNull)(p)) {
|
|
74
|
+
(0, exports.warn)("\"".concat(funcName, "\" -> \"").concat(argName, "\" should exist!"));
|
|
75
|
+
}
|
|
76
|
+
return scope;
|
|
77
|
+
}; };
|
|
78
|
+
var shouldBeMeters = function (scope, funcName, argName) { return function (p) {
|
|
79
|
+
if (!p.likePseudoMercator) {
|
|
80
|
+
(0, exports.warn)("\"".concat(funcName, "\" -> \"").concat(argName, "\" should be meters!"));
|
|
81
|
+
}
|
|
82
|
+
return scope;
|
|
83
|
+
}; };
|
|
84
|
+
var checkFunction = function (funcName) { return ({
|
|
85
|
+
checkArgument: function (argName) {
|
|
86
|
+
if (!exports.DGeo.DEBUG) {
|
|
87
|
+
return {
|
|
88
|
+
shouldBeDegree: hook(this),
|
|
89
|
+
shouldBeMeters: hook(this),
|
|
90
|
+
shouldBeInt: hook(this),
|
|
91
|
+
shouldBeUInt: hook(this),
|
|
92
|
+
shouldBeRadians: hook(this),
|
|
93
|
+
shouldExist: hook(this)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
shouldBeDegree: shouldBeDegree(this, funcName, argName),
|
|
98
|
+
shouldBeMeters: shouldBeMeters(this, funcName, argName),
|
|
99
|
+
shouldBeInt: shouldBeInt(this, funcName, argName),
|
|
100
|
+
shouldBeUInt: shouldBeUInt(this, funcName, argName),
|
|
101
|
+
shouldBeRadians: shouldBeRadians(this, funcName, argName),
|
|
102
|
+
shouldExist: shouldExist(this, funcName, argName)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}); };
|
|
106
|
+
exports.checkFunction = checkFunction;
|
|
107
|
+
var createArray = function (v, fillSymbol) {
|
|
108
|
+
if (fillSymbol === void 0) { fillSymbol = 0; }
|
|
109
|
+
return new Array(v).fill(fillSymbol);
|
|
110
|
+
};
|
|
111
|
+
exports.createArray = createArray;
|
|
112
|
+
var createMatrix = function (_a, fillSymbol) {
|
|
113
|
+
var h = _a.h, w = _a.w;
|
|
114
|
+
if (fillSymbol === void 0) { fillSymbol = 0; }
|
|
115
|
+
return (0, exports.createArray)(h)
|
|
116
|
+
.map(function () { return (0, exports.createArray)(w, fillSymbol); });
|
|
117
|
+
};
|
|
118
|
+
exports.createMatrix = createMatrix;
|
|
119
|
+
var gaussianElimination = function (matrix) {
|
|
120
|
+
var n = matrix.length;
|
|
121
|
+
var matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
|
|
122
|
+
for (var i = 0; i < n; i++) {
|
|
123
|
+
for (var j = 0; j < n + 1; j++) {
|
|
124
|
+
matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
|
|
125
|
+
matrixClone[i][j] = matrix[i][j];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (var k = 0; k < n; k++) {
|
|
129
|
+
for (var i = 0; i < n + 1; i++) {
|
|
130
|
+
matrixClone[k][i] /= matrix[k][k];
|
|
131
|
+
}
|
|
132
|
+
for (var i = k + 1; i < n; i++) {
|
|
133
|
+
var K = matrixClone[i][k] / matrixClone[k][k];
|
|
134
|
+
for (var j = 0; j < n + 1; j++) {
|
|
135
|
+
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (var i = 0; i < n; i++) {
|
|
139
|
+
for (var j = 0; j < n + 1; j++) {
|
|
140
|
+
matrix[i][j] = matrixClone[i][j];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (var k = n - 1; k > -1; k--) {
|
|
145
|
+
for (var i = n; i > -1; i--) {
|
|
146
|
+
matrixClone[k][i] /= matrix[k][k];
|
|
147
|
+
}
|
|
148
|
+
for (var i = k - 1; i > -1; i--) {
|
|
149
|
+
var K = matrixClone[i][k] / matrixClone[k][k];
|
|
150
|
+
for (var j = n; j > -1; j--) {
|
|
151
|
+
matrixClone[i][j] -= matrixClone[k][j] * K;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
var answer = (0, exports.createArray)(n);
|
|
156
|
+
for (var i = 0; i < n; i++) {
|
|
157
|
+
answer[i] = matrixClone[i][n];
|
|
158
|
+
}
|
|
159
|
+
return answer;
|
|
160
|
+
};
|
|
161
|
+
exports.gaussianElimination = gaussianElimination;
|
|
162
|
+
exports.gaussianElimination.MIN = 1e-10;
|
|
163
|
+
var createCanvas = function (a, b, c) {
|
|
164
|
+
var _a;
|
|
165
|
+
var w = 0;
|
|
166
|
+
var h = 0;
|
|
167
|
+
var offscreen = false;
|
|
168
|
+
if (a instanceof DPoint_1.DPoint) {
|
|
169
|
+
var x = a.x, y = a.y;
|
|
170
|
+
w = x;
|
|
171
|
+
h = y;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
w = a;
|
|
175
|
+
h = a;
|
|
176
|
+
}
|
|
177
|
+
if (typeof b === 'boolean') {
|
|
178
|
+
offscreen = b;
|
|
179
|
+
}
|
|
180
|
+
else if (typeof b === 'number') {
|
|
181
|
+
h = b;
|
|
182
|
+
}
|
|
183
|
+
if (typeof c === 'boolean') {
|
|
184
|
+
offscreen = c;
|
|
185
|
+
}
|
|
186
|
+
var canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
187
|
+
if (!offscreen) {
|
|
188
|
+
canvas.width = w;
|
|
189
|
+
canvas.height = h;
|
|
190
|
+
}
|
|
191
|
+
return [canvas, canvas.getContext('2d')];
|
|
192
|
+
};
|
|
193
|
+
exports.createCanvas = createCanvas;
|
|
194
|
+
var f = function (a, b) { return [].concat.apply([], __spreadArray([], __read(a.map(function (c) { return b.map(function (d) { return [].concat(c, d); }); })), false)); };
|
|
195
|
+
var cartesianProduct = function (a, b) {
|
|
196
|
+
var c = [];
|
|
197
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
198
|
+
c[_i - 2] = arguments[_i];
|
|
199
|
+
}
|
|
200
|
+
return b ? exports.cartesianProduct.apply(void 0, __spreadArray([f(a, b)], __read(c), false)) : a;
|
|
201
|
+
};
|
|
202
|
+
exports.cartesianProduct = cartesianProduct;
|
|
203
|
+
var getCombinations = function (arr) {
|
|
204
|
+
if (arr.length === 1) {
|
|
205
|
+
return arr[0];
|
|
206
|
+
}
|
|
207
|
+
var ans = [];
|
|
208
|
+
var otherCases = (0, exports.getCombinations)(arr.slice(1));
|
|
209
|
+
for (var i = 0; i < otherCases.length; i++) {
|
|
210
|
+
for (var j = 0; j < arr[0].length; j++) {
|
|
211
|
+
ans.push(__spreadArray([arr[0][j]], __read(otherCases[i]), false));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return ans;
|
|
215
|
+
};
|
|
216
|
+
exports.getCombinations = getCombinations;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
class DCircle {
|
|
8
|
-
constructor(center = DPoint_1.DPoint.zero(), r = 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) {
|
|
9
6
|
this.center = center;
|
|
10
7
|
this.r = r;
|
|
11
8
|
}
|
|
@@ -40,10 +37,10 @@ class DCircle {
|
|
|
40
37
|
const y32 = y2 + hd * dx;
|
|
41
38
|
const res = [];
|
|
42
39
|
if (!isNaN(x31) && !isNaN(y31)) {
|
|
43
|
-
res.push(new
|
|
40
|
+
res.push(new DPoint(x31, y31));
|
|
44
41
|
}
|
|
45
42
|
if (!isNaN(x32) && !isNaN(y32) && !(x31 === x32 && y31 === y32)) {
|
|
46
|
-
res.push(new
|
|
43
|
+
res.push(new DPoint(x32, y32));
|
|
47
44
|
}
|
|
48
45
|
return res;
|
|
49
46
|
}
|
|
@@ -55,17 +52,17 @@ class DCircle {
|
|
|
55
52
|
const points = [];
|
|
56
53
|
let angle = startAngle;
|
|
57
54
|
while (angle < stopAngle - step) {
|
|
58
|
-
points.push(new
|
|
55
|
+
points.push(new DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
|
|
59
56
|
.move(this.center));
|
|
60
57
|
angle += step;
|
|
61
58
|
}
|
|
62
59
|
const x = this.r * Math.cos(stopAngle) + this.center.x;
|
|
63
60
|
const y = this.r * Math.sin(stopAngle) + this.center.y;
|
|
64
|
-
points.push(new
|
|
65
|
-
return new
|
|
61
|
+
points.push(new DPoint(x, y));
|
|
62
|
+
return new DPolygon(points);
|
|
66
63
|
}
|
|
67
64
|
findPolygonInsideOnSphere(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
|
|
68
|
-
|
|
65
|
+
checkFunction('findPolygonInsideOnSphere')
|
|
69
66
|
.checkArgument('center')
|
|
70
67
|
.shouldBeDegree(this.center);
|
|
71
68
|
const step = 2 * Math.PI / pointCount;
|
|
@@ -76,16 +73,15 @@ class DCircle {
|
|
|
76
73
|
angle += step;
|
|
77
74
|
}
|
|
78
75
|
points.push(this.sphereOffset(stopAngle));
|
|
79
|
-
return new
|
|
76
|
+
return new DPolygon(points);
|
|
80
77
|
}
|
|
81
|
-
sphereOffset(bearing, earthRadius =
|
|
78
|
+
sphereOffset(bearing, earthRadius = EARTH_RADIUS_IN_METERS) {
|
|
82
79
|
const { x: lon1, y: lat1 } = this.center.clone().degreeToRadians();
|
|
83
80
|
const dByR = this.r / earthRadius;
|
|
84
81
|
const lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
|
|
85
82
|
Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
|
|
86
83
|
const lon = lon1 +
|
|
87
84
|
Math.atan2(Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
|
|
88
|
-
return new
|
|
85
|
+
return new DPoint(lon, lat).radiansToDegrees();
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
|
-
exports.DCircle = DCircle;
|