dgeoutils 2.2.12 → 2.2.13
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 -0
- package/dist/DPoint.js +24 -4
- package/dist/DPolygon.d.ts +2 -0
- package/dist/DPolygon.js +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -1
- package/dist/utils.d.ts +10 -3
- package/dist/utils.js +36 -3
- package/package.json +1 -1
package/dist/DPoint.d.ts
CHANGED
|
@@ -70,9 +70,11 @@ export declare class DPoint {
|
|
|
70
70
|
scale(v: number): DPoint;
|
|
71
71
|
scale(p: DPoint): DPoint;
|
|
72
72
|
scale(x: number, y: number): DPoint;
|
|
73
|
+
scale(x: number, y: number, z: number): DPoint;
|
|
73
74
|
divide(v: number): DPoint;
|
|
74
75
|
divide(p: DPoint): DPoint;
|
|
75
76
|
divide(x: number, y: number): DPoint;
|
|
77
|
+
divide(x: number, y: number, z: number): DPoint;
|
|
76
78
|
equal(p: DPoint): boolean;
|
|
77
79
|
like(p: DPoint, d?: number): boolean;
|
|
78
80
|
flipVertically(size: DPoint): DPoint;
|
package/dist/DPoint.js
CHANGED
|
@@ -182,7 +182,7 @@ class DPoint {
|
|
|
182
182
|
this.y = -x * Math.sin(a) + y * Math.cos(a);
|
|
183
183
|
return this;
|
|
184
184
|
}
|
|
185
|
-
move(x, y = x, z
|
|
185
|
+
move(x, y = x, z) {
|
|
186
186
|
let xV = 0;
|
|
187
187
|
let yV = 0;
|
|
188
188
|
let zV = undefined;
|
|
@@ -278,34 +278,54 @@ class DPoint {
|
|
|
278
278
|
this.y = Math.abs(this.y);
|
|
279
279
|
return this;
|
|
280
280
|
}
|
|
281
|
-
scale(x, y = x) {
|
|
281
|
+
scale(x, y = x, z) {
|
|
282
282
|
let xV = 0;
|
|
283
283
|
let yV = 0;
|
|
284
|
+
let zV = undefined;
|
|
284
285
|
if (x instanceof DPoint) {
|
|
285
286
|
xV = this.x * x.x;
|
|
286
287
|
yV = this.y * x.y;
|
|
288
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
|
|
289
|
+
zV = this.z * x.z;
|
|
290
|
+
}
|
|
287
291
|
}
|
|
288
292
|
else {
|
|
289
293
|
xV = this.x * x;
|
|
290
294
|
yV = this.y * y;
|
|
295
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
296
|
+
zV = this.z * z;
|
|
297
|
+
}
|
|
291
298
|
}
|
|
292
299
|
this.x = xV;
|
|
293
300
|
this.y = yV;
|
|
301
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
302
|
+
this.z = zV;
|
|
303
|
+
}
|
|
294
304
|
return this;
|
|
295
305
|
}
|
|
296
|
-
divide(x, y = x) {
|
|
306
|
+
divide(x, y = x, z) {
|
|
297
307
|
let xV = 0;
|
|
298
308
|
let yV = 0;
|
|
309
|
+
let zV = undefined;
|
|
299
310
|
if (x instanceof DPoint) {
|
|
300
311
|
xV = this.x / x.x;
|
|
301
312
|
yV = this.y / x.y;
|
|
313
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(x.z)) {
|
|
314
|
+
zV = this.z / x.z;
|
|
315
|
+
}
|
|
302
316
|
}
|
|
303
317
|
else {
|
|
304
318
|
xV = this.x / x;
|
|
305
319
|
yV = this.y / y;
|
|
320
|
+
if ((0, utils_1.isDefAndNotNull)(this.z) && (0, utils_1.isDefAndNotNull)(z)) {
|
|
321
|
+
zV = this.z / z;
|
|
322
|
+
}
|
|
306
323
|
}
|
|
307
324
|
this.x = xV;
|
|
308
325
|
this.y = yV;
|
|
326
|
+
if ((0, utils_1.isDefAndNotNull)(zV)) {
|
|
327
|
+
this.z = zV;
|
|
328
|
+
}
|
|
309
329
|
return this;
|
|
310
330
|
}
|
|
311
331
|
equal(p) {
|
|
@@ -407,7 +427,7 @@ class DPoint {
|
|
|
407
427
|
return this;
|
|
408
428
|
}
|
|
409
429
|
minus() {
|
|
410
|
-
return this.
|
|
430
|
+
return this.scale(-1);
|
|
411
431
|
}
|
|
412
432
|
orthodromicPath(point, pointsCount = 360) {
|
|
413
433
|
(0, utils_1.checkFunction)('orthodromicPath')
|
package/dist/DPolygon.d.ts
CHANGED
|
@@ -101,6 +101,8 @@ export declare class DPolygon {
|
|
|
101
101
|
getTrianglesPointIndexes(): number[];
|
|
102
102
|
get closed(): boolean;
|
|
103
103
|
buffer(v: number, quadrantSegments?: number, type?: number): DPolygon;
|
|
104
|
+
bezier(step?: number): DPolygon;
|
|
105
|
+
private getBezierPoint;
|
|
104
106
|
private simpleIncludeX;
|
|
105
107
|
private simpleIncludeY;
|
|
106
108
|
private douglasPeucker;
|
package/dist/DPolygon.js
CHANGED
|
@@ -807,6 +807,26 @@ class DPolygon {
|
|
|
807
807
|
.getCoordinates();
|
|
808
808
|
return new DPolygon(points.map(({ x, y }) => new DPoint_1.DPoint(x, y)));
|
|
809
809
|
}
|
|
810
|
+
bezier(step = 0.1) {
|
|
811
|
+
const res = new DPolygon();
|
|
812
|
+
for (let i = 0; i < 1; i += step) {
|
|
813
|
+
res.push(this.clone().getBezierPoint(i));
|
|
814
|
+
}
|
|
815
|
+
return res;
|
|
816
|
+
}
|
|
817
|
+
getBezierPoint(v) {
|
|
818
|
+
if (this.length === 1) {
|
|
819
|
+
return this.first;
|
|
820
|
+
}
|
|
821
|
+
for (let i = 0; i < this.length - 1; i++) {
|
|
822
|
+
const p1 = this.at(i);
|
|
823
|
+
const p2 = this.at(i + 1);
|
|
824
|
+
p1.move(p2.clone().move(p1.clone().minus())
|
|
825
|
+
.scale(v));
|
|
826
|
+
}
|
|
827
|
+
this.pop();
|
|
828
|
+
return this.getBezierPoint(v);
|
|
829
|
+
}
|
|
810
830
|
simpleIncludeX(p) {
|
|
811
831
|
const { x } = p;
|
|
812
832
|
return this.minX <= x && this.maxX >= x;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './FastSearch';
|
|
|
7
7
|
export * from './TraceMatrix';
|
|
8
8
|
export * from './DPolygonLoop';
|
|
9
9
|
export * from './DPlane';
|
|
10
|
+
export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull } from './utils';
|
|
10
11
|
export declare const DGeo: {
|
|
11
12
|
DEBUG: boolean;
|
|
12
13
|
};
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.DGeo = void 0;
|
|
13
|
+
exports.DGeo = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
|
|
14
14
|
__exportStar(require("./DCircle"), exports);
|
|
15
15
|
__exportStar(require("./DLine"), exports);
|
|
16
16
|
__exportStar(require("./DNumbers"), exports);
|
|
@@ -20,6 +20,12 @@ __exportStar(require("./FastSearch"), exports);
|
|
|
20
20
|
__exportStar(require("./TraceMatrix"), exports);
|
|
21
21
|
__exportStar(require("./DPolygonLoop"), exports);
|
|
22
22
|
__exportStar(require("./DPlane"), exports);
|
|
23
|
+
var utils_1 = require("./utils");
|
|
24
|
+
Object.defineProperty(exports, "gaussianElimination", { enumerable: true, get: function () { return utils_1.gaussianElimination; } });
|
|
25
|
+
Object.defineProperty(exports, "createCanvas", { enumerable: true, get: function () { return utils_1.createCanvas; } });
|
|
26
|
+
Object.defineProperty(exports, "createArray", { enumerable: true, get: function () { return utils_1.createArray; } });
|
|
27
|
+
Object.defineProperty(exports, "createMatrix", { enumerable: true, get: function () { return utils_1.createMatrix; } });
|
|
28
|
+
Object.defineProperty(exports, "isDefAndNotNull", { enumerable: true, get: function () { return utils_1.isDefAndNotNull; } });
|
|
23
29
|
exports.DGeo = {
|
|
24
30
|
DEBUG: false
|
|
25
31
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="offscreencanvas" />
|
|
1
2
|
import { DPoint } from './DPoint';
|
|
2
3
|
export declare const warn: (...args: any[]) => void;
|
|
3
4
|
declare type CheckFunc = (p: DPoint) => CheckFunction;
|
|
@@ -12,8 +13,14 @@ interface CheckFunction {
|
|
|
12
13
|
checkArgument: (argName: string) => CheckArgument;
|
|
13
14
|
}
|
|
14
15
|
export declare const checkFunction: (funcName: string) => CheckFunction;
|
|
15
|
-
export declare const createArray: (v: number) => number[];
|
|
16
|
-
export declare const createMatrix: ({ h, w }: DPoint) => number[][];
|
|
16
|
+
export declare const createArray: (v: number, fillSymbol?: any) => number[];
|
|
17
|
+
export declare const createMatrix: ({ h, w }: DPoint, fillSymbol?: any) => number[][];
|
|
17
18
|
export declare const gaussianElimination: (matrix: number[][]) => number[];
|
|
18
19
|
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
19
|
-
|
|
20
|
+
declare function createCanvas(size: number): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
21
|
+
declare function createCanvas(size: number, offscreen: boolean): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
22
|
+
declare function createCanvas(w: number, h: number): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
23
|
+
declare function createCanvas(w: number, h: number, offscreen: boolean): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
24
|
+
declare function createCanvas(size: DPoint): [HTMLCanvasElement, CanvasRenderingContext2D];
|
|
25
|
+
declare function createCanvas(size: DPoint, offscreen: boolean): [OffscreenCanvas, OffscreenCanvasRenderingContext2D];
|
|
26
|
+
export { createCanvas };
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDefAndNotNull = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.warn = void 0;
|
|
3
|
+
exports.createCanvas = exports.isDefAndNotNull = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.warn = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
const DPoint_1 = require("./DPoint");
|
|
6
6
|
const warn = (...args) => {
|
|
@@ -63,9 +63,10 @@ const checkFunction = (funcName) => ({
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
exports.checkFunction = checkFunction;
|
|
66
|
-
const createArray = (v) => new Array(v).fill(
|
|
66
|
+
const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
|
|
67
67
|
exports.createArray = createArray;
|
|
68
|
-
const createMatrix = ({ h, w }
|
|
68
|
+
const createMatrix = ({ h, w }, fillSymbol = 0) => (0, exports.createArray)(h)
|
|
69
|
+
.map(() => (0, exports.createArray)(w, fillSymbol));
|
|
69
70
|
exports.createMatrix = createMatrix;
|
|
70
71
|
const GAUSSIAN_ELIMINATION_MIN = 1e-10;
|
|
71
72
|
const gaussianElimination = (matrix) => {
|
|
@@ -113,3 +114,35 @@ const gaussianElimination = (matrix) => {
|
|
|
113
114
|
exports.gaussianElimination = gaussianElimination;
|
|
114
115
|
const isDefAndNotNull = (a) => a != undefined;
|
|
115
116
|
exports.isDefAndNotNull = isDefAndNotNull;
|
|
117
|
+
function createCanvas(a, b, c) {
|
|
118
|
+
var _a;
|
|
119
|
+
let w = 0;
|
|
120
|
+
let h = 0;
|
|
121
|
+
let offscreen = false;
|
|
122
|
+
if (a instanceof DPoint_1.DPoint) {
|
|
123
|
+
const { x, y } = a;
|
|
124
|
+
w = x;
|
|
125
|
+
h = y;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
w = a;
|
|
129
|
+
h = a;
|
|
130
|
+
}
|
|
131
|
+
if (typeof b === 'boolean') {
|
|
132
|
+
offscreen = b;
|
|
133
|
+
}
|
|
134
|
+
else if (typeof b === 'number') {
|
|
135
|
+
h = b;
|
|
136
|
+
}
|
|
137
|
+
if (typeof c === 'boolean') {
|
|
138
|
+
offscreen = c;
|
|
139
|
+
}
|
|
140
|
+
const canvas = offscreen ? new OffscreenCanvas(w, h) : ((_a = createCanvas.document) !== null && _a !== void 0 ? _a : document).createElement('canvas');
|
|
141
|
+
if (!offscreen) {
|
|
142
|
+
canvas.width = w;
|
|
143
|
+
canvas.height = h;
|
|
144
|
+
}
|
|
145
|
+
const ctx = canvas.getContext('2d');
|
|
146
|
+
return [canvas, ctx];
|
|
147
|
+
}
|
|
148
|
+
exports.createCanvas = createCanvas;
|