geometrix 0.5.13 → 0.5.15

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +112 -21
  2. package/dist/index.js +203 -88
  3. package/package.json +9 -9
package/dist/index.d.ts CHANGED
@@ -34,15 +34,23 @@ declare function adjustRect(p1x: number, p1y: number, p2x: number, p2y: number,
34
34
  declare function adjustScale(iFactor: number, iAdjust: tCanvasAdjust): tCanvasAdjust;
35
35
  declare function adjustTranslate(p1x: number, p1y: number, p2x: number, p2y: number, iAdjust: tCanvasAdjust): tCanvasAdjust;
36
36
 
37
+ declare const tolerance: number;
37
38
  declare function degToRad(degrees: number): number;
38
39
  declare function radToDeg(rad: number): number;
39
40
  declare function roundZero(ix: number): number;
40
41
  declare function withinZero2Pi(ia: number): number;
41
42
  declare function withinPiPi(ia: number): number;
43
+ declare function withinZeroPi(ia: number): number;
44
+ declare function withinHPiHPi(ia: number): number;
45
+ declare function orientedArc(aStart: number, aStop: number, ccw: boolean): number;
46
+ declare function isWithin(aNew: number, aStart: number, aStop: number, ccw: boolean): boolean;
42
47
  declare function ffix(ifloat: number): string;
43
48
 
49
+ declare function rightTriLaFromLbLc(ilb: number, ilc: number): number;
50
+ declare function rightTriLbFromLaLc(ila: number, ilc: number): number;
44
51
  declare function lcFromLaLbAc(la: number, lb: number, ac: number): number;
45
52
  declare function aCFromLaLbLc(la: number, lb: number, lc: number): number;
53
+ declare function aCFromAaAb(iaA: number, iaB: number): number;
46
54
  declare function lbFromLaAaAb(ila: number, iaA: number, iaB: number): number;
47
55
  declare function aBFromLaLbAa(ila: number, ilb: number, iaA: number): number;
48
56
 
@@ -84,6 +92,7 @@ declare class Point {
84
92
  equidistantPoint(p2: Point, dist: number, p3: Point): Point;
85
93
  }
86
94
  declare function point(ix: number, iy: number, ishape?: ShapePoint): Point;
95
+ declare function pointMinMax(aPoint: Point[]): [number, number, number, number];
87
96
 
88
97
  interface tAffine {
89
98
  quasiVertical: boolean;
@@ -130,6 +139,60 @@ declare function linePP(ip1: Point, ip2: Point): Line;
130
139
  declare function bisector(ip1: Point, ip2: Point): Line;
131
140
  declare function circleCenter(ip1: Point, ip2: Point, ip3: Point): Point;
132
141
 
142
+ declare enum SegEnum {
143
+ eStroke = 0,
144
+ eArc = 1,
145
+ ePointed = 2,
146
+ eRounded = 3,
147
+ eWidened = 4,
148
+ eWideAcc = 5,// Widened Access
149
+ eStart = 6
150
+ }
151
+ declare function isSeg(iSegEnum: SegEnum): boolean;
152
+ declare function isAddPoint(iSegEnum: SegEnum): boolean;
153
+ declare function isActiveCorner(iSegEnum: SegEnum): boolean;
154
+ declare function isCorner(iSegEnum: SegEnum): boolean;
155
+ declare class Segment1 {
156
+ sType: SegEnum;
157
+ px: number;
158
+ py: number;
159
+ radius: number;
160
+ arcLarge: boolean;
161
+ arcCcw: boolean;
162
+ constructor(iType: SegEnum, ix: number, iy: number, iRadius: number, iArcLarge?: boolean, iArcCcw?: boolean);
163
+ clone(): Segment1;
164
+ }
165
+ declare class Segment2 {
166
+ sType: SegEnum;
167
+ p1: Point;
168
+ p2: Point;
169
+ pc: Point;
170
+ radius: number;
171
+ a1: number;
172
+ a2: number;
173
+ arcCcw: boolean;
174
+ constructor(iType: SegEnum, ip1: Point, ip2: Point, ipc: Point, iRadius: number, ia1: number, ia2: number, iArcCcw?: boolean);
175
+ }
176
+ declare class SegDbg {
177
+ debugPoints: Point[];
178
+ debugLines: Line[];
179
+ logMessage: string;
180
+ constructor();
181
+ addPoint(ip: Point): void;
182
+ getPoints(): Point[];
183
+ clearPoints(): void;
184
+ addLine(il: Line): void;
185
+ getLines(): Line[];
186
+ clearLines(): void;
187
+ addMsg(iMsg: string): void;
188
+ getMsg(): string;
189
+ clearMsg(): void;
190
+ }
191
+ declare const gSegDbg: SegDbg;
192
+ declare function arcSeg1To2(px1: number, py1: number, iSeg1: Segment1): Segment2;
193
+ declare function arcSeg2To1(iSeg2: Segment2): Segment1;
194
+ declare function makeCorner(s1: Segment2, s2: Segment2, s3: Segment2): Segment2[];
195
+
133
196
  type tCartesian = [number, number];
134
197
  declare class Vector {
135
198
  ca: number;
@@ -151,26 +214,6 @@ declare class Vector {
151
214
  }
152
215
  declare function vector(ia: number, il: number, iDrawPoint: Point): Vector;
153
216
 
154
- declare enum SegEnum {
155
- eStroke = 0,
156
- eArc = 1,
157
- ePointed = 2,
158
- eRounded = 3,
159
- eWidened = 4,
160
- eWideAcc = 5,// Widened Access
161
- eStart = 6
162
- }
163
- declare class Segment1 {
164
- sType: SegEnum;
165
- px: number;
166
- py: number;
167
- radius: number;
168
- arcLarge: boolean;
169
- arcCcw: boolean;
170
- constructor(iType: SegEnum, ix: number, iy: number, iRadius: number, iArcLarge?: boolean, iArcCcw?: boolean);
171
- clone(): Segment1;
172
- }
173
-
174
217
  declare class DxfSeg {
175
218
  arc: boolean;
176
219
  p1x: number;
@@ -182,6 +225,19 @@ declare class DxfSeg {
182
225
  p2y: number;
183
226
  constructor(arc: boolean, p1x: number, p1y: number, radius: number, a1: number, a2: number, p2x: number, p2y: number);
184
227
  }
228
+ declare function dxfSegLine(p1x: number, p1y: number, p2x: number, p2y: number): DxfSeg;
229
+ declare function dxfSegArc(p1x: number, p1y: number, radius: number, aa1: number, aa2: number, arcCcw: boolean): DxfSeg;
230
+ declare function dxfSegCircle(p1x: number, p1y: number, radius: number): DxfSeg;
231
+ declare class DxfWrite {
232
+ dxfStr: string;
233
+ constructor();
234
+ addCircle(cx: number, cy: number, radius: number): void;
235
+ addLine(p1x: number, p1y: number, p2x: number, p2y: number): void;
236
+ addArc(cx: number, cy: number, ra: number, a1: number, a2: number): void;
237
+ close(): void;
238
+ stringify(): string;
239
+ }
240
+ declare function dxfWriter(): DxfWrite;
185
241
 
186
242
  interface tPaxContourCircle {
187
243
  circle: boolean;
@@ -213,6 +269,16 @@ interface tPaxContourPath {
213
269
  seg: tPaxSeg[];
214
270
  }
215
271
  type tPaxContour = tPaxContourPath | tPaxContourCircle;
272
+ declare function paxCircle(cx: number, cy: number, radius: number): tPaxContourCircle;
273
+ declare class PaxPath {
274
+ seg: tPaxSeg[];
275
+ constructor();
276
+ addStart(px: number, py: number): void;
277
+ addStroke(px: number, py: number): void;
278
+ addArc(cx: number, cy: number, radius: number, large: boolean, ccw: boolean): void;
279
+ toJson(): tPaxContourPath;
280
+ }
281
+ declare function paxPath(): PaxPath;
216
282
 
217
283
  declare abstract class AContour {
218
284
  abstract circle: boolean;
@@ -227,7 +293,12 @@ declare abstract class AContour {
227
293
  abstract toDxfSeg(): DxfSeg[];
228
294
  abstract toPax(): tPaxContour;
229
295
  }
296
+ /**
297
+ * class `Contour`
298
+ *
299
+ */
230
300
  declare class Contour extends AContour {
301
+ /** @internal */
231
302
  circle: boolean;
232
303
  segments: Segment1[];
233
304
  points: Point[];
@@ -235,14 +306,23 @@ declare class Contour extends AContour {
235
306
  debugLines: Line[];
236
307
  lastPoint: Point;
237
308
  imposedColor: string;
309
+ /**
310
+ * @param ix - the X absolute coordinate of the first point of the contour
311
+ * @param iy - the Y absolute coordinate of the first point of the contour
312
+ * @param icolor - an optional color name to be used instead of the default color
313
+ */
238
314
  constructor(ix: number, iy: number, icolor?: string);
315
+ /** @internal */
239
316
  setLastPoint(ix: number, iy: number): void;
317
+ /** @internal */
240
318
  getLastPoint(): Point;
241
319
  addPointA(ax: number, ay: number): Contour;
242
320
  addPointAP(aa: number, al: number): Contour;
243
321
  addPointR(rx: number, ry: number): Contour;
244
322
  addPointRP(ra: number, rl: number): Contour;
323
+ /** @internal */
245
324
  addSeg(iSeg: Segment1): Contour;
325
+ /** @internal */
246
326
  addSegStroke(): Contour;
247
327
  addSegStrokeA(ax: number, ay: number): Contour;
248
328
  addSegStrokeAP(aa: number, al: number): Contour;
@@ -258,6 +338,7 @@ declare class Contour extends AContour {
258
338
  addCornerWideAcc(iRadius: number): Contour;
259
339
  closeSegStroke(): Contour;
260
340
  closeSegArc(iRadius: number, iLarge: boolean, iCcw: boolean): Contour;
341
+ /** @internal */
261
342
  clone(): Contour;
262
343
  translate(ix: number, iy: number): Contour;
263
344
  translatePolar(ia: number, il: number): Contour;
@@ -269,12 +350,17 @@ declare class Contour extends AContour {
269
350
  generateContour(): Contour;
270
351
  generatePoints(): Point[];
271
352
  generateLines(): Line[];
353
+ /** @internal */
272
354
  checkContour(ctr: Contour): void;
273
355
  check(): string;
274
356
  toSvg(yCeiling: number, color?: string): string;
275
357
  toDxfSeg(): DxfSeg[];
276
358
  toPax(): tPaxContourPath;
277
359
  }
360
+ /**
361
+ * class `ContourCircle`
362
+ *
363
+ */
278
364
  declare class ContourCircle extends AContour {
279
365
  circle: boolean;
280
366
  px: number;
@@ -282,6 +368,7 @@ declare class ContourCircle extends AContour {
282
368
  radius: number;
283
369
  imposedColor: string;
284
370
  constructor(ix: number, iy: number, iRadius: number, icolor?: string);
371
+ /** @internal */
285
372
  clone(): ContourCircle;
286
373
  translate(ix: number, iy: number): ContourCircle;
287
374
  translatePolar(ia: number, il: number): ContourCircle;
@@ -339,9 +426,11 @@ declare class Figure {
339
426
  rotate(ix: number, iy: number, ia: number): Figure;
340
427
  mergeFigure(ifig: Figure, mainToSecond?: boolean): void;
341
428
  clear(): void;
429
+ /** @internal */
342
430
  getMinMax(): void;
343
431
  getAdjustFull(iCanvasWidth: number, iCanvasHeight: number): tCanvasAdjust;
344
432
  getAdjustZoom(iCanvasWidth: number, iCanvasHeight: number): tCanvasAdjust;
433
+ /** @internal */
345
434
  quantifyRuler(canvasWidth: number, adjust: tCanvasAdjust): number[];
346
435
  drawRuler(ctx: CanvasRenderingContext2D, adjust: tCanvasAdjust, color: string): void;
347
436
  draw(ctx: CanvasRenderingContext2D, adjust: tCanvasAdjust, layers: tLayers): void;
@@ -510,4 +599,6 @@ interface tPackage {
510
599
  }
511
600
  declare function version_details(appPackage: tPackage): string[];
512
601
 
513
- export { DesignParam, EBVolume, EExtrude, EFormat, Figure, PType, Point, ShapePoint, aBFromLaLbAa, aCFromLaLbLc, adjustCenter, adjustInit, adjustRect, adjustScale, adjustTranslate, adjustZero, bisector, canvas2point, canvasTranslatePolar, checkGeom, circleCenter, colors, contour, contourCircle, copyLayers, createParamFile, degToRad, designParam, ffix, figure, fileBin, fileBinContent, fileMime, fileSuffix, fileTextContent, fround, initGeom, initLayers, lbFromLaAaAb, lcFromLaLbAc, line, linePP, mergeFaces, oneDesignParam, pCheckbox, pDropdown, pNumber, paramListToVal, parseParamFile, point, point2canvas, prefixLog, radToDeg, radius2canvas, roundZero, type tAllLink, type tAllPageDef, type tBVolume, type tCanvasAdjust, type tContour, type tDesignParamList, type tExtrude, type tFaces, type tGeom, type tGeomFunc, type tInherit, type tLayers, type tPackage, type tPageDef, type tParamDef, type tParamVal, type tParamValInFile, type tPosiOrien, type tSubDesign, type tSubInst, type tVolume, vector, version_details, withinPiPi, withinZero2Pi };
602
+ declare function checkImpPages(pages: tAllPageDef): [boolean, string];
603
+
604
+ 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, 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 };
package/dist/index.js CHANGED
@@ -172,6 +172,9 @@ function adjustTranslate(p1x, p1y, p2x, p2y, iAdjust) {
172
172
  }
173
173
 
174
174
  // src/triangle_utils.ts
175
+ function rightTriLaFromLbLc(ilb, ilc) {
176
+ return Math.sqrt(ilb ** 2 + ilc ** 2);
177
+ }
175
178
  function rightTriLbFromLaLc(ila, ilc) {
176
179
  let rlb = 0;
177
180
  if (ilc > ila) {
@@ -203,6 +206,18 @@ function aCFromLaLbLc(la, lb, lc) {
203
206
  }
204
207
  return rac;
205
208
  }
209
+ function aCFromAaAb(iaA, iaB) {
210
+ let rac = 0;
211
+ const aA = Math.abs(withinPiPi(iaA));
212
+ const aB = Math.abs(withinPiPi(iaB));
213
+ const sum = aA + aB;
214
+ if (sum > Math.PI) {
215
+ throw `err739: impossible triangle with angles ${iaA} and ${iaB}`;
216
+ } else {
217
+ rac = Math.PI - sum;
218
+ }
219
+ return rac;
220
+ }
206
221
  function lbFromLaAaAb(ila, iaA, iaB) {
207
222
  let rlb = 0;
208
223
  const args = [ila, iaA, iaB];
@@ -753,93 +768,17 @@ function circleCenter(ip1, ip2, ip3) {
753
768
  return rp;
754
769
  }
755
770
 
756
- // src/vector.ts
757
- var Vector = class _Vector {
758
- ca;
759
- cl;
760
- drawPoint;
761
- constructor(ia, il, iDrawPoint) {
762
- this.ca = ia;
763
- this.cl = il;
764
- this.drawPoint = iDrawPoint;
765
- }
766
- draw(ctx, cAdjust, color = colors.vector) {
767
- const radius = ctx.canvas.width * (0.7 / 100);
768
- const [cx2, cy2] = point2canvas(this.drawPoint.cx, this.drawPoint.cy, cAdjust);
769
- const [cx3, cy3] = canvasTranslatePolar(cx2, cy2, this.ca + Math.PI / 2, 2 * radius);
770
- const [cx4, cy4] = canvasTranslatePolar(cx2, cy2, this.ca - Math.PI / 2, 2 * radius);
771
- const p3 = this.drawPoint.translatePolar(this.ca, this.cl);
772
- const [cx5, cy5] = point2canvas(p3.cx, p3.cy, cAdjust);
773
- const [cx6, cy6] = canvasTranslatePolar(cx5, cy5, this.ca + 3 * Math.PI / 4, 4 * radius);
774
- const [cx7, cy7] = canvasTranslatePolar(cx5, cy5, this.ca + 5 * Math.PI / 4, 4 * radius);
775
- ctx.beginPath();
776
- ctx.moveTo(cx3, cy3);
777
- ctx.lineTo(cx4, cy4);
778
- ctx.moveTo(cx2, cy2);
779
- ctx.lineTo(cx5, cy5);
780
- ctx.lineTo(cx6, cy6);
781
- ctx.moveTo(cx5, cy5);
782
- ctx.lineTo(cx7, cy7);
783
- ctx.strokeStyle = color;
784
- ctx.stroke();
785
- }
786
- getCartesian() {
787
- return [this.cl * Math.cos(this.ca), this.cl * Math.sin(this.ca)];
788
- }
789
- setCartesian(ix, iy) {
790
- return new _Vector(Math.atan2(iy, ix), Math.sqrt(ix ** 2 + iy ** 2), this.drawPoint);
791
- }
792
- translatePoint(ip) {
793
- const [x1, y1] = this.getCartesian();
794
- return ip.translate(x1, y1);
795
- }
796
- add(iVect) {
797
- const [x1, y1] = this.getCartesian();
798
- const [x2, y2] = iVect.getCartesian();
799
- const rVect = this.setCartesian(x1 + x2, y1 + y2);
800
- return rVect;
801
- }
802
- addCart(ix, iy) {
803
- const [x1, y1] = this.getCartesian();
804
- const rVect = this.setCartesian(x1 + ix, y1 + iy);
805
- return rVect;
806
- }
807
- // transforms
808
- translate(ix, iy) {
809
- const rVec = new _Vector(this.ca, this.cl, this.drawPoint.translate(ix, iy));
810
- return rVec;
811
- }
812
- rotate(ic, ia) {
813
- const rVec = new _Vector(this.ca + ia, this.cl, this.drawPoint.rotate(ic, ia));
814
- return rVec;
815
- }
816
- clone() {
817
- const rVec = new _Vector(this.ca, this.cl, this.drawPoint.clone());
818
- return rVec;
819
- }
820
- // point comparison
821
- isEqual(iVect) {
822
- const [x1, y1] = this.getCartesian();
823
- const [x2, y2] = iVect.getCartesian();
824
- const rb = roundZero(x2 - x1) === 0 && roundZero(y2 - y1) === 0;
825
- return rb;
826
- }
827
- // dot product
828
- dotProduct(iVect) {
829
- const angle = withinPiPi(iVect.ca - this.ca);
830
- return this.cl * iVect.cl * Math.cos(angle);
831
- }
832
- // cross product
833
- crossProduct(iVect) {
834
- const angle = withinPiPi(iVect.ca - this.ca);
835
- return this.cl * iVect.cl * Math.sin(angle);
836
- }
837
- };
838
- function vector(ia, il, iDrawPoint) {
839
- return new Vector(ia, il, iDrawPoint);
840
- }
841
-
842
771
  // src/segment.ts
772
+ var SegEnum = /* @__PURE__ */ ((SegEnum2) => {
773
+ SegEnum2[SegEnum2["eStroke"] = 0] = "eStroke";
774
+ SegEnum2[SegEnum2["eArc"] = 1] = "eArc";
775
+ SegEnum2[SegEnum2["ePointed"] = 2] = "ePointed";
776
+ SegEnum2[SegEnum2["eRounded"] = 3] = "eRounded";
777
+ SegEnum2[SegEnum2["eWidened"] = 4] = "eWidened";
778
+ SegEnum2[SegEnum2["eWideAcc"] = 5] = "eWideAcc";
779
+ SegEnum2[SegEnum2["eStart"] = 6] = "eStart";
780
+ return SegEnum2;
781
+ })(SegEnum || {});
843
782
  function isSeg(iSegEnum) {
844
783
  let rIsSeg = false;
845
784
  if (iSegEnum === 0 /* eStroke */ || iSegEnum === 1 /* eArc */) {
@@ -1382,6 +1321,92 @@ function makeCorner(s1, s2, s3) {
1382
1321
  return rsegs;
1383
1322
  }
1384
1323
 
1324
+ // src/vector.ts
1325
+ var Vector = class _Vector {
1326
+ ca;
1327
+ cl;
1328
+ drawPoint;
1329
+ constructor(ia, il, iDrawPoint) {
1330
+ this.ca = ia;
1331
+ this.cl = il;
1332
+ this.drawPoint = iDrawPoint;
1333
+ }
1334
+ draw(ctx, cAdjust, color = colors.vector) {
1335
+ const radius = ctx.canvas.width * (0.7 / 100);
1336
+ const [cx2, cy2] = point2canvas(this.drawPoint.cx, this.drawPoint.cy, cAdjust);
1337
+ const [cx3, cy3] = canvasTranslatePolar(cx2, cy2, this.ca + Math.PI / 2, 2 * radius);
1338
+ const [cx4, cy4] = canvasTranslatePolar(cx2, cy2, this.ca - Math.PI / 2, 2 * radius);
1339
+ const p3 = this.drawPoint.translatePolar(this.ca, this.cl);
1340
+ const [cx5, cy5] = point2canvas(p3.cx, p3.cy, cAdjust);
1341
+ const [cx6, cy6] = canvasTranslatePolar(cx5, cy5, this.ca + 3 * Math.PI / 4, 4 * radius);
1342
+ const [cx7, cy7] = canvasTranslatePolar(cx5, cy5, this.ca + 5 * Math.PI / 4, 4 * radius);
1343
+ ctx.beginPath();
1344
+ ctx.moveTo(cx3, cy3);
1345
+ ctx.lineTo(cx4, cy4);
1346
+ ctx.moveTo(cx2, cy2);
1347
+ ctx.lineTo(cx5, cy5);
1348
+ ctx.lineTo(cx6, cy6);
1349
+ ctx.moveTo(cx5, cy5);
1350
+ ctx.lineTo(cx7, cy7);
1351
+ ctx.strokeStyle = color;
1352
+ ctx.stroke();
1353
+ }
1354
+ getCartesian() {
1355
+ return [this.cl * Math.cos(this.ca), this.cl * Math.sin(this.ca)];
1356
+ }
1357
+ setCartesian(ix, iy) {
1358
+ return new _Vector(Math.atan2(iy, ix), Math.sqrt(ix ** 2 + iy ** 2), this.drawPoint);
1359
+ }
1360
+ translatePoint(ip) {
1361
+ const [x1, y1] = this.getCartesian();
1362
+ return ip.translate(x1, y1);
1363
+ }
1364
+ add(iVect) {
1365
+ const [x1, y1] = this.getCartesian();
1366
+ const [x2, y2] = iVect.getCartesian();
1367
+ const rVect = this.setCartesian(x1 + x2, y1 + y2);
1368
+ return rVect;
1369
+ }
1370
+ addCart(ix, iy) {
1371
+ const [x1, y1] = this.getCartesian();
1372
+ const rVect = this.setCartesian(x1 + ix, y1 + iy);
1373
+ return rVect;
1374
+ }
1375
+ // transforms
1376
+ translate(ix, iy) {
1377
+ const rVec = new _Vector(this.ca, this.cl, this.drawPoint.translate(ix, iy));
1378
+ return rVec;
1379
+ }
1380
+ rotate(ic, ia) {
1381
+ const rVec = new _Vector(this.ca + ia, this.cl, this.drawPoint.rotate(ic, ia));
1382
+ return rVec;
1383
+ }
1384
+ clone() {
1385
+ const rVec = new _Vector(this.ca, this.cl, this.drawPoint.clone());
1386
+ return rVec;
1387
+ }
1388
+ // point comparison
1389
+ isEqual(iVect) {
1390
+ const [x1, y1] = this.getCartesian();
1391
+ const [x2, y2] = iVect.getCartesian();
1392
+ const rb = roundZero(x2 - x1) === 0 && roundZero(y2 - y1) === 0;
1393
+ return rb;
1394
+ }
1395
+ // dot product
1396
+ dotProduct(iVect) {
1397
+ const angle = withinPiPi(iVect.ca - this.ca);
1398
+ return this.cl * iVect.cl * Math.cos(angle);
1399
+ }
1400
+ // cross product
1401
+ crossProduct(iVect) {
1402
+ const angle = withinPiPi(iVect.ca - this.ca);
1403
+ return this.cl * iVect.cl * Math.sin(angle);
1404
+ }
1405
+ };
1406
+ function vector(ia, il, iDrawPoint) {
1407
+ return new Vector(ia, il, iDrawPoint);
1408
+ }
1409
+
1385
1410
  // src/write_svg.ts
1386
1411
  function ff(ifloat) {
1387
1412
  return ifloat.toFixed(4);
@@ -1577,6 +1602,12 @@ function ff3(ifloat) {
1577
1602
  const rFloat = ifloat;
1578
1603
  return rFloat;
1579
1604
  }
1605
+ var PSeg = /* @__PURE__ */ ((PSeg2) => {
1606
+ PSeg2[PSeg2["eStart"] = 0] = "eStart";
1607
+ PSeg2[PSeg2["eStroke"] = 1] = "eStroke";
1608
+ PSeg2[PSeg2["eArc"] = 2] = "eArc";
1609
+ return PSeg2;
1610
+ })(PSeg || {});
1580
1611
  function paxCircle(cx, cy, radius) {
1581
1612
  const rPax = {
1582
1613
  circle: true,
@@ -1636,6 +1667,7 @@ function paxPath() {
1636
1667
  var AContour = class {
1637
1668
  };
1638
1669
  var Contour = class _Contour extends AContour {
1670
+ /** @internal */
1639
1671
  circle = false;
1640
1672
  segments;
1641
1673
  points;
@@ -1643,6 +1675,11 @@ var Contour = class _Contour extends AContour {
1643
1675
  debugLines;
1644
1676
  lastPoint;
1645
1677
  imposedColor;
1678
+ /**
1679
+ * @param ix - the X absolute coordinate of the first point of the contour
1680
+ * @param iy - the Y absolute coordinate of the first point of the contour
1681
+ * @param icolor - an optional color name to be used instead of the default color
1682
+ */
1646
1683
  constructor(ix, iy, icolor = "") {
1647
1684
  super();
1648
1685
  this.segments = [new Segment1(6 /* eStart */, ix, iy, 0)];
@@ -1652,9 +1689,11 @@ var Contour = class _Contour extends AContour {
1652
1689
  this.lastPoint = point(ix, iy);
1653
1690
  this.imposedColor = icolor;
1654
1691
  }
1692
+ /** @internal */
1655
1693
  setLastPoint(ix, iy) {
1656
1694
  this.lastPoint = point(ix, iy);
1657
1695
  }
1696
+ /** @internal */
1658
1697
  getLastPoint() {
1659
1698
  return this.lastPoint;
1660
1699
  }
@@ -1682,10 +1721,12 @@ var Contour = class _Contour extends AContour {
1682
1721
  this.addPointA(p1.cx, p1.cy);
1683
1722
  return this;
1684
1723
  }
1724
+ /** @internal */
1685
1725
  addSeg(iSeg) {
1686
1726
  this.segments.push(iSeg);
1687
1727
  return this;
1688
1728
  }
1729
+ /** @internal */
1689
1730
  addSegStroke() {
1690
1731
  if (this.points.length !== 1) {
1691
1732
  throw `err554: contour addSegStroke with unexpected points.length ${this.points.length}`;
@@ -1894,6 +1935,7 @@ var Contour = class _Contour extends AContour {
1894
1935
  this.addPointA(px, py).addSegArc(iRadius, iLarge, iCcw);
1895
1936
  return this;
1896
1937
  }
1938
+ /** @internal */
1897
1939
  clone() {
1898
1940
  const rctr = new _Contour(this.segments[0].px, this.segments[0].py);
1899
1941
  for (const seg of this.segments) {
@@ -1983,7 +2025,17 @@ var Contour = class _Contour extends AContour {
1983
2025
  if (this.points.length > 0) {
1984
2026
  throw `err911: addPartial, points should be used ${this.points.length}`;
1985
2027
  }
1986
- for (const seg of iContour.segments) {
2028
+ let iCtr = iContour;
2029
+ if (iContour.segments.length > 0) {
2030
+ const p0 = iContour.segments[0];
2031
+ const pLast = this.getLastPoint();
2032
+ const dx = p0.px - pLast.cx;
2033
+ const dy = p0.py - pLast.cy;
2034
+ if (p0.sType === 6 /* eStart */) {
2035
+ iCtr = iContour.translate(-dx, -dy);
2036
+ }
2037
+ }
2038
+ for (const seg of iCtr.segments) {
1987
2039
  if (seg.sType !== 6 /* eStart */) {
1988
2040
  this.addSeg(seg);
1989
2041
  if (isSeg(seg.sType)) {
@@ -2174,6 +2226,7 @@ var Contour = class _Contour extends AContour {
2174
2226
  rLines.push(...this.debugLines);
2175
2227
  return rLines;
2176
2228
  }
2229
+ /** @internal */
2177
2230
  checkContour(ctr) {
2178
2231
  if (ctr.segments[0].sType !== 6 /* eStart */) {
2179
2232
  throw `err412: contour check first seg is not eStart ${ctr.segments[0].sType}`;
@@ -2276,6 +2329,7 @@ var ContourCircle = class _ContourCircle extends AContour {
2276
2329
  this.radius = iRadius;
2277
2330
  this.imposedColor = icolor;
2278
2331
  }
2332
+ /** @internal */
2279
2333
  clone() {
2280
2334
  const rctr = new _ContourCircle(this.px, this.py, this.radius, this.imposedColor);
2281
2335
  return rctr;
@@ -2493,6 +2547,7 @@ var Figure = class _Figure {
2493
2547
  this.secondBList = [];
2494
2548
  this.dynamicsList = [];
2495
2549
  }
2550
+ /** @internal */
2496
2551
  getMinMax() {
2497
2552
  [this.xMin, this.xMax, this.yMin, this.yMax] = pointMinMax(this.pointList);
2498
2553
  }
@@ -2528,6 +2583,7 @@ var Figure = class _Figure {
2528
2583
  }
2529
2584
  return rCanvasAdjust;
2530
2585
  }
2586
+ /** @internal */
2531
2587
  quantifyRuler(canvasWidth, adjust) {
2532
2588
  const minWidth = canvasWidth / 10;
2533
2589
  const lsizep = minWidth / adjust.scaleX;
@@ -3802,13 +3858,49 @@ function version_details(appPackage) {
3802
3858
  }
3803
3859
  return rStr;
3804
3860
  }
3861
+
3862
+ // src/dynamicImport.ts
3863
+ function checkImpPages(pages) {
3864
+ let rMsg = "";
3865
+ let rError = false;
3866
+ const pageNames = Object.keys(pages);
3867
+ rMsg += `found ${pageNames.length} designs
3868
+ `;
3869
+ if (pageNames.length === 0) {
3870
+ rError = true;
3871
+ }
3872
+ const props = ["pTitle", "pDescription", "pDef", "pGeom"];
3873
+ for (const pagN of pageNames) {
3874
+ const pag = pages[pagN];
3875
+ for (const prop of props) {
3876
+ if (!(prop in pag)) {
3877
+ rMsg += `err323: ${pagN} has no property ${prop}
3878
+ `;
3879
+ rError = true;
3880
+ }
3881
+ }
3882
+ }
3883
+ return [rError, rMsg];
3884
+ }
3805
3885
  export {
3886
+ Contour,
3887
+ ContourCircle,
3806
3888
  EBVolume,
3807
3889
  EExtrude,
3808
3890
  EFormat,
3891
+ Line,
3892
+ PSeg,
3809
3893
  PType,
3894
+ PaxPath,
3895
+ Point,
3896
+ SegDbg,
3897
+ SegEnum,
3898
+ Segment1,
3899
+ Segment2,
3810
3900
  ShapePoint,
3901
+ Vector,
3811
3902
  aBFromLaLbAa,
3903
+ aCFromAaAb,
3812
3904
  aCFromLaLbLc,
3813
3905
  adjustCenter,
3814
3906
  adjustInit,
@@ -3816,10 +3908,13 @@ export {
3816
3908
  adjustScale,
3817
3909
  adjustTranslate,
3818
3910
  adjustZero,
3911
+ arcSeg1To2,
3912
+ arcSeg2To1,
3819
3913
  bisector,
3820
3914
  canvas2point,
3821
3915
  canvasTranslatePolar,
3822
3916
  checkGeom,
3917
+ checkImpPages,
3823
3918
  circleCenter,
3824
3919
  colors,
3825
3920
  contour,
@@ -3828,6 +3923,10 @@ export {
3828
3923
  createParamFile,
3829
3924
  degToRad,
3830
3925
  designParam,
3926
+ dxfSegArc,
3927
+ dxfSegCircle,
3928
+ dxfSegLine,
3929
+ dxfWriter,
3831
3930
  ffix,
3832
3931
  figure,
3833
3932
  fileBin,
@@ -3836,28 +3935,44 @@ export {
3836
3935
  fileSuffix,
3837
3936
  fileTextContent,
3838
3937
  fround,
3938
+ gSegDbg,
3839
3939
  initGeom,
3840
3940
  initLayers,
3941
+ isActiveCorner,
3942
+ isAddPoint,
3943
+ isCorner,
3944
+ isSeg,
3945
+ isWithin,
3841
3946
  lbFromLaAaAb,
3842
3947
  lcFromLaLbAc,
3843
3948
  line,
3844
3949
  linePP,
3950
+ makeCorner,
3845
3951
  mergeFaces,
3846
3952
  oneDesignParam,
3953
+ orientedArc,
3847
3954
  pCheckbox,
3848
3955
  pDropdown,
3849
3956
  pNumber,
3850
3957
  paramListToVal,
3851
3958
  parseParamFile,
3959
+ paxCircle,
3960
+ paxPath,
3852
3961
  point,
3853
3962
  point2canvas,
3963
+ pointMinMax,
3854
3964
  prefixLog,
3855
3965
  radToDeg,
3856
3966
  radius2canvas,
3967
+ rightTriLaFromLbLc,
3968
+ rightTriLbFromLaLc,
3857
3969
  roundZero,
3970
+ tolerance,
3858
3971
  vector,
3859
3972
  version_details,
3973
+ withinHPiHPi,
3860
3974
  withinPiPi,
3861
- withinZero2Pi
3975
+ withinZero2Pi,
3976
+ withinZeroPi
3862
3977
  };
3863
3978
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geometrix",
3
- "version": "0.5.13",
3
+ "version": "0.5.15",
4
4
  "description": "The 2D geometry engine of the parametrix",
5
5
  "private": false,
6
6
  "repository": {
@@ -37,26 +37,26 @@
37
37
  "lint": "eslint .",
38
38
  "test:unit": "vitest",
39
39
  "test:unit:once": "vitest --run",
40
- "ci": "run-s check build pretty lint test:unit:once",
41
- "svgo": "svgo --config ../paramui/svgo.config.cjs -f svg -o ../paramui/static",
40
+ "ci": "run-s check build pretty lint test:unit:once svgo",
41
+ "svgo": "svgo --config ../paramui/svgo.config.cjs -f svg -o ../paramui/static/geomdocs/",
42
42
  "clean": "shx rm -fr dist node_modules"
43
43
  },
44
44
  "dependencies": {
45
- "@zip.js/zip.js": "^2.7.32"
45
+ "@zip.js/zip.js": "^2.7.34"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/node": "^20.10.7",
49
- "@typescript-eslint/eslint-plugin": "^6.18.0",
50
- "@typescript-eslint/parser": "^6.18.0",
48
+ "@types/node": "^20.11.16",
49
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
50
+ "@typescript-eslint/parser": "^6.20.0",
51
51
  "eslint": "^8.56.0",
52
52
  "eslint-config-prettier": "^9.1.0",
53
53
  "npm-run-all": "^4.1.5",
54
- "prettier": "^3.1.1",
54
+ "prettier": "^3.2.5",
55
55
  "shx": "^0.3.4",
56
56
  "svgo": "^3.2.0",
57
57
  "tsup": "^8.0.1",
58
58
  "typescript": "^5.3.3",
59
- "vitest": "^1.1.3"
59
+ "vitest": "^1.2.2"
60
60
  },
61
61
  "exports": {
62
62
  ".": {