dgeoutils 2.4.1 → 2.4.4
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 +63 -52
- package/dist/cjs/DLine.js +181 -132
- package/dist/cjs/DNumbers.js +20 -16
- package/dist/cjs/DPlane.js +79 -56
- package/dist/cjs/DPoint.js +338 -240
- package/dist/cjs/DPolygon.js +1151 -635
- package/dist/cjs/DPolygonLoop.js +143 -138
- package/dist/cjs/FastSearch.js +37 -13
- package/dist/cjs/TraceMatrix.js +139 -87
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/utils.js +103 -61
- package/dist/esm/DCircle.js +1 -1
- package/dist/esm/DLine.js +2 -2
- package/dist/esm/DPoint.js +2 -2
- package/dist/esm/DPolygon.js +7 -7
- package/dist/esm/utils.js +6 -6
- package/dist/umd/dgeoutils.js +19 -19
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +5 -10
package/dist/cjs/DPoint.js
CHANGED
|
@@ -1,75 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
2
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
30
|
exports.DPoint = exports.DEGREE_TO_PI = exports.PI_TO_DEGREE = exports.DOUBLE_PI_IN_DEGREE = exports.PI_IN_DEGREE = exports.HALF_PI_IN_DEGREE = exports.EARTH_RADIUS_IN_METERS = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
31
|
+
var DLine_1 = require("./DLine");
|
|
32
|
+
var DPolygon_1 = require("./DPolygon");
|
|
33
|
+
var utils_1 = require("./utils");
|
|
34
|
+
var diff = 0;
|
|
35
|
+
var radiansPolygon = new DPolygon_1.DPolygon();
|
|
36
|
+
var pseudoMercatorPolygon = new DPolygon_1.DPolygon();
|
|
37
|
+
var worldGeodeticPolygon = new DPolygon_1.DPolygon();
|
|
11
38
|
exports.EARTH_RADIUS_IN_METERS = 6371008.8;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
39
|
+
var EARTH_IN_MITERS = 20037508.34;
|
|
40
|
+
var DEGREES_IN_EARTH = 180;
|
|
41
|
+
var MITERS_IN_ONE_DEGREE = EARTH_IN_MITERS / DEGREES_IN_EARTH;
|
|
42
|
+
var DEGREES_IN_ONE_MITER = DEGREES_IN_EARTH / EARTH_IN_MITERS;
|
|
16
43
|
exports.HALF_PI_IN_DEGREE = 90;
|
|
17
44
|
exports.PI_IN_DEGREE = 180;
|
|
18
45
|
exports.DOUBLE_PI_IN_DEGREE = 360;
|
|
19
46
|
exports.PI_TO_DEGREE = Math.PI / exports.PI_IN_DEGREE;
|
|
20
47
|
exports.DEGREE_TO_PI = exports.PI_IN_DEGREE / Math.PI;
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
var DPoint = (function () {
|
|
49
|
+
function DPoint(x, y, z) {
|
|
50
|
+
if (x === void 0) { x = 0; }
|
|
51
|
+
if (y === void 0) { y = x; }
|
|
23
52
|
this.x = x;
|
|
24
53
|
this.y = y;
|
|
25
54
|
this.z = z;
|
|
26
55
|
this.properties = {};
|
|
27
56
|
}
|
|
28
|
-
|
|
57
|
+
DPoint.zero = function () {
|
|
29
58
|
return new DPoint();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
59
|
+
};
|
|
60
|
+
DPoint.parse = function (c) {
|
|
61
|
+
var _a = c, lat = _a.lat, lng = _a.lng;
|
|
33
62
|
if (lat && lng) {
|
|
34
63
|
return new DPoint(lat, lng, 0);
|
|
35
64
|
}
|
|
36
|
-
|
|
65
|
+
var _b = __read(c, 3), x = _b[0], y = _b[1], z = _b[2];
|
|
37
66
|
return new DPoint(x, y, z);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
67
|
+
};
|
|
68
|
+
DPoint.parseFromWKT = function (wkt) {
|
|
69
|
+
var regexp = /POINT \((?<data>(?:(?!\)).)*?)\)$/miu;
|
|
70
|
+
var data = wkt.trim().toUpperCase();
|
|
71
|
+
var res = regexp.exec(data);
|
|
72
|
+
var _a = __read(res.groups.data.split(' ').map(Number), 3), x = _a[0], y = _a[1], z = _a[2];
|
|
44
73
|
return new DPoint(x, y, z);
|
|
45
|
-
}
|
|
46
|
-
|
|
74
|
+
};
|
|
75
|
+
DPoint.random = function () {
|
|
47
76
|
return new DPoint(Math.random(), Math.random());
|
|
48
|
-
}
|
|
49
|
-
getTileFromCoords
|
|
77
|
+
};
|
|
78
|
+
DPoint.prototype.getTileFromCoords = function (zoom) {
|
|
79
|
+
if (zoom === void 0) { zoom = this.z; }
|
|
50
80
|
(0, utils_1.checkFunction)('getTileFromCoords')
|
|
51
81
|
.checkArgument('this')
|
|
52
82
|
.shouldBeDegree(this);
|
|
53
|
-
|
|
54
|
-
|
|
83
|
+
var x = Math.floor((this.x + exports.PI_IN_DEGREE) / exports.DOUBLE_PI_IN_DEGREE * (Math.pow(2, zoom)));
|
|
84
|
+
var y = Math.floor((1 - Math.log(Math.tan(this.y * exports.PI_TO_DEGREE) + 1 / Math.cos(this.y * exports.PI_TO_DEGREE)) / Math.PI) / 2 * (Math.pow(2, zoom)));
|
|
55
85
|
return new DPoint(x, y, zoom);
|
|
56
|
-
}
|
|
57
|
-
getCoordsFromTile
|
|
86
|
+
};
|
|
87
|
+
DPoint.prototype.getCoordsFromTile = function (zoom) {
|
|
88
|
+
if (zoom === void 0) { zoom = this.z; }
|
|
58
89
|
(0, utils_1.checkFunction)('getCoordsFromTile')
|
|
59
90
|
.checkArgument('this')
|
|
60
91
|
.shouldBeUInt(this);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
92
|
+
var n = Math.PI - 2 * Math.PI * this.y / (Math.pow(2, zoom));
|
|
93
|
+
var x = this.x / (Math.pow(2, zoom)) * exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE;
|
|
94
|
+
var y = exports.PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
|
|
64
95
|
return new DPoint(x, y, zoom);
|
|
65
|
-
}
|
|
66
|
-
toCoords() {
|
|
96
|
+
};
|
|
97
|
+
DPoint.prototype.toCoords = function () {
|
|
67
98
|
if (this.z === undefined) {
|
|
68
99
|
return [this.x, this.y];
|
|
69
100
|
}
|
|
70
101
|
return [this.x, this.y, this.z];
|
|
71
|
-
}
|
|
72
|
-
findLine(p) {
|
|
102
|
+
};
|
|
103
|
+
DPoint.prototype.findLine = function (p) {
|
|
73
104
|
(0, utils_1.checkFunction)('findLine')
|
|
74
105
|
.checkArgument('this')
|
|
75
106
|
.shouldBeMeters(this)
|
|
@@ -78,9 +109,9 @@ class DPoint {
|
|
|
78
109
|
if (this.equal(p)) {
|
|
79
110
|
return this.findLine(p.clone().move(0, 1));
|
|
80
111
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
var a = this.y - p.y - diff;
|
|
113
|
+
var b = p.x - this.x - diff;
|
|
114
|
+
var c = this.x * p.y - p.x * this.y - diff;
|
|
84
115
|
if (a === 0) {
|
|
85
116
|
return new DLine_1.DLine(0, 1, c / b, this, p);
|
|
86
117
|
}
|
|
@@ -88,8 +119,8 @@ class DPoint {
|
|
|
88
119
|
return new DLine_1.DLine(1, 0, c / a, this, p);
|
|
89
120
|
}
|
|
90
121
|
return new DLine_1.DLine(a, b, c, this, p);
|
|
91
|
-
}
|
|
92
|
-
findInnerAngle(p1, p3) {
|
|
122
|
+
};
|
|
123
|
+
DPoint.prototype.findInnerAngle = function (p1, p3) {
|
|
93
124
|
(0, utils_1.checkFunction)('findInnerAngle')
|
|
94
125
|
.checkArgument('this')
|
|
95
126
|
.shouldBeMeters(this)
|
|
@@ -97,38 +128,38 @@ class DPoint {
|
|
|
97
128
|
.shouldBeMeters(p1)
|
|
98
129
|
.checkArgument('p3')
|
|
99
130
|
.shouldBeMeters(p3);
|
|
100
|
-
|
|
101
|
-
|
|
131
|
+
var a1 = this.findLine(p1).getFi();
|
|
132
|
+
var a2 = this.findLine(p3).getFi();
|
|
102
133
|
if (a2 >= a1) {
|
|
103
134
|
return a2 - a1;
|
|
104
135
|
}
|
|
105
136
|
return a2 + Math.PI * 2 - a1;
|
|
106
|
-
}
|
|
107
|
-
toString() {
|
|
108
|
-
return
|
|
109
|
-
}
|
|
110
|
-
getValue() {
|
|
137
|
+
};
|
|
138
|
+
DPoint.prototype.toString = function () {
|
|
139
|
+
return "".concat(this.x, " ").concat(this.y);
|
|
140
|
+
};
|
|
141
|
+
DPoint.prototype.getValue = function () {
|
|
111
142
|
return [this.x, this.y];
|
|
112
|
-
}
|
|
113
|
-
height(z) {
|
|
143
|
+
};
|
|
144
|
+
DPoint.prototype.height = function (z) {
|
|
114
145
|
this.z = z;
|
|
115
146
|
return this;
|
|
116
|
-
}
|
|
117
|
-
toWKT() {
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
distance(p) {
|
|
147
|
+
};
|
|
148
|
+
DPoint.prototype.toWKT = function () {
|
|
149
|
+
var _a = this, x = _a.x, y = _a.y;
|
|
150
|
+
return "POINT (".concat(x, " ").concat(y, ")");
|
|
151
|
+
};
|
|
152
|
+
DPoint.prototype.distance = function (p) {
|
|
122
153
|
(0, utils_1.checkFunction)('distance')
|
|
123
154
|
.checkArgument('this')
|
|
124
155
|
.shouldBeMeters(this)
|
|
125
156
|
.checkArgument('p')
|
|
126
157
|
.shouldBeMeters(p);
|
|
127
|
-
|
|
128
|
-
|
|
158
|
+
var dx = p.x - this.x;
|
|
159
|
+
var dy = p.y - this.y;
|
|
129
160
|
return Math.sqrt(dx * dx + dy * dy);
|
|
130
|
-
}
|
|
131
|
-
distance3d(p) {
|
|
161
|
+
};
|
|
162
|
+
DPoint.prototype.distance3d = function (p) {
|
|
132
163
|
(0, utils_1.checkFunction)('distance3d')
|
|
133
164
|
.checkArgument('this')
|
|
134
165
|
.shouldBeMeters(this)
|
|
@@ -138,69 +169,70 @@ class DPoint {
|
|
|
138
169
|
.shouldExist(this.z)
|
|
139
170
|
.checkArgument('p.z')
|
|
140
171
|
.shouldExist(p.z);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
172
|
+
var dx = p.x - this.x;
|
|
173
|
+
var dy = p.y - this.y;
|
|
174
|
+
var dz = p.z - this.z;
|
|
144
175
|
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
145
|
-
}
|
|
146
|
-
setX(x) {
|
|
176
|
+
};
|
|
177
|
+
DPoint.prototype.setX = function (x) {
|
|
147
178
|
this.x = typeof x === 'number' ? x : x(this);
|
|
148
179
|
return this;
|
|
149
|
-
}
|
|
150
|
-
setZ(z) {
|
|
180
|
+
};
|
|
181
|
+
DPoint.prototype.setZ = function (z) {
|
|
151
182
|
this.z = typeof z === 'number' ? z : z(this);
|
|
152
183
|
return this;
|
|
153
|
-
}
|
|
154
|
-
setY(y) {
|
|
184
|
+
};
|
|
185
|
+
DPoint.prototype.setY = function (y) {
|
|
155
186
|
this.y = typeof y === 'number' ? y : y(this);
|
|
156
187
|
return this;
|
|
157
|
-
}
|
|
158
|
-
clone() {
|
|
159
|
-
|
|
160
|
-
p.properties =
|
|
188
|
+
};
|
|
189
|
+
DPoint.prototype.clone = function () {
|
|
190
|
+
var p = new DPoint(this.x, this.y, this.z);
|
|
191
|
+
p.properties = __assign({}, this.properties);
|
|
161
192
|
return p;
|
|
162
|
-
}
|
|
163
|
-
gt(p) {
|
|
193
|
+
};
|
|
194
|
+
DPoint.prototype.gt = function (p) {
|
|
164
195
|
return this.x > p.x && this.y > p.y;
|
|
165
|
-
}
|
|
166
|
-
lt(p) {
|
|
196
|
+
};
|
|
197
|
+
DPoint.prototype.lt = function (p) {
|
|
167
198
|
return this.x < p.x && this.y < p.y;
|
|
168
|
-
}
|
|
169
|
-
gtOrEqual(p) {
|
|
199
|
+
};
|
|
200
|
+
DPoint.prototype.gtOrEqual = function (p) {
|
|
170
201
|
return this.gt(p) || this.equal(p);
|
|
171
|
-
}
|
|
172
|
-
ltOrEqual(p) {
|
|
202
|
+
};
|
|
203
|
+
DPoint.prototype.ltOrEqual = function (p) {
|
|
173
204
|
return this.lt(p) || this.equal(p);
|
|
174
|
-
}
|
|
175
|
-
rotate(a) {
|
|
176
|
-
|
|
177
|
-
|
|
205
|
+
};
|
|
206
|
+
DPoint.prototype.rotate = function (a) {
|
|
207
|
+
var x = this.x * Math.cos(a) - this.y * Math.sin(a);
|
|
208
|
+
var y = this.x * Math.sin(a) + this.y * Math.cos(a);
|
|
178
209
|
this.x = x;
|
|
179
210
|
this.y = y;
|
|
180
211
|
return this;
|
|
181
|
-
}
|
|
182
|
-
rotate3dX(a) {
|
|
183
|
-
|
|
212
|
+
};
|
|
213
|
+
DPoint.prototype.rotate3dX = function (a) {
|
|
214
|
+
var _a = this, y = _a.y, z = _a.z;
|
|
184
215
|
this.y = y * Math.cos(a) + z * Math.sin(a);
|
|
185
216
|
this.z = -y * Math.sin(a) + z * Math.cos(a);
|
|
186
217
|
return this;
|
|
187
|
-
}
|
|
188
|
-
rotate3dY(a) {
|
|
189
|
-
|
|
218
|
+
};
|
|
219
|
+
DPoint.prototype.rotate3dY = function (a) {
|
|
220
|
+
var _a = this, x = _a.x, z = _a.z;
|
|
190
221
|
this.x = x * Math.cos(a) + z * Math.sin(a);
|
|
191
222
|
this.z = -x * Math.sin(a) + z * Math.cos(a);
|
|
192
223
|
return this;
|
|
193
|
-
}
|
|
194
|
-
rotate3dZ(a) {
|
|
195
|
-
|
|
224
|
+
};
|
|
225
|
+
DPoint.prototype.rotate3dZ = function (a) {
|
|
226
|
+
var _a = this, x = _a.x, y = _a.y;
|
|
196
227
|
this.x = x * Math.cos(a) - y * Math.sin(a);
|
|
197
228
|
this.y = -x * Math.sin(a) + y * Math.cos(a);
|
|
198
229
|
return this;
|
|
199
|
-
}
|
|
200
|
-
move(x, y
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
};
|
|
231
|
+
DPoint.prototype.move = function (x, y, z) {
|
|
232
|
+
if (y === void 0) { y = x; }
|
|
233
|
+
var xV = 0;
|
|
234
|
+
var yV = 0;
|
|
235
|
+
var zV = undefined;
|
|
204
236
|
if (x instanceof DPoint) {
|
|
205
237
|
xV = this.x + x.x;
|
|
206
238
|
yV = this.y + x.y;
|
|
@@ -221,82 +253,84 @@ class DPoint {
|
|
|
221
253
|
this.z = zV;
|
|
222
254
|
}
|
|
223
255
|
return this;
|
|
224
|
-
}
|
|
225
|
-
degreeToMeters() {
|
|
256
|
+
};
|
|
257
|
+
DPoint.prototype.degreeToMeters = function () {
|
|
226
258
|
(0, utils_1.checkFunction)('degreeToMeters')
|
|
227
259
|
.checkArgument('this')
|
|
228
260
|
.shouldBeDegree(this);
|
|
229
|
-
|
|
230
|
-
|
|
261
|
+
var x = ((this.x + exports.PI_IN_DEGREE) % exports.DOUBLE_PI_IN_DEGREE - exports.PI_IN_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
262
|
+
var y = (Math.log(Math.tan(((this.y + exports.HALF_PI_IN_DEGREE) % exports.PI_IN_DEGREE) *
|
|
231
263
|
(Math.PI / exports.DOUBLE_PI_IN_DEGREE))) / exports.PI_TO_DEGREE) * MITERS_IN_ONE_DEGREE;
|
|
232
264
|
this.x = x;
|
|
233
265
|
this.y = y;
|
|
234
266
|
return this;
|
|
235
|
-
}
|
|
236
|
-
metersToDegree() {
|
|
267
|
+
};
|
|
268
|
+
DPoint.prototype.metersToDegree = function () {
|
|
237
269
|
(0, utils_1.checkFunction)('metersToDegree')
|
|
238
270
|
.checkArgument('this')
|
|
239
271
|
.shouldBeMeters(this);
|
|
240
|
-
|
|
241
|
-
|
|
272
|
+
var lon = this.x * DEGREES_IN_ONE_MITER;
|
|
273
|
+
var lat = Math.atan(Math.pow(Math.E, ((this.y / MITERS_IN_ONE_DEGREE) * exports.PI_TO_DEGREE))) *
|
|
242
274
|
(exports.DOUBLE_PI_IN_DEGREE / Math.PI) - exports.HALF_PI_IN_DEGREE;
|
|
243
275
|
this.x = lon;
|
|
244
276
|
this.y = lat;
|
|
245
277
|
return this;
|
|
246
|
-
}
|
|
247
|
-
degreeToRadians() {
|
|
278
|
+
};
|
|
279
|
+
DPoint.prototype.degreeToRadians = function () {
|
|
248
280
|
(0, utils_1.checkFunction)('degreeToRadians')
|
|
249
281
|
.checkArgument('this')
|
|
250
282
|
.shouldBeDegree(this);
|
|
251
283
|
return this.scale(exports.PI_TO_DEGREE);
|
|
252
|
-
}
|
|
253
|
-
radiansToDegrees() {
|
|
284
|
+
};
|
|
285
|
+
DPoint.prototype.radiansToDegrees = function () {
|
|
254
286
|
(0, utils_1.checkFunction)('radiansToDegrees')
|
|
255
287
|
.checkArgument('this')
|
|
256
288
|
.shouldBeRadians(this);
|
|
257
289
|
return this.scale(exports.DEGREE_TO_PI);
|
|
258
|
-
}
|
|
259
|
-
radiansToMeters() {
|
|
290
|
+
};
|
|
291
|
+
DPoint.prototype.radiansToMeters = function () {
|
|
260
292
|
(0, utils_1.checkFunction)('radiansToMeters')
|
|
261
293
|
.checkArgument('this')
|
|
262
294
|
.shouldBeRadians(this);
|
|
263
295
|
return this.radiansToDegrees().degreeToMeters();
|
|
264
|
-
}
|
|
265
|
-
metersToRadians() {
|
|
296
|
+
};
|
|
297
|
+
DPoint.prototype.metersToRadians = function () {
|
|
266
298
|
(0, utils_1.checkFunction)('metersToRadians')
|
|
267
299
|
.checkArgument('this')
|
|
268
300
|
.shouldBeMeters(this);
|
|
269
301
|
return this.metersToDegree().degreeToRadians();
|
|
270
|
-
}
|
|
271
|
-
round() {
|
|
302
|
+
};
|
|
303
|
+
DPoint.prototype.round = function () {
|
|
272
304
|
this.x = Math.round(this.x);
|
|
273
305
|
this.y = Math.round(this.y);
|
|
274
306
|
return this;
|
|
275
|
-
}
|
|
276
|
-
ceil() {
|
|
307
|
+
};
|
|
308
|
+
DPoint.prototype.ceil = function () {
|
|
277
309
|
this.x = Math.ceil(this.x);
|
|
278
310
|
this.y = Math.ceil(this.y);
|
|
279
311
|
return this;
|
|
280
|
-
}
|
|
281
|
-
floor() {
|
|
312
|
+
};
|
|
313
|
+
DPoint.prototype.floor = function () {
|
|
282
314
|
this.x = Math.floor(this.x);
|
|
283
315
|
this.y = Math.floor(this.y);
|
|
284
316
|
return this;
|
|
285
|
-
}
|
|
286
|
-
toFixed
|
|
317
|
+
};
|
|
318
|
+
DPoint.prototype.toFixed = function (n) {
|
|
319
|
+
if (n === void 0) { n = 2; }
|
|
287
320
|
this.x = parseFloat(this.x.toFixed(n));
|
|
288
321
|
this.y = parseFloat(this.y.toFixed(n));
|
|
289
322
|
return this;
|
|
290
|
-
}
|
|
291
|
-
abs() {
|
|
323
|
+
};
|
|
324
|
+
DPoint.prototype.abs = function () {
|
|
292
325
|
this.x = Math.abs(this.x);
|
|
293
326
|
this.y = Math.abs(this.y);
|
|
294
327
|
return this;
|
|
295
|
-
}
|
|
296
|
-
scale(x, y
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
328
|
+
};
|
|
329
|
+
DPoint.prototype.scale = function (x, y, z) {
|
|
330
|
+
if (y === void 0) { y = x; }
|
|
331
|
+
var xV = 0;
|
|
332
|
+
var yV = 0;
|
|
333
|
+
var zV = undefined;
|
|
300
334
|
if (x instanceof DPoint) {
|
|
301
335
|
xV = this.x * x.x;
|
|
302
336
|
yV = this.y * x.y;
|
|
@@ -317,11 +351,12 @@ class DPoint {
|
|
|
317
351
|
this.z = zV;
|
|
318
352
|
}
|
|
319
353
|
return this;
|
|
320
|
-
}
|
|
321
|
-
divide(x, y
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
354
|
+
};
|
|
355
|
+
DPoint.prototype.divide = function (x, y, z) {
|
|
356
|
+
if (y === void 0) { y = x; }
|
|
357
|
+
var xV = 0;
|
|
358
|
+
var yV = 0;
|
|
359
|
+
var zV = undefined;
|
|
325
360
|
if (x instanceof DPoint) {
|
|
326
361
|
xV = this.x / x.x;
|
|
327
362
|
yV = this.y / x.y;
|
|
@@ -342,135 +377,198 @@ class DPoint {
|
|
|
342
377
|
this.z = zV;
|
|
343
378
|
}
|
|
344
379
|
return this;
|
|
345
|
-
}
|
|
346
|
-
equal(p) {
|
|
380
|
+
};
|
|
381
|
+
DPoint.prototype.equal = function (p) {
|
|
347
382
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
348
|
-
}
|
|
349
|
-
like(p, d
|
|
383
|
+
};
|
|
384
|
+
DPoint.prototype.like = function (p, d) {
|
|
350
385
|
var _a, _b, _c, _d;
|
|
386
|
+
if (d === void 0) { d = 0.001; }
|
|
351
387
|
if (this.equal(p)) {
|
|
352
388
|
return true;
|
|
353
389
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
390
|
+
var likeX = Math.abs(this.x - p.x) < d;
|
|
391
|
+
var likeY = Math.abs(this.y - p.y) < d;
|
|
392
|
+
var likeZ = Math.abs(((_b = (_a = this.z) !== null && _a !== void 0 ? _a : p.z) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = p.z) !== null && _c !== void 0 ? _c : this.z) !== null && _d !== void 0 ? _d : 0)) < d;
|
|
357
393
|
return likeX && likeY && likeZ;
|
|
358
|
-
}
|
|
359
|
-
flipVertically(size) {
|
|
360
|
-
|
|
394
|
+
};
|
|
395
|
+
DPoint.prototype.flipVertically = function (size) {
|
|
396
|
+
var v = size;
|
|
361
397
|
if (size instanceof DPoint) {
|
|
362
398
|
v = size.y;
|
|
363
399
|
}
|
|
364
400
|
this.y = v - this.y;
|
|
365
401
|
return this;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
402
|
+
};
|
|
403
|
+
Object.defineProperty(DPoint.prototype, "likeRadians", {
|
|
404
|
+
get: function () {
|
|
405
|
+
if (radiansPolygon.length === 0) {
|
|
406
|
+
radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2));
|
|
407
|
+
}
|
|
408
|
+
return radiansPolygon.simpleInclude(this);
|
|
409
|
+
},
|
|
410
|
+
enumerable: false,
|
|
411
|
+
configurable: true
|
|
412
|
+
});
|
|
413
|
+
Object.defineProperty(DPoint.prototype, "likeWorldGeodeticSystem", {
|
|
414
|
+
get: function () {
|
|
415
|
+
if (worldGeodeticPolygon.length === 0) {
|
|
416
|
+
worldGeodeticPolygon.push(new DPoint(-180, -90), new DPoint(180, 90));
|
|
417
|
+
}
|
|
418
|
+
return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this);
|
|
419
|
+
},
|
|
420
|
+
enumerable: false,
|
|
421
|
+
configurable: true
|
|
422
|
+
});
|
|
423
|
+
Object.defineProperty(DPoint.prototype, "likePseudoMercator", {
|
|
424
|
+
get: function () {
|
|
425
|
+
if (pseudoMercatorPolygon.length === 0) {
|
|
426
|
+
pseudoMercatorPolygon.push(new DPoint(-20026376.39, -20048966.10), new DPoint(20026376.39, 20048966.10));
|
|
427
|
+
}
|
|
428
|
+
return !this.likeRadians && !this.likeWorldGeodeticSystem && pseudoMercatorPolygon.simpleInclude(this);
|
|
429
|
+
},
|
|
430
|
+
enumerable: false,
|
|
431
|
+
configurable: true
|
|
432
|
+
});
|
|
433
|
+
Object.defineProperty(DPoint.prototype, "w", {
|
|
434
|
+
get: function () {
|
|
435
|
+
return this.x;
|
|
436
|
+
},
|
|
437
|
+
set: function (x) {
|
|
438
|
+
this.x = x;
|
|
439
|
+
},
|
|
440
|
+
enumerable: false,
|
|
441
|
+
configurable: true
|
|
442
|
+
});
|
|
443
|
+
Object.defineProperty(DPoint.prototype, "h", {
|
|
444
|
+
get: function () {
|
|
445
|
+
return this.y;
|
|
446
|
+
},
|
|
447
|
+
set: function (y) {
|
|
448
|
+
this.y = y;
|
|
449
|
+
},
|
|
450
|
+
enumerable: false,
|
|
451
|
+
configurable: true
|
|
452
|
+
});
|
|
453
|
+
Object.defineProperty(DPoint.prototype, "area", {
|
|
454
|
+
get: function () {
|
|
455
|
+
(0, utils_1.checkFunction)('area')
|
|
456
|
+
.checkArgument('this')
|
|
457
|
+
.shouldBeMeters(this);
|
|
458
|
+
return this.w * this.h;
|
|
459
|
+
},
|
|
460
|
+
enumerable: false,
|
|
461
|
+
configurable: true
|
|
462
|
+
});
|
|
463
|
+
Object.defineProperty(DPoint.prototype, "hip", {
|
|
464
|
+
get: function () {
|
|
465
|
+
(0, utils_1.checkFunction)('hip')
|
|
466
|
+
.checkArgument('this')
|
|
467
|
+
.shouldBeMeters(this);
|
|
468
|
+
return Math.sqrt(this.w * this.w + this.h * this.h);
|
|
469
|
+
},
|
|
470
|
+
enumerable: false,
|
|
471
|
+
configurable: true
|
|
472
|
+
});
|
|
473
|
+
Object.defineProperty(DPoint.prototype, "min", {
|
|
474
|
+
get: function () {
|
|
475
|
+
return Math.min(this.x, this.y);
|
|
476
|
+
},
|
|
477
|
+
enumerable: false,
|
|
478
|
+
configurable: true
|
|
479
|
+
});
|
|
480
|
+
Object.defineProperty(DPoint.prototype, "max", {
|
|
481
|
+
get: function () {
|
|
482
|
+
return Math.max(this.x, this.y);
|
|
483
|
+
},
|
|
484
|
+
enumerable: false,
|
|
485
|
+
configurable: true
|
|
486
|
+
});
|
|
487
|
+
Object.defineProperty(DPoint.prototype, "hipPoint", {
|
|
488
|
+
get: function () {
|
|
489
|
+
var hip = this.hip;
|
|
490
|
+
return new DPoint(hip, hip);
|
|
491
|
+
},
|
|
492
|
+
enumerable: false,
|
|
493
|
+
configurable: true
|
|
494
|
+
});
|
|
495
|
+
Object.defineProperty(DPoint.prototype, "xPoint", {
|
|
496
|
+
get: function () {
|
|
497
|
+
var x = this.x;
|
|
498
|
+
return new DPoint(x, x);
|
|
499
|
+
},
|
|
500
|
+
enumerable: false,
|
|
501
|
+
configurable: true
|
|
502
|
+
});
|
|
503
|
+
Object.defineProperty(DPoint.prototype, "yPoint", {
|
|
504
|
+
get: function () {
|
|
505
|
+
var y = this.y;
|
|
506
|
+
return new DPoint(y, y);
|
|
507
|
+
},
|
|
508
|
+
enumerable: false,
|
|
509
|
+
configurable: true
|
|
510
|
+
});
|
|
511
|
+
Object.defineProperty(DPoint.prototype, "wPoint", {
|
|
512
|
+
get: function () {
|
|
513
|
+
return this.xPoint;
|
|
514
|
+
},
|
|
515
|
+
enumerable: false,
|
|
516
|
+
configurable: true
|
|
517
|
+
});
|
|
518
|
+
Object.defineProperty(DPoint.prototype, "hPoint", {
|
|
519
|
+
get: function () {
|
|
520
|
+
return this.yPoint;
|
|
521
|
+
},
|
|
522
|
+
enumerable: false,
|
|
523
|
+
configurable: true
|
|
524
|
+
});
|
|
525
|
+
DPoint.prototype.simple = function (xKey, yKey) {
|
|
526
|
+
var _a;
|
|
527
|
+
if (xKey === void 0) { xKey = 'x'; }
|
|
528
|
+
if (yKey === void 0) { yKey = 'y'; }
|
|
529
|
+
return _a = {},
|
|
530
|
+
_a[xKey] = this.x,
|
|
531
|
+
_a[yKey] = this.y,
|
|
532
|
+
_a;
|
|
533
|
+
};
|
|
534
|
+
DPoint.prototype.setIfLessThan = function (p) {
|
|
440
535
|
this.x = Math.max(this.x, p.x);
|
|
441
536
|
this.y = Math.max(this.y, p.y);
|
|
442
537
|
return this;
|
|
443
|
-
}
|
|
444
|
-
minus() {
|
|
538
|
+
};
|
|
539
|
+
DPoint.prototype.minus = function () {
|
|
445
540
|
return this.scale(-1);
|
|
446
|
-
}
|
|
447
|
-
orthodromicPath(point, pointsCount
|
|
541
|
+
};
|
|
542
|
+
DPoint.prototype.orthodromicPath = function (point, pointsCount) {
|
|
543
|
+
if (pointsCount === void 0) { pointsCount = 360; }
|
|
448
544
|
(0, utils_1.checkFunction)('orthodromicPath')
|
|
449
545
|
.checkArgument('this')
|
|
450
546
|
.shouldBeDegree(this)
|
|
451
547
|
.checkArgument('point')
|
|
452
548
|
.shouldBeDegree(point);
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
549
|
+
var t = this.clone().degreeToRadians();
|
|
550
|
+
var p = point.clone().degreeToRadians();
|
|
551
|
+
var d = Math.sin(p.x - t.x);
|
|
552
|
+
var step = (p.x - t.x) / (pointsCount - 1);
|
|
457
553
|
return new DPolygon_1.DPolygon((0, utils_1.createArray)(pointsCount)
|
|
458
|
-
.map((v, i)
|
|
459
|
-
|
|
460
|
-
|
|
554
|
+
.map(function (v, i) {
|
|
555
|
+
var x = t.x + step * i;
|
|
556
|
+
var y = Math.atan((Math.tan(t.y) * Math.sin(p.x - x)) / d +
|
|
461
557
|
(Math.tan(p.y) * Math.sin(x - t.x)) / d);
|
|
462
558
|
return new DPoint(x, y).radiansToDegrees();
|
|
463
559
|
}));
|
|
464
|
-
}
|
|
465
|
-
sortByDistance(p) {
|
|
560
|
+
};
|
|
561
|
+
DPoint.prototype.sortByDistance = function (p) {
|
|
562
|
+
var _this = this;
|
|
466
563
|
return p
|
|
467
564
|
.clone()
|
|
468
|
-
.map((d, index)
|
|
469
|
-
d.properties.distance = d.distance(
|
|
565
|
+
.map(function (d, index) {
|
|
566
|
+
d.properties.distance = d.distance(_this);
|
|
470
567
|
d.properties.index = index;
|
|
471
568
|
return d;
|
|
472
569
|
})
|
|
473
|
-
.sort((a, b)
|
|
474
|
-
}
|
|
475
|
-
|
|
570
|
+
.sort(function (a, b) { return a.properties.distance - b.properties.distance; });
|
|
571
|
+
};
|
|
572
|
+
return DPoint;
|
|
573
|
+
}());
|
|
476
574
|
exports.DPoint = DPoint;
|