dgeoutils 2.2.23 → 2.3.2

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.
Files changed (50) hide show
  1. package/README.md +7 -0
  2. package/dist/{DCircle.d.ts → cjs/DCircle.d.ts} +0 -0
  3. package/dist/cjs/DCircle.js +102 -0
  4. package/dist/{DLine.d.ts → cjs/DLine.d.ts} +0 -0
  5. package/dist/cjs/DLine.js +300 -0
  6. package/dist/{DNumbers.d.ts → cjs/DNumbers.d.ts} +0 -0
  7. package/dist/cjs/DNumbers.js +30 -0
  8. package/dist/{DPlane.d.ts → cjs/DPlane.d.ts} +0 -0
  9. package/dist/cjs/DPlane.js +132 -0
  10. package/dist/{DPoint.d.ts → cjs/DPoint.d.ts} +0 -0
  11. package/dist/cjs/DPoint.js +574 -0
  12. package/dist/{DPolygon.d.ts → cjs/DPolygon.d.ts} +7 -1
  13. package/dist/cjs/DPolygon.js +1555 -0
  14. package/dist/{DPolygonLoop.d.ts → cjs/DPolygonLoop.d.ts} +0 -0
  15. package/dist/cjs/DPolygonLoop.js +401 -0
  16. package/dist/{FastSearch.d.ts → cjs/FastSearch.d.ts} +0 -0
  17. package/dist/cjs/FastSearch.js +53 -0
  18. package/dist/{TraceMatrix.d.ts → cjs/TraceMatrix.d.ts} +0 -0
  19. package/dist/cjs/TraceMatrix.js +256 -0
  20. package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  21. package/dist/{index.js → cjs/index.js} +0 -0
  22. package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
  23. package/dist/cjs/utils.js +191 -0
  24. package/dist/{DCircle.js → es2015/DCircle.js} +14 -18
  25. package/dist/{DLine.js → es2015/DLine.js} +24 -28
  26. package/dist/es2015/DNumbers.js +22 -0
  27. package/dist/{DPlane.js → es2015/DPlane.js} +22 -26
  28. package/dist/{DPoint.js → es2015/DPoint.js} +52 -56
  29. package/dist/{DPolygon.js → es2015/DPolygon.js} +90 -86
  30. package/dist/{DPolygonLoop.js → es2015/DPolygonLoop.js} +1 -5
  31. package/dist/{FastSearch.js → es2015/FastSearch.js} +1 -5
  32. package/dist/{TraceMatrix.js → es2015/TraceMatrix.js} +35 -39
  33. package/dist/es2015/index.js +13 -0
  34. package/dist/{utils.js → es2015/utils.js} +26 -36
  35. package/dist/esm/DCircle.js +99 -0
  36. package/dist/esm/DLine.js +297 -0
  37. package/dist/esm/DNumbers.js +27 -0
  38. package/dist/esm/DPlane.js +129 -0
  39. package/dist/esm/DPoint.js +571 -0
  40. package/dist/esm/DPolygon.js +1552 -0
  41. package/dist/esm/DPolygonLoop.js +398 -0
  42. package/dist/esm/FastSearch.js +50 -0
  43. package/dist/esm/TraceMatrix.js +253 -0
  44. package/dist/esm/index.js +13 -0
  45. package/dist/esm/utils.js +181 -0
  46. package/dist/umd/dgeoutils.js +3569 -0
  47. package/dist/umd/dgeoutils.min.js +1 -0
  48. package/dist/umd/dgeoutils.min.js.map +1 -0
  49. package/package.json +17 -10
  50. 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
File without changes
File without changes
@@ -0,0 +1,191 @@
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.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = void 0;
29
+ var index_1 = require("./index");
30
+ var DPoint_1 = require("./DPoint");
31
+ var warn = function () {
32
+ var args = [];
33
+ for (var _i = 0; _i < arguments.length; _i++) {
34
+ args[_i] = arguments[_i];
35
+ }
36
+ if (index_1.DGeo.DEBUG) {
37
+ console.warn.apply(console, __spreadArray([], __read(args), false));
38
+ }
39
+ };
40
+ exports.warn = warn;
41
+ var isDefAndNotNull = function (a) { return a != undefined; };
42
+ exports.isDefAndNotNull = isDefAndNotNull;
43
+ var hook = function (scope) { return function () { return scope; }; };
44
+ var shouldBeInt = function (scope, funcName, argName) { return function (p) {
45
+ if (!p.clone().round()
46
+ .equal(p)) {
47
+ (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be Int!");
48
+ }
49
+ return scope;
50
+ }; };
51
+ var shouldBeUInt = function (scope, funcName, argName) { return function (p) {
52
+ if (!p.clone().round()
53
+ .equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
54
+ (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be UInt!");
55
+ }
56
+ return scope;
57
+ }; };
58
+ var shouldBeDegree = function (scope, funcName, argName) { return function (p) {
59
+ if (!p.likeWorldGeodeticSystem) {
60
+ (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be degree!");
61
+ }
62
+ return scope;
63
+ }; };
64
+ var shouldBeRadians = function (scope, funcName, argName) { return function (p) {
65
+ if (!p.likeRadians) {
66
+ (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be radians!");
67
+ }
68
+ return scope;
69
+ }; };
70
+ var shouldExist = function (scope, funcName, argName) { return function (p) {
71
+ if (!(0, exports.isDefAndNotNull)(p)) {
72
+ (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should exist!");
73
+ }
74
+ return scope;
75
+ }; };
76
+ var shouldBeMeters = function (scope, funcName, argName) { return function (p) {
77
+ if (!p.likePseudoMercator) {
78
+ (0, exports.warn)("\"" + funcName + "\" -> \"" + argName + "\" should be meters!");
79
+ }
80
+ return scope;
81
+ }; };
82
+ var checkFunction = function (funcName) { return ({
83
+ checkArgument: function (argName) {
84
+ if (!index_1.DGeo.DEBUG) {
85
+ return {
86
+ shouldBeDegree: hook(this),
87
+ shouldBeMeters: hook(this),
88
+ shouldBeInt: hook(this),
89
+ shouldBeUInt: hook(this),
90
+ shouldBeRadians: hook(this),
91
+ shouldExist: hook(this)
92
+ };
93
+ }
94
+ return {
95
+ shouldBeDegree: shouldBeDegree(this, funcName, argName),
96
+ shouldBeMeters: shouldBeMeters(this, funcName, argName),
97
+ shouldBeInt: shouldBeInt(this, funcName, argName),
98
+ shouldBeUInt: shouldBeUInt(this, funcName, argName),
99
+ shouldBeRadians: shouldBeRadians(this, funcName, argName),
100
+ shouldExist: shouldExist(this, funcName, argName)
101
+ };
102
+ }
103
+ }); };
104
+ exports.checkFunction = checkFunction;
105
+ var createArray = function (v, fillSymbol) {
106
+ if (fillSymbol === void 0) { fillSymbol = 0; }
107
+ return new Array(v).fill(fillSymbol);
108
+ };
109
+ exports.createArray = createArray;
110
+ var createMatrix = function (_a, fillSymbol) {
111
+ var h = _a.h, w = _a.w;
112
+ if (fillSymbol === void 0) { fillSymbol = 0; }
113
+ return (0, exports.createArray)(h)
114
+ .map(function () { return (0, exports.createArray)(w, fillSymbol); });
115
+ };
116
+ exports.createMatrix = createMatrix;
117
+ var gaussianElimination = function (matrix) {
118
+ var n = matrix.length;
119
+ var matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
120
+ for (var i = 0; i < n; i++) {
121
+ for (var j = 0; j < n + 1; j++) {
122
+ matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
123
+ matrixClone[i][j] = matrix[i][j];
124
+ }
125
+ }
126
+ for (var k = 0; k < n; k++) {
127
+ for (var i = 0; i < n + 1; i++) {
128
+ matrixClone[k][i] /= matrix[k][k];
129
+ }
130
+ for (var i = k + 1; i < n; i++) {
131
+ var K = matrixClone[i][k] / matrixClone[k][k];
132
+ for (var j = 0; j < n + 1; j++) {
133
+ matrixClone[i][j] -= matrixClone[k][j] * K;
134
+ }
135
+ }
136
+ for (var i = 0; i < n; i++) {
137
+ for (var j = 0; j < n + 1; j++) {
138
+ matrix[i][j] = matrixClone[i][j];
139
+ }
140
+ }
141
+ }
142
+ for (var k = n - 1; k > -1; k--) {
143
+ for (var i = n; i > -1; i--) {
144
+ matrixClone[k][i] /= matrix[k][k];
145
+ }
146
+ for (var i = k - 1; i > -1; i--) {
147
+ var K = matrixClone[i][k] / matrixClone[k][k];
148
+ for (var j = n; j > -1; j--) {
149
+ matrixClone[i][j] -= matrixClone[k][j] * K;
150
+ }
151
+ }
152
+ }
153
+ var answer = (0, exports.createArray)(n);
154
+ for (var i = 0; i < n; i++) {
155
+ answer[i] = matrixClone[i][n];
156
+ }
157
+ return answer;
158
+ };
159
+ exports.gaussianElimination = gaussianElimination;
160
+ exports.gaussianElimination.MIN = 1e-10;
161
+ var createCanvas = function (a, b, c) {
162
+ var _a;
163
+ var w = 0;
164
+ var h = 0;
165
+ var offscreen = false;
166
+ if (a instanceof DPoint_1.DPoint) {
167
+ var x = a.x, y = a.y;
168
+ w = x;
169
+ h = y;
170
+ }
171
+ else {
172
+ w = a;
173
+ h = a;
174
+ }
175
+ if (typeof b === 'boolean') {
176
+ offscreen = b;
177
+ }
178
+ else if (typeof b === 'number') {
179
+ h = b;
180
+ }
181
+ if (typeof c === 'boolean') {
182
+ offscreen = c;
183
+ }
184
+ var canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
185
+ if (!offscreen) {
186
+ canvas.width = w;
187
+ canvas.height = h;
188
+ }
189
+ return [canvas, canvas.getContext('2d')];
190
+ };
191
+ exports.createCanvas = createCanvas;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DCircle = void 0;
4
- const DPoint_1 = require("./DPoint");
5
- const DPolygon_1 = require("./DPolygon");
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 DPoint_1.DPoint(x31, y31));
40
+ res.push(new DPoint(x31, y31));
44
41
  }
45
42
  if (!isNaN(x32) && !isNaN(y32) && !(x31 === x32 && y31 === y32)) {
46
- res.push(new DPoint_1.DPoint(x32, y32));
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 DPoint_1.DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
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 DPoint_1.DPoint(x, y));
65
- return new DPolygon_1.DPolygon(points);
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
- (0, utils_1.checkFunction)('findPolygonInsideOnSphere')
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 DPolygon_1.DPolygon(points);
76
+ return new DPolygon(points);
80
77
  }
81
- sphereOffset(bearing, earthRadius = DPoint_1.EARTH_RADIUS_IN_METERS) {
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 DPoint_1.DPoint(lon, lat).radiansToDegrees();
85
+ return new DPoint(lon, lat).radiansToDegrees();
89
86
  }
90
87
  }
91
- exports.DCircle = DCircle;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DLine = void 0;
4
- const DPoint_1 = require("./DPoint");
5
- const utils_1 = require("./utils");
6
- const DNumbers_1 = require("./DNumbers");
7
- class DLine {
8
- constructor(a, b, c, begin = DPoint_1.DPoint.zero(), end = DPoint_1.DPoint.zero()) {
1
+ import { DPoint } from './DPoint';
2
+ import { checkFunction } from './utils';
3
+ import { DNumbers } from './DNumbers';
4
+ export class DLine {
5
+ constructor(a, b, c, begin = DPoint.zero(), end = DPoint.zero()) {
9
6
  this.a = a;
10
7
  this.b = b;
11
8
  this.c = c;
@@ -16,7 +13,7 @@ class DLine {
16
13
  return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
17
14
  }
18
15
  findPerpendicular(p) {
19
- (0, utils_1.checkFunction)('findPerpendicular')
16
+ checkFunction('findPerpendicular')
20
17
  .checkArgument('this.begin')
21
18
  .shouldBeMeters(this.begin)
22
19
  .checkArgument('this.end')
@@ -26,7 +23,7 @@ class DLine {
26
23
  return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
27
24
  }
28
25
  perpendicularDistance(p) {
29
- (0, utils_1.checkFunction)('perpendicularDistance')
26
+ checkFunction('perpendicularDistance')
30
27
  .checkArgument('this.begin')
31
28
  .shouldBeMeters(this.begin)
32
29
  .checkArgument('this.end')
@@ -140,21 +137,21 @@ class DLine {
140
137
  }
141
138
  x(p) {
142
139
  if (this.isParallelY) {
143
- return new DPoint_1.DPoint(-this.c / this.a, p.y);
140
+ return new DPoint(-this.c / this.a, p.y);
144
141
  }
145
142
  if (this.isParallelX) {
146
- return new DPoint_1.DPoint(p.x, -this.c / this.b);
143
+ return new DPoint(p.x, -this.c / this.b);
147
144
  }
148
- return new DPoint_1.DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
145
+ return new DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
149
146
  }
150
147
  y(p) {
151
148
  if (this.isParallelY) {
152
- return new DPoint_1.DPoint(-this.c / this.a, p.y);
149
+ return new DPoint(-this.c / this.a, p.y);
153
150
  }
154
151
  if (this.isParallelX) {
155
- return new DPoint_1.DPoint(p.x, -this.c / this.b);
152
+ return new DPoint(p.x, -this.c / this.b);
156
153
  }
157
- return new DPoint_1.DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
154
+ return new DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
158
155
  }
159
156
  findPoint(l) {
160
157
  if (this.isParallelY && l.isParallelY) {
@@ -164,28 +161,28 @@ class DLine {
164
161
  return null;
165
162
  }
166
163
  if (this.isParallelX && l.isParallelY) {
167
- return new DPoint_1.DPoint(-l.c / l.a, -this.c / this.b);
164
+ return new DPoint(-l.c / l.a, -this.c / this.b);
168
165
  }
169
166
  if (this.isParallelY && l.isParallelX) {
170
- return new DPoint_1.DPoint(-this.c / this.a, -l.c / l.b);
167
+ return new DPoint(-this.c / this.a, -l.c / l.b);
171
168
  }
172
169
  if (this.isParallelY) {
173
170
  const x = -this.c / this.a;
174
- return l.y(new DPoint_1.DPoint(x));
171
+ return l.y(new DPoint(x));
175
172
  }
176
173
  if (this.isParallelX) {
177
174
  const y = -this.c / this.b;
178
- return l.x(new DPoint_1.DPoint(0, y));
175
+ return l.x(new DPoint(0, y));
179
176
  }
180
177
  if (l.isParallelY) {
181
178
  const x = -l.c / l.a;
182
- return this.y(new DPoint_1.DPoint(x));
179
+ return this.y(new DPoint(x));
183
180
  }
184
181
  if (l.isParallelX) {
185
182
  const y = -l.c / l.b;
186
- return this.x(new DPoint_1.DPoint(0, y));
183
+ return this.x(new DPoint(0, y));
187
184
  }
188
- const res = this.y(new DPoint_1.DPoint((l.c / l.b - this.c / this.b) / (this.a / this.b - l.a / l.b)));
185
+ const res = this.y(new DPoint((l.c / l.b - this.c / this.b) / (this.a / this.b - l.a / l.b)));
189
186
  if (!isFinite(res.x) && !isFinite(res.y)) {
190
187
  return null;
191
188
  }
@@ -204,7 +201,7 @@ class DLine {
204
201
  return [this.begin, this.end];
205
202
  }
206
203
  getFi() {
207
- (0, utils_1.checkFunction)('getFi')
204
+ checkFunction('getFi')
208
205
  .checkArgument('this.begin')
209
206
  .shouldBeMeters(this.begin)
210
207
  .checkArgument('this.end')
@@ -222,12 +219,12 @@ class DLine {
222
219
  }
223
220
  movePoint(p, d) {
224
221
  const fi = this.findFi(new DLine(1, 0, 0));
225
- const td = this.x(new DPoint_1.DPoint(1, 1)).distance(this.x(new DPoint_1.DPoint(2, 2))) / 2;
226
- const sinCos = new DPoint_1.DPoint(Math.sin(fi), Math.cos(fi));
222
+ const td = this.x(new DPoint(1, 1)).distance(this.x(new DPoint(2, 2))) / 2;
223
+ const sinCos = new DPoint(Math.sin(fi), Math.cos(fi));
227
224
  const dt = sinCos.clone().scale(td);
228
225
  const p1T = p.clone().move(dt.clone().minus());
229
226
  const p2T = p.clone().move(dt);
230
- if (DNumbers_1.DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers_1.DNumbers.like(this.y(p2T).y, p2T.y)) {
227
+ if (DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers.like(this.y(p2T).y, p2T.y)) {
231
228
  return p.clone().move(sinCos.scale(d));
232
229
  }
233
230
  return p.clone().move(sinCos.scale(d).setX(({ x }) => -x));
@@ -248,4 +245,3 @@ class DLine {
248
245
  return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
249
246
  }
250
247
  }
251
- exports.DLine = DLine;
@@ -0,0 +1,22 @@
1
+ import { DEGREE_TO_PI, DOUBLE_PI_IN_DEGREE, PI_IN_DEGREE, PI_TO_DEGREE } from './DPoint';
2
+ const delta = 0.001;
3
+ export class DNumbers {
4
+ static like(v, s, d = delta) {
5
+ return Math.abs(v - s) < d;
6
+ }
7
+ static likeZero(v) {
8
+ return DNumbers.like(v, 0);
9
+ }
10
+ static like2PI(v) {
11
+ return DNumbers.like(DNumbers.rad2Deg(v), DOUBLE_PI_IN_DEGREE);
12
+ }
13
+ static likePI(v) {
14
+ return DNumbers.like(DNumbers.rad2Deg(v), PI_IN_DEGREE);
15
+ }
16
+ static rad2Deg(v) {
17
+ return v * DEGREE_TO_PI;
18
+ }
19
+ static deg2Rad(v) {
20
+ return v * PI_TO_DEGREE;
21
+ }
22
+ }