geometrix 0.5.34 → 0.5.36
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/README.md +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +63 -18
- package/package.json +29 -27
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -292,6 +292,7 @@ declare abstract class AContour {
|
|
|
292
292
|
abstract toSvg(yCeiling: number, color?: string): string;
|
|
293
293
|
abstract toDxfSeg(): DxfSeg[];
|
|
294
294
|
abstract toPax(): tPaxContour;
|
|
295
|
+
abstract getPerimeter(): number;
|
|
295
296
|
}
|
|
296
297
|
/**
|
|
297
298
|
* class `Contour`
|
|
@@ -357,6 +358,7 @@ declare class Contour extends AContour {
|
|
|
357
358
|
toSvg(yCeiling: number, color?: string): string;
|
|
358
359
|
toDxfSeg(): DxfSeg[];
|
|
359
360
|
toPax(): tPaxContourPath;
|
|
361
|
+
getPerimeter(): number;
|
|
360
362
|
}
|
|
361
363
|
/**
|
|
362
364
|
* class `ContourCircle`
|
|
@@ -383,6 +385,7 @@ declare class ContourCircle extends AContour {
|
|
|
383
385
|
toSvg(yCeiling: number, color?: string): string;
|
|
384
386
|
toDxfSeg(): DxfSeg[];
|
|
385
387
|
toPax(): tPaxContourCircle;
|
|
388
|
+
getPerimeter(): number;
|
|
386
389
|
}
|
|
387
390
|
declare function contour(ix: number, iy: number, icolor?: string): Contour;
|
|
388
391
|
declare function contourCircle(ix: number, iy: number, iRadius: number, icolor?: string): ContourCircle;
|
|
@@ -580,10 +583,11 @@ declare enum EFormat {
|
|
|
580
583
|
eSVGALL = 1,
|
|
581
584
|
eDXF = 2,
|
|
582
585
|
eDXFALL = 3,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
586
|
+
eTXTLOG = 4,
|
|
587
|
+
ePAX = 5,
|
|
588
|
+
eOPENSCAD = 6,
|
|
589
|
+
eJSCAD = 7,
|
|
590
|
+
eZIP = 8
|
|
587
591
|
}
|
|
588
592
|
declare function fileTextContent(fgeom: tGeomFunc, paramVal: tParamVal, ipDef: tParamDef, eFace: string, exportFormat: EFormat): string;
|
|
589
593
|
declare function fileBinContent(fgeom: tGeomFunc, tSim: number, paramVal: tParamVal, ipDef: tParamDef, exportFormat: EFormat): Promise<Blob>;
|
package/dist/index.js
CHANGED
|
@@ -2327,6 +2327,34 @@ var Contour = class _Contour extends AContour {
|
|
|
2327
2327
|
const rPaxC = pPath.toJson();
|
|
2328
2328
|
return rPaxC;
|
|
2329
2329
|
}
|
|
2330
|
+
getPerimeter() {
|
|
2331
|
+
let rPerimeter = 0;
|
|
2332
|
+
const ctrG = this.generateContour();
|
|
2333
|
+
let plx = 0;
|
|
2334
|
+
let ply = 0;
|
|
2335
|
+
for (const seg of ctrG.segments) {
|
|
2336
|
+
if (seg.sType === 6 /* eStart */) {
|
|
2337
|
+
plx = seg.px;
|
|
2338
|
+
ply = seg.py;
|
|
2339
|
+
} else if (seg.sType === 0 /* eStroke */) {
|
|
2340
|
+
const segLen = Math.sqrt((seg.px - plx) ** 2 + (seg.py - ply) ** 2);
|
|
2341
|
+
plx = seg.px;
|
|
2342
|
+
ply = seg.py;
|
|
2343
|
+
rPerimeter += segLen;
|
|
2344
|
+
} else if (seg.sType === 1 /* eArc */) {
|
|
2345
|
+
const seg2 = arcSeg1To2(plx, ply, seg);
|
|
2346
|
+
const daCcw = withinZero2Pi(seg2.a2 - seg2.a1);
|
|
2347
|
+
const da = seg2.arcCcw ? daCcw : withinZero2Pi(2 * Math.PI - daCcw);
|
|
2348
|
+
const segLen = seg.radius * da;
|
|
2349
|
+
plx = seg.px;
|
|
2350
|
+
ply = seg.py;
|
|
2351
|
+
rPerimeter += segLen;
|
|
2352
|
+
} else {
|
|
2353
|
+
console.log(`err760: contour.getPerimeter has unknown segment type ${seg.sType}`);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
return rPerimeter;
|
|
2357
|
+
}
|
|
2330
2358
|
};
|
|
2331
2359
|
var ContourCircle = class _ContourCircle extends AContour {
|
|
2332
2360
|
circle = true;
|
|
@@ -2408,6 +2436,10 @@ var ContourCircle = class _ContourCircle extends AContour {
|
|
|
2408
2436
|
const rPaxC = paxCircle(this.px, this.py, this.radius);
|
|
2409
2437
|
return rPaxC;
|
|
2410
2438
|
}
|
|
2439
|
+
getPerimeter() {
|
|
2440
|
+
const rPerimeter = 2 * Math.PI * this.radius;
|
|
2441
|
+
return rPerimeter;
|
|
2442
|
+
}
|
|
2411
2443
|
};
|
|
2412
2444
|
function contour(ix, iy, icolor = "") {
|
|
2413
2445
|
return new Contour(ix, iy, icolor);
|
|
@@ -3690,6 +3722,11 @@ function figureToDxf(aCtr) {
|
|
|
3690
3722
|
const rDxf = dxf.stringify();
|
|
3691
3723
|
return rDxf;
|
|
3692
3724
|
}
|
|
3725
|
+
function makeLog(geome0) {
|
|
3726
|
+
let rStr = "";
|
|
3727
|
+
rStr += geome0.logstr;
|
|
3728
|
+
return rStr;
|
|
3729
|
+
}
|
|
3693
3730
|
function makePax(paramVal, geome0, ipDef) {
|
|
3694
3731
|
const rStr = paxWrite().getPaxStr(paramVal, geome0, ipDef);
|
|
3695
3732
|
return rStr;
|
|
@@ -3750,10 +3787,11 @@ var EFormat = /* @__PURE__ */ ((EFormat2) => {
|
|
|
3750
3787
|
EFormat2[EFormat2["eSVGALL"] = 1] = "eSVGALL";
|
|
3751
3788
|
EFormat2[EFormat2["eDXF"] = 2] = "eDXF";
|
|
3752
3789
|
EFormat2[EFormat2["eDXFALL"] = 3] = "eDXFALL";
|
|
3753
|
-
EFormat2[EFormat2["
|
|
3754
|
-
EFormat2[EFormat2["
|
|
3755
|
-
EFormat2[EFormat2["
|
|
3756
|
-
EFormat2[EFormat2["
|
|
3790
|
+
EFormat2[EFormat2["eTXTLOG"] = 4] = "eTXTLOG";
|
|
3791
|
+
EFormat2[EFormat2["ePAX"] = 5] = "ePAX";
|
|
3792
|
+
EFormat2[EFormat2["eOPENSCAD"] = 6] = "eOPENSCAD";
|
|
3793
|
+
EFormat2[EFormat2["eJSCAD"] = 7] = "eJSCAD";
|
|
3794
|
+
EFormat2[EFormat2["eZIP"] = 8] = "eZIP";
|
|
3757
3795
|
return EFormat2;
|
|
3758
3796
|
})(EFormat || {});
|
|
3759
3797
|
function fileTextContent(fgeom, paramVal, ipDef, eFace, exportFormat) {
|
|
@@ -3781,11 +3819,13 @@ function fileTextContent(fgeom, paramVal, ipDef, eFace, exportFormat) {
|
|
|
3781
3819
|
} else if (exportFormat === 3 /* eDXFALL */) {
|
|
3782
3820
|
const figu = mergeFaces(geome0.fig);
|
|
3783
3821
|
rFileContent = figureToDxf(figu.mainList);
|
|
3784
|
-
} else if (exportFormat === 4 /*
|
|
3822
|
+
} else if (exportFormat === 4 /* eTXTLOG */) {
|
|
3823
|
+
rFileContent = makeLog(geome0);
|
|
3824
|
+
} else if (exportFormat === 5 /* ePAX */) {
|
|
3785
3825
|
rFileContent = makePax(paramVal, geome0, ipDef);
|
|
3786
|
-
} else if (exportFormat ===
|
|
3826
|
+
} else if (exportFormat === 6 /* eOPENSCAD */) {
|
|
3787
3827
|
rFileContent = makeOpenscad(geome0);
|
|
3788
|
-
} else if (exportFormat ===
|
|
3828
|
+
} else if (exportFormat === 7 /* eJSCAD */) {
|
|
3789
3829
|
rFileContent = makeOpenjscad(geome0);
|
|
3790
3830
|
} else {
|
|
3791
3831
|
console.log(`err912: unknown exportFormat ${exportFormat}`);
|
|
@@ -3800,7 +3840,7 @@ async function fileBinContent(fgeom, tSim, paramVal, ipDef, exportFormat) {
|
|
|
3800
3840
|
const geome1 = fgeom(tSim, paramVal);
|
|
3801
3841
|
let rFileContent = new Blob();
|
|
3802
3842
|
if (!geome0.calcErr && !geome1.calcErr) {
|
|
3803
|
-
if (exportFormat ===
|
|
3843
|
+
if (exportFormat === 8 /* eZIP */) {
|
|
3804
3844
|
rFileContent = await makeZip(paramVal, geome0, tSim, geome1, ipDef);
|
|
3805
3845
|
} else {
|
|
3806
3846
|
console.log(`err913: unknown exportFormat ${exportFormat}`);
|
|
@@ -3816,13 +3856,15 @@ function fileMime(exportFormat) {
|
|
|
3816
3856
|
rMime = "image/svg+xml";
|
|
3817
3857
|
} else if (exportFormat === 2 /* eDXF */ || exportFormat === 3 /* eDXFALL */) {
|
|
3818
3858
|
rMime = "application/dxf";
|
|
3819
|
-
} else if (exportFormat === 4 /*
|
|
3859
|
+
} else if (exportFormat === 4 /* eTXTLOG */) {
|
|
3860
|
+
rMime = "text/plain";
|
|
3861
|
+
} else if (exportFormat === 5 /* ePAX */) {
|
|
3820
3862
|
rMime = "application/json";
|
|
3821
|
-
} else if (exportFormat ===
|
|
3863
|
+
} else if (exportFormat === 6 /* eOPENSCAD */) {
|
|
3822
3864
|
rMime = "text/plain";
|
|
3823
|
-
} else if (exportFormat ===
|
|
3865
|
+
} else if (exportFormat === 7 /* eJSCAD */) {
|
|
3824
3866
|
rMime = "text/plain";
|
|
3825
|
-
} else if (exportFormat ===
|
|
3867
|
+
} else if (exportFormat === 8 /* eZIP */) {
|
|
3826
3868
|
rMime = "application/zip";
|
|
3827
3869
|
}
|
|
3828
3870
|
return rMime;
|
|
@@ -3833,26 +3875,29 @@ function fileSuffix(exportFormat) {
|
|
|
3833
3875
|
rSuffix = ".svg";
|
|
3834
3876
|
} else if (exportFormat === 2 /* eDXF */ || exportFormat === 3 /* eDXFALL */) {
|
|
3835
3877
|
rSuffix = ".dxf";
|
|
3836
|
-
} else if (exportFormat === 4 /*
|
|
3878
|
+
} else if (exportFormat === 4 /* eTXTLOG */) {
|
|
3879
|
+
rSuffix = ".log";
|
|
3880
|
+
} else if (exportFormat === 5 /* ePAX */) {
|
|
3837
3881
|
rSuffix = ".pax.json";
|
|
3838
|
-
} else if (exportFormat ===
|
|
3882
|
+
} else if (exportFormat === 6 /* eOPENSCAD */) {
|
|
3839
3883
|
rSuffix = "_noarc_openscad.scad";
|
|
3840
|
-
} else if (exportFormat ===
|
|
3884
|
+
} else if (exportFormat === 7 /* eJSCAD */) {
|
|
3841
3885
|
rSuffix = "_noarc_jscad.js";
|
|
3842
|
-
} else if (exportFormat ===
|
|
3886
|
+
} else if (exportFormat === 8 /* eZIP */) {
|
|
3843
3887
|
rSuffix = ".zip";
|
|
3844
3888
|
}
|
|
3845
3889
|
return rSuffix;
|
|
3846
3890
|
}
|
|
3847
3891
|
function fileBin(exportFormat) {
|
|
3848
3892
|
let rBin = false;
|
|
3849
|
-
if (exportFormat ===
|
|
3893
|
+
if (exportFormat === 8 /* eZIP */) {
|
|
3850
3894
|
rBin = true;
|
|
3851
3895
|
}
|
|
3852
3896
|
return rBin;
|
|
3853
3897
|
}
|
|
3854
3898
|
|
|
3855
3899
|
// src/paramFile.ts
|
|
3900
|
+
import JSON5 from "json5";
|
|
3856
3901
|
function createParamFile(lastModif, iPartName, idparams, comment) {
|
|
3857
3902
|
const allVal = {
|
|
3858
3903
|
lastModif,
|
|
@@ -3864,7 +3909,7 @@ function createParamFile(lastModif, iPartName, idparams, comment) {
|
|
|
3864
3909
|
return fContentStr;
|
|
3865
3910
|
}
|
|
3866
3911
|
function parseParamFile(fContentStr) {
|
|
3867
|
-
const wholeJson =
|
|
3912
|
+
const wholeJson = JSON5.parse(fContentStr);
|
|
3868
3913
|
const lastModifKey = "lastModif";
|
|
3869
3914
|
const partNameKey = "partName";
|
|
3870
3915
|
const pValKey = "pVal";
|
package/package.json
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geometrix",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.36",
|
|
4
4
|
"description": "The 2D geometry engine of the parametrix",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"private": false,
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"default": "./dist/index.js"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"dist",
|
|
15
|
-
"!dist/**/*.map",
|
|
16
|
-
"!dist/**/*.test.*",
|
|
17
|
-
"!dist/**/*.spec.*"
|
|
18
|
-
],
|
|
19
6
|
"repository": {
|
|
20
7
|
"type": "git",
|
|
21
8
|
"url": "git+https://github.com/charlyoleg2/parametrix.git"
|
|
22
9
|
},
|
|
23
10
|
"homepage": "https://charlyoleg2.github.io/parametrix/",
|
|
11
|
+
"author": "charlyoleg",
|
|
12
|
+
"license": "ISC",
|
|
24
13
|
"keywords": [
|
|
25
14
|
"cad",
|
|
26
15
|
"programmatic",
|
|
@@ -30,7 +19,19 @@
|
|
|
30
19
|
"arc",
|
|
31
20
|
"gear"
|
|
32
21
|
],
|
|
33
|
-
"
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"!dist/**/*.map",
|
|
32
|
+
"!dist/**/*.test.*",
|
|
33
|
+
"!dist/**/*.spec.*"
|
|
34
|
+
],
|
|
34
35
|
"tsup": {
|
|
35
36
|
"entry": [
|
|
36
37
|
"src/index.ts"
|
|
@@ -41,6 +42,14 @@
|
|
|
41
42
|
"sourcemap": true,
|
|
42
43
|
"clean": true
|
|
43
44
|
},
|
|
45
|
+
"prettier": {
|
|
46
|
+
"useTabs": true,
|
|
47
|
+
"singleQuote": true,
|
|
48
|
+
"trailingComma": "none",
|
|
49
|
+
"printWidth": 100,
|
|
50
|
+
"plugins": [],
|
|
51
|
+
"overrides": []
|
|
52
|
+
},
|
|
44
53
|
"scripts": {
|
|
45
54
|
"dev": "tsup --watch",
|
|
46
55
|
"build": "tsup",
|
|
@@ -54,10 +63,11 @@
|
|
|
54
63
|
"clean": "shx rm -fr dist node_modules"
|
|
55
64
|
},
|
|
56
65
|
"dependencies": {
|
|
57
|
-
"@zip.js/zip.js": "^2.7.
|
|
66
|
+
"@zip.js/zip.js": "^2.7.44",
|
|
67
|
+
"json5": "^2.2.3"
|
|
58
68
|
},
|
|
59
69
|
"devDependencies": {
|
|
60
|
-
"@types/node": "^20.12.
|
|
70
|
+
"@types/node": "^20.12.10",
|
|
61
71
|
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
62
72
|
"@typescript-eslint/parser": "^7.0.1",
|
|
63
73
|
"eslint": "^8.57.0",
|
|
@@ -66,15 +76,7 @@
|
|
|
66
76
|
"prettier": "^3.2.5",
|
|
67
77
|
"shx": "^0.3.4",
|
|
68
78
|
"tsup": "^8.0.2",
|
|
69
|
-
"typescript": "^5.4.
|
|
70
|
-
"vitest": "^1.
|
|
71
|
-
},
|
|
72
|
-
"prettier": {
|
|
73
|
-
"useTabs": true,
|
|
74
|
-
"singleQuote": true,
|
|
75
|
-
"trailingComma": "none",
|
|
76
|
-
"printWidth": 100,
|
|
77
|
-
"plugins": [],
|
|
78
|
-
"overrides": []
|
|
79
|
+
"typescript": "^5.4.5",
|
|
80
|
+
"vitest": "^1.6.0"
|
|
79
81
|
}
|
|
80
82
|
}
|