dgeoutils 2.2.15 → 2.2.19

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/DLine.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DLine = void 0;
4
4
  const DPoint_1 = require("./DPoint");
5
5
  const utils_1 = require("./utils");
6
+ const DNumbers_1 = require("./DNumbers");
6
7
  class DLine {
7
8
  constructor(a, b, c, begin = DPoint_1.DPoint.zero(), end = DPoint_1.DPoint.zero()) {
8
9
  this.a = a;
@@ -221,19 +222,15 @@ class DLine {
221
222
  }
222
223
  movePoint(p, d) {
223
224
  const fi = this.findFi(new DLine(1, 0, 0));
224
- const td = this.begin.distance(this.end) / 2;
225
- const dcosT = td * Math.cos(fi);
226
- const dsinT = td * Math.sin(fi);
227
- const p1T = new DPoint_1.DPoint(p.x - dsinT, p.y - dcosT);
228
- const p2T = new DPoint_1.DPoint(p.x + dsinT, p.y + dcosT);
229
- const dcos = d * Math.cos(fi);
230
- const dsin = d * Math.sin(fi);
231
- const p2 = new DPoint_1.DPoint(p.x + dsin, p.y + dcos);
232
- const p3 = new DPoint_1.DPoint(p.x - dsin, p.y + dcos);
233
- if (this.inRange(p1T) || this.inRange(p2T)) {
234
- return p2;
235
- }
236
- return p3;
225
+ const td = this.x(new DPoint_1.DPoint(1, 1)).distance(this.x(new DPoint_1.DPoint(2, 2))) / 2;
226
+ const sinCos = new DPoint_1.DPoint(Math.sin(fi), Math.cos(fi));
227
+ const dt = sinCos.clone().scale(td);
228
+ const p1T = p.clone().move(dt.clone().minus());
229
+ const p2T = p.clone().move(dt);
230
+ if (DNumbers_1.DNumbers.like(this.y(p1T).y, p1T.y) || DNumbers_1.DNumbers.like(this.y(p2T).y, p2T.y)) {
231
+ return p.clone().move(sinCos.scale(d));
232
+ }
233
+ return p.clone().move(sinCos.scale(d).setX(({ x }) => -x));
237
234
  }
238
235
  findFi({ a, b }, delta = 1.0001) {
239
236
  const { a: q, b: w } = this;
package/dist/DPoint.d.ts CHANGED
@@ -102,5 +102,5 @@ export declare class DPoint {
102
102
  setIfLessThan(p: DPoint): DPoint;
103
103
  minus(): DPoint;
104
104
  orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
105
- findCloserPoint(p: DPolygon): DPoint;
105
+ sortByDistance(p: DPolygon): DPolygon;
106
106
  }
package/dist/DPoint.js CHANGED
@@ -462,17 +462,15 @@ class DPoint {
462
462
  return new DPoint(x, y).radiansToDegrees();
463
463
  }));
464
464
  }
465
- findCloserPoint(p) {
466
- let d = Infinity;
467
- let res = DPoint.zero();
468
- for (const t of p.points) {
469
- const td = this.distance(t);
470
- if (td < d) {
471
- d = td;
472
- res = t.clone();
473
- }
474
- }
475
- return res;
465
+ sortByDistance(p) {
466
+ return p
467
+ .clone()
468
+ .map((d, index) => {
469
+ d.properties.distance = d.distance(this);
470
+ d.properties.index = index;
471
+ return d;
472
+ })
473
+ .sort((a, b) => a.properties.distance - b.properties.distance);
476
474
  }
477
475
  }
478
476
  exports.DPoint = DPoint;
@@ -58,6 +58,7 @@ export declare class DPolygon {
58
58
  filter(f: (p: DPoint) => boolean): DPolygon;
59
59
  map(f: (r: DPoint) => DPoint): DPolygon;
60
60
  map(f: (r: DPoint, index: number) => DPoint): DPolygon;
61
+ sort(f: (a: DPoint, b: DPoint) => number): DPolygon;
61
62
  at(index: number): DPoint;
62
63
  pop(): DPoint;
63
64
  push(...args: DPoint[]): number;
@@ -102,6 +103,7 @@ export declare class DPolygon {
102
103
  get closed(): boolean;
103
104
  buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
104
105
  bezier(step?: number): DPolygon;
106
+ setGrowingHeight(from: number, to: number): DPolygon;
105
107
  private getBezierPoint;
106
108
  private simpleIncludeX;
107
109
  private simpleIncludeY;
package/dist/DPolygon.js CHANGED
@@ -7,6 +7,7 @@ const DCircle_1 = require("./DCircle");
7
7
  const DNumbers_1 = require("./DNumbers");
8
8
  const jsts_1 = require("jsts");
9
9
  const DPolygonLoop_1 = require("./DPolygonLoop");
10
+ const utils_1 = require("./utils");
10
11
  const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = jsts_1.operation;
11
12
  exports.MIN_POINTS_IN_VALID_POLYGON = 3;
12
13
  const APPROXIMATION_VALUE = 0.1;
@@ -19,11 +20,11 @@ class DPolygon {
19
20
  this.holes = [];
20
21
  this.searchStore = {};
21
22
  }
22
- static arrayOfTrianglesToVertices(triangles, height = 0) {
23
- return triangles.map((v) => v
23
+ static arrayOfTrianglesToVertices(triangles, height) {
24
+ return triangles.map((v) => ((0, utils_1.isDefAndNotNull)(height) ? v
24
25
  .loop()
25
26
  .height(height)
26
- .run()
27
+ .run() : v)
27
28
  .toArrayOfCoords())
28
29
  .flat(2);
29
30
  }
@@ -348,6 +349,10 @@ class DPolygon {
348
349
  this.holes = this.holes.map((h) => h.map(f));
349
350
  return this;
350
351
  }
352
+ sort(f) {
353
+ this.points.sort(f);
354
+ return this;
355
+ }
351
356
  at(index) {
352
357
  const { length } = this;
353
358
  return this.points[(index % length + length) % length];
@@ -814,6 +819,20 @@ class DPolygon {
814
819
  }
815
820
  return res;
816
821
  }
822
+ setGrowingHeight(from, to) {
823
+ const { fullLength } = this;
824
+ let { first: prevPoint } = this;
825
+ const d = to - from;
826
+ let currentDistance = 0;
827
+ this.loop()
828
+ .setZ((p) => {
829
+ currentDistance += prevPoint.distance(p);
830
+ prevPoint = p;
831
+ return from + currentDistance / fullLength * d;
832
+ })
833
+ .run();
834
+ return this;
835
+ }
817
836
  getBezierPoint(v) {
818
837
  if (this.length === 1) {
819
838
  return this.first;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgeoutils",
3
- "version": "2.2.15",
3
+ "version": "2.2.19",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "node_modules/.bin/tsc",