dgeoutils 2.2.7 → 2.2.11

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/DPoint.js CHANGED
@@ -19,12 +19,10 @@ exports.DOUBLE_PI_IN_DEGREE = 360;
19
19
  exports.PI_TO_DEGREE = Math.PI / exports.PI_IN_DEGREE;
20
20
  exports.DEGREE_TO_PI = exports.PI_IN_DEGREE / Math.PI;
21
21
  class DPoint {
22
- // eslint-disable-next-line no-empty-function,no-useless-constructor
23
22
  constructor(x = 0, y = x, z) {
24
23
  this.x = x;
25
24
  this.y = y;
26
25
  this.z = z;
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
26
  this.properties = {};
29
27
  }
30
28
  static zero() {
@@ -48,13 +46,6 @@ class DPoint {
48
46
  static random() {
49
47
  return new DPoint(Math.random(), Math.random());
50
48
  }
51
- /**
52
- * @remark Point should be Lng/Lat.
53
- *
54
- * @remark `z` value default for `zoom` argument.
55
- *
56
- * @param [zoom=this.z]
57
- */
58
49
  getTileFromCoords(zoom = this.z) {
59
50
  (0, utils_1.checkFunction)('getTileFromCoords')
60
51
  .checkArgument('this')
@@ -63,13 +54,6 @@ class DPoint {
63
54
  const 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)));
64
55
  return new DPoint(x, y, zoom);
65
56
  }
66
- /**
67
- * Result would be Lng/Lat.
68
- *
69
- * @remark `z` value default for `zoom` argument.
70
- *
71
- * @param [zoom=this.z]
72
- */
73
57
  getCoordsFromTile(zoom = this.z) {
74
58
  (0, utils_1.checkFunction)('getCoordsFromTile')
75
59
  .checkArgument('this')
@@ -85,10 +69,6 @@ class DPoint {
85
69
  }
86
70
  return [this.x, this.y, this.z];
87
71
  }
88
- /**
89
- * Find line between two points.
90
- * @param p
91
- */
92
72
  findLine(p) {
93
73
  (0, utils_1.checkFunction)('findLine')
94
74
  .checkArgument('this')
@@ -177,10 +157,6 @@ class DPoint {
177
157
  ltOrEqual(p) {
178
158
  return this.lt(p) || this.equal(p);
179
159
  }
180
- /**
181
- * Clockwise rotation
182
- * @param a radians
183
- */
184
160
  rotate(a) {
185
161
  const x = this.x * Math.cos(a) - this.y * Math.sin(a);
186
162
  const y = this.x * Math.sin(a) + this.y * Math.cos(a);
@@ -188,19 +164,47 @@ class DPoint {
188
164
  this.y = y;
189
165
  return this;
190
166
  }
191
- move(x, y = x) {
167
+ rotate3dX(a) {
168
+ const { y, z } = this;
169
+ this.y = y * Math.cos(a) + z * Math.sin(a);
170
+ this.z = -y * Math.sin(a) + z * Math.cos(a);
171
+ return this;
172
+ }
173
+ rotate3dY(a) {
174
+ const { x, z } = this;
175
+ this.x = x * Math.cos(a) + z * Math.sin(a);
176
+ this.z = -x * Math.sin(a) + z * Math.cos(a);
177
+ return this;
178
+ }
179
+ rotate3dZ(a) {
180
+ const { x, y } = this;
181
+ this.x = x * Math.cos(a) - y * Math.sin(a);
182
+ this.y = -x * Math.sin(a) + y * Math.cos(a);
183
+ return this;
184
+ }
185
+ move(x, y = x, z = x) {
192
186
  let xV = 0;
193
187
  let yV = 0;
188
+ let zV = undefined;
194
189
  if (x instanceof DPoint) {
195
190
  xV = this.x + x.x;
196
191
  yV = this.y + x.y;
192
+ if (this.z && x.z) {
193
+ zV = this.z + x.z;
194
+ }
197
195
  }
198
196
  else {
199
197
  xV = this.x + x;
200
198
  yV = this.y + y;
199
+ if (this.z && z) {
200
+ zV = this.z + z;
201
+ }
201
202
  }
202
203
  this.x = xV;
203
204
  this.y = yV;
205
+ if (zV) {
206
+ this.z = zV;
207
+ }
204
208
  return this;
205
209
  }
206
210
  degreeToMeters() {
@@ -264,9 +268,6 @@ class DPoint {
264
268
  this.y = Math.floor(this.y);
265
269
  return this;
266
270
  }
267
- /**
268
- * @param [n=2]
269
- */
270
271
  toFixed(n = 2) {
271
272
  this.x = parseFloat(this.x.toFixed(n));
272
273
  this.y = parseFloat(this.y.toFixed(n));
@@ -310,17 +311,14 @@ class DPoint {
310
311
  equal(p) {
311
312
  return this.x === p.x && this.y === p.y && this.z === p.z;
312
313
  }
313
- /**
314
- * @param p
315
- * @param [d=0.001]
316
- */
317
314
  like(p, d = 0.001) {
315
+ var _a, _b, _c, _d;
318
316
  if (this.equal(p)) {
319
317
  return true;
320
318
  }
321
319
  const likeX = Math.abs(this.x - p.x) < d;
322
320
  const likeY = Math.abs(this.y - p.y) < d;
323
- const likeZ = Math.abs((this.z || 0) - (p.z || 0)) < d;
321
+ const 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;
324
322
  return likeX && likeY && likeZ;
325
323
  }
326
324
  flipVertically(size) {
@@ -331,27 +329,18 @@ class DPoint {
331
329
  this.y = v - this.y;
332
330
  return this;
333
331
  }
334
- /**
335
- * Check if point looks like radians
336
- */
337
332
  get likeRadians() {
338
333
  if (radiansPolygon.length === 0) {
339
334
  radiansPolygon.push(new DPoint(-Math.PI, -Math.PI / 2), new DPoint(Math.PI, Math.PI / 2));
340
335
  }
341
336
  return radiansPolygon.simpleInclude(this);
342
337
  }
343
- /**
344
- * Check if point looks like `EPSG:4326` (degrees)
345
- */
346
338
  get likeWorldGeodeticSystem() {
347
339
  if (worldGeodeticPolygon.length === 0) {
348
340
  worldGeodeticPolygon.push(new DPoint(-180, -90), new DPoint(180, 90));
349
341
  }
350
342
  return !this.likeRadians && worldGeodeticPolygon.simpleInclude(this);
351
343
  }
352
- /**
353
- * Check if point looks like `EPSG:3857` (meters)
354
- */
355
344
  get likePseudoMercator() {
356
345
  if (pseudoMercatorPolygon.length === 0) {
357
346
  pseudoMercatorPolygon.push(new DPoint(-20026376.39, -20048966.10), new DPoint(20026376.39, 20048966.10));
@@ -420,16 +409,6 @@ class DPoint {
420
409
  minus() {
421
410
  return this.clone().scale(-1);
422
411
  }
423
- /**
424
- * Find [orthodromic path](https://en.wikipedia.org/wiki/Great-circle_navigation) between to points.
425
- *
426
- * @remark Points should be Lng/Lat.
427
- *
428
- * ![example](/media/examples/orthodromicPath.png)
429
- *
430
- * @param point
431
- * @param [pointsCount=360]
432
- */
433
412
  orthodromicPath(point, pointsCount = 360) {
434
413
  (0, utils_1.checkFunction)('orthodromicPath')
435
414
  .checkArgument('this')
@@ -11,53 +11,12 @@ export declare class DPolygon {
11
11
  holes: DPolygon[];
12
12
  private searchStore;
13
13
  constructor(pPoints?: DPoint[]);
14
- /**
15
- * Specifies a round line buffer end cap style.
16
- */
17
14
  static CAP_ROUND: number;
18
- /**
19
- * Specifies a flat line buffer end cap style.
20
- */
21
15
  static CAP_FLAT: number;
22
- /**
23
- * Specifies a square line buffer end cap style.
24
- */
25
16
  static CAP_SQUARE: number;
26
- /**
27
- * Transform array of triangles to Three.JS vertices
28
- *
29
- * ```
30
- * const geometry = new THREE.BufferGeometry();
31
- * // create a simple square shape. We duplicate the top left and bottom right
32
- * // vertices because each vertex needs to appear once per triangle.
33
- * const vertices = new Float32Array( DPolygon.arrayOfTrianglesToVertices(triangles, 10) );
34
- *
35
- * // itemSize = 3 because there are 3 values (components) per vertex
36
- * geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
37
- * const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
38
- * mesh = new THREE.Mesh( geometry, material );
39
- *
40
- * scene.add( mesh );
41
- * ```
42
- *
43
- * @param triangles
44
- * @param [height=0]
45
- */
46
17
  static arrayOfTrianglesToVertices(triangles: DPolygon[], height?: number): number[];
47
- /**
48
- * Get size of min area rectangle.
49
- * @param poly should be `minAreaRectangle`
50
- */
51
18
  static minAreaRectangleSize(poly: DPolygon): DPoint;
52
- /**
53
- * Slice line string to dashes.
54
- * @param poly should be `divideToPieces` at first
55
- */
56
19
  static toDash(poly: DPolygon): DPolygon[];
57
- /**
58
- * Get min area rectangle direction
59
- * @param poly should be `minAreaRectangle`
60
- */
61
20
  static minAreaRectangleDirection(poly: DPolygon): number;
62
21
  static parseFromWKT(wkt: string): DPolygon;
63
22
  static createSquareBySize(size: DPoint): DPolygon;
@@ -68,119 +27,34 @@ export declare class DPolygon {
68
27
  get minX(): number;
69
28
  get maxY(): number;
70
29
  get minY(): number;
71
- /**
72
- * Get center coordinates
73
- */
74
30
  get center(): DPoint;
75
- /**
76
- * Difference between `maxY` and `minY`. Equal `ΔY` (`dY`)
77
- */
78
31
  get h(): number;
79
- /**
80
- * Difference between `maxX` and `minX`. Equal `ΔX` (`dX`)
81
- */
82
32
  get w(): number;
83
- /**
84
- * Difference between `maxY` and `minY`. Equal `height` (`h`)
85
- */
86
33
  get dY(): number;
87
- /**
88
- * Difference between `maxX` and `minX`. Equal `width` (`w`)
89
- */
90
34
  get dX(): number;
91
- /**
92
- * Get closed extend polygon
93
- */
94
35
  get extend(): DPolygon;
95
- /**
96
- * Point with `width` value as `x` and `height` value as `y`
97
- */
98
36
  get size(): DPoint;
99
- /**
100
- * Point with minimal `x` and `y`
101
- */
102
37
  get leftTop(): DPoint;
103
- /**
104
- * Point with maximal `x` and `y`
105
- */
106
38
  get rightBottom(): DPoint;
107
- /**
108
- * Next point index
109
- */
110
39
  get length(): number;
111
- /**
112
- * Get length of line string.
113
- */
114
40
  get fullLength(): number;
115
- /**
116
- * Get perimeter.
117
- */
118
41
  get perimeter(): number;
119
- /**
120
- * Get polygon area
121
- */
122
42
  get area(): number;
123
- /**
124
- * Get deintesected polygon.
125
- */
126
43
  get deintersection(): DPolygon;
127
- /**
128
- * Check if polygon contain more than three points
129
- */
130
44
  get valid(): boolean;
131
- /**
132
- * Get first point
133
- */
134
45
  get first(): DPoint;
135
- /**
136
- * Get second point
137
- */
138
46
  get second(): DPoint;
139
- /**
140
- * Get last point
141
- */
142
47
  get last(): DPoint;
143
- /**
144
- * Get min area rectangle
145
- */
146
48
  get minAreaRectangle(): DPolygon;
147
- /**
148
- * Get convex polygon
149
- */
150
49
  get convex(): DPolygon;
151
- /**
152
- * Check polygon direction
153
- */
154
50
  get isClockwise(): boolean;
155
- /**
156
- * Get clockwise polygon
157
- */
158
51
  get clockWise(): DPolygon;
159
- /**
160
- * Get polygon clone without holes
161
- */
162
52
  get noHoles(): DPolygon;
163
- /**
164
- * Check polygon intersection with line
165
- * @param l
166
- * @param [includeOnly=false]
167
- */
168
53
  intersection(l: DLine, includeOnly?: boolean): DPoint[];
169
- /**
170
- * Set polygon center
171
- * @param newCenter
172
- */
173
54
  setCenter(newCenter: DPoint): DPolygon;
174
55
  static WKT_LINESTRING: string;
175
56
  static WKT_POLYGON: string;
176
- /**
177
- * @param [type = DPolygon.WKT_POLYGON] Available values `DPolygon.WKT_POLYGON`, `DPolygon.WKT_LINESTRING`
178
- */
179
- toWKT(type?: string): string;
180
- /**
181
- * Filter points
182
- * @param f
183
- */
57
+ toWKT(type?: string, withZ?: boolean): string;
184
58
  filter(f: (p: DPoint) => boolean): DPolygon;
185
59
  map(f: (r: DPoint) => DPoint): DPolygon;
186
60
  map(f: (r: DPoint, index: number) => DPoint): DPolygon;
@@ -192,129 +66,45 @@ export declare class DPolygon {
192
66
  reverse(): DPolygon;
193
67
  getValue(): string;
194
68
  toString(): string;
195
- /**
196
- * Add to the end of polygon point equal to first point if it not exist
197
- */
198
69
  close(): DPolygon;
199
- /**
200
- * Remove from the end of polygon point equal to first point if it exist
201
- */
202
70
  open(): DPolygon;
203
71
  add(poly: DPolygon): DPolygon;
204
- /**
205
- * Check if has point in list of points
206
- * @param p
207
- */
208
72
  has(p: DPoint): boolean;
209
73
  clone(): DPolygon;
210
- /**
211
- * Check is it fully equal.
212
- * @param p
213
- */
214
74
  equal(p: DPolygon | null): boolean;
215
- /**
216
- * Check is polygons are same. They can be with different directions and different start points.
217
- * @param p
218
- */
219
75
  same(p: DPolygon): boolean;
220
76
  findIndex(p: DPoint): number;
221
- /**
222
- * Get polygon approximation by
223
- * [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)
224
- * @param [e=Math.sqrt(this.perimeter)*APPROXIMATION_VALUE]
225
- */
226
77
  approximation(e?: number): DPolygon;
227
78
  insertAfter(index: number, ...points: DPoint[]): void;
228
79
  removePart(index: number, count: number): DPoint[];
229
- /**
230
- * Check intersection with other polygon
231
- * @param p
232
- */
233
80
  hasSimpleIntersection(p: DPolygon): boolean;
234
- /**
235
- * Check if it possible to include point
236
- * @param p
237
- */
238
81
  simpleInclude(p: DPoint): boolean;
239
82
  drawPolygonOnCanvas(canvas: HTMLCanvasElement | OffscreenCanvas, fillColor?: string, strokeColor?: string, shadowColor?: string, lineWidth?: number, steps?: number): void;
240
83
  clearPolygonOnCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): void;
241
- /**
242
- * Check if contain point
243
- * @param p
244
- * @param [isBorderInside=false]
245
- * @param [move=(0,0)] Ignore this parameter
246
- */
247
- contain(p: DPoint, isBorderInside?: boolean, move?: DPoint): boolean;
248
- /**
249
- * Check if point on border
250
- * @param p
251
- */
84
+ contain(p: DPoint, isBorderInside?: boolean): boolean;
252
85
  onBorder(p: DPoint): boolean;
253
- /**
254
- * Change start point to second point
255
- */
256
86
  nextStart(): DPolygon;
257
- /**
258
- * Remove duplicates points
259
- */
260
87
  removeDuplicates(): DPolygon;
261
- /**
262
- * Parse from [OpenLayers](https://openlayers.org/) coordinates
263
- * @param a
264
- */
265
88
  static parse(a: LatLng[]): DPolygon;
266
- /**
267
- * Parse from [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) coordinates
268
- * @param a
269
- */
270
89
  static parse(a: number[][]): DPolygon;
271
- /**
272
- * Parse from [OpenLayers](https://openlayers.org/) coordinates
273
- * @param a
274
- */
275
90
  static parse(a: DCoord[]): DPolygon;
276
- /**
277
- * Transform to array of coordinates for [OpenLayers](https://openlayers.org/) or
278
- * [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON)
279
- */
280
91
  toArrayOfCoords(): DCoord[];
281
- /**
282
- * Divide line string to pieces by length
283
- * @param piecesCount
284
- */
285
92
  divideToPieces(piecesCount: number): DPolygon;
286
93
  prepareToFastSearch(): void;
287
94
  fastHas({ x, y, z }: DPoint): boolean;
288
- /**
289
- * Get line string as line string with growing length. For animation.
290
- */
291
95
  get growingPiecesGenerator(): () => Generator<DPolygon, DPolygon>;
292
96
  simpleUnion(p: DPolygon): DPolygon | null;
293
97
  simpleIntersection(p: DPolygon): DPolygon | null | DPolygon[];
294
98
  simpleDifference(p: DPolygon): DPolygon | null | DPolygon[];
295
99
  smartUnion(p: DPolygon): DPolygon | null;
296
- /**
297
- * Divide polygon to triangles
298
- *
299
- * ![Example](https://edejin.github.io/DGeoUtils/media/examples/toTriangles.png)
300
- */
301
100
  toTriangles(): DPolygon[];
302
- /**
303
- * Divide polygon to triangles and return points indexes
304
- */
305
101
  getTrianglesPointIndexes(): number[];
306
102
  get closed(): boolean;
307
- /**
308
- * @param v
309
- * @param [quadrantSegments=64]
310
- * @param [type=DPolygon.CAP_ROUND] DPolygon.CAP_ROUND || DPolygon.CAP_FLAT || DPolygon.CAP_SQUARE
311
- */
312
103
  buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
313
104
  private simpleIncludeX;
314
105
  private simpleIncludeY;
315
106
  private douglasPeucker;
316
107
  private goByPath;
317
- private contain2;
318
108
  private getJSTSGeometry;
319
109
  private simpleLogicFunction;
320
110
  }