geometrix 0.5.43 → 0.5.44
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/index.d.ts +2 -2
- package/dist/index.js +92 -65
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -430,12 +430,12 @@ declare class Figure {
|
|
|
430
430
|
addLines(ilines: Line[]): void;
|
|
431
431
|
addVector(ivector: Vector): void;
|
|
432
432
|
/**
|
|
433
|
-
* add one Outer contour and several Inner contours to the Main Layer
|
|
433
|
+
* add one face (one Outer contour and several Inner contours) to the Main Layer
|
|
434
434
|
* @param {tOuterInner} iFace - the Face (i.e one Outer and several Inner contours) to be added
|
|
435
435
|
*/
|
|
436
436
|
addMainOI(iFace: tOuterInner): void;
|
|
437
437
|
/**
|
|
438
|
-
* add one Outer contour to the Main Layer
|
|
438
|
+
* add a simple face (one Outer contour) to the Main Layer
|
|
439
439
|
* @param {tContour} iFace - the Face (without inner contours) to be added
|
|
440
440
|
*/
|
|
441
441
|
addMainO(iFace: tContour): void;
|
package/dist/index.js
CHANGED
|
@@ -2499,7 +2499,7 @@ var Figure = class _Figure {
|
|
|
2499
2499
|
this.vectorList.push(ivector);
|
|
2500
2500
|
}
|
|
2501
2501
|
/**
|
|
2502
|
-
* add one Outer contour and several Inner contours to the Main Layer
|
|
2502
|
+
* add one face (one Outer contour and several Inner contours) to the Main Layer
|
|
2503
2503
|
* @param {tOuterInner} iFace - the Face (i.e one Outer and several Inner contours) to be added
|
|
2504
2504
|
*/
|
|
2505
2505
|
addMainOI(iFace) {
|
|
@@ -2514,7 +2514,7 @@ var Figure = class _Figure {
|
|
|
2514
2514
|
this.mainList.push(oneFace);
|
|
2515
2515
|
}
|
|
2516
2516
|
/**
|
|
2517
|
-
* add one Outer contour to the Main Layer
|
|
2517
|
+
* add a simple face (one Outer contour) to the Main Layer
|
|
2518
2518
|
* @param {tContour} iFace - the Face (without inner contours) to be added
|
|
2519
2519
|
*/
|
|
2520
2520
|
addMainO(iFace) {
|
|
@@ -3427,8 +3427,8 @@ function oscadWrite() {
|
|
|
3427
3427
|
}
|
|
3428
3428
|
|
|
3429
3429
|
// src/write_openjscad.ts
|
|
3430
|
-
var approxMaxAngle2 = Math.PI /
|
|
3431
|
-
var approxMaxLength2 =
|
|
3430
|
+
var approxMaxAngle2 = Math.PI / 16;
|
|
3431
|
+
var approxMaxLength2 = 2;
|
|
3432
3432
|
function ojscadSegLine(p2x, p2y) {
|
|
3433
3433
|
const rSeg = [[p2x, p2y]];
|
|
3434
3434
|
return rSeg;
|
|
@@ -3437,7 +3437,7 @@ function ojscadSegArc(cx, cy, radius, aa1, aa2, arcCcw) {
|
|
|
3437
3437
|
const rSeg = arc_to_stroke(cx, cy, radius, aa1, aa2, arcCcw, approxMaxAngle2, approxMaxLength2);
|
|
3438
3438
|
return rSeg;
|
|
3439
3439
|
}
|
|
3440
|
-
function
|
|
3440
|
+
function jcSegContour(paxCtr) {
|
|
3441
3441
|
const rOjscadSeg = [];
|
|
3442
3442
|
let px1 = 0;
|
|
3443
3443
|
let py1 = 0;
|
|
@@ -3477,82 +3477,108 @@ function toOpenjscadSeg(paxCtr) {
|
|
|
3477
3477
|
}
|
|
3478
3478
|
return rOjscadSeg;
|
|
3479
3479
|
}
|
|
3480
|
-
function
|
|
3480
|
+
function jcSegCircle(cx, cy, radius) {
|
|
3481
3481
|
const rSeg = circle_to_stroke(cx, cy, radius, approxMaxAngle2, approxMaxLength2);
|
|
3482
3482
|
return rSeg;
|
|
3483
3483
|
}
|
|
3484
3484
|
function ff5(ifloat) {
|
|
3485
3485
|
return ifloat.toFixed(4);
|
|
3486
3486
|
}
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
const
|
|
3494
|
-
|
|
3495
|
-
const [px, py] = pt;
|
|
3496
|
-
pts2.push(`[ ${ff5(px)}, ${ff5(py)} ]`);
|
|
3497
|
-
}
|
|
3498
|
-
const ptStr = `[ ${pts2.join(",")} ]`;
|
|
3499
|
-
this.pts.push(ptStr);
|
|
3487
|
+
function fid(iIdx) {
|
|
3488
|
+
return iIdx.toString().padStart(3, "0");
|
|
3489
|
+
}
|
|
3490
|
+
function makeContourString(iCtr, ctrId) {
|
|
3491
|
+
const pts2 = [];
|
|
3492
|
+
for (const pt of iCtr) {
|
|
3493
|
+
const [px, py] = pt;
|
|
3494
|
+
pts2.push(`[ ${ff5(px)}, ${ff5(py)} ]`);
|
|
3500
3495
|
}
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
for (const idx of this.pts.keys()) {
|
|
3505
|
-
const aId = `ctr_${faceId}_${idx}`;
|
|
3506
|
-
rStr += `const ${aId} = polygon({ points: ${this.pts[idx]} });
|
|
3496
|
+
const ptStr = `[ ${pts2.join(",\n ")} ]`;
|
|
3497
|
+
const rStr = `const ${ctrId} = polygon({ points: ${ptStr} });
|
|
3498
|
+
|
|
3507
3499
|
`;
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3500
|
+
return rStr;
|
|
3501
|
+
}
|
|
3502
|
+
function jcFaceCircle(cx, cy, radius, ctrName) {
|
|
3503
|
+
const ctr = jcSegCircle(cx, cy, radius);
|
|
3504
|
+
const rStr = makeContourString(ctr, ctrName);
|
|
3505
|
+
return rStr;
|
|
3506
|
+
}
|
|
3507
|
+
function jcFaceContour(paxCtr, ctrName) {
|
|
3508
|
+
const ctr = jcSegContour(paxCtr);
|
|
3509
|
+
const rStr = makeContourString(ctr, ctrName);
|
|
3510
|
+
return rStr;
|
|
3511
|
+
}
|
|
3512
|
+
function jcOneFace(ctrNames, outName) {
|
|
3513
|
+
let rStr = "";
|
|
3514
|
+
const outer = ctrNames[0];
|
|
3515
|
+
const inner = ctrNames.slice(1);
|
|
3516
|
+
if (inner.length > 0) {
|
|
3517
|
+
rStr += `${outName} = subtract( ${ctrNames.join(", ")} );
|
|
3512
3518
|
`;
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
rStr += `const face_${faceId} = subtract( ${ctrList} )
|
|
3519
|
+
} else {
|
|
3520
|
+
rStr += `${outName} = ${outer};
|
|
3516
3521
|
`;
|
|
3517
|
-
}
|
|
3518
|
-
return rStr;
|
|
3519
3522
|
}
|
|
3520
|
-
|
|
3523
|
+
return rStr;
|
|
3524
|
+
}
|
|
3525
|
+
function jcOneFig(faceNames, outName) {
|
|
3526
|
+
let rStr = "";
|
|
3527
|
+
const firstFace = faceNames[0];
|
|
3528
|
+
const otherFace = faceNames.slice(1);
|
|
3529
|
+
if (otherFace.length > 0) {
|
|
3530
|
+
rStr += `${outName} = union( ${faceNames.join(", ")} );
|
|
3531
|
+
`;
|
|
3532
|
+
} else {
|
|
3533
|
+
rStr += `${outName} = ${firstFace};
|
|
3534
|
+
`;
|
|
3535
|
+
}
|
|
3536
|
+
return rStr;
|
|
3537
|
+
}
|
|
3521
3538
|
var OpenjscadWrite = class {
|
|
3522
3539
|
//constructor() {}
|
|
3523
3540
|
getHeader() {
|
|
3524
3541
|
const rStr = `// Generated by Parametrix
|
|
3525
|
-
|
|
3542
|
+
|
|
3543
|
+
const { polygon } = require('@jscad/modeling').primitives;
|
|
3526
3544
|
//const { subtract } = require('@jscad/modeling').booleans;
|
|
3527
|
-
const { union, intersect, scission, subtract } = require('@jscad/modeling').booleans
|
|
3545
|
+
//const { union, intersect, scission, subtract } = require('@jscad/modeling').booleans;
|
|
3546
|
+
const { union, intersect, subtract } = require('@jscad/modeling').booleans;
|
|
3528
3547
|
const { extrudeLinear, extrudeRotate } = require('@jscad/modeling').extrusions;
|
|
3529
|
-
const { translate, rotate } = require('@jscad/modeling').transforms
|
|
3548
|
+
const { translate, rotate } = require('@jscad/modeling').transforms;
|
|
3549
|
+
|
|
3530
3550
|
const main = () => {
|
|
3551
|
+
|
|
3531
3552
|
`;
|
|
3532
3553
|
return rStr;
|
|
3533
3554
|
}
|
|
3534
|
-
getOneFigure(aFaces,
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3555
|
+
getOneFigure(aFaces, figName) {
|
|
3556
|
+
let rStr = "";
|
|
3557
|
+
const figFaceList = [];
|
|
3558
|
+
for (const [faceIdx, paxFace] of aFaces.entries()) {
|
|
3559
|
+
const faceName = `face_${figName}_Fa${fid(faceIdx)}`;
|
|
3560
|
+
const faceCtrList = [];
|
|
3561
|
+
for (const [ctrIdx, paxCtr] of paxFace.entries()) {
|
|
3562
|
+
const subFaceName = `ctr_${faceName}_Ctr${fid(ctrIdx)}`;
|
|
3538
3563
|
if (paxCtr.circle === true) {
|
|
3539
3564
|
const paxCircle2 = paxCtr;
|
|
3540
|
-
|
|
3541
|
-
ojscadWF.addContour(ojscadSeg);
|
|
3565
|
+
rStr += jcFaceCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius, subFaceName);
|
|
3542
3566
|
} else {
|
|
3543
3567
|
const paxPath2 = paxCtr;
|
|
3544
|
-
|
|
3545
|
-
ojscadWF.addContour(ojscadSeg);
|
|
3568
|
+
rStr += jcFaceContour(paxPath2.seg, subFaceName);
|
|
3546
3569
|
}
|
|
3570
|
+
faceCtrList.push(subFaceName);
|
|
3547
3571
|
}
|
|
3572
|
+
rStr += jcOneFace(faceCtrList, faceName);
|
|
3573
|
+
figFaceList.push(faceName);
|
|
3548
3574
|
}
|
|
3549
|
-
|
|
3550
|
-
return
|
|
3575
|
+
rStr += jcOneFig(figFaceList, figName);
|
|
3576
|
+
return rStr;
|
|
3551
3577
|
}
|
|
3552
|
-
getAllFigures(
|
|
3578
|
+
getAllFigures(figs, partName) {
|
|
3553
3579
|
let rStr = "";
|
|
3554
|
-
for (const
|
|
3555
|
-
const figu = this.getOneFigure(
|
|
3580
|
+
for (const ifig in figs) {
|
|
3581
|
+
const figu = this.getOneFigure(figs[ifig], `fig_${partName}_${ifig}`);
|
|
3556
3582
|
rStr += figu;
|
|
3557
3583
|
}
|
|
3558
3584
|
return rStr;
|
|
@@ -3571,9 +3597,10 @@ const main = () => {
|
|
|
3571
3597
|
const ${extrud.outName} =
|
|
3572
3598
|
translate( [ ${extrud.translate[0]}, ${extrud.translate[1]}, ${extrud.translate[2]}, ],
|
|
3573
3599
|
rotate( [ ${extrud.rotate[0]}, ${extrud.rotate[1]}, ${extrud.rotate[2]}, ],
|
|
3574
|
-
${extrudMethod}( ${extrudOption},
|
|
3600
|
+
${extrudMethod}( ${extrudOption}, fig_${extrud.face} )
|
|
3575
3601
|
)
|
|
3576
3602
|
);
|
|
3603
|
+
|
|
3577
3604
|
`;
|
|
3578
3605
|
return rStr;
|
|
3579
3606
|
}
|
|
@@ -3660,7 +3687,7 @@ const ${inherit.outName} =
|
|
|
3660
3687
|
}
|
|
3661
3688
|
getFooter(partName) {
|
|
3662
3689
|
const rStr = `
|
|
3663
|
-
|
|
3690
|
+
return pax_${partName};
|
|
3664
3691
|
}
|
|
3665
3692
|
module.exports = { main };
|
|
3666
3693
|
`;
|
|
@@ -3683,7 +3710,7 @@ function ojscadWrite() {
|
|
|
3683
3710
|
function ff6(ifloat) {
|
|
3684
3711
|
return ifloat.toFixed(4);
|
|
3685
3712
|
}
|
|
3686
|
-
function
|
|
3713
|
+
function fid2(iIdx) {
|
|
3687
3714
|
return iIdx.toString().padStart(3, "0");
|
|
3688
3715
|
}
|
|
3689
3716
|
function fcFaceCircle(cx, cy, radius, outName) {
|
|
@@ -3707,18 +3734,18 @@ function fcFaceContour(paxCtr, outName) {
|
|
|
3707
3734
|
let sIdx = 0;
|
|
3708
3735
|
for (const [segIdx, seg] of paxCtr.entries()) {
|
|
3709
3736
|
if (seg.typ === 0 /* eStart */) {
|
|
3710
|
-
rStr += ` P${
|
|
3737
|
+
rStr += ` P${fid2(pIdx)} = App.Vector(${ff6(seg.px)}, ${ff6(seg.py)}, 0)
|
|
3711
3738
|
`;
|
|
3712
3739
|
pIdx += 1;
|
|
3713
3740
|
} else if (seg.typ === 1 /* eStroke */) {
|
|
3714
|
-
rStr += ` P${
|
|
3741
|
+
rStr += ` P${fid2(pIdx)} = App.Vector(${ff6(seg.px)}, ${ff6(seg.py)}, 0)
|
|
3715
3742
|
`;
|
|
3716
3743
|
if (segIdx < paxCtr.length - 1) {
|
|
3717
3744
|
pIdxLast = pIdx;
|
|
3718
3745
|
} else {
|
|
3719
3746
|
pIdxLast = 0;
|
|
3720
3747
|
}
|
|
3721
|
-
rStr += ` S${
|
|
3748
|
+
rStr += ` S${fid2(sIdx)} = Part.LineSegment(P${fid2(pIdx - 1)}, P${fid2(pIdxLast)})
|
|
3722
3749
|
`;
|
|
3723
3750
|
pIdx += 1;
|
|
3724
3751
|
sIdx += 1;
|
|
@@ -3726,20 +3753,20 @@ function fcFaceContour(paxCtr, outName) {
|
|
|
3726
3753
|
try {
|
|
3727
3754
|
const seg1 = convPaxToSeg1(seg);
|
|
3728
3755
|
const p4 = midArcPoint(px1, py1, seg1);
|
|
3729
|
-
rStr += ` P${
|
|
3756
|
+
rStr += ` P${fid2(pIdx)} = App.Vector(${ff6(p4.cx)}, ${ff6(p4.cy)}, 0)
|
|
3730
3757
|
`;
|
|
3731
3758
|
pIdx += 1;
|
|
3732
3759
|
} catch (emsg) {
|
|
3733
3760
|
console.log("err730: " + emsg);
|
|
3734
3761
|
}
|
|
3735
|
-
rStr += ` P${
|
|
3762
|
+
rStr += ` P${fid2(pIdx)} = App.Vector(${ff6(seg.px)}, ${ff6(seg.py)}, 0)
|
|
3736
3763
|
`;
|
|
3737
3764
|
if (segIdx < paxCtr.length - 1) {
|
|
3738
3765
|
pIdxLast = pIdx;
|
|
3739
3766
|
} else {
|
|
3740
3767
|
pIdxLast = 0;
|
|
3741
3768
|
}
|
|
3742
|
-
rStr += ` S${
|
|
3769
|
+
rStr += ` S${fid2(sIdx)} = Part.Arc(P${fid2(pIdx - 2)}, P${fid2(pIdx - 1)}, P${fid2(pIdxLast)})
|
|
3743
3770
|
`;
|
|
3744
3771
|
pIdx += 1;
|
|
3745
3772
|
sIdx += 1;
|
|
@@ -3747,7 +3774,7 @@ function fcFaceContour(paxCtr, outName) {
|
|
|
3747
3774
|
px1 = seg.px;
|
|
3748
3775
|
py1 = seg.py;
|
|
3749
3776
|
}
|
|
3750
|
-
const segList = Array.from({ length: sIdx }, (v, i) => `S${
|
|
3777
|
+
const segList = Array.from({ length: sIdx }, (v, i) => `S${fid2(i)}`);
|
|
3751
3778
|
rStr += ` aShape = Part.Shape([${segList.join(", ")}])
|
|
3752
3779
|
aWire = Part.Wire(aShape.Edges)
|
|
3753
3780
|
subFace = Part.Face(aWire)
|
|
@@ -3762,7 +3789,7 @@ function fcOneFace(ctrNames, outName) {
|
|
|
3762
3789
|
`;
|
|
3763
3790
|
const ctrShorts = [];
|
|
3764
3791
|
for (const [idx, ctr] of ctrNames.entries()) {
|
|
3765
|
-
const short = `FC${
|
|
3792
|
+
const short = `FC${fid2(idx)}`;
|
|
3766
3793
|
rStr += ` ${short} = ${ctr}()
|
|
3767
3794
|
`;
|
|
3768
3795
|
ctrShorts.push(short);
|
|
@@ -3787,7 +3814,7 @@ function fcOneFig(faceNames, outName) {
|
|
|
3787
3814
|
`;
|
|
3788
3815
|
const faceShorts = [];
|
|
3789
3816
|
for (const [idx, face] of faceNames.entries()) {
|
|
3790
|
-
const short = `FA${
|
|
3817
|
+
const short = `FA${fid2(idx)}`;
|
|
3791
3818
|
rStr += ` ${short} = ${face}()
|
|
3792
3819
|
`;
|
|
3793
3820
|
faceShorts.push(short);
|
|
@@ -3917,11 +3944,11 @@ ${extrud.outName} = fex_${extrud.outName}()
|
|
|
3917
3944
|
`;
|
|
3918
3945
|
let vidx = 0;
|
|
3919
3946
|
for (const vol of othersV) {
|
|
3920
|
-
rStr += ` V${
|
|
3947
|
+
rStr += ` V${fid2(vidx + 1)} = V${fid2(vidx)}.${combMethod}(${vol})
|
|
3921
3948
|
`;
|
|
3922
3949
|
vidx += 1;
|
|
3923
3950
|
}
|
|
3924
|
-
rStr += ` VFC = V${
|
|
3951
|
+
rStr += ` VFC = V${fid2(vidx)}.removeSplitter()
|
|
3925
3952
|
return VFC
|
|
3926
3953
|
${volum.outName} = fvol_${volum.outName}()
|
|
3927
3954
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geometrix",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.44",
|
|
4
4
|
"description": "The 2D geometry engine of the parametrix",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
"json5": "^2.2.3"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@types/node": "^20.14.
|
|
70
|
+
"@types/node": "^20.14.2",
|
|
71
71
|
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
72
72
|
"@typescript-eslint/parser": "^7.0.1",
|
|
73
73
|
"eslint": "^8.57.0",
|
|
74
74
|
"eslint-config-prettier": "^9.1.0",
|
|
75
75
|
"npm-run-all": "^4.1.5",
|
|
76
|
-
"prettier": "^3.3.
|
|
76
|
+
"prettier": "^3.3.2",
|
|
77
77
|
"shx": "^0.3.4",
|
|
78
78
|
"tsup": "^8.1.0",
|
|
79
79
|
"typescript": "^5.4.5",
|