geometrix 0.5.43 → 0.5.45
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 +105 -75
- 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) {
|
|
@@ -3157,8 +3157,14 @@ function arc_to_stroke(cx, cy, radius, a1, a2, ccw, max_angle = Math.PI / 6, max
|
|
|
3157
3157
|
}
|
|
3158
3158
|
|
|
3159
3159
|
// src/write_openscad.ts
|
|
3160
|
-
var approxMaxAngle = Math.PI /
|
|
3161
|
-
var approxMaxLength =
|
|
3160
|
+
var approxMaxAngle = Math.PI / 16;
|
|
3161
|
+
var approxMaxLength = 2;
|
|
3162
|
+
function ff4(ifloat) {
|
|
3163
|
+
return ifloat.toFixed(4);
|
|
3164
|
+
}
|
|
3165
|
+
function fid(iIdx) {
|
|
3166
|
+
return iIdx.toString().padStart(3, "0");
|
|
3167
|
+
}
|
|
3162
3168
|
function oscadSegLine(p2x, p2y) {
|
|
3163
3169
|
const rSeg = [[p2x, p2y]];
|
|
3164
3170
|
return rSeg;
|
|
@@ -3211,9 +3217,6 @@ function toOpenscadSeg(paxCtr) {
|
|
|
3211
3217
|
}
|
|
3212
3218
|
return rOscadSeg;
|
|
3213
3219
|
}
|
|
3214
|
-
function ff4(ifloat) {
|
|
3215
|
-
return ifloat.toFixed(4);
|
|
3216
|
-
}
|
|
3217
3220
|
var OpenscadWriteFigure = class {
|
|
3218
3221
|
pts;
|
|
3219
3222
|
ptIdx;
|
|
@@ -3242,8 +3245,8 @@ var OpenscadWriteFigure = class {
|
|
|
3242
3245
|
const aList = [];
|
|
3243
3246
|
const bList = [];
|
|
3244
3247
|
for (const idx of this.pts.keys()) {
|
|
3245
|
-
const aId = `ca_${faceId}_${idx}`;
|
|
3246
|
-
const bId = `cb_${faceId}_${idx}`;
|
|
3248
|
+
const aId = `ca_${faceId}_${fid(idx)}`;
|
|
3249
|
+
const bId = `cb_${faceId}_${fid(idx)}`;
|
|
3247
3250
|
rStr += `${aId} = ${this.pts[idx]};
|
|
3248
3251
|
`;
|
|
3249
3252
|
rStr += `${bId} = ${this.ptIdx[idx]};
|
|
@@ -3427,8 +3430,14 @@ function oscadWrite() {
|
|
|
3427
3430
|
}
|
|
3428
3431
|
|
|
3429
3432
|
// src/write_openjscad.ts
|
|
3430
|
-
var approxMaxAngle2 = Math.PI /
|
|
3431
|
-
var approxMaxLength2 =
|
|
3433
|
+
var approxMaxAngle2 = Math.PI / 16;
|
|
3434
|
+
var approxMaxLength2 = 2;
|
|
3435
|
+
function ff5(ifloat) {
|
|
3436
|
+
return ifloat.toFixed(4);
|
|
3437
|
+
}
|
|
3438
|
+
function fid2(iIdx) {
|
|
3439
|
+
return iIdx.toString().padStart(3, "0");
|
|
3440
|
+
}
|
|
3432
3441
|
function ojscadSegLine(p2x, p2y) {
|
|
3433
3442
|
const rSeg = [[p2x, p2y]];
|
|
3434
3443
|
return rSeg;
|
|
@@ -3437,7 +3446,7 @@ function ojscadSegArc(cx, cy, radius, aa1, aa2, arcCcw) {
|
|
|
3437
3446
|
const rSeg = arc_to_stroke(cx, cy, radius, aa1, aa2, arcCcw, approxMaxAngle2, approxMaxLength2);
|
|
3438
3447
|
return rSeg;
|
|
3439
3448
|
}
|
|
3440
|
-
function
|
|
3449
|
+
function jcSegContour(paxCtr) {
|
|
3441
3450
|
const rOjscadSeg = [];
|
|
3442
3451
|
let px1 = 0;
|
|
3443
3452
|
let py1 = 0;
|
|
@@ -3477,82 +3486,102 @@ function toOpenjscadSeg(paxCtr) {
|
|
|
3477
3486
|
}
|
|
3478
3487
|
return rOjscadSeg;
|
|
3479
3488
|
}
|
|
3480
|
-
function
|
|
3489
|
+
function jcSegCircle(cx, cy, radius) {
|
|
3481
3490
|
const rSeg = circle_to_stroke(cx, cy, radius, approxMaxAngle2, approxMaxLength2);
|
|
3482
3491
|
return rSeg;
|
|
3483
3492
|
}
|
|
3484
|
-
function
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
constructor() {
|
|
3490
|
-
this.pts = [];
|
|
3491
|
-
}
|
|
3492
|
-
addContour(ictr) {
|
|
3493
|
-
const pts2 = [];
|
|
3494
|
-
for (const pt of ictr) {
|
|
3495
|
-
const [px, py] = pt;
|
|
3496
|
-
pts2.push(`[ ${ff5(px)}, ${ff5(py)} ]`);
|
|
3497
|
-
}
|
|
3498
|
-
const ptStr = `[ ${pts2.join(",")} ]`;
|
|
3499
|
-
this.pts.push(ptStr);
|
|
3493
|
+
function makeContourString(iCtr, ctrId) {
|
|
3494
|
+
const pts2 = [];
|
|
3495
|
+
for (const pt of iCtr) {
|
|
3496
|
+
const [px, py] = pt;
|
|
3497
|
+
pts2.push(`[ ${ff5(px)}, ${ff5(py)} ]`);
|
|
3500
3498
|
}
|
|
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]} });
|
|
3499
|
+
const ptStr = `[ ${pts2.join(",\n ")} ]`;
|
|
3500
|
+
const rStr = `const ${ctrId} = polygon({ points: ${ptStr} });
|
|
3501
|
+
|
|
3507
3502
|
`;
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3503
|
+
return rStr;
|
|
3504
|
+
}
|
|
3505
|
+
function jcFaceCircle(cx, cy, radius, ctrName) {
|
|
3506
|
+
const ctr = jcSegCircle(cx, cy, radius);
|
|
3507
|
+
const rStr = makeContourString(ctr, ctrName);
|
|
3508
|
+
return rStr;
|
|
3509
|
+
}
|
|
3510
|
+
function jcFaceContour(paxCtr, ctrName) {
|
|
3511
|
+
const ctr = jcSegContour(paxCtr);
|
|
3512
|
+
const rStr = makeContourString(ctr, ctrName);
|
|
3513
|
+
return rStr;
|
|
3514
|
+
}
|
|
3515
|
+
function jcOneFace(ctrNames, outName) {
|
|
3516
|
+
let rStr = "";
|
|
3517
|
+
const outer = ctrNames[0];
|
|
3518
|
+
const inner = ctrNames.slice(1);
|
|
3519
|
+
if (inner.length > 0) {
|
|
3520
|
+
rStr += `${outName} = subtract( ${ctrNames.join(", ")} );
|
|
3512
3521
|
`;
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
rStr += `const face_${faceId} = subtract( ${ctrList} )
|
|
3522
|
+
} else {
|
|
3523
|
+
rStr += `${outName} = ${outer};
|
|
3516
3524
|
`;
|
|
3517
|
-
}
|
|
3518
|
-
return rStr;
|
|
3519
3525
|
}
|
|
3520
|
-
|
|
3526
|
+
return rStr;
|
|
3527
|
+
}
|
|
3528
|
+
function jcOneFig(faceNames, outName) {
|
|
3529
|
+
let rStr = "";
|
|
3530
|
+
const firstFace = faceNames[0];
|
|
3531
|
+
const otherFace = faceNames.slice(1);
|
|
3532
|
+
if (otherFace.length > 0) {
|
|
3533
|
+
rStr += `${outName} = union( ${faceNames.join(", ")} );
|
|
3534
|
+
`;
|
|
3535
|
+
} else {
|
|
3536
|
+
rStr += `${outName} = ${firstFace};
|
|
3537
|
+
`;
|
|
3538
|
+
}
|
|
3539
|
+
return rStr;
|
|
3540
|
+
}
|
|
3521
3541
|
var OpenjscadWrite = class {
|
|
3522
3542
|
//constructor() {}
|
|
3523
3543
|
getHeader() {
|
|
3524
3544
|
const rStr = `// Generated by Parametrix
|
|
3525
|
-
|
|
3545
|
+
|
|
3546
|
+
const { polygon } = require('@jscad/modeling').primitives;
|
|
3526
3547
|
//const { subtract } = require('@jscad/modeling').booleans;
|
|
3527
|
-
const { union, intersect, scission, subtract } = require('@jscad/modeling').booleans
|
|
3548
|
+
//const { union, intersect, scission, subtract } = require('@jscad/modeling').booleans;
|
|
3549
|
+
const { union, intersect, subtract } = require('@jscad/modeling').booleans;
|
|
3528
3550
|
const { extrudeLinear, extrudeRotate } = require('@jscad/modeling').extrusions;
|
|
3529
|
-
const { translate, rotate } = require('@jscad/modeling').transforms
|
|
3551
|
+
const { translate, rotate } = require('@jscad/modeling').transforms;
|
|
3552
|
+
|
|
3530
3553
|
const main = () => {
|
|
3554
|
+
|
|
3531
3555
|
`;
|
|
3532
3556
|
return rStr;
|
|
3533
3557
|
}
|
|
3534
|
-
getOneFigure(aFaces,
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3558
|
+
getOneFigure(aFaces, figName) {
|
|
3559
|
+
let rStr = "";
|
|
3560
|
+
const figFaceList = [];
|
|
3561
|
+
for (const [faceIdx, paxFace] of aFaces.entries()) {
|
|
3562
|
+
const faceName = `face_${figName}_Fa${fid2(faceIdx)}`;
|
|
3563
|
+
const faceCtrList = [];
|
|
3564
|
+
for (const [ctrIdx, paxCtr] of paxFace.entries()) {
|
|
3565
|
+
const subFaceName = `ctr_${faceName}_Ctr${fid2(ctrIdx)}`;
|
|
3538
3566
|
if (paxCtr.circle === true) {
|
|
3539
3567
|
const paxCircle2 = paxCtr;
|
|
3540
|
-
|
|
3541
|
-
ojscadWF.addContour(ojscadSeg);
|
|
3568
|
+
rStr += jcFaceCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius, subFaceName);
|
|
3542
3569
|
} else {
|
|
3543
3570
|
const paxPath2 = paxCtr;
|
|
3544
|
-
|
|
3545
|
-
ojscadWF.addContour(ojscadSeg);
|
|
3571
|
+
rStr += jcFaceContour(paxPath2.seg, subFaceName);
|
|
3546
3572
|
}
|
|
3573
|
+
faceCtrList.push(subFaceName);
|
|
3547
3574
|
}
|
|
3575
|
+
rStr += jcOneFace(faceCtrList, faceName);
|
|
3576
|
+
figFaceList.push(faceName);
|
|
3548
3577
|
}
|
|
3549
|
-
|
|
3550
|
-
return
|
|
3578
|
+
rStr += jcOneFig(figFaceList, figName);
|
|
3579
|
+
return rStr;
|
|
3551
3580
|
}
|
|
3552
|
-
getAllFigures(
|
|
3581
|
+
getAllFigures(figs, partName) {
|
|
3553
3582
|
let rStr = "";
|
|
3554
|
-
for (const
|
|
3555
|
-
const figu = this.getOneFigure(
|
|
3583
|
+
for (const ifig in figs) {
|
|
3584
|
+
const figu = this.getOneFigure(figs[ifig], `fig_${partName}_${ifig}`);
|
|
3556
3585
|
rStr += figu;
|
|
3557
3586
|
}
|
|
3558
3587
|
return rStr;
|
|
@@ -3571,9 +3600,10 @@ const main = () => {
|
|
|
3571
3600
|
const ${extrud.outName} =
|
|
3572
3601
|
translate( [ ${extrud.translate[0]}, ${extrud.translate[1]}, ${extrud.translate[2]}, ],
|
|
3573
3602
|
rotate( [ ${extrud.rotate[0]}, ${extrud.rotate[1]}, ${extrud.rotate[2]}, ],
|
|
3574
|
-
${extrudMethod}( ${extrudOption},
|
|
3603
|
+
${extrudMethod}( ${extrudOption}, fig_${extrud.face} )
|
|
3575
3604
|
)
|
|
3576
3605
|
);
|
|
3606
|
+
|
|
3577
3607
|
`;
|
|
3578
3608
|
return rStr;
|
|
3579
3609
|
}
|
|
@@ -3660,7 +3690,7 @@ const ${inherit.outName} =
|
|
|
3660
3690
|
}
|
|
3661
3691
|
getFooter(partName) {
|
|
3662
3692
|
const rStr = `
|
|
3663
|
-
|
|
3693
|
+
return pax_${partName};
|
|
3664
3694
|
}
|
|
3665
3695
|
module.exports = { main };
|
|
3666
3696
|
`;
|
|
@@ -3683,7 +3713,7 @@ function ojscadWrite() {
|
|
|
3683
3713
|
function ff6(ifloat) {
|
|
3684
3714
|
return ifloat.toFixed(4);
|
|
3685
3715
|
}
|
|
3686
|
-
function
|
|
3716
|
+
function fid3(iIdx) {
|
|
3687
3717
|
return iIdx.toString().padStart(3, "0");
|
|
3688
3718
|
}
|
|
3689
3719
|
function fcFaceCircle(cx, cy, radius, outName) {
|
|
@@ -3707,18 +3737,18 @@ function fcFaceContour(paxCtr, outName) {
|
|
|
3707
3737
|
let sIdx = 0;
|
|
3708
3738
|
for (const [segIdx, seg] of paxCtr.entries()) {
|
|
3709
3739
|
if (seg.typ === 0 /* eStart */) {
|
|
3710
|
-
rStr += ` P${
|
|
3740
|
+
rStr += ` P${fid3(pIdx)} = App.Vector(${ff6(seg.px)}, ${ff6(seg.py)}, 0)
|
|
3711
3741
|
`;
|
|
3712
3742
|
pIdx += 1;
|
|
3713
3743
|
} else if (seg.typ === 1 /* eStroke */) {
|
|
3714
|
-
rStr += ` P${
|
|
3744
|
+
rStr += ` P${fid3(pIdx)} = App.Vector(${ff6(seg.px)}, ${ff6(seg.py)}, 0)
|
|
3715
3745
|
`;
|
|
3716
3746
|
if (segIdx < paxCtr.length - 1) {
|
|
3717
3747
|
pIdxLast = pIdx;
|
|
3718
3748
|
} else {
|
|
3719
3749
|
pIdxLast = 0;
|
|
3720
3750
|
}
|
|
3721
|
-
rStr += ` S${
|
|
3751
|
+
rStr += ` S${fid3(sIdx)} = Part.LineSegment(P${fid3(pIdx - 1)}, P${fid3(pIdxLast)})
|
|
3722
3752
|
`;
|
|
3723
3753
|
pIdx += 1;
|
|
3724
3754
|
sIdx += 1;
|
|
@@ -3726,20 +3756,20 @@ function fcFaceContour(paxCtr, outName) {
|
|
|
3726
3756
|
try {
|
|
3727
3757
|
const seg1 = convPaxToSeg1(seg);
|
|
3728
3758
|
const p4 = midArcPoint(px1, py1, seg1);
|
|
3729
|
-
rStr += ` P${
|
|
3759
|
+
rStr += ` P${fid3(pIdx)} = App.Vector(${ff6(p4.cx)}, ${ff6(p4.cy)}, 0)
|
|
3730
3760
|
`;
|
|
3731
3761
|
pIdx += 1;
|
|
3732
3762
|
} catch (emsg) {
|
|
3733
3763
|
console.log("err730: " + emsg);
|
|
3734
3764
|
}
|
|
3735
|
-
rStr += ` P${
|
|
3765
|
+
rStr += ` P${fid3(pIdx)} = App.Vector(${ff6(seg.px)}, ${ff6(seg.py)}, 0)
|
|
3736
3766
|
`;
|
|
3737
3767
|
if (segIdx < paxCtr.length - 1) {
|
|
3738
3768
|
pIdxLast = pIdx;
|
|
3739
3769
|
} else {
|
|
3740
3770
|
pIdxLast = 0;
|
|
3741
3771
|
}
|
|
3742
|
-
rStr += ` S${
|
|
3772
|
+
rStr += ` S${fid3(sIdx)} = Part.Arc(P${fid3(pIdx - 2)}, P${fid3(pIdx - 1)}, P${fid3(pIdxLast)})
|
|
3743
3773
|
`;
|
|
3744
3774
|
pIdx += 1;
|
|
3745
3775
|
sIdx += 1;
|
|
@@ -3747,7 +3777,7 @@ function fcFaceContour(paxCtr, outName) {
|
|
|
3747
3777
|
px1 = seg.px;
|
|
3748
3778
|
py1 = seg.py;
|
|
3749
3779
|
}
|
|
3750
|
-
const segList = Array.from({ length: sIdx }, (v, i) => `S${
|
|
3780
|
+
const segList = Array.from({ length: sIdx }, (v, i) => `S${fid3(i)}`);
|
|
3751
3781
|
rStr += ` aShape = Part.Shape([${segList.join(", ")}])
|
|
3752
3782
|
aWire = Part.Wire(aShape.Edges)
|
|
3753
3783
|
subFace = Part.Face(aWire)
|
|
@@ -3762,7 +3792,7 @@ function fcOneFace(ctrNames, outName) {
|
|
|
3762
3792
|
`;
|
|
3763
3793
|
const ctrShorts = [];
|
|
3764
3794
|
for (const [idx, ctr] of ctrNames.entries()) {
|
|
3765
|
-
const short = `FC${
|
|
3795
|
+
const short = `FC${fid3(idx)}`;
|
|
3766
3796
|
rStr += ` ${short} = ${ctr}()
|
|
3767
3797
|
`;
|
|
3768
3798
|
ctrShorts.push(short);
|
|
@@ -3787,7 +3817,7 @@ function fcOneFig(faceNames, outName) {
|
|
|
3787
3817
|
`;
|
|
3788
3818
|
const faceShorts = [];
|
|
3789
3819
|
for (const [idx, face] of faceNames.entries()) {
|
|
3790
|
-
const short = `FA${
|
|
3820
|
+
const short = `FA${fid3(idx)}`;
|
|
3791
3821
|
rStr += ` ${short} = ${face}()
|
|
3792
3822
|
`;
|
|
3793
3823
|
faceShorts.push(short);
|
|
@@ -3917,11 +3947,11 @@ ${extrud.outName} = fex_${extrud.outName}()
|
|
|
3917
3947
|
`;
|
|
3918
3948
|
let vidx = 0;
|
|
3919
3949
|
for (const vol of othersV) {
|
|
3920
|
-
rStr += ` V${
|
|
3950
|
+
rStr += ` V${fid3(vidx + 1)} = V${fid3(vidx)}.${combMethod}(${vol})
|
|
3921
3951
|
`;
|
|
3922
3952
|
vidx += 1;
|
|
3923
3953
|
}
|
|
3924
|
-
rStr += ` VFC = V${
|
|
3954
|
+
rStr += ` VFC = V${fid3(vidx)}.removeSplitter()
|
|
3925
3955
|
return VFC
|
|
3926
3956
|
${volum.outName} = fvol_${volum.outName}()
|
|
3927
3957
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geometrix",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.45",
|
|
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",
|