dgeoutils 2.4.0 → 2.4.1
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.js +52 -63
- package/dist/cjs/DLine.js +132 -181
- package/dist/cjs/DNumbers.js +16 -20
- package/dist/cjs/DPlane.js +56 -79
- package/dist/cjs/DPoint.js +240 -338
- package/dist/cjs/DPolygon.js +635 -1151
- package/dist/cjs/DPolygonLoop.js +138 -143
- package/dist/cjs/FastSearch.js +13 -37
- package/dist/cjs/TraceMatrix.js +87 -139
- package/dist/cjs/utils.js +61 -103
- package/package.json +2 -2
package/dist/cjs/DCircle.js
CHANGED
|
@@ -1,46 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DCircle = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (center === void 0) { center = DPoint_1.DPoint.zero(); }
|
|
10
|
-
if (r === void 0) { r = 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) {
|
|
11
9
|
this.center = center;
|
|
12
10
|
this.r = r;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
12
|
+
toString() {
|
|
13
|
+
return `(${this.center.toString()}, ${this.r})`;
|
|
14
|
+
}
|
|
15
|
+
getValue() {
|
|
18
16
|
return { center: this.center, r: this.r };
|
|
19
|
-
}
|
|
20
|
-
|
|
17
|
+
}
|
|
18
|
+
clone() {
|
|
21
19
|
return new DCircle(this.center, this.r);
|
|
22
|
-
}
|
|
23
|
-
|
|
20
|
+
}
|
|
21
|
+
findPoints(c) {
|
|
24
22
|
if (this.equal(c)) {
|
|
25
23
|
return Infinity;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
const { center: { x: x0, y: y0 }, r: r0 } = this;
|
|
26
|
+
const { center: { x: x1, y: y1 }, r: r1 } = c;
|
|
27
|
+
const r02 = r0 * r0;
|
|
28
|
+
const d = this.center.distance(c.center);
|
|
29
|
+
const a = (r02 - r1 * r1 + d * d) / (2 * d);
|
|
30
|
+
const h = Math.sqrt(r02 - a * a);
|
|
31
|
+
const ad = a / d;
|
|
32
|
+
const dy = y1 - y0;
|
|
33
|
+
const dx = x1 - x0;
|
|
34
|
+
const hd = h / d;
|
|
35
|
+
const x2 = x0 + ad * (x1 - x0);
|
|
36
|
+
const y2 = y0 + ad * (y1 - y0);
|
|
37
|
+
const x31 = x2 + hd * dy;
|
|
38
|
+
const y31 = y2 - hd * dx;
|
|
39
|
+
const x32 = x2 - hd * dy;
|
|
40
|
+
const y32 = y2 + hd * dx;
|
|
41
|
+
const res = [];
|
|
44
42
|
if (!isNaN(x31) && !isNaN(y31)) {
|
|
45
43
|
res.push(new DPoint_1.DPoint(x31, y31));
|
|
46
44
|
}
|
|
@@ -48,55 +46,46 @@ var DCircle = (function () {
|
|
|
48
46
|
res.push(new DPoint_1.DPoint(x32, y32));
|
|
49
47
|
}
|
|
50
48
|
return res;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var center = _a.center, r = _a.r;
|
|
49
|
+
}
|
|
50
|
+
equal({ center, r }) {
|
|
54
51
|
return this.center.equal(center) && this.r === r;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var step = 2 * Math.PI / pointCount;
|
|
61
|
-
var points = [];
|
|
62
|
-
var angle = startAngle;
|
|
52
|
+
}
|
|
53
|
+
findPolygonInside(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
|
|
54
|
+
const step = 2 * Math.PI / pointCount;
|
|
55
|
+
const points = [];
|
|
56
|
+
let angle = startAngle;
|
|
63
57
|
while (angle < stopAngle - step) {
|
|
64
58
|
points.push(new DPoint_1.DPoint(this.r).scale(Math.cos(angle), Math.sin(angle))
|
|
65
59
|
.move(this.center));
|
|
66
60
|
angle += step;
|
|
67
61
|
}
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
const x = this.r * Math.cos(stopAngle) + this.center.x;
|
|
63
|
+
const y = this.r * Math.sin(stopAngle) + this.center.y;
|
|
70
64
|
points.push(new DPoint_1.DPoint(x, y));
|
|
71
65
|
return new DPolygon_1.DPolygon(points);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (pointCount === void 0) { pointCount = 64; }
|
|
75
|
-
if (startAngle === void 0) { startAngle = 0; }
|
|
76
|
-
if (stopAngle === void 0) { stopAngle = 2 * Math.PI; }
|
|
66
|
+
}
|
|
67
|
+
findPolygonInsideOnSphere(pointCount = 64, startAngle = 0, stopAngle = 2 * Math.PI) {
|
|
77
68
|
(0, utils_1.checkFunction)('findPolygonInsideOnSphere')
|
|
78
69
|
.checkArgument('center')
|
|
79
70
|
.shouldBeDegree(this.center);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
const step = 2 * Math.PI / pointCount;
|
|
72
|
+
const points = [];
|
|
73
|
+
let angle = startAngle;
|
|
83
74
|
while (angle < stopAngle - step) {
|
|
84
75
|
points.push(this.sphereOffset(angle));
|
|
85
76
|
angle += step;
|
|
86
77
|
}
|
|
87
78
|
points.push(this.sphereOffset(stopAngle));
|
|
88
79
|
return new DPolygon_1.DPolygon(points);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
|
|
80
|
+
}
|
|
81
|
+
sphereOffset(bearing, earthRadius = DPoint_1.EARTH_RADIUS_IN_METERS) {
|
|
82
|
+
const { x: lon1, y: lat1 } = this.center.clone().degreeToRadians();
|
|
83
|
+
const dByR = this.r / earthRadius;
|
|
84
|
+
const lat = Math.asin(Math.sin(lat1) * Math.cos(dByR) +
|
|
95
85
|
Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
|
|
96
|
-
|
|
86
|
+
const lon = lon1 +
|
|
97
87
|
Math.atan2(Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
|
|
98
88
|
return new DPoint_1.DPoint(lon, lat).radiansToDegrees();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
102
91
|
exports.DCircle = DCircle;
|
package/dist/cjs/DLine.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DLine = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (begin === void 0) { begin = DPoint_1.DPoint.zero(); }
|
|
10
|
-
if (end === void 0) { end = DPoint_1.DPoint.zero(); }
|
|
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()) {
|
|
11
9
|
this.a = a;
|
|
12
10
|
this.b = b;
|
|
13
11
|
this.c = c;
|
|
14
12
|
this.begin = begin;
|
|
15
13
|
this.end = end;
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
clone() {
|
|
18
16
|
return new DLine(this.a, this.b, this.c, this.begin.clone(), this.end.clone());
|
|
19
|
-
}
|
|
20
|
-
|
|
17
|
+
}
|
|
18
|
+
findPerpendicular(p) {
|
|
21
19
|
(0, utils_1.checkFunction)('findPerpendicular')
|
|
22
20
|
.checkArgument('this.begin')
|
|
23
21
|
.shouldBeMeters(this.begin)
|
|
@@ -26,8 +24,8 @@ var DLine = (function () {
|
|
|
26
24
|
.checkArgument('p')
|
|
27
25
|
.shouldBeMeters(p);
|
|
28
26
|
return new DLine(-this.b, this.a, this.b * p.x - this.a * p.y);
|
|
29
|
-
}
|
|
30
|
-
|
|
27
|
+
}
|
|
28
|
+
perpendicularDistance(p) {
|
|
31
29
|
(0, utils_1.checkFunction)('perpendicularDistance')
|
|
32
30
|
.checkArgument('this.begin')
|
|
33
31
|
.shouldBeMeters(this.begin)
|
|
@@ -35,14 +33,12 @@ var DLine = (function () {
|
|
|
35
33
|
.shouldBeMeters(this.end)
|
|
36
34
|
.checkArgument('p')
|
|
37
35
|
.shouldBeMeters(p);
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const perpendicularLine = this.findPerpendicular(p);
|
|
37
|
+
const targetPoint = perpendicularLine.findPoint(this);
|
|
40
38
|
return targetPoint.distance(p);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (includeOnly === void 0) { includeOnly = false; }
|
|
45
|
-
var p = this.findPoint(l);
|
|
39
|
+
}
|
|
40
|
+
intersection(l, d = 0, includeOnly = false) {
|
|
41
|
+
const p = this.findPoint(l);
|
|
46
42
|
if (p) {
|
|
47
43
|
if (includeOnly) {
|
|
48
44
|
return this.insideRange(p, d) && l.insideRange(p, d) ? p : null;
|
|
@@ -50,12 +46,12 @@ var DLine = (function () {
|
|
|
50
46
|
return this.inRange(p, d) && l.inRange(p, d) ? p : null;
|
|
51
47
|
}
|
|
52
48
|
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
}
|
|
50
|
+
intersectionWithCircle(circle) {
|
|
51
|
+
const { center, r } = circle;
|
|
52
|
+
const per = this.findPerpendicular(center);
|
|
53
|
+
const t = this.findPoint(per);
|
|
54
|
+
let distance = t.distance(center);
|
|
59
55
|
if (this.begin.equal(center)) {
|
|
60
56
|
distance = 0;
|
|
61
57
|
}
|
|
@@ -63,108 +59,86 @@ var DLine = (function () {
|
|
|
63
59
|
distance = 0;
|
|
64
60
|
}
|
|
65
61
|
if (distance < r) {
|
|
66
|
-
|
|
62
|
+
const { a, b, c } = this;
|
|
67
63
|
if (this.isParallel) {
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
const ct = center.distance(t);
|
|
65
|
+
const move = Math.sqrt(r * r - ct * ct);
|
|
70
66
|
if (this.isParallelY) {
|
|
71
67
|
t.x = this.begin.x;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return [
|
|
68
|
+
const r1 = t.clone().move(0, -move);
|
|
69
|
+
const r2 = t.clone().move(0, move);
|
|
70
|
+
return [r1, r2];
|
|
75
71
|
}
|
|
76
72
|
if (this.isParallelX) {
|
|
77
73
|
t.y = this.begin.y;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return [
|
|
74
|
+
const r1 = t.clone().move(move, 0);
|
|
75
|
+
const r2 = t.clone().move(-move, 0);
|
|
76
|
+
return [r1, r2];
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
79
|
if (this.begin.like(center)) {
|
|
84
|
-
|
|
80
|
+
const p = this.begin.clone();
|
|
85
81
|
return [this.movePoint(p, r), this.movePoint(p, -r)];
|
|
86
82
|
}
|
|
87
83
|
if (this.end.like(center)) {
|
|
88
|
-
|
|
84
|
+
const p = this.end.clone();
|
|
89
85
|
return [this.movePoint(p, r), this.movePoint(p, -r)];
|
|
90
86
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
const s = a * a + b * b;
|
|
88
|
+
const d = r * r - c * c / s;
|
|
89
|
+
const mult = Math.sqrt(d / s);
|
|
90
|
+
const r1 = t.clone().move(b * mult, -a * mult);
|
|
91
|
+
const r2 = t.clone().move(-b * mult, a * mult);
|
|
96
92
|
return [r1, r2];
|
|
97
93
|
}
|
|
98
94
|
if (distance === r) {
|
|
99
95
|
return t;
|
|
100
96
|
}
|
|
101
97
|
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var isInY = y >= minY - d && y <= maxY + d;
|
|
98
|
+
}
|
|
99
|
+
inRange(p, d = 0) {
|
|
100
|
+
const { minX, minY, maxX, maxY } = this;
|
|
101
|
+
const { x, y } = p;
|
|
102
|
+
const isInX = x >= minX - d && x <= maxX + d;
|
|
103
|
+
const isInY = y >= minY - d && y <= maxY + d;
|
|
109
104
|
return isInX && isInY;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
var _a = this, begin = _a.begin, end = _a.end;
|
|
105
|
+
}
|
|
106
|
+
insideRange(p, d = 0) {
|
|
107
|
+
const { begin, end } = this;
|
|
114
108
|
return this.inRange(p, d) && !begin.like(p, 0.00001) && !end.like(p, 0.00001);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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 () {
|
|
109
|
+
}
|
|
110
|
+
get center() {
|
|
111
|
+
return this.begin
|
|
112
|
+
.clone()
|
|
113
|
+
.setIfLessThan(this.end)
|
|
114
|
+
.move(this.end
|
|
115
|
+
.clone()
|
|
116
|
+
.move(this.begin
|
|
117
|
+
.clone()
|
|
118
|
+
.minus())
|
|
119
|
+
.abs()
|
|
120
|
+
.minus()
|
|
121
|
+
.divide(2));
|
|
122
|
+
}
|
|
123
|
+
get minX() {
|
|
124
|
+
return Math.min(this.begin.x, this.end.x);
|
|
125
|
+
}
|
|
126
|
+
get minY() {
|
|
127
|
+
return Math.min(this.begin.y, this.end.y);
|
|
128
|
+
}
|
|
129
|
+
get maxX() {
|
|
130
|
+
return Math.max(this.begin.x, this.end.x);
|
|
131
|
+
}
|
|
132
|
+
get maxY() {
|
|
133
|
+
return Math.max(this.begin.y, this.end.y);
|
|
134
|
+
}
|
|
135
|
+
toString() {
|
|
136
|
+
return `(${this.a}, ${this.b}, ${this.c})`;
|
|
137
|
+
}
|
|
138
|
+
getValue() {
|
|
165
139
|
return [this.a, this.b, this.c];
|
|
166
|
-
}
|
|
167
|
-
|
|
140
|
+
}
|
|
141
|
+
x(p) {
|
|
168
142
|
if (this.isParallelY) {
|
|
169
143
|
return new DPoint_1.DPoint(-this.c / this.a, p.y);
|
|
170
144
|
}
|
|
@@ -172,8 +146,8 @@ var DLine = (function () {
|
|
|
172
146
|
return new DPoint_1.DPoint(p.x, -this.c / this.b);
|
|
173
147
|
}
|
|
174
148
|
return new DPoint_1.DPoint(-this.b / this.a * p.y - this.c / this.a, p.y);
|
|
175
|
-
}
|
|
176
|
-
|
|
149
|
+
}
|
|
150
|
+
y(p) {
|
|
177
151
|
if (this.isParallelY) {
|
|
178
152
|
return new DPoint_1.DPoint(-this.c / this.a, p.y);
|
|
179
153
|
}
|
|
@@ -181,8 +155,8 @@ var DLine = (function () {
|
|
|
181
155
|
return new DPoint_1.DPoint(p.x, -this.c / this.b);
|
|
182
156
|
}
|
|
183
157
|
return new DPoint_1.DPoint(p.x, -this.a / this.b * p.x - this.c / this.b);
|
|
184
|
-
}
|
|
185
|
-
|
|
158
|
+
}
|
|
159
|
+
findPoint(l) {
|
|
186
160
|
if (this.isParallelY && l.isParallelY) {
|
|
187
161
|
return null;
|
|
188
162
|
}
|
|
@@ -196,102 +170,81 @@ var DLine = (function () {
|
|
|
196
170
|
return new DPoint_1.DPoint(-this.c / this.a, -l.c / l.b);
|
|
197
171
|
}
|
|
198
172
|
if (this.isParallelY) {
|
|
199
|
-
|
|
173
|
+
const x = -this.c / this.a;
|
|
200
174
|
return l.y(new DPoint_1.DPoint(x));
|
|
201
175
|
}
|
|
202
176
|
if (this.isParallelX) {
|
|
203
|
-
|
|
177
|
+
const y = -this.c / this.b;
|
|
204
178
|
return l.x(new DPoint_1.DPoint(0, y));
|
|
205
179
|
}
|
|
206
180
|
if (l.isParallelY) {
|
|
207
|
-
|
|
181
|
+
const x = -l.c / l.a;
|
|
208
182
|
return this.y(new DPoint_1.DPoint(x));
|
|
209
183
|
}
|
|
210
184
|
if (l.isParallelX) {
|
|
211
|
-
|
|
185
|
+
const y = -l.c / l.b;
|
|
212
186
|
return this.x(new DPoint_1.DPoint(0, y));
|
|
213
187
|
}
|
|
214
|
-
|
|
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)));
|
|
215
189
|
if (!isFinite(res.x) && !isFinite(res.y)) {
|
|
216
190
|
return null;
|
|
217
191
|
}
|
|
218
192
|
return res;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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 () {
|
|
193
|
+
}
|
|
194
|
+
get isParallel() {
|
|
195
|
+
return this.isParallelX || this.isParallelY;
|
|
196
|
+
}
|
|
197
|
+
get isParallelY() {
|
|
198
|
+
return Math.abs(this.b) < 0.001;
|
|
199
|
+
}
|
|
200
|
+
get isParallelX() {
|
|
201
|
+
return Math.abs(this.a) < 0.001;
|
|
202
|
+
}
|
|
203
|
+
get points() {
|
|
204
|
+
return [this.begin, this.end];
|
|
205
|
+
}
|
|
206
|
+
getFi() {
|
|
249
207
|
(0, utils_1.checkFunction)('getFi')
|
|
250
208
|
.checkArgument('this.begin')
|
|
251
209
|
.shouldBeMeters(this.begin)
|
|
252
210
|
.checkArgument('this.end')
|
|
253
211
|
.shouldBeMeters(this.end);
|
|
254
|
-
|
|
255
|
-
|
|
212
|
+
const { x, y } = this.end.clone().move(this.begin.clone().minus());
|
|
213
|
+
let v = Math.atan2(y, x) - Math.PI;
|
|
256
214
|
if (v > 0) {
|
|
257
215
|
v = Math.PI - v;
|
|
258
216
|
}
|
|
259
217
|
return (Math.PI - v) % (Math.PI * 2);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
218
|
+
}
|
|
219
|
+
toWKT() {
|
|
220
|
+
const { begin: { x: x1, y: y1 }, end: { x: x2, y: y2 } } = this;
|
|
221
|
+
return `LINESTRING (${x1} ${y1}, ${x2} ${y2})`;
|
|
222
|
+
}
|
|
223
|
+
movePoint(i, k) {
|
|
224
|
+
const isArray = Array.isArray(i);
|
|
225
|
+
const p = isArray ? i : [i];
|
|
226
|
+
const d = (isArray ? k : [k]);
|
|
227
|
+
const fi = this.findFi(new DLine(1, 0, 0));
|
|
228
|
+
const td = this.x(new DPoint_1.DPoint(1, 1)).distance(this.x(new DPoint_1.DPoint(2, 2))) / 2;
|
|
229
|
+
const sinCos = new DPoint_1.DPoint(Math.sin(fi), Math.cos(fi));
|
|
230
|
+
const dt = sinCos.clone().scale(td);
|
|
231
|
+
const p1T = p[0].clone().move(dt.clone().minus());
|
|
232
|
+
const p2T = p[0].clone().move(dt);
|
|
233
|
+
let res = [];
|
|
276
234
|
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(
|
|
278
|
-
.move(sinCos.clone().scale(d[index]))
|
|
235
|
+
res = p.map((t, index) => t.clone()
|
|
236
|
+
.move(sinCos.clone().scale(d[index])));
|
|
279
237
|
}
|
|
280
238
|
else {
|
|
281
|
-
res = p.map(
|
|
239
|
+
res = p.map((t, index) => t.clone()
|
|
282
240
|
.move(sinCos.clone().scale(d[index])
|
|
283
|
-
.setX(
|
|
284
|
-
var x = _a.x;
|
|
285
|
-
return -x;
|
|
286
|
-
})); });
|
|
241
|
+
.setX(({ x }) => -x)));
|
|
287
242
|
}
|
|
288
243
|
return isArray ? res : res[0];
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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));
|
|
244
|
+
}
|
|
245
|
+
findFi({ a, b }, delta = 1.0001) {
|
|
246
|
+
const { a: q, b: w } = this;
|
|
247
|
+
let val = (q * a + w * b) / (Math.sqrt(q * q + w * w) * Math.sqrt(a * a + b * b));
|
|
295
248
|
if (val > 1 && val < delta) {
|
|
296
249
|
val = 1;
|
|
297
250
|
}
|
|
@@ -299,12 +252,10 @@ var DLine = (function () {
|
|
|
299
252
|
val = -1;
|
|
300
253
|
}
|
|
301
254
|
return Math.acos(val);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
var _b = this, q = _b.a, w = _b.b, e = _b.c;
|
|
255
|
+
}
|
|
256
|
+
vectorProduct({ a, b, c }) {
|
|
257
|
+
const { a: q, b: w, c: e } = this;
|
|
306
258
|
return new DLine(w * c - e * b, e * a - q * c, q * b - w * a);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
}());
|
|
259
|
+
}
|
|
260
|
+
}
|
|
310
261
|
exports.DLine = DLine;
|
package/dist/cjs/DNumbers.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DNumbers = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
DNumbers.like = function (v, s, d) {
|
|
10
|
-
if (d === void 0) { d = delta; }
|
|
4
|
+
const DPoint_1 = require("./DPoint");
|
|
5
|
+
const delta = 0.001;
|
|
6
|
+
class DNumbers {
|
|
7
|
+
static like(v, s, d = delta) {
|
|
11
8
|
return Math.abs(v - s) < d;
|
|
12
|
-
}
|
|
13
|
-
|
|
9
|
+
}
|
|
10
|
+
static likeZero(v) {
|
|
14
11
|
return DNumbers.like(v, 0);
|
|
15
|
-
}
|
|
16
|
-
|
|
12
|
+
}
|
|
13
|
+
static like2PI(v) {
|
|
17
14
|
return DNumbers.like(DNumbers.rad2Deg(v), DPoint_1.DOUBLE_PI_IN_DEGREE);
|
|
18
|
-
}
|
|
19
|
-
|
|
15
|
+
}
|
|
16
|
+
static likePI(v) {
|
|
20
17
|
return DNumbers.like(DNumbers.rad2Deg(v), DPoint_1.PI_IN_DEGREE);
|
|
21
|
-
}
|
|
22
|
-
|
|
18
|
+
}
|
|
19
|
+
static rad2Deg(v) {
|
|
23
20
|
return v * DPoint_1.DEGREE_TO_PI;
|
|
24
|
-
}
|
|
25
|
-
|
|
21
|
+
}
|
|
22
|
+
static deg2Rad(v) {
|
|
26
23
|
return v * DPoint_1.PI_TO_DEGREE;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
30
26
|
exports.DNumbers = DNumbers;
|