dgeoutils 2.3.7 → 2.4.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.
- package/dist/{cjs/DCircle.d.ts → DCircle.d.ts} +0 -0
- package/dist/{es2015/DCircle.js → DCircle.js} +18 -14
- package/dist/{cjs/DLine.d.ts → DLine.d.ts} +0 -0
- package/dist/{es2015/DLine.js → DLine.js} +28 -24
- package/dist/{cjs/DNumbers.d.ts → DNumbers.d.ts} +0 -0
- package/dist/DNumbers.js +26 -0
- package/dist/{cjs/DPlane.d.ts → DPlane.d.ts} +0 -0
- package/dist/{es2015/DPlane.js → DPlane.js} +26 -22
- package/dist/{cjs/DPoint.d.ts → DPoint.d.ts} +0 -0
- package/dist/{es2015/DPoint.js → DPoint.js} +56 -52
- package/dist/{cjs/DPolygon.d.ts → DPolygon.d.ts} +1 -1
- package/dist/{es2015/DPolygon.js → DPolygon.js} +50 -42
- package/dist/{cjs/DPolygonLoop.d.ts → DPolygonLoop.d.ts} +0 -0
- package/dist/{es2015/DPolygonLoop.js → DPolygonLoop.js} +5 -1
- package/dist/{cjs/FastSearch.d.ts → FastSearch.d.ts} +0 -0
- package/dist/{es2015/FastSearch.js → FastSearch.js} +5 -1
- package/dist/{cjs/TraceMatrix.d.ts → TraceMatrix.d.ts} +0 -0
- package/dist/{es2015/TraceMatrix.js → TraceMatrix.js} +39 -35
- package/dist/esm/DPolygon.js +6 -1
- package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- package/dist/{cjs/index.js → index.js} +0 -0
- package/dist/umd/dgeoutils.js +7 -2
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
- package/dist/{es2015/utils.js → utils.js} +41 -29
- package/package.json +5 -6
- package/dist/cjs/DCircle.js +0 -102
- package/dist/cjs/DLine.js +0 -310
- package/dist/cjs/DNumbers.js +0 -30
- package/dist/cjs/DPlane.js +0 -132
- package/dist/cjs/DPoint.js +0 -574
- package/dist/cjs/DPolygon.js +0 -1555
- package/dist/cjs/DPolygonLoop.js +0 -401
- package/dist/cjs/FastSearch.js +0 -53
- package/dist/cjs/TraceMatrix.js +0 -256
- package/dist/cjs/utils.js +0 -216
- package/dist/es2015/DNumbers.js +0 -22
- package/dist/es2015/index.js +0 -10
|
@@ -1,55 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
exports.DGeo = {
|
|
3
6
|
DEBUG: false
|
|
4
7
|
};
|
|
5
|
-
|
|
6
|
-
if (DGeo.DEBUG) {
|
|
8
|
+
const warn = (...args) => {
|
|
9
|
+
if (exports.DGeo.DEBUG) {
|
|
7
10
|
console.warn(...args);
|
|
8
11
|
}
|
|
9
12
|
};
|
|
10
|
-
|
|
13
|
+
exports.warn = warn;
|
|
14
|
+
const isDefAndNotNull = (a) => a != undefined;
|
|
15
|
+
exports.isDefAndNotNull = isDefAndNotNull;
|
|
11
16
|
const hook = (scope) => () => scope;
|
|
12
17
|
const shouldBeInt = (scope, funcName, argName) => (p) => {
|
|
13
18
|
if (!p.clone().round()
|
|
14
19
|
.equal(p)) {
|
|
15
|
-
warn(`"${funcName}" -> "${argName}" should be Int!`);
|
|
20
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be Int!`);
|
|
16
21
|
}
|
|
17
22
|
return scope;
|
|
18
23
|
};
|
|
19
24
|
const shouldBeUInt = (scope, funcName, argName) => (p) => {
|
|
20
25
|
if (!p.clone().round()
|
|
21
|
-
.equal(p) || !p.gtOrEqual(DPoint.zero())) {
|
|
22
|
-
warn(`"${funcName}" -> "${argName}" should be UInt!`);
|
|
26
|
+
.equal(p) || !p.gtOrEqual(DPoint_1.DPoint.zero())) {
|
|
27
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be UInt!`);
|
|
23
28
|
}
|
|
24
29
|
return scope;
|
|
25
30
|
};
|
|
26
31
|
const shouldBeDegree = (scope, funcName, argName) => (p) => {
|
|
27
32
|
if (!p.likeWorldGeodeticSystem) {
|
|
28
|
-
warn(`"${funcName}" -> "${argName}" should be degree!`);
|
|
33
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be degree!`);
|
|
29
34
|
}
|
|
30
35
|
return scope;
|
|
31
36
|
};
|
|
32
37
|
const shouldBeRadians = (scope, funcName, argName) => (p) => {
|
|
33
38
|
if (!p.likeRadians) {
|
|
34
|
-
warn(`"${funcName}" -> "${argName}" should be radians!`);
|
|
39
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be radians!`);
|
|
35
40
|
}
|
|
36
41
|
return scope;
|
|
37
42
|
};
|
|
38
43
|
const shouldExist = (scope, funcName, argName) => (p) => {
|
|
39
|
-
if (!isDefAndNotNull(p)) {
|
|
40
|
-
warn(`"${funcName}" -> "${argName}" should exist!`);
|
|
44
|
+
if (!(0, exports.isDefAndNotNull)(p)) {
|
|
45
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should exist!`);
|
|
41
46
|
}
|
|
42
47
|
return scope;
|
|
43
48
|
};
|
|
44
49
|
const shouldBeMeters = (scope, funcName, argName) => (p) => {
|
|
45
50
|
if (!p.likePseudoMercator) {
|
|
46
|
-
warn(`"${funcName}" -> "${argName}" should be meters!`);
|
|
51
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should be meters!`);
|
|
47
52
|
}
|
|
48
53
|
return scope;
|
|
49
54
|
};
|
|
50
|
-
|
|
55
|
+
const checkFunction = (funcName) => ({
|
|
51
56
|
checkArgument: function (argName) {
|
|
52
|
-
if (!DGeo.DEBUG) {
|
|
57
|
+
if (!exports.DGeo.DEBUG) {
|
|
53
58
|
return {
|
|
54
59
|
shouldBeDegree: hook(this),
|
|
55
60
|
shouldBeMeters: hook(this),
|
|
@@ -69,15 +74,18 @@ export const checkFunction = (funcName) => ({
|
|
|
69
74
|
};
|
|
70
75
|
}
|
|
71
76
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
exports.checkFunction = checkFunction;
|
|
78
|
+
const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
|
|
79
|
+
exports.createArray = createArray;
|
|
80
|
+
const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
|
|
81
|
+
.map(() => (0, exports.createArray)(w, fillSymbol));
|
|
82
|
+
exports.createMatrix = createMatrix;
|
|
83
|
+
const gaussianElimination = (matrix) => {
|
|
76
84
|
const n = matrix.length;
|
|
77
|
-
const matrixClone = createMatrix(new DPoint(n + 1, n));
|
|
85
|
+
const matrixClone = (0, exports.createMatrix)(new DPoint_1.DPoint(n + 1, n));
|
|
78
86
|
for (let i = 0; i < n; i++) {
|
|
79
87
|
for (let j = 0; j < n + 1; j++) {
|
|
80
|
-
matrix[i][j] = matrix[i][j] === 0 ? gaussianElimination.MIN : matrix[i][j];
|
|
88
|
+
matrix[i][j] = matrix[i][j] === 0 ? exports.gaussianElimination.MIN : matrix[i][j];
|
|
81
89
|
matrixClone[i][j] = matrix[i][j];
|
|
82
90
|
}
|
|
83
91
|
}
|
|
@@ -108,19 +116,20 @@ export const gaussianElimination = (matrix) => {
|
|
|
108
116
|
}
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
|
-
const answer = createArray(n);
|
|
119
|
+
const answer = (0, exports.createArray)(n);
|
|
112
120
|
for (let i = 0; i < n; i++) {
|
|
113
121
|
answer[i] = matrixClone[i][n];
|
|
114
122
|
}
|
|
115
123
|
return answer;
|
|
116
124
|
};
|
|
117
|
-
gaussianElimination
|
|
118
|
-
|
|
125
|
+
exports.gaussianElimination = gaussianElimination;
|
|
126
|
+
exports.gaussianElimination.MIN = 1e-10;
|
|
127
|
+
const createCanvas = (a, b, c) => {
|
|
119
128
|
var _a;
|
|
120
129
|
let w = 0;
|
|
121
130
|
let h = 0;
|
|
122
131
|
let offscreen = false;
|
|
123
|
-
if (a instanceof DPoint) {
|
|
132
|
+
if (a instanceof DPoint_1.DPoint) {
|
|
124
133
|
const { x, y } = a;
|
|
125
134
|
w = x;
|
|
126
135
|
h = y;
|
|
@@ -138,21 +147,23 @@ export const createCanvas = (a, b, c) => {
|
|
|
138
147
|
if (typeof c === 'boolean') {
|
|
139
148
|
offscreen = c;
|
|
140
149
|
}
|
|
141
|
-
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
150
|
+
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = exports.createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
142
151
|
if (!offscreen) {
|
|
143
152
|
canvas.width = w;
|
|
144
153
|
canvas.height = h;
|
|
145
154
|
}
|
|
146
155
|
return [canvas, canvas.getContext('2d')];
|
|
147
156
|
};
|
|
157
|
+
exports.createCanvas = createCanvas;
|
|
148
158
|
const f = (a, b) => [].concat(...a.map((c) => b.map((d) => [].concat(c, d))));
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
const cartesianProduct = (a, b, ...c) => b ? (0, exports.cartesianProduct)(f(a, b), ...c) : a;
|
|
160
|
+
exports.cartesianProduct = cartesianProduct;
|
|
161
|
+
const getCombinations = (arr) => {
|
|
151
162
|
if (arr.length === 1) {
|
|
152
163
|
return arr[0];
|
|
153
164
|
}
|
|
154
165
|
const ans = [];
|
|
155
|
-
const otherCases = getCombinations(arr.slice(1));
|
|
166
|
+
const otherCases = (0, exports.getCombinations)(arr.slice(1));
|
|
156
167
|
for (let i = 0; i < otherCases.length; i++) {
|
|
157
168
|
for (let j = 0; j < arr[0].length; j++) {
|
|
158
169
|
ans.push([arr[0][j], ...otherCases[i]]);
|
|
@@ -160,3 +171,4 @@ export const getCombinations = (arr) => {
|
|
|
160
171
|
}
|
|
161
172
|
return ans;
|
|
162
173
|
};
|
|
174
|
+
exports.getCombinations = getCombinations;
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dgeoutils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "Geometries utils for my projects",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "npm run build:
|
|
7
|
-
"build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015",
|
|
6
|
+
"build": "npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
|
|
8
7
|
"build:esm": "tsc --module es2015 --target es5 --downlevelIteration --outDir dist/esm",
|
|
9
|
-
"build:cjs": "tsc
|
|
8
|
+
"build:cjs": "tsc",
|
|
10
9
|
"build:umd": "rollup dist/esm/index.js --format umd -e \"jsts\" -g \"jsts:jsts\" --name \"DGeoUtils\" -m inline --file dist/umd/dgeoutils.js",
|
|
11
10
|
"build:umd:min": "cd dist/umd && uglifyjs --compress --mangle --source-map --comments -o dgeoutils.min.js -- dgeoutils.js",
|
|
12
11
|
"prepublishOnly": "npm run lint:report && npm run test && npm run test:badges && npm run doc && npm run build",
|
|
@@ -21,8 +20,8 @@
|
|
|
21
20
|
},
|
|
22
21
|
"author": "Efim Dejin <efim@dej.in.ua>",
|
|
23
22
|
"license": "MIT",
|
|
24
|
-
"main": "dist/
|
|
25
|
-
"types": "dist/
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
26
25
|
"files": [
|
|
27
26
|
"/dist"
|
|
28
27
|
],
|
package/dist/cjs/DCircle.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DCircle = void 0;
|
|
4
|
-
var DPoint_1 = require("./DPoint");
|
|
5
|
-
var DPolygon_1 = require("./DPolygon");
|
|
6
|
-
var utils_1 = require("./utils");
|
|
7
|
-
var DCircle = (function () {
|
|
8
|
-
function DCircle(center, r) {
|
|
9
|
-
if (center === void 0) { center = DPoint_1.DPoint.zero(); }
|
|
10
|
-
if (r === void 0) { r = 0; }
|
|
11
|
-
this.center = center;
|
|
12
|
-
this.r = r;
|
|
13
|
-
}
|
|
14
|
-
DCircle.prototype.toString = function () {
|
|
15
|
-
return "(" + this.center.toString() + ", " + this.r + ")";
|
|
16
|
-
};
|
|
17
|
-
DCircle.prototype.getValue = function () {
|
|
18
|
-
return { center: this.center, r: this.r };
|
|
19
|
-
};
|
|
20
|
-
DCircle.prototype.clone = function () {
|
|
21
|
-
return new DCircle(this.center, this.r);
|
|
22
|
-
};
|
|
23
|
-
DCircle.prototype.findPoints = function (c) {
|
|
24
|
-
if (this.equal(c)) {
|
|
25
|
-
return Infinity;
|
|
26
|
-
}
|
|
27
|
-
var _a = this, _b = _a.center, x0 = _b.x, y0 = _b.y, r0 = _a.r;
|
|
28
|
-
var _c = c.center, x1 = _c.x, y1 = _c.y, r1 = c.r;
|
|
29
|
-
var r02 = r0 * r0;
|
|
30
|
-
var d = this.center.distance(c.center);
|
|
31
|
-
var a = (r02 - r1 * r1 + d * d) / (2 * d);
|
|
32
|
-
var h = Math.sqrt(r02 - a * a);
|
|
33
|
-
var ad = a / d;
|
|
34
|
-
var dy = y1 - y0;
|
|
35
|
-
var dx = x1 - x0;
|
|
36
|
-
var hd = h / d;
|
|
37
|
-
var x2 = x0 + ad * (x1 - x0);
|
|
38
|
-
var y2 = y0 + ad * (y1 - y0);
|
|
39
|
-
var x31 = x2 + hd * dy;
|
|
40
|
-
var y31 = y2 - hd * dx;
|
|
41
|
-
var x32 = x2 - hd * dy;
|
|
42
|
-
var y32 = y2 + hd * dx;
|
|
43
|
-
var res = [];
|
|
44
|
-
if (!isNaN(x31) && !isNaN(y31)) {
|
|
45
|
-
res.push(new DPoint_1.DPoint(x31, y31));
|
|
46
|
-
}
|
|
47
|
-
if (!isNaN(x32) && !isNaN(y32) && !(x31 === x32 && y31 === y32)) {
|
|
48
|
-
res.push(new DPoint_1.DPoint(x32, y32));
|
|
49
|
-
}
|
|
50
|
-
return res;
|
|
51
|
-
};
|
|
52
|
-
DCircle.prototype.equal = function (_a) {
|
|
53
|
-
var center = _a.center, r = _a.r;
|
|
54
|
-
return this.center.equal(center) && this.r === r;
|
|
55
|
-
};
|
|
56
|
-
DCircle.prototype.findPolygonInside = function (pointCount, startAngle, stopAngle) {
|
|
57
|
-
if (pointCount === void 0) { pointCount = 64; }
|
|
58
|
-
if (startAngle === void 0) { startAngle = 0; }
|
|
59
|
-
if (stopAngle === void 0) { stopAngle = 2 * Math.PI; }
|
|
60
|
-
var step = 2 * Math.PI / pointCount;
|
|
61
|
-
var points = [];
|
|
62
|
-
var angle = startAngle;
|
|
63
|
-
while (angle < stopAngle - step) {
|
|
64
|
-
points.push(new DPoint_1.DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
|
|
65
|
-
.move(this.center));
|
|
66
|
-
angle += step;
|
|
67
|
-
}
|
|
68
|
-
var x = this.r * Math.cos(stopAngle) + this.center.x;
|
|
69
|
-
var y = this.r * Math.sin(stopAngle) + this.center.y;
|
|
70
|
-
points.push(new DPoint_1.DPoint(x, y));
|
|
71
|
-
return new DPolygon_1.DPolygon(points);
|
|
72
|
-
};
|
|
73
|
-
DCircle.prototype.findPolygonInsideOnSphere = function (pointCount, startAngle, stopAngle) {
|
|
74
|
-
if (pointCount === void 0) { pointCount = 64; }
|
|
75
|
-
if (startAngle === void 0) { startAngle = 0; }
|
|
76
|
-
if (stopAngle === void 0) { stopAngle = 2 * Math.PI; }
|
|
77
|
-
(0, utils_1.checkFunction)('findPolygonInsideOnSphere')
|
|
78
|
-
.checkArgument('center')
|
|
79
|
-
.shouldBeDegree(this.center);
|
|
80
|
-
var step = 2 * Math.PI / pointCount;
|
|
81
|
-
var points = [];
|
|
82
|
-
var angle = startAngle;
|
|
83
|
-
while (angle < stopAngle - step) {
|
|
84
|
-
points.push(this.sphereOffset(angle));
|
|
85
|
-
angle += step;
|
|
86
|
-
}
|
|
87
|
-
points.push(this.sphereOffset(stopAngle));
|
|
88
|
-
return new DPolygon_1.DPolygon(points);
|
|
89
|
-
};
|
|
90
|
-
DCircle.prototype.sphereOffset = function (bearing, earthRadius) {
|
|
91
|
-
if (earthRadius === void 0) { earthRadius = DPoint_1.EARTH_RADIUS_IN_METERS; }
|
|
92
|
-
var _a = this.center.clone().degreeToRadians(), lon1 = _a.x, lat1 = _a.y;
|
|
93
|
-
var dByR = this.r / earthRadius;
|
|
94
|
-
var lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
|
|
95
|
-
Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
|
|
96
|
-
var lon = lon1 +
|
|
97
|
-
Math.atan2(Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
|
|
98
|
-
return new DPoint_1.DPoint(lon, lat).radiansToDegrees();
|
|
99
|
-
};
|
|
100
|
-
return DCircle;
|
|
101
|
-
}());
|
|
102
|
-
exports.DCircle = DCircle;
|
package/dist/cjs/DLine.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DLine = void 0;
|
|
4
|
-
var DPoint_1 = require("./DPoint");
|
|
5
|
-
var utils_1 = require("./utils");
|
|
6
|
-
var DNumbers_1 = require("./DNumbers");
|
|
7
|
-
var DLine = (function () {
|
|
8
|
-
function DLine(a, b, c, begin, end) {
|
|
9
|
-
if (begin === void 0) { begin = DPoint_1.DPoint.zero(); }
|
|
10
|
-
if (end === void 0) { end = DPoint_1.DPoint.zero(); }
|
|
11
|
-
this.a = a;
|
|
12
|
-
this.b = b;
|
|
13
|
-
this.c = c;
|
|
14
|
-
this.begin = begin;
|
|
15
|
-
this.end = end;
|
|
16
|
-
}
|
|
17
|
-
DLine.prototype.clone = function () {
|
|
18
|
-
return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
|
|
19
|
-
};
|
|
20
|
-
DLine.prototype.findPerpendicular = function (p) {
|
|
21
|
-
(0, utils_1.checkFunction)('findPerpendicular')
|
|
22
|
-
.checkArgument('this.begin')
|
|
23
|
-
.shouldBeMeters(this.begin)
|
|
24
|
-
.checkArgument('this.end')
|
|
25
|
-
.shouldBeMeters(this.end)
|
|
26
|
-
.checkArgument('p')
|
|
27
|
-
.shouldBeMeters(p);
|
|
28
|
-
return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
|
|
29
|
-
};
|
|
30
|
-
DLine.prototype.perpendicularDistance = function (p) {
|
|
31
|
-
(0, utils_1.checkFunction)('perpendicularDistance')
|
|
32
|
-
.checkArgument('this.begin')
|
|
33
|
-
.shouldBeMeters(this.begin)
|
|
34
|
-
.checkArgument('this.end')
|
|
35
|
-
.shouldBeMeters(this.end)
|
|
36
|
-
.checkArgument('p')
|
|
37
|
-
.shouldBeMeters(p);
|
|
38
|
-
var perpendicularLine = this.findPerpendicular(p);
|
|
39
|
-
var targetPoint = perpendicularLine.findPoint(this);
|
|
40
|
-
return targetPoint.distance(p);
|
|
41
|
-
};
|
|
42
|
-
DLine.prototype.intersection = function (l, d, includeOnly) {
|
|
43
|
-
if (d === void 0) { d = 0; }
|
|
44
|
-
if (includeOnly === void 0) { includeOnly = false; }
|
|
45
|
-
var p = this.findPoint(l);
|
|
46
|
-
if (p) {
|
|
47
|
-
if (includeOnly) {
|
|
48
|
-
return this.insideRange(p, d) && l.insideRange(p, d) ? p : null;
|
|
49
|
-
}
|
|
50
|
-
return this.inRange(p, d) && l.inRange(p, d) ? p : null;
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
};
|
|
54
|
-
DLine.prototype.intersectionWithCircle = function (circle) {
|
|
55
|
-
var center = circle.center, r = circle.r;
|
|
56
|
-
var per = this.findPerpendicular(center);
|
|
57
|
-
var t = this.findPoint(per);
|
|
58
|
-
var distance = t.distance(center);
|
|
59
|
-
if (this.begin.equal(center)) {
|
|
60
|
-
distance = 0;
|
|
61
|
-
}
|
|
62
|
-
if (this.end.equal(center)) {
|
|
63
|
-
distance = 0;
|
|
64
|
-
}
|
|
65
|
-
if (distance < r) {
|
|
66
|
-
var _a = this, a = _a.a, b = _a.b, c = _a.c;
|
|
67
|
-
if (this.isParallel) {
|
|
68
|
-
var ct = center.distance(t);
|
|
69
|
-
var move = Math.sqrt(r * r - ct * ct);
|
|
70
|
-
if (this.isParallelY) {
|
|
71
|
-
t.x = this.begin.x;
|
|
72
|
-
var r1_1 = t.clone().move(0, -move);
|
|
73
|
-
var r2_1 = t.clone().move(0, move);
|
|
74
|
-
return [r1_1, r2_1];
|
|
75
|
-
}
|
|
76
|
-
if (this.isParallelX) {
|
|
77
|
-
t.y = this.begin.y;
|
|
78
|
-
var r1_2 = t.clone().move(move, 0);
|
|
79
|
-
var r2_2 = t.clone().move(-move, 0);
|
|
80
|
-
return [r1_2, r2_2];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (this.begin.like(center)) {
|
|
84
|
-
var p = this.begin.clone();
|
|
85
|
-
return [this.movePoint(p, r), this.movePoint(p, -r)];
|
|
86
|
-
}
|
|
87
|
-
if (this.end.like(center)) {
|
|
88
|
-
var p = this.end.clone();
|
|
89
|
-
return [this.movePoint(p, r), this.movePoint(p, -r)];
|
|
90
|
-
}
|
|
91
|
-
var s = a * a + b * b;
|
|
92
|
-
var d = r * r - c * c / s;
|
|
93
|
-
var mult = Math.sqrt(d / s);
|
|
94
|
-
var r1 = t.clone().move(b * mult, -a * mult);
|
|
95
|
-
var r2 = t.clone().move(-b * mult, a * mult);
|
|
96
|
-
return [r1, r2];
|
|
97
|
-
}
|
|
98
|
-
if (distance === r) {
|
|
99
|
-
return t;
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
102
|
-
};
|
|
103
|
-
DLine.prototype.inRange = function (p, d) {
|
|
104
|
-
if (d === void 0) { d = 0; }
|
|
105
|
-
var _a = this, minX = _a.minX, minY = _a.minY, maxX = _a.maxX, maxY = _a.maxY;
|
|
106
|
-
var x = p.x, y = p.y;
|
|
107
|
-
var isInX = x >= minX - d && x <= maxX + d;
|
|
108
|
-
var isInY = y >= minY - d && y <= maxY + d;
|
|
109
|
-
return isInX && isInY;
|
|
110
|
-
};
|
|
111
|
-
DLine.prototype.insideRange = function (p, d) {
|
|
112
|
-
if (d === void 0) { d = 0; }
|
|
113
|
-
var _a = this, begin = _a.begin, end = _a.end;
|
|
114
|
-
return this.inRange(p, d) && !begin.like(p, 0.00001) && !end.like(p, 0.00001);
|
|
115
|
-
};
|
|
116
|
-
Object.defineProperty(DLine.prototype, "center", {
|
|
117
|
-
get: function () {
|
|
118
|
-
return this.begin
|
|
119
|
-
.clone()
|
|
120
|
-
.setIfLessThan(this.end)
|
|
121
|
-
.move(this.end
|
|
122
|
-
.clone()
|
|
123
|
-
.move(this.begin
|
|
124
|
-
.clone()
|
|
125
|
-
.minus())
|
|
126
|
-
.abs()
|
|
127
|
-
.minus()
|
|
128
|
-
.divide(2));
|
|
129
|
-
},
|
|
130
|
-
enumerable: false,
|
|
131
|
-
configurable: true
|
|
132
|
-
});
|
|
133
|
-
Object.defineProperty(DLine.prototype, "minX", {
|
|
134
|
-
get: function () {
|
|
135
|
-
return Math.min(this.begin.x, this.end.x);
|
|
136
|
-
},
|
|
137
|
-
enumerable: false,
|
|
138
|
-
configurable: true
|
|
139
|
-
});
|
|
140
|
-
Object.defineProperty(DLine.prototype, "minY", {
|
|
141
|
-
get: function () {
|
|
142
|
-
return Math.min(this.begin.y, this.end.y);
|
|
143
|
-
},
|
|
144
|
-
enumerable: false,
|
|
145
|
-
configurable: true
|
|
146
|
-
});
|
|
147
|
-
Object.defineProperty(DLine.prototype, "maxX", {
|
|
148
|
-
get: function () {
|
|
149
|
-
return Math.max(this.begin.x, this.end.x);
|
|
150
|
-
},
|
|
151
|
-
enumerable: false,
|
|
152
|
-
configurable: true
|
|
153
|
-
});
|
|
154
|
-
Object.defineProperty(DLine.prototype, "maxY", {
|
|
155
|
-
get: function () {
|
|
156
|
-
return Math.max(this.begin.y, this.end.y);
|
|
157
|
-
},
|
|
158
|
-
enumerable: false,
|
|
159
|
-
configurable: true
|
|
160
|
-
});
|
|
161
|
-
DLine.prototype.toString = function () {
|
|
162
|
-
return "(" + this.a + ", " + this.b + ", " + this.c + ")";
|
|
163
|
-
};
|
|
164
|
-
DLine.prototype.getValue = function () {
|
|
165
|
-
return [this.a, this.b, this.c];
|
|
166
|
-
};
|
|
167
|
-
DLine.prototype.x = function (p) {
|
|
168
|
-
if (this.isParallelY) {
|
|
169
|
-
return new DPoint_1.DPoint(-this.c / this.a, p.y);
|
|
170
|
-
}
|
|
171
|
-
if (this.isParallelX) {
|
|
172
|
-
return new DPoint_1.DPoint(p.x, -this.c / this.b);
|
|
173
|
-
}
|
|
174
|
-
return new DPoint_1.DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
|
|
175
|
-
};
|
|
176
|
-
DLine.prototype.y = function (p) {
|
|
177
|
-
if (this.isParallelY) {
|
|
178
|
-
return new DPoint_1.DPoint(-this.c / this.a, p.y);
|
|
179
|
-
}
|
|
180
|
-
if (this.isParallelX) {
|
|
181
|
-
return new DPoint_1.DPoint(p.x, -this.c / this.b);
|
|
182
|
-
}
|
|
183
|
-
return new DPoint_1.DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
|
|
184
|
-
};
|
|
185
|
-
DLine.prototype.findPoint = function (l) {
|
|
186
|
-
if (this.isParallelY && l.isParallelY) {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
if (this.isParallelX && l.isParallelX) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
if (this.isParallelX && l.isParallelY) {
|
|
193
|
-
return new DPoint_1.DPoint(-l.c / l.a, -this.c / this.b);
|
|
194
|
-
}
|
|
195
|
-
if (this.isParallelY && l.isParallelX) {
|
|
196
|
-
return new DPoint_1.DPoint(-this.c / this.a, -l.c / l.b);
|
|
197
|
-
}
|
|
198
|
-
if (this.isParallelY) {
|
|
199
|
-
var x = -this.c / this.a;
|
|
200
|
-
return l.y(new DPoint_1.DPoint(x));
|
|
201
|
-
}
|
|
202
|
-
if (this.isParallelX) {
|
|
203
|
-
var y = -this.c / this.b;
|
|
204
|
-
return l.x(new DPoint_1.DPoint(0, y));
|
|
205
|
-
}
|
|
206
|
-
if (l.isParallelY) {
|
|
207
|
-
var x = -l.c / l.a;
|
|
208
|
-
return this.y(new DPoint_1.DPoint(x));
|
|
209
|
-
}
|
|
210
|
-
if (l.isParallelX) {
|
|
211
|
-
var y = -l.c / l.b;
|
|
212
|
-
return this.x(new DPoint_1.DPoint(0, y));
|
|
213
|
-
}
|
|
214
|
-
var res = this.y(new DPoint_1.DPoint((l.c / l.b - this.c / this.b) / (this.a / this.b - l.a / l.b)));
|
|
215
|
-
if (!isFinite(res.x) && !isFinite(res.y)) {
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
return res;
|
|
219
|
-
};
|
|
220
|
-
Object.defineProperty(DLine.prototype, "isParallel", {
|
|
221
|
-
get: function () {
|
|
222
|
-
return this.isParallelX || this.isParallelY;
|
|
223
|
-
},
|
|
224
|
-
enumerable: false,
|
|
225
|
-
configurable: true
|
|
226
|
-
});
|
|
227
|
-
Object.defineProperty(DLine.prototype, "isParallelY", {
|
|
228
|
-
get: function () {
|
|
229
|
-
return Math.abs(this.b) < 0.001;
|
|
230
|
-
},
|
|
231
|
-
enumerable: false,
|
|
232
|
-
configurable: true
|
|
233
|
-
});
|
|
234
|
-
Object.defineProperty(DLine.prototype, "isParallelX", {
|
|
235
|
-
get: function () {
|
|
236
|
-
return Math.abs(this.a) < 0.001;
|
|
237
|
-
},
|
|
238
|
-
enumerable: false,
|
|
239
|
-
configurable: true
|
|
240
|
-
});
|
|
241
|
-
Object.defineProperty(DLine.prototype, "points", {
|
|
242
|
-
get: function () {
|
|
243
|
-
return [this.begin, this.end];
|
|
244
|
-
},
|
|
245
|
-
enumerable: false,
|
|
246
|
-
configurable: true
|
|
247
|
-
});
|
|
248
|
-
DLine.prototype.getFi = function () {
|
|
249
|
-
(0, utils_1.checkFunction)('getFi')
|
|
250
|
-
.checkArgument('this.begin')
|
|
251
|
-
.shouldBeMeters(this.begin)
|
|
252
|
-
.checkArgument('this.end')
|
|
253
|
-
.shouldBeMeters(this.end);
|
|
254
|
-
var _a = this.end.clone().move(this.begin.clone().minus()), x = _a.x, y = _a.y;
|
|
255
|
-
var v = Math.atan2(y, x) - Math.PI;
|
|
256
|
-
if (v > 0) {
|
|
257
|
-
v = Math.PI - v;
|
|
258
|
-
}
|
|
259
|
-
return (Math.PI - v) % (Math.PI * 2);
|
|
260
|
-
};
|
|
261
|
-
DLine.prototype.toWKT = function () {
|
|
262
|
-
var _a = this, _b = _a.begin, x1 = _b.x, y1 = _b.y, _c = _a.end, x2 = _c.x, y2 = _c.y;
|
|
263
|
-
return "LINESTRING (" + x1 + " " + y1 + ", " + x2 + " " + y2 + ")";
|
|
264
|
-
};
|
|
265
|
-
DLine.prototype.movePoint = function (i, k) {
|
|
266
|
-
var isArray = Array.isArray(i);
|
|
267
|
-
var p = isArray ? i : [i];
|
|
268
|
-
var d = (isArray ? k : [k]);
|
|
269
|
-
var fi = this.findFi(new DLine(1, 0, 0));
|
|
270
|
-
var td = this.x(new DPoint_1.DPoint(1, 1)).distance(this.x(new DPoint_1.DPoint(2, 2))) / 2;
|
|
271
|
-
var sinCos = new DPoint_1.DPoint(Math.sin(fi), Math.cos(fi));
|
|
272
|
-
var dt = sinCos.clone().scale(td);
|
|
273
|
-
var p1T = p[0].clone().move(dt.clone().minus());
|
|
274
|
-
var p2T = p[0].clone().move(dt);
|
|
275
|
-
var res = [];
|
|
276
|
-
if (DNumbers_1.DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers_1.DNumbers.like(this.y(p2T).y, p2T.y)) {
|
|
277
|
-
res = p.map(function (t, index) { return t.clone()
|
|
278
|
-
.move(sinCos.clone().scale(d[index])); });
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
res = p.map(function (t, index) { return t.clone()
|
|
282
|
-
.move(sinCos.clone().scale(d[index])
|
|
283
|
-
.setX(function (_a) {
|
|
284
|
-
var x = _a.x;
|
|
285
|
-
return -x;
|
|
286
|
-
})); });
|
|
287
|
-
}
|
|
288
|
-
return isArray ? res : res[0];
|
|
289
|
-
};
|
|
290
|
-
DLine.prototype.findFi = function (_a, delta) {
|
|
291
|
-
var a = _a.a, b = _a.b;
|
|
292
|
-
if (delta === void 0) { delta = 1.0001; }
|
|
293
|
-
var _b = this, q = _b.a, w = _b.b;
|
|
294
|
-
var val = (q * a + w * b) / (Math.sqrt(q * q + w * w) * Math.sqrt(a * a + b * b));
|
|
295
|
-
if (val > 1 && val < delta) {
|
|
296
|
-
val = 1;
|
|
297
|
-
}
|
|
298
|
-
else if (val < -1 && val > -delta) {
|
|
299
|
-
val = -1;
|
|
300
|
-
}
|
|
301
|
-
return Math.acos(val);
|
|
302
|
-
};
|
|
303
|
-
DLine.prototype.vectorProduct = function (_a) {
|
|
304
|
-
var a = _a.a, b = _a.b, c = _a.c;
|
|
305
|
-
var _b = this, q = _b.a, w = _b.b, e = _b.c;
|
|
306
|
-
return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
|
|
307
|
-
};
|
|
308
|
-
return DLine;
|
|
309
|
-
}());
|
|
310
|
-
exports.DLine = DLine;
|
package/dist/cjs/DNumbers.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DNumbers = void 0;
|
|
4
|
-
var DPoint_1 = require("./DPoint");
|
|
5
|
-
var delta = 0.001;
|
|
6
|
-
var DNumbers = (function () {
|
|
7
|
-
function DNumbers() {
|
|
8
|
-
}
|
|
9
|
-
DNumbers.like = function (v, s, d) {
|
|
10
|
-
if (d === void 0) { d = delta; }
|
|
11
|
-
return Math.abs(v - s) < d;
|
|
12
|
-
};
|
|
13
|
-
DNumbers.likeZero = function (v) {
|
|
14
|
-
return DNumbers.like(v, 0);
|
|
15
|
-
};
|
|
16
|
-
DNumbers.like2PI = function (v) {
|
|
17
|
-
return DNumbers.like(DNumbers.rad2Deg(v), DPoint_1.DOUBLE_PI_IN_DEGREE);
|
|
18
|
-
};
|
|
19
|
-
DNumbers.likePI = function (v) {
|
|
20
|
-
return DNumbers.like(DNumbers.rad2Deg(v), DPoint_1.PI_IN_DEGREE);
|
|
21
|
-
};
|
|
22
|
-
DNumbers.rad2Deg = function (v) {
|
|
23
|
-
return v * DPoint_1.DEGREE_TO_PI;
|
|
24
|
-
};
|
|
25
|
-
DNumbers.deg2Rad = function (v) {
|
|
26
|
-
return v * DPoint_1.PI_TO_DEGREE;
|
|
27
|
-
};
|
|
28
|
-
return DNumbers;
|
|
29
|
-
}());
|
|
30
|
-
exports.DNumbers = DNumbers;
|