dgeoutils 2.2.14 → 2.2.18
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.d.ts +2 -1
- package/dist/DPoint.js +24 -11
- package/dist/DPolygon.d.ts +2 -0
- package/dist/DPolygon.js +22 -3
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +13 -5
- package/package.json +1 -1
package/dist/DPoint.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare class DPoint {
|
|
|
37
37
|
height(z: number): DPoint;
|
|
38
38
|
toWKT(): string;
|
|
39
39
|
distance(p: DPoint): number;
|
|
40
|
+
distance3d(p: DPoint): number;
|
|
40
41
|
setX(x: number): DPoint;
|
|
41
42
|
setX(f: SetterFunction): DPoint;
|
|
42
43
|
setZ(z: number): DPoint;
|
|
@@ -101,5 +102,5 @@ export declare class DPoint {
|
|
|
101
102
|
setIfLessThan(p: DPoint): DPoint;
|
|
102
103
|
minus(): DPoint;
|
|
103
104
|
orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
|
|
104
|
-
|
|
105
|
+
sortByDistance(p: DPolygon): DPolygon;
|
|
105
106
|
}
|
package/dist/DPoint.js
CHANGED
|
@@ -128,6 +128,21 @@ class DPoint {
|
|
|
128
128
|
const dy = p.y - this.y;
|
|
129
129
|
return Math.sqrt(dx * dx + dy * dy);
|
|
130
130
|
}
|
|
131
|
+
distance3d(p) {
|
|
132
|
+
(0, utils_1.checkFunction)('distance3d')
|
|
133
|
+
.checkArgument('this')
|
|
134
|
+
.shouldBeMeters(this)
|
|
135
|
+
.checkArgument('p')
|
|
136
|
+
.shouldBeMeters(p)
|
|
137
|
+
.checkArgument('this.z')
|
|
138
|
+
.shouldExist(this.z)
|
|
139
|
+
.checkArgument('p.z')
|
|
140
|
+
.shouldExist(p.z);
|
|
141
|
+
const dx = p.x - this.x;
|
|
142
|
+
const dy = p.y - this.y;
|
|
143
|
+
const dz = p.z - this.z;
|
|
144
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
145
|
+
}
|
|
131
146
|
setX(x) {
|
|
132
147
|
this.x = typeof x === 'number' ? x : x(this);
|
|
133
148
|
return this;
|
|
@@ -447,17 +462,15 @@ class DPoint {
|
|
|
447
462
|
return new DPoint(x, y).radiansToDegrees();
|
|
448
463
|
}));
|
|
449
464
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
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);
|
|
461
474
|
}
|
|
462
475
|
}
|
|
463
476
|
exports.DPoint = DPoint;
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -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
|
|
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/dist/utils.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/// <reference types="offscreencanvas" />
|
|
2
2
|
import { DPoint } from './DPoint';
|
|
3
3
|
export declare const warn: (...args: any[]) => void;
|
|
4
|
+
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
4
5
|
declare type CheckFunc = (p: DPoint) => CheckFunction;
|
|
6
|
+
declare type CheckFunc2 = (p: any) => CheckFunction;
|
|
5
7
|
interface CheckArgument {
|
|
6
8
|
shouldBeDegree: CheckFunc;
|
|
7
9
|
shouldBeMeters: CheckFunc;
|
|
8
10
|
shouldBeInt: CheckFunc;
|
|
9
11
|
shouldBeUInt: CheckFunc;
|
|
10
12
|
shouldBeRadians: CheckFunc;
|
|
13
|
+
shouldExist: CheckFunc2;
|
|
11
14
|
}
|
|
12
15
|
interface CheckFunction {
|
|
13
16
|
checkArgument: (argName: string) => CheckArgument;
|
|
@@ -19,7 +22,6 @@ export declare const gaussianElimination: {
|
|
|
19
22
|
(matrix: number[][]): number[];
|
|
20
23
|
MIN: number;
|
|
21
24
|
};
|
|
22
|
-
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
23
25
|
declare type True = true;
|
|
24
26
|
export declare const createCanvas: {
|
|
25
27
|
(size: number): [HTMLCanvasElement, CanvasRenderingContext2D];
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCanvas = exports.
|
|
3
|
+
exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
const DPoint_1 = require("./DPoint");
|
|
6
6
|
const warn = (...args) => {
|
|
@@ -9,6 +9,8 @@ const warn = (...args) => {
|
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
exports.warn = warn;
|
|
12
|
+
const isDefAndNotNull = (a) => a != undefined;
|
|
13
|
+
exports.isDefAndNotNull = isDefAndNotNull;
|
|
12
14
|
const hook = (scope) => () => scope;
|
|
13
15
|
const shouldBeInt = (scope, funcName, argName) => (p) => {
|
|
14
16
|
if (!p.clone().round()
|
|
@@ -36,6 +38,12 @@ const shouldBeRadians = (scope, funcName, argName) => (p) => {
|
|
|
36
38
|
}
|
|
37
39
|
return scope;
|
|
38
40
|
};
|
|
41
|
+
const shouldExist = (scope, funcName, argName) => (p) => {
|
|
42
|
+
if (!(0, exports.isDefAndNotNull)(p)) {
|
|
43
|
+
(0, exports.warn)(`"${funcName}" -> "${argName}" should exist!`);
|
|
44
|
+
}
|
|
45
|
+
return scope;
|
|
46
|
+
};
|
|
39
47
|
const shouldBeMeters = (scope, funcName, argName) => (p) => {
|
|
40
48
|
if (!p.likePseudoMercator) {
|
|
41
49
|
(0, exports.warn)(`"${funcName}" -> "${argName}" should be meters!`);
|
|
@@ -50,7 +58,8 @@ const checkFunction = (funcName) => ({
|
|
|
50
58
|
shouldBeMeters: hook(this),
|
|
51
59
|
shouldBeInt: hook(this),
|
|
52
60
|
shouldBeUInt: hook(this),
|
|
53
|
-
shouldBeRadians: hook(this)
|
|
61
|
+
shouldBeRadians: hook(this),
|
|
62
|
+
shouldExist: hook(this)
|
|
54
63
|
};
|
|
55
64
|
}
|
|
56
65
|
return {
|
|
@@ -58,7 +67,8 @@ const checkFunction = (funcName) => ({
|
|
|
58
67
|
shouldBeMeters: shouldBeMeters(this, funcName, argName),
|
|
59
68
|
shouldBeInt: shouldBeInt(this, funcName, argName),
|
|
60
69
|
shouldBeUInt: shouldBeUInt(this, funcName, argName),
|
|
61
|
-
shouldBeRadians: shouldBeRadians(this, funcName, argName)
|
|
70
|
+
shouldBeRadians: shouldBeRadians(this, funcName, argName),
|
|
71
|
+
shouldExist: shouldExist(this, funcName, argName)
|
|
62
72
|
};
|
|
63
73
|
}
|
|
64
74
|
});
|
|
@@ -112,8 +122,6 @@ const gaussianElimination = (matrix) => {
|
|
|
112
122
|
};
|
|
113
123
|
exports.gaussianElimination = gaussianElimination;
|
|
114
124
|
exports.gaussianElimination.MIN = 1e-10;
|
|
115
|
-
const isDefAndNotNull = (a) => a != undefined;
|
|
116
|
-
exports.isDefAndNotNull = isDefAndNotNull;
|
|
117
125
|
const createCanvas = (a, b, c) => {
|
|
118
126
|
var _a;
|
|
119
127
|
let w = 0;
|