dgeoutils 2.2.24 → 2.3.0

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 (49) hide show
  1. package/dist/{DCircle.d.ts → cjs/DCircle.d.ts} +0 -0
  2. package/dist/cjs/DCircle.js +102 -0
  3. package/dist/{DLine.d.ts → cjs/DLine.d.ts} +0 -0
  4. package/dist/cjs/DLine.js +300 -0
  5. package/dist/{DNumbers.d.ts → cjs/DNumbers.d.ts} +0 -0
  6. package/dist/cjs/DNumbers.js +30 -0
  7. package/dist/{DPlane.d.ts → cjs/DPlane.d.ts} +0 -0
  8. package/dist/cjs/DPlane.js +132 -0
  9. package/dist/{DPoint.d.ts → cjs/DPoint.d.ts} +0 -0
  10. package/dist/cjs/DPoint.js +574 -0
  11. package/dist/{DPolygon.d.ts → cjs/DPolygon.d.ts} +0 -0
  12. package/dist/cjs/DPolygon.js +1555 -0
  13. package/dist/{DPolygonLoop.d.ts → cjs/DPolygonLoop.d.ts} +0 -0
  14. package/dist/cjs/DPolygonLoop.js +401 -0
  15. package/dist/{FastSearch.d.ts → cjs/FastSearch.d.ts} +0 -0
  16. package/dist/cjs/FastSearch.js +53 -0
  17. package/dist/{TraceMatrix.d.ts → cjs/TraceMatrix.d.ts} +0 -0
  18. package/dist/cjs/TraceMatrix.js +256 -0
  19. package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  20. package/dist/{index.js → cjs/index.js} +0 -0
  21. package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
  22. package/dist/cjs/utils.js +191 -0
  23. package/dist/{DCircle.js → es2015/DCircle.js} +14 -18
  24. package/dist/{DLine.js → es2015/DLine.js} +24 -28
  25. package/dist/es2015/DNumbers.js +22 -0
  26. package/dist/{DPlane.js → es2015/DPlane.js} +22 -26
  27. package/dist/{DPoint.js → es2015/DPoint.js} +52 -56
  28. package/dist/{DPolygon.js → es2015/DPolygon.js} +41 -45
  29. package/dist/{DPolygonLoop.js → es2015/DPolygonLoop.js} +1 -5
  30. package/dist/{FastSearch.js → es2015/FastSearch.js} +1 -5
  31. package/dist/{TraceMatrix.js → es2015/TraceMatrix.js} +35 -39
  32. package/dist/es2015/index.js +13 -0
  33. package/dist/{utils.js → es2015/utils.js} +26 -36
  34. package/dist/esm/DCircle.js +99 -0
  35. package/dist/esm/DLine.js +297 -0
  36. package/dist/esm/DNumbers.js +27 -0
  37. package/dist/esm/DPlane.js +129 -0
  38. package/dist/esm/DPoint.js +571 -0
  39. package/dist/esm/DPolygon.js +1552 -0
  40. package/dist/esm/DPolygonLoop.js +398 -0
  41. package/dist/esm/FastSearch.js +50 -0
  42. package/dist/esm/TraceMatrix.js +253 -0
  43. package/dist/esm/index.js +13 -0
  44. package/dist/esm/utils.js +181 -0
  45. package/dist/umd/dgeoutils.js +3569 -0
  46. package/dist/umd/dgeoutils.min.js +1 -0
  47. package/dist/umd/dgeoutils.min.js.map +1 -0
  48. package/package.json +17 -10
  49. package/dist/DNumbers.js +0 -26
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TraceMatrix = exports.TraceMatrixValues = void 0;
4
- const DPoint_1 = require("./DPoint");
5
- const DPolygon_1 = require("./DPolygon");
6
- const FastSearch_1 = require("./FastSearch");
7
- const utils_1 = require("./utils");
8
- var TraceMatrixValues;
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;
9
6
  (function (TraceMatrixValues) {
10
7
  TraceMatrixValues[TraceMatrixValues["f"] = 0] = "f";
11
8
  TraceMatrixValues[TraceMatrixValues["t"] = 1] = "t";
12
- })(TraceMatrixValues = exports.TraceMatrixValues || (exports.TraceMatrixValues = {}));
9
+ })(TraceMatrixValues || (TraceMatrixValues = {}));
13
10
  const getByPosition = (m, p, defaultValue = TraceMatrixValues.f) => {
14
11
  if (m[p.y] === undefined || m[p.y][p.x] === undefined) {
15
12
  return defaultValue;
@@ -23,11 +20,11 @@ const setByPosition = (m, p, value) => {
23
20
  m[p.y][p.x] = value;
24
21
  return m[p.y][p.x];
25
22
  };
26
- class TraceMatrix {
23
+ export class TraceMatrix {
27
24
  constructor(size, f) {
28
25
  this.size = size;
29
26
  this.findGroupByIndex = (m, s) => {
30
- const res = new DPolygon_1.DPolygon();
27
+ const res = new DPolygon();
31
28
  if (s && getByPosition(m, s) === TraceMatrixValues.t) {
32
29
  res.push(s);
33
30
  let startIndex = 0;
@@ -37,7 +34,7 @@ class TraceMatrix {
37
34
  const r = res.at(startIndex);
38
35
  for (let i = -1; i < 2; i++) {
39
36
  for (let j = -1; j < 2; j++) {
40
- const t = new DPoint_1.DPoint(r.x + i, r.y + j);
37
+ const t = new DPoint(r.x + i, r.y + j);
41
38
  if (getByPosition(marked, t, TraceMatrixValues.t) === TraceMatrixValues.f &&
42
39
  getByPosition(m, t, TraceMatrixValues.f) === TraceMatrixValues.t) {
43
40
  res.push(t);
@@ -59,7 +56,7 @@ class TraceMatrix {
59
56
  const groups = [group];
60
57
  let groupSum = group.length;
61
58
  let allGroups = [...group.points];
62
- const fs = new FastSearch_1.FastSearch();
59
+ const fs = new FastSearch();
63
60
  fs.add(allGroups);
64
61
  while (groupSum < this.totalCountInMatrix(m)) {
65
62
  let mark = this.findMarked(m);
@@ -76,22 +73,22 @@ class TraceMatrix {
76
73
  };
77
74
  this.traceGroup = (m, group) => {
78
75
  const traceDirections = [
79
- new DPoint_1.DPoint(-1, -1),
80
- new DPoint_1.DPoint(-1, 0),
81
- new DPoint_1.DPoint(-1, 1),
82
- new DPoint_1.DPoint(0, 1),
83
- new DPoint_1.DPoint(1, 1),
84
- new DPoint_1.DPoint(1, 0),
85
- new DPoint_1.DPoint(1, -1),
86
- new DPoint_1.DPoint(0, -1)
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)
87
84
  ];
88
85
  const left = (d) => (d + traceDirections.length + 1) % traceDirections.length;
89
86
  const right = (d) => (d + traceDirections.length - 1) % traceDirections.length;
90
87
  if (group.length < 2) {
91
88
  const t = group.at(0).clone();
92
- return new DPolygon_1.DPolygon([t, t, t]);
89
+ return new DPolygon([t, t, t]);
93
90
  }
94
- const points = new DPolygon_1.DPolygon();
91
+ const points = new DPolygon();
95
92
  let direction = 0;
96
93
  let prevDirection = Infinity;
97
94
  let p = group.at(0);
@@ -115,22 +112,22 @@ class TraceMatrix {
115
112
  };
116
113
  this.createHoleMatrix = (group) => {
117
114
  const fullTraceDirections = [
118
- new DPoint_1.DPoint(-1, 0),
119
- new DPoint_1.DPoint(0, 1),
120
- new DPoint_1.DPoint(1, 0),
121
- new DPoint_1.DPoint(0, -1)
115
+ new DPoint(-1, 0),
116
+ new DPoint(0, 1),
117
+ new DPoint(1, 0),
118
+ new DPoint(0, -1)
122
119
  ];
123
120
  group.prepareToFastSearch();
124
121
  const tmpMatrix = TraceMatrix
125
122
  .createMatrix(this.size, (p) => group.fastHas(p) ? TraceMatrixValues.t : TraceMatrixValues.f);
126
- const startCoords = new DPolygon_1.DPolygon();
123
+ const startCoords = new DPolygon();
127
124
  for (let i = 0; i < this.size.w; i++) {
128
- startCoords.push(new DPoint_1.DPoint(i, -1));
129
- startCoords.push(new DPoint_1.DPoint(i, this.size.h));
125
+ startCoords.push(new DPoint(i, -1));
126
+ startCoords.push(new DPoint(i, this.size.h));
130
127
  }
131
128
  for (let i = 0; i < this.size.h; i++) {
132
- startCoords.push(new DPoint_1.DPoint(-1, i));
133
- startCoords.push(new DPoint_1.DPoint(this.size.w, i));
129
+ startCoords.push(new DPoint(-1, i));
130
+ startCoords.push(new DPoint(this.size.w, i));
134
131
  }
135
132
  while (startCoords.length) {
136
133
  const point = startCoords.pop();
@@ -154,7 +151,7 @@ class TraceMatrix {
154
151
  const holeMatrixs = groups.map(this.createHoleMatrix);
155
152
  const holesGroups = holeMatrixs.map((m) => m && this.findAllGroupsInMatrix(m));
156
153
  const holesPaths = holesGroups.map((hg, index) => hg && hg.map((g) => this
157
- .traceGroup(holeMatrixs[index], g)).filter((r) => r.length > DPolygon_1.MIN_POINTS_IN_VALID_POLYGON));
154
+ .traceGroup(holeMatrixs[index], g)).filter((r) => r.length > MIN_POINTS_IN_VALID_POLYGON));
158
155
  return groups.map((g, index) => {
159
156
  const res = paths[index];
160
157
  if (holesGroups[index] && holesGroups[index].length) {
@@ -177,8 +174,8 @@ class TraceMatrix {
177
174
  ini = true;
178
175
  continue;
179
176
  }
180
- if (getByPosition(m, new DPoint_1.DPoint(i, j)) === TraceMatrixValues.t) {
181
- return new DPoint_1.DPoint(i, j);
177
+ if (getByPosition(m, new DPoint(i, j)) === TraceMatrixValues.t) {
178
+ return new DPoint(i, j);
182
179
  }
183
180
  }
184
181
  }
@@ -189,7 +186,7 @@ class TraceMatrix {
189
186
  const s = this.size;
190
187
  for (let i = 0; i < s.w; i++) {
191
188
  for (let j = 0; j < s.h; j++) {
192
- if (getByPosition(m, new DPoint_1.DPoint(i, j))) {
189
+ if (getByPosition(m, new DPoint(i, j))) {
193
190
  res++;
194
191
  }
195
192
  }
@@ -197,8 +194,7 @@ class TraceMatrix {
197
194
  return res;
198
195
  }
199
196
  static createMatrix(size, f = () => TraceMatrixValues.f) {
200
- return (0, utils_1.createArray)(size.h)
201
- .map((v, i) => (0, utils_1.createArray)(size.w).map((v2, j) => f(new DPoint_1.DPoint(j, i))));
197
+ return createArray(size.h)
198
+ .map((v, i) => createArray(size.w).map((v2, j) => f(new DPoint(j, i))));
202
199
  }
203
200
  }
204
- exports.TraceMatrix = TraceMatrix;
@@ -0,0 +1,13 @@
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 './DPolygonLoop';
9
+ export * from './DPlane';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull } from './utils';
11
+ export const DGeo = {
12
+ DEBUG: false
13
+ };
@@ -1,58 +1,53 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = void 0;
4
- const index_1 = require("./index");
5
- const DPoint_1 = require("./DPoint");
6
- const warn = (...args) => {
7
- if (index_1.DGeo.DEBUG) {
1
+ import { DGeo } from './index';
2
+ import { DPoint } from './DPoint';
3
+ export const warn = (...args) => {
4
+ if (DGeo.DEBUG) {
8
5
  console.warn(...args);
9
6
  }
10
7
  };
11
- exports.warn = warn;
12
- const isDefAndNotNull = (a) => a != undefined;
13
- exports.isDefAndNotNull = isDefAndNotNull;
8
+ export const isDefAndNotNull = (a) => a != undefined;
14
9
  const hook = (scope) => () => scope;
15
10
  const shouldBeInt = (scope, funcName, argName) => (p) => {
16
11
  if (!p.clone().round()
17
12
  .equal(p)) {
18
- (0, exports.warn)(`"${funcName}" -> "${argName}" should be Int!`);
13
+ warn(`"${funcName}" -> "${argName}" should be Int!`);
19
14
  }
20
15
  return scope;
21
16
  };
22
17
  const shouldBeUInt = (scope, funcName, argName) => (p) => {
23
18
  if (!p.clone().round()
24
- .equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
25
- (0, exports.warn)(`"${funcName}" -> "${argName}" should be UInt!`);
19
+ .equal(p) || !p.gtOrEqual(DPoint.zero())) {
20
+ warn(`"${funcName}" -> "${argName}" should be UInt!`);
26
21
  }
27
22
  return scope;
28
23
  };
29
24
  const shouldBeDegree = (scope, funcName, argName) => (p) => {
30
25
  if (!p.likeWorldGeodeticSystem) {
31
- (0, exports.warn)(`"${funcName}" -> "${argName}" should be degree!`);
26
+ warn(`"${funcName}" -> "${argName}" should be degree!`);
32
27
  }
33
28
  return scope;
34
29
  };
35
30
  const shouldBeRadians = (scope, funcName, argName) => (p) => {
36
31
  if (!p.likeRadians) {
37
- (0, exports.warn)(`"${funcName}" -> "${argName}" should be radians!`);
32
+ warn(`"${funcName}" -> "${argName}" should be radians!`);
38
33
  }
39
34
  return scope;
40
35
  };
41
36
  const shouldExist = (scope, funcName, argName) => (p) => {
42
- if (!(0, exports.isDefAndNotNull)(p)) {
43
- (0, exports.warn)(`"${funcName}" -> "${argName}" should exist!`);
37
+ if (!isDefAndNotNull(p)) {
38
+ warn(`"${funcName}" -> "${argName}" should exist!`);
44
39
  }
45
40
  return scope;
46
41
  };
47
42
  const shouldBeMeters = (scope, funcName, argName) => (p) => {
48
43
  if (!p.likePseudoMercator) {
49
- (0, exports.warn)(`"${funcName}" -> "${argName}" should be meters!`);
44
+ warn(`"${funcName}" -> "${argName}" should be meters!`);
50
45
  }
51
46
  return scope;
52
47
  };
53
- const checkFunction = (funcName) => ({
48
+ export const checkFunction = (funcName) => ({
54
49
  checkArgument: function (argName) {
55
- if (!index_1.DGeo.DEBUG) {
50
+ if (!DGeo.DEBUG) {
56
51
  return {
57
52
  shouldBeDegree: hook(this),
58
53
  shouldBeMeters: hook(this),
@@ -72,18 +67,15 @@ const checkFunction = (funcName) => ({
72
67
  };
73
68
  }
74
69
  });
75
- exports.checkFunction = checkFunction;
76
- const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
77
- exports.createArray = createArray;
78
- const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
79
- .map(() => (0, exports.createArray)(w, fillSymbol));
80
- exports.createMatrix = createMatrix;
81
- const gaussianElimination = (matrix) => {
70
+ export const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
71
+ export const createMatrix = ({ h, w }, fillSymbol = 0) => createArray(h)
72
+ .map(() => createArray(w, fillSymbol));
73
+ export const gaussianElimination = (matrix) => {
82
74
  const n = matrix.length;
83
- const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
75
+ const matrixClone = createMatrix(new DPoint(n + 1, n));
84
76
  for (let i = 0; i < n; i++) {
85
77
  for (let j = 0; j < n + 1; j++) {
86
- matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
78
+ matrix[i][j] = matrix[i][j] === 0 ? gaussianElimination.MIN : matrix[i][j];
87
79
  matrixClone[i][j] = matrix[i][j];
88
80
  }
89
81
  }
@@ -114,20 +106,19 @@ const gaussianElimination = (matrix) => {
114
106
  }
115
107
  }
116
108
  }
117
- const answer = (0, exports.createArray)(n);
109
+ const answer = createArray(n);
118
110
  for (let i = 0; i < n; i++) {
119
111
  answer[i] = matrixClone[i][n];
120
112
  }
121
113
  return answer;
122
114
  };
123
- exports.gaussianElimination = gaussianElimination;
124
- exports.gaussianElimination.MIN = 1e-10;
125
- const createCanvas = (a, b, c) => {
115
+ gaussianElimination.MIN = 1e-10;
116
+ export const createCanvas = (a, b, c) => {
126
117
  var _a;
127
118
  let w = 0;
128
119
  let h = 0;
129
120
  let offscreen = false;
130
- if (a instanceof DPoint_1.DPoint) {
121
+ if (a instanceof DPoint) {
131
122
  const { x, y } = a;
132
123
  w = x;
133
124
  h = y;
@@ -145,11 +136,10 @@ const createCanvas = (a, b, c) => {
145
136
  if (typeof c === 'boolean') {
146
137
  offscreen = c;
147
138
  }
148
- const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
139
+ const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
149
140
  if (!offscreen) {
150
141
  canvas.width = w;
151
142
  canvas.height = h;
152
143
  }
153
144
  return [canvas, canvas.getContext('2d')];
154
145
  };
155
- exports.createCanvas = createCanvas;
@@ -0,0 +1,99 @@
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 "(" + this.center.toString() + ", " + 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 };