geometrix 0.5.24 → 0.5.26

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 CHANGED
@@ -599,6 +599,23 @@ interface tParamValInFile {
599
599
  declare function createParamFile(lastModif: string, iPartName: string, idparams: tParamVal, comment: string): string;
600
600
  declare function parseParamFile(fContentStr: string): [tParamValInFile, string];
601
601
 
602
+ type tVec3 = [number, number, number];
603
+ type tVec4 = [number, number, number, number];
604
+ type tT3dMatrix = [tVec4, tVec4, tVec4, tVec4];
605
+ declare class Transform3d {
606
+ mmat: tT3dMatrix;
607
+ constructor(iMat: tT3dMatrix);
608
+ addRotation(ax: number, ay: number, az: number): void;
609
+ addTranslation(ax: number, ay: number, az: number): void;
610
+ getMatrix(): tT3dMatrix;
611
+ getRotation(): tVec3;
612
+ getTranslation(): tVec3;
613
+ transform(iv: tVec3): tVec3;
614
+ }
615
+ declare function transform3d(initM?: tT3dMatrix): Transform3d;
616
+
617
+ declare function ctrRectangle(ox: number, oy: number, width: number, height: number, cornerRounded?: number): tContour;
618
+
602
619
  /** For cli-app and ui-app */
603
620
  type tDependencies = Record<string, string>;
604
621
  /** For cli-app and ui-app */
@@ -612,4 +629,4 @@ declare function version_details(appPackage: tPackage): string[];
612
629
 
613
630
  declare function checkImpPages(pages: tAllPageDef): [boolean, string];
614
631
 
615
- export { Contour, ContourCircle, DesignParam, DxfSeg, DxfWrite, EBVolume, EExtrude, EFormat, Figure, Line, PSeg, PType, PaxPath, Point, SegDbg, SegEnum, Segment1, Segment2, ShapePoint, Vector, aBFromLaLbAa, aCFromAaAb, aCFromLaLbLc, adjustCenter, adjustInit, adjustRect, adjustScale, adjustTranslate, adjustZero, arcSeg1To2, arcSeg2To1, bisector, canvas2point, canvasTranslatePolar, checkGeom, checkImpPages, circleCenter, colors, contour, contourCircle, copyLayers, createParamFile, degToRad, designParam, dxfSegArc, dxfSegCircle, dxfSegLine, dxfWriter, ffix, figure, fileBin, fileBinContent, fileMime, fileSuffix, fileTextContent, fround, gSegDbg, initGeom, initLayers, isActiveCorner, isAddPoint, isCorner, isSeg, isWithin, lbFromLaAaAb, lcFromLaLbAc, line, linePP, makeCorner, mergeFaces, oneDesignParam, orientedArc, pCheckbox, pDropdown, pNumber, pSectionSeparator, paramListToVal, parseParamFile, paxCircle, paxPath, point, point2canvas, pointMinMax, prefixLog, radToDeg, radius2canvas, rightTriLaFromLbLc, rightTriLbFromLaLc, roundZero, type tAffine, type tAllLink, type tAllPageDef, type tBVolume, type tCanvasAdjust, type tCartesian, type tContour, type tDependencies, type tDesignParamList, type tDesignParamOne, type tExtrude, type tFaces, type tGeom, type tGeomFunc, type tInherit, type tLayers, type tPackage, type tPageDef, type tParam, type tParamChanged, type tParamDef, type tParamVal, type tParamValInFile, type tPaxContour, type tPaxContourCircle, type tPaxContourPath, type tPaxSeg, type tPaxSegArc, type tPaxSegSt, type tPolar, type tPosiOrien, type tSimTime, type tSubDesign, type tSubInst, type tVolume, tolerance, vector, version_details, withinHPiHPi, withinPiPi, withinZero2Pi, withinZeroPi, zeroPDef };
632
+ export { Contour, ContourCircle, DesignParam, DxfSeg, DxfWrite, EBVolume, EExtrude, EFormat, Figure, Line, PSeg, PType, PaxPath, Point, SegDbg, SegEnum, Segment1, Segment2, ShapePoint, Transform3d, Vector, aBFromLaLbAa, aCFromAaAb, aCFromLaLbLc, adjustCenter, adjustInit, adjustRect, adjustScale, adjustTranslate, adjustZero, arcSeg1To2, arcSeg2To1, bisector, canvas2point, canvasTranslatePolar, checkGeom, checkImpPages, circleCenter, colors, contour, contourCircle, copyLayers, createParamFile, ctrRectangle, degToRad, designParam, dxfSegArc, dxfSegCircle, dxfSegLine, dxfWriter, ffix, figure, fileBin, fileBinContent, fileMime, fileSuffix, fileTextContent, fround, gSegDbg, initGeom, initLayers, isActiveCorner, isAddPoint, isCorner, isSeg, isWithin, lbFromLaAaAb, lcFromLaLbAc, line, linePP, makeCorner, mergeFaces, oneDesignParam, orientedArc, pCheckbox, pDropdown, pNumber, pSectionSeparator, paramListToVal, parseParamFile, paxCircle, paxPath, point, point2canvas, pointMinMax, prefixLog, radToDeg, radius2canvas, rightTriLaFromLbLc, rightTriLbFromLaLc, roundZero, type tAffine, type tAllLink, type tAllPageDef, type tBVolume, type tCanvasAdjust, type tCartesian, type tContour, type tDependencies, type tDesignParamList, type tDesignParamOne, type tExtrude, type tFaces, type tGeom, type tGeomFunc, type tInherit, type tLayers, type tPackage, type tPageDef, type tParam, type tParamChanged, type tParamDef, type tParamVal, type tParamValInFile, type tPaxContour, type tPaxContourCircle, type tPaxContourPath, type tPaxSeg, type tPaxSegArc, type tPaxSegSt, type tPolar, type tPosiOrien, type tSimTime, type tSubDesign, type tSubInst, type tT3dMatrix, type tVec3, type tVec4, type tVolume, tolerance, transform3d, vector, version_details, withinHPiHPi, withinPiPi, withinZero2Pi, withinZeroPi, zeroPDef };
package/dist/index.js CHANGED
@@ -1799,13 +1799,15 @@ var Contour = class _Contour extends AContour {
1799
1799
  const p0p2middle = p0.middlePoint(p2);
1800
1800
  const a0 = p0p2middle.angleToPoint(p0);
1801
1801
  const a1 = p0p2middle.angleToPoint(p1);
1802
- const a3 = p0p2middle.angleToPoint(p3);
1803
1802
  const a01 = withinPiPi(a1 - a0);
1804
- const a03 = withinPiPi(a3 - a0);
1805
1803
  let large = false;
1806
1804
  let ccw = false;
1807
- if (Math.sign(a03) * Math.sign(a01) > 0) {
1808
- large = true;
1805
+ if (!p0p2middle.isEqual(p3)) {
1806
+ const a3 = p0p2middle.angleToPoint(p3);
1807
+ const a03 = withinPiPi(a3 - a0);
1808
+ if (Math.sign(a03) * Math.sign(a01) > 0) {
1809
+ large = true;
1810
+ }
1809
1811
  }
1810
1812
  if (Math.sign(a01) > 0) {
1811
1813
  ccw = true;
@@ -3883,6 +3885,173 @@ function parseParamFile(fContentStr) {
3883
3885
  return [rObj, rlog];
3884
3886
  }
3885
3887
 
3888
+ // src/transform3d.ts
3889
+ function t3dInitNull() {
3890
+ const rM = [
3891
+ [0, 0, 0, 0],
3892
+ [0, 0, 0, 0],
3893
+ [0, 0, 0, 0],
3894
+ [0, 0, 0, 0]
3895
+ ];
3896
+ return rM;
3897
+ }
3898
+ function t3dInitIdentity() {
3899
+ const rM = [
3900
+ [1, 0, 0, 0],
3901
+ [0, 1, 0, 0],
3902
+ [0, 0, 1, 0],
3903
+ [0, 0, 0, 1]
3904
+ ];
3905
+ return rM;
3906
+ }
3907
+ function t3dRotateX(ax) {
3908
+ const rM = t3dInitIdentity();
3909
+ const cos = Math.cos(ax);
3910
+ const sin = Math.sin(ax);
3911
+ rM[1][1] = cos;
3912
+ rM[2][2] = cos;
3913
+ rM[2][1] = sin;
3914
+ rM[1][2] = -sin;
3915
+ return rM;
3916
+ }
3917
+ function t3dRotateY(ay) {
3918
+ const rM = t3dInitIdentity();
3919
+ const cos = Math.cos(ay);
3920
+ const sin = Math.sin(ay);
3921
+ rM[0][0] = cos;
3922
+ rM[2][2] = cos;
3923
+ rM[0][2] = sin;
3924
+ rM[2][0] = -sin;
3925
+ return rM;
3926
+ }
3927
+ function t3dRotateZ(az) {
3928
+ const rM = t3dInitIdentity();
3929
+ const cos = Math.cos(az);
3930
+ const sin = Math.sin(az);
3931
+ rM[0][0] = cos;
3932
+ rM[1][1] = cos;
3933
+ rM[0][1] = -sin;
3934
+ rM[1][0] = sin;
3935
+ return rM;
3936
+ }
3937
+ function t3dMatMultiply(ma, mb) {
3938
+ const rM = t3dInitNull();
3939
+ for (let i = 0; i < 4; i++) {
3940
+ for (let j = 0; j < 4; j++) {
3941
+ let t = 0;
3942
+ for (let k = 0; k < 4; k++) {
3943
+ t += ma[i][k] * mb[k][j];
3944
+ }
3945
+ rM[i][j] = t;
3946
+ }
3947
+ }
3948
+ return rM;
3949
+ }
3950
+ function t3dCombine(tM) {
3951
+ let rM = t3dInitIdentity();
3952
+ for (const tmi of tM) {
3953
+ rM = t3dMatMultiply(tmi, rM);
3954
+ }
3955
+ return rM;
3956
+ }
3957
+ function t3dRotate(ax, ay, az) {
3958
+ const rM = t3dCombine([t3dRotateX(ax), t3dRotateY(ay), t3dRotateZ(az)]);
3959
+ return rM;
3960
+ }
3961
+ function t3dTranslate(ax, ay, az) {
3962
+ const rM = t3dInitIdentity();
3963
+ rM[0][3] = ax;
3964
+ rM[1][3] = ay;
3965
+ rM[2][3] = az;
3966
+ return rM;
3967
+ }
3968
+ function t3dCopyMatrix(tm) {
3969
+ const rM = t3dInitNull();
3970
+ for (let i = 0; i < 4; i++) {
3971
+ for (let j = 0; j < 4; j++) {
3972
+ rM[i][j] = tm[i][j];
3973
+ }
3974
+ }
3975
+ return rM;
3976
+ }
3977
+ function t3dApply(ma, va) {
3978
+ const vb = [va[0], va[1], va[2], 1];
3979
+ const rV = [0, 0, 0];
3980
+ for (let i = 0; i < 3; i++) {
3981
+ let t = 0;
3982
+ for (let k = 0; k < 4; k++) {
3983
+ t += ma[i][k] * vb[k];
3984
+ }
3985
+ rV[i] = t;
3986
+ }
3987
+ return rV;
3988
+ }
3989
+ function t3dGetTranslation(tm) {
3990
+ const rVT = [tm[0][3], tm[1][3], tm[2][3]];
3991
+ return rVT;
3992
+ }
3993
+ function t3dGetRotation(tm) {
3994
+ let ax = 0;
3995
+ let ay = 0;
3996
+ let az = 0;
3997
+ const tm20 = tm[2][0];
3998
+ const yota = 10 ** -5;
3999
+ if (Math.abs(tm20 - 1) < yota) {
4000
+ az = 0;
4001
+ ay = -Math.PI / 2;
4002
+ ax = -az + Math.atan2(-tm[0][1], -tm[0][2]);
4003
+ } else if (Math.abs(tm20 + 1) < yota) {
4004
+ az = 0;
4005
+ ay = Math.PI / 2;
4006
+ ax = az + Math.atan2(tm[0][1], tm[0][2]);
4007
+ } else {
4008
+ ax = Math.atan2(tm[2][1], tm[2][2]);
4009
+ ay = Math.atan2(-tm[2][0], Math.sqrt(tm[2][1] ** 2 + tm[2][2] ** 2));
4010
+ az = Math.atan2(tm[1][0], tm[0][0]);
4011
+ }
4012
+ const rVR = [ax, ay, az];
4013
+ return rVR;
4014
+ }
4015
+ var Transform3d = class {
4016
+ mmat;
4017
+ constructor(iMat) {
4018
+ this.mmat = t3dCopyMatrix(iMat);
4019
+ }
4020
+ addRotation(ax, ay, az) {
4021
+ const mR = t3dRotate(ax, ay, az);
4022
+ this.mmat = t3dCombine([this.mmat, mR]);
4023
+ }
4024
+ addTranslation(ax, ay, az) {
4025
+ const mT = t3dTranslate(ax, ay, az);
4026
+ this.mmat = t3dCombine([this.mmat, mT]);
4027
+ }
4028
+ getMatrix() {
4029
+ return this.mmat;
4030
+ }
4031
+ getRotation() {
4032
+ const rVR = t3dGetRotation(this.mmat);
4033
+ return rVR;
4034
+ }
4035
+ getTranslation() {
4036
+ const rVT = t3dGetTranslation(this.mmat);
4037
+ return rVT;
4038
+ }
4039
+ transform(iv) {
4040
+ const rV = t3dApply(this.mmat, iv);
4041
+ return rV;
4042
+ }
4043
+ };
4044
+ var initMid = t3dInitIdentity();
4045
+ function transform3d(initM = initMid) {
4046
+ return new Transform3d(initM);
4047
+ }
4048
+
4049
+ // src/common_contours.ts
4050
+ function ctrRectangle(ox, oy, width, height, cornerRounded = 0) {
4051
+ const rCtr = contour(ox, oy).addCornerRounded(cornerRounded).addSegStrokeR(width, 0).addCornerRounded(cornerRounded).addSegStrokeR(0, height).addCornerRounded(cornerRounded).addSegStrokeR(-width, 0).addCornerRounded(cornerRounded).closeSegStroke();
4052
+ return rCtr;
4053
+ }
4054
+
3886
4055
  // src/version_details.ts
3887
4056
  function version_details(appPackage) {
3888
4057
  const rStr = [];
@@ -3936,6 +4105,7 @@ export {
3936
4105
  Segment1,
3937
4106
  Segment2,
3938
4107
  ShapePoint,
4108
+ Transform3d,
3939
4109
  Vector,
3940
4110
  aBFromLaLbAa,
3941
4111
  aCFromAaAb,
@@ -3959,6 +4129,7 @@ export {
3959
4129
  contourCircle,
3960
4130
  copyLayers,
3961
4131
  createParamFile,
4132
+ ctrRectangle,
3962
4133
  degToRad,
3963
4134
  designParam,
3964
4135
  dxfSegArc,
@@ -4007,6 +4178,7 @@ export {
4007
4178
  rightTriLbFromLaLc,
4008
4179
  roundZero,
4009
4180
  tolerance,
4181
+ transform3d,
4010
4182
  vector,
4011
4183
  version_details,
4012
4184
  withinHPiHPi,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geometrix",
3
- "version": "0.5.24",
3
+ "version": "0.5.26",
4
4
  "description": "The 2D geometry engine of the parametrix",
5
5
  "private": false,
6
6
  "repository": {
@@ -41,10 +41,10 @@
41
41
  "clean": "shx rm -fr dist node_modules"
42
42
  },
43
43
  "dependencies": {
44
- "@zip.js/zip.js": "^2.7.37"
44
+ "@zip.js/zip.js": "^2.7.40"
45
45
  },
46
46
  "devDependencies": {
47
- "@types/node": "^20.11.25",
47
+ "@types/node": "^20.11.30",
48
48
  "@typescript-eslint/eslint-plugin": "^7.0.1",
49
49
  "@typescript-eslint/parser": "^7.0.1",
50
50
  "eslint": "^8.57.0",
@@ -53,8 +53,8 @@
53
53
  "prettier": "^3.2.5",
54
54
  "shx": "^0.3.4",
55
55
  "tsup": "^8.0.2",
56
- "typescript": "^5.4.2",
57
- "vitest": "^1.3.1"
56
+ "typescript": "^5.4.3",
57
+ "vitest": "^1.4.0"
58
58
  },
59
59
  "exports": {
60
60
  ".": {