geometrix 0.5.10 → 0.5.11

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 (90) hide show
  1. package/dist/index.d.ts +505 -0
  2. package/dist/index.js +3848 -0
  3. package/dist/index.js.map +1 -0
  4. package/package.json +6 -1
  5. package/.eslintignore +0 -17
  6. package/.eslintrc.cjs +0 -24
  7. package/.prettierignore +0 -15
  8. package/.prettierrc +0 -8
  9. package/src/aaExportContent.ts +0 -213
  10. package/src/aaExportFile.ts +0 -141
  11. package/src/aaParamGeom.ts +0 -62
  12. package/src/angle_utils.test.ts +0 -83
  13. package/src/angle_utils.ts +0 -98
  14. package/src/arc_to_stroke.ts +0 -73
  15. package/src/canvas_utils.test.ts +0 -28
  16. package/src/canvas_utils.ts +0 -159
  17. package/src/contour.test.ts +0 -37
  18. package/src/contour.ts +0 -806
  19. package/src/designParams.ts +0 -178
  20. package/src/figure.test.ts +0 -21
  21. package/src/figure.ts +0 -400
  22. package/src/index.ts +0 -16
  23. package/src/line.test.ts +0 -78
  24. package/src/line.ts +0 -359
  25. package/src/paramFile.ts +0 -52
  26. package/src/point.test.ts +0 -36
  27. package/src/point.ts +0 -246
  28. package/src/prepare_pax.ts +0 -102
  29. package/src/segment.test.ts +0 -26
  30. package/src/segment.ts +0 -701
  31. package/src/sub_design.ts +0 -16
  32. package/src/triangle_utils.test.ts +0 -38
  33. package/src/triangle_utils.ts +0 -112
  34. package/src/vector.test.ts +0 -28
  35. package/src/vector.ts +0 -122
  36. package/src/volume.ts +0 -50
  37. package/src/write_dxf.ts +0 -100
  38. package/src/write_openjscad.ts +0 -284
  39. package/src/write_openscad.ts +0 -305
  40. package/src/write_pax.ts +0 -73
  41. package/src/write_svg.ts +0 -101
  42. package/svg/any_triangle.svg +0 -156
  43. package/svg/arc_definition.svg +0 -506
  44. package/svg/construct_corner_rounded_ext_arc_ext_arc.svg +0 -378
  45. package/svg/construct_corner_rounded_int_arc_ext_arc.svg +0 -359
  46. package/svg/construct_corner_rounded_int_arc_int_arc.svg +0 -356
  47. package/svg/construct_corner_rounded_stroke_ext_arc.svg +0 -374
  48. package/svg/construct_corner_rounded_stroke_ext_arc_obtuse.svg +0 -370
  49. package/svg/construct_corner_rounded_stroke_ext_arc_obtuse_method2.svg +0 -311
  50. package/svg/construct_corner_rounded_stroke_int_arc.svg +0 -364
  51. package/svg/construct_corner_rounded_stroke_int_arc_obtuse.svg +0 -358
  52. package/svg/construct_corner_rounded_stroke_int_arc_obtuse_method2.svg +0 -237
  53. package/svg/construct_corner_rounded_stroke_stroke.svg +0 -280
  54. package/svg/construct_corner_wideacc.svg +0 -286
  55. package/svg/construct_corner_widened.svg +0 -278
  56. package/svg/construction_of_line_intersection_1.svg +0 -187
  57. package/svg/construction_of_line_intersection_2.svg +0 -189
  58. package/svg/contour_arc_definition_options.svg +0 -324
  59. package/svg/contour_point_absolute_relative.svg +0 -258
  60. package/svg/contour_tangential_two_arcs.svg +0 -531
  61. package/svg/contour_tangential_two_arcs_impossible_case.svg +0 -175
  62. package/svg/contour_tangential_two_arcs_requirements.svg +0 -364
  63. package/svg/corner_rounded_ext_arc_ext_arc.svg +0 -281
  64. package/svg/corner_rounded_int_arc_ext_arc.svg +0 -281
  65. package/svg/corner_rounded_int_arc_int_arc.svg +0 -279
  66. package/svg/corner_rounded_stroke_ext_arc.svg +0 -218
  67. package/svg/corner_rounded_stroke_int_arc.svg +0 -225
  68. package/svg/corner_rounded_stroke_stroke.svg +0 -174
  69. package/svg/geom_dev.svg +0 -14708
  70. package/svg/geom_modules.svg +0 -246
  71. package/svg/geom_user.svg +0 -58
  72. package/svg/line_axis_x_cases.svg +0 -1408
  73. package/svg/line_axis_y_cases.svg +0 -1369
  74. package/svg/line_distanceOrig.svg +0 -318
  75. package/svg/line_getAxisXIntersection.svg +0 -262
  76. package/svg/line_getAxisXIntersection_2.svg +0 -244
  77. package/svg/line_getAxisYIntersection.svg +0 -304
  78. package/svg/line_getAxisYIntersection_2.svg +0 -285
  79. package/svg/line_getAxisYIntersection_3.svg +0 -277
  80. package/svg/line_intersection.svg +0 -346
  81. package/svg/line_projectPoint.svg +0 -311
  82. package/svg/point_1.svg +0 -243
  83. package/svg/point_2.svg +0 -409
  84. package/svg/point_3.svg +0 -298
  85. package/svg/point_4.svg +0 -272
  86. package/svg/point_5.svg +0 -356
  87. package/svg/right_triangle.svg +0 -194
  88. package/svg/vector_definition.svg +0 -130
  89. package/tsconfig.json +0 -13
  90. package/vitest.config.ts +0 -7
package/dist/index.js ADDED
@@ -0,0 +1,3848 @@
1
+ // src/angle_utils.ts
2
+ var tolerance = 10 ** -4;
3
+ function degToRad(degrees) {
4
+ return degrees * (Math.PI / 180);
5
+ }
6
+ function radToDeg(rad) {
7
+ return rad / (Math.PI / 180);
8
+ }
9
+ function roundZero(ix) {
10
+ let rx = ix;
11
+ if (Math.abs(rx) < tolerance) {
12
+ rx = 0;
13
+ }
14
+ return rx;
15
+ }
16
+ function withinZero2Pi(ia) {
17
+ let ra = ia % (2 * Math.PI);
18
+ if (ra < 0) {
19
+ ra += 2 * Math.PI;
20
+ }
21
+ return ra;
22
+ }
23
+ function withinPiPi(ia) {
24
+ let ra = withinZero2Pi(ia);
25
+ if (ra > Math.PI) {
26
+ ra -= 2 * Math.PI;
27
+ }
28
+ return ra;
29
+ }
30
+ function withinZeroPi(ia) {
31
+ let ra = ia % Math.PI;
32
+ if (ra < 0) {
33
+ ra += Math.PI;
34
+ }
35
+ return ra;
36
+ }
37
+ function withinHPiHPi(ia) {
38
+ let ra = withinZeroPi(ia);
39
+ if (ra > Math.PI / 2) {
40
+ ra -= Math.PI;
41
+ }
42
+ return ra;
43
+ }
44
+ function orientedArc(aStart, aStop, ccw) {
45
+ const arc = withinPiPi(aStop) - withinPiPi(aStart);
46
+ const arc2 = ccw ? withinZero2Pi(arc) : withinZero2Pi(arc) - 2 * Math.PI;
47
+ return arc2;
48
+ }
49
+ function isWithin(aNew, aStart, aStop, ccw) {
50
+ let rYes = false;
51
+ if (roundZero(withinPiPi(aNew - aStart)) === 0) {
52
+ rYes = true;
53
+ } else if (roundZero(withinPiPi(aNew - aStop)) === 0) {
54
+ rYes = true;
55
+ } else {
56
+ const arcOrig = orientedArc(aStart, aStop, ccw);
57
+ const arcNew = orientedArc(aStart, aNew, ccw);
58
+ if (Math.abs(arcNew) < Math.abs(arcOrig)) {
59
+ rYes = true;
60
+ }
61
+ }
62
+ return rYes;
63
+ }
64
+ function ffix(ifloat) {
65
+ return ifloat.toFixed(2);
66
+ }
67
+
68
+ // src/canvas_utils.ts
69
+ var colors = {
70
+ point: "grey",
71
+ line: "grey",
72
+ vector: "DarkTurquoise",
73
+ contour: "green",
74
+ main: "SteelBlue",
75
+ mainB: "SlateGrey",
76
+ second: "Violet",
77
+ secondB: "SlateGrey",
78
+ dynamics: "Tomato",
79
+ ruler: "blue",
80
+ origin: "red",
81
+ reference: "blue",
82
+ mouse: "yellow"
83
+ };
84
+ function point2canvas(px, py, iAdjust) {
85
+ const cx2 = iAdjust.shiftX + (px - iAdjust.xMin) * iAdjust.scaleX;
86
+ const cy2 = iAdjust.shiftY + (py - iAdjust.yMin) * iAdjust.scaleY;
87
+ return [cx2, cy2];
88
+ }
89
+ function canvas2point(cx, cy, iAdjust) {
90
+ const px2 = (cx - iAdjust.shiftX) / iAdjust.scaleX + iAdjust.xMin;
91
+ const py2 = (cy - iAdjust.shiftY) / iAdjust.scaleY + iAdjust.yMin;
92
+ return [px2, py2];
93
+ }
94
+ function canvasTranslatePolar(cx, cy, ia, il) {
95
+ const cx2 = cx + il * Math.cos(ia);
96
+ const cy2 = cy - il * Math.sin(ia);
97
+ return [cx2, cy2];
98
+ }
99
+ function radius2canvas(iRadius, iAdjust) {
100
+ if (roundZero(iAdjust.scaleX - Math.abs(iAdjust.scaleY)) !== 0) {
101
+ throw `err683: iAdjust.scaleX and scaleY differ ${iAdjust.scaleX} ${iAdjust.scaleY}`;
102
+ }
103
+ const rRadius = iRadius * iAdjust.scaleX;
104
+ return rRadius;
105
+ }
106
+ function adjustZero() {
107
+ const rAdjustZero = {
108
+ init: 0,
109
+ xMin: 0,
110
+ yMin: 0,
111
+ xyDiff: 1,
112
+ shiftX: 0,
113
+ shiftY: 0,
114
+ scaleX: 1,
115
+ scaleY: 1
116
+ };
117
+ return rAdjustZero;
118
+ }
119
+ function adjustInit(xMin, xMax, yMin, yMax, cWidth, cHeight) {
120
+ const rAdjust = adjustZero();
121
+ const xDiff = Math.max(xMax - xMin, 1);
122
+ const yDiff = Math.max(yMax - yMin, 1);
123
+ const xScale = cWidth / xDiff;
124
+ const yScale = cHeight / yDiff;
125
+ let xyScale = 0.9 * xScale;
126
+ let xyDiff = xDiff;
127
+ if (yScale < xScale) {
128
+ xyScale = 0.9 * yScale;
129
+ xyDiff = yDiff;
130
+ }
131
+ rAdjust.init = 1;
132
+ rAdjust.xMin = xMin;
133
+ rAdjust.yMin = yMin;
134
+ rAdjust.xyDiff = xyDiff;
135
+ rAdjust.shiftX = 0.05 * cWidth;
136
+ rAdjust.scaleX = xyScale;
137
+ rAdjust.shiftY = cHeight - 0.05 * cHeight;
138
+ rAdjust.scaleY = -1 * xyScale;
139
+ return rAdjust;
140
+ }
141
+ function adjustCenter(px, py, iAdjust) {
142
+ const rAdjust = structuredClone(iAdjust);
143
+ rAdjust.xMin = px - rAdjust.xyDiff / 2;
144
+ rAdjust.yMin = py - rAdjust.xyDiff / 2;
145
+ return rAdjust;
146
+ }
147
+ function adjustRect(p1x, p1y, p2x, p2y, cWidth, cHeight) {
148
+ const xMin = Math.min(p1x, p2x);
149
+ const xMax = Math.max(p1x, p2x);
150
+ const yMin = Math.min(p1y, p2y);
151
+ const yMax = Math.max(p1y, p2y);
152
+ const rAdjust = adjustInit(xMin, xMax, yMin, yMax, cWidth, cHeight);
153
+ return rAdjust;
154
+ }
155
+ function adjustScale(iFactor, iAdjust) {
156
+ const rAdjust = structuredClone(iAdjust);
157
+ const shift = (1 - iFactor) / 2;
158
+ rAdjust.xMin += shift * iAdjust.xyDiff;
159
+ rAdjust.yMin += shift * iAdjust.xyDiff;
160
+ rAdjust.xyDiff *= iFactor;
161
+ rAdjust.scaleX *= 1 / iFactor;
162
+ rAdjust.scaleY *= 1 / iFactor;
163
+ return rAdjust;
164
+ }
165
+ function adjustTranslate(p1x, p1y, p2x, p2y, iAdjust) {
166
+ const rAdjust = structuredClone(iAdjust);
167
+ const xDiff = p2x - p1x;
168
+ const yDiff = p2y - p1y;
169
+ rAdjust.xMin += -xDiff;
170
+ rAdjust.yMin += -yDiff;
171
+ return rAdjust;
172
+ }
173
+
174
+ // src/triangle_utils.ts
175
+ function rightTriLbFromLaLc(ila, ilc) {
176
+ let rlb = 0;
177
+ if (ilc > ila) {
178
+ throw `err539: ila < ilc ${ila} ${ilc}`;
179
+ } else {
180
+ rlb = Math.sqrt(ila ** 2 - ilc ** 2);
181
+ }
182
+ return rlb;
183
+ }
184
+ function lcFromLaLbAc(la, lb, ac) {
185
+ const rlc = Math.sqrt(la ** 2 + lb ** 2 - 2 * la * lb * Math.cos(ac));
186
+ return rlc;
187
+ }
188
+ function aCFromLaLbLc(la, lb, lc) {
189
+ let rac = 0;
190
+ const l3 = [la, lb, lc];
191
+ for (let i = 0; i < l3.length; i++) {
192
+ if (l3[i] < 0) {
193
+ throw `err209: l3[${i}] = ${l3[i]}`;
194
+ }
195
+ }
196
+ const l3s = l3.sort(function(a, b) {
197
+ return b - a;
198
+ });
199
+ if (l3s[0] > l3s[1] + l3s[2]) {
200
+ throw `err839: impossible triangle with length ${la}, ${lb} and ${lc}`;
201
+ } else {
202
+ rac = Math.acos((la ** 2 + lb ** 2 - lc ** 2) / (2 * la * lb));
203
+ }
204
+ return rac;
205
+ }
206
+ function lbFromLaAaAb(ila, iaA, iaB) {
207
+ let rlb = 0;
208
+ const args = [ila, iaA, iaB];
209
+ for (let i = 0; i < args.length; i++) {
210
+ if (roundZero(args[i]) === 0 || args[i] < 0) {
211
+ throw `err329: negative or zero triangle-args ${i} : ${args[i]}`;
212
+ }
213
+ }
214
+ const aA = withinZeroPi(iaA);
215
+ const aB = withinZeroPi(iaB);
216
+ const sum = aA + aB;
217
+ if (sum > Math.PI) {
218
+ throw `err939: impossible triangle with angles ${iaA} and ${iaB}`;
219
+ } else {
220
+ rlb = ila * Math.sin(iaB) / Math.sin(iaA);
221
+ }
222
+ return rlb;
223
+ }
224
+ function aBFromLaLbAa(ila, ilb, iaA) {
225
+ let rab = 0;
226
+ const args = [ila, ilb, iaA];
227
+ for (let i = 0; i < args.length; i++) {
228
+ if (args[i] <= 0) {
229
+ throw `err429: negative or zero triangle-args ${i} : ${args[i]}`;
230
+ }
231
+ }
232
+ rab = Math.asin(ilb * Math.sin(iaA) / ila);
233
+ return rab;
234
+ }
235
+
236
+ // src/point.ts
237
+ var ShapePoint = /* @__PURE__ */ ((ShapePoint2) => {
238
+ ShapePoint2[ShapePoint2["eDefault"] = 0] = "eDefault";
239
+ ShapePoint2[ShapePoint2["eCircle"] = 1] = "eCircle";
240
+ ShapePoint2[ShapePoint2["eCross"] = 2] = "eCross";
241
+ ShapePoint2[ShapePoint2["eSquare"] = 3] = "eSquare";
242
+ ShapePoint2[ShapePoint2["eBigSquare"] = 4] = "eBigSquare";
243
+ ShapePoint2[ShapePoint2["eTwoTri"] = 5] = "eTwoTri";
244
+ ShapePoint2[ShapePoint2["eTri1"] = 6] = "eTri1";
245
+ ShapePoint2[ShapePoint2["eTri2"] = 7] = "eTri2";
246
+ ShapePoint2[ShapePoint2["eTri3"] = 8] = "eTri3";
247
+ ShapePoint2[ShapePoint2["eTri4"] = 9] = "eTri4";
248
+ return ShapePoint2;
249
+ })(ShapePoint || {});
250
+ var Point = class _Point {
251
+ cx;
252
+ cy;
253
+ shape;
254
+ constructor(ix, iy, ishape = 0 /* eDefault */) {
255
+ this.cx = ix;
256
+ this.cy = iy;
257
+ this.shape = ishape;
258
+ }
259
+ draw(ctx, cAdjust, color = colors.point, ishape = 0 /* eDefault */) {
260
+ if (isFinite(this.cx) && isFinite(this.cy)) {
261
+ const radius = ctx.canvas.width * (0.7 / 100);
262
+ const radius2 = 2 * radius;
263
+ const [cx2, cy2] = point2canvas(this.cx, this.cy, cAdjust);
264
+ let shape = ishape;
265
+ if (shape === 0 /* eDefault */) {
266
+ shape = this.shape;
267
+ }
268
+ ctx.beginPath();
269
+ switch (shape) {
270
+ case 2 /* eCross */:
271
+ ctx.moveTo(cx2 - radius2, cy2);
272
+ ctx.lineTo(cx2 + radius2, cy2);
273
+ ctx.moveTo(cx2, cy2 - radius2);
274
+ ctx.lineTo(cx2, cy2 + radius2);
275
+ break;
276
+ case 3 /* eSquare */:
277
+ ctx.rect(cx2 - radius, cy2 - radius, 2 * radius, 2 * radius);
278
+ break;
279
+ case 4 /* eBigSquare */:
280
+ ctx.rect(cx2 - 2 * radius, cy2 - 2 * radius, 4 * radius, 4 * radius);
281
+ break;
282
+ case 5 /* eTwoTri */:
283
+ ctx.moveTo(cx2 - radius2, cy2);
284
+ ctx.lineTo(cx2 + radius2, cy2);
285
+ ctx.lineTo(cx2, cy2 + radius2);
286
+ ctx.lineTo(cx2, cy2 - radius2);
287
+ ctx.lineTo(cx2 - radius2, cy2);
288
+ break;
289
+ case 6 /* eTri1 */:
290
+ ctx.moveTo(cx2 - radius2, cy2);
291
+ ctx.lineTo(cx2 + radius2, cy2);
292
+ ctx.lineTo(cx2, cy2 - radius2);
293
+ ctx.lineTo(cx2, cy2 + radius2);
294
+ break;
295
+ case 7 /* eTri2 */:
296
+ ctx.moveTo(cx2 + radius2, cy2);
297
+ ctx.lineTo(cx2 - radius2, cy2);
298
+ ctx.lineTo(cx2, cy2 - radius2);
299
+ ctx.lineTo(cx2, cy2 + radius2);
300
+ break;
301
+ case 8 /* eTri3 */:
302
+ ctx.moveTo(cx2 + radius2, cy2);
303
+ ctx.lineTo(cx2 - radius2, cy2);
304
+ ctx.lineTo(cx2, cy2 + radius2);
305
+ ctx.lineTo(cx2, cy2 - radius2);
306
+ break;
307
+ case 9 /* eTri4 */:
308
+ ctx.moveTo(cx2 - radius2, cy2);
309
+ ctx.lineTo(cx2 + radius2, cy2);
310
+ ctx.lineTo(cx2, cy2 + radius2);
311
+ ctx.lineTo(cx2, cy2 - radius2);
312
+ break;
313
+ case 1 /* eCircle */:
314
+ default:
315
+ ctx.arc(cx2, cy2, radius, 0, 2 * Math.PI);
316
+ }
317
+ ctx.strokeStyle = color;
318
+ ctx.stroke();
319
+ } else {
320
+ console.log(`INFO489: point not draw because of infinity ${this.cx} ${this.cy}`);
321
+ }
322
+ }
323
+ distanceOrig() {
324
+ return Math.sqrt(this.cx ** 2 + this.cy ** 2);
325
+ }
326
+ angleOrig() {
327
+ return Math.atan2(this.cy, this.cx);
328
+ }
329
+ getPolar() {
330
+ return [this.angleOrig(), this.distanceOrig()];
331
+ }
332
+ setPolar(ia, il) {
333
+ return new _Point(il * Math.cos(ia), il * Math.sin(ia));
334
+ }
335
+ translate(ix, iy) {
336
+ return new _Point(this.cx + ix, this.cy + iy);
337
+ }
338
+ translatePolar(ia, il) {
339
+ return new _Point(this.cx + il * Math.cos(ia), this.cy + il * Math.sin(ia));
340
+ }
341
+ clone(ishape = 0 /* eDefault */) {
342
+ return new _Point(this.cx, this.cy, ishape);
343
+ }
344
+ rotateOrig(ia) {
345
+ const polar = this.getPolar();
346
+ return this.setPolar(polar[0] + ia, polar[1]);
347
+ }
348
+ scaleOrig(ir) {
349
+ const polar = this.getPolar();
350
+ return this.setPolar(polar[0], polar[1] * ir);
351
+ }
352
+ rotate(ic, ia) {
353
+ const p1 = this.translate(-1 * ic.cx, -1 * ic.cy);
354
+ const polar = p1.getPolar();
355
+ const p2 = this.setPolar(polar[0] + ia, polar[1]);
356
+ return p2.translate(ic.cx, ic.cy);
357
+ }
358
+ scale(ic, ir) {
359
+ const p1 = this.translate(-1 * ic.cx, -1 * ic.cy);
360
+ const polar = p1.getPolar();
361
+ const p2 = this.setPolar(polar[0], polar[1] * ir);
362
+ return p2.translate(ic.cx, ic.cy);
363
+ }
364
+ // point comparison
365
+ isEqual(ic) {
366
+ const rb = roundZero(this.cx - ic.cx) === 0 && roundZero(this.cy - ic.cy) === 0;
367
+ return rb;
368
+ }
369
+ // measurement
370
+ distanceToPoint(p2) {
371
+ const rd = Math.sqrt((p2.cx - this.cx) ** 2 + (p2.cy - this.cy) ** 2);
372
+ return rd;
373
+ }
374
+ angleToPoint(p2) {
375
+ if (roundZero(this.distanceToPoint(p2)) === 0) {
376
+ throw `err434: no angle because points identical ${this.cx} ${p2.cx} ${this.cy} ${p2.cy}`;
377
+ }
378
+ const ra = Math.atan2(p2.cy - this.cy, p2.cx - this.cx);
379
+ return ra;
380
+ }
381
+ angleFromToPoints(p2, p3) {
382
+ const ap2 = this.angleToPoint(p2);
383
+ const ap3 = this.angleToPoint(p3);
384
+ const ra = withinPiPi(ap3 - ap2);
385
+ return ra;
386
+ }
387
+ // from 2 points create a new point
388
+ middlePoint(p2) {
389
+ const rx = (this.cx + p2.cx) / 2;
390
+ const ry = (this.cy + p2.cy) / 2;
391
+ return new _Point(rx, ry);
392
+ }
393
+ equidistantPoint(p2, dist, p3) {
394
+ const lp1p2h = this.distanceToPoint(p2) / 2;
395
+ if (this.isEqual(p2)) {
396
+ throw `err633: no equidistance because identical point ${this.cx} ${this.cy}`;
397
+ }
398
+ if (dist < lp1p2h) {
399
+ throw `err392: equidistance ${dist} smaller than lp1p2h ${lp1p2h}`;
400
+ }
401
+ const pbi = this.middlePoint(p2);
402
+ const abi = this.angleToPoint(p2) + Math.PI / 2;
403
+ const oppos = Math.sqrt(dist ** 2 - lp1p2h ** 2);
404
+ const rp1 = pbi.translatePolar(abi, oppos);
405
+ const rp2 = pbi.translatePolar(abi + Math.PI, oppos);
406
+ const dp1 = p3.distanceToPoint(rp1);
407
+ const dp2 = p3.distanceToPoint(rp2);
408
+ if (oppos !== 0 && dp1 === dp2) {
409
+ throw `err284: magnet point p3 is on line p1p2. cx ${p3.cx} cy: ${p3.cy}`;
410
+ }
411
+ let rp = rp1;
412
+ if (dp2 < dp1) {
413
+ rp = rp2;
414
+ }
415
+ return rp;
416
+ }
417
+ };
418
+ function point(ix, iy, ishape = 0 /* eDefault */) {
419
+ return new Point(ix, iy, ishape);
420
+ }
421
+ function pointMinMax(aPoint) {
422
+ let xMin = 0;
423
+ let xMax = 0;
424
+ let yMin = 0;
425
+ let yMax = 0;
426
+ if (aPoint.length > 0) {
427
+ const p0 = aPoint[0];
428
+ if (p0.cx === Number.NEGATIVE_INFINITY || p0.cx === Number.POSITIVE_INFINITY || p0.cy === Number.NEGATIVE_INFINITY || p0.cy === Number.POSITIVE_INFINITY) {
429
+ throw `err292: pointMinMax first point with infinity: ${p0.cx} ${p0.cy}`;
430
+ }
431
+ xMin = aPoint[0].cx;
432
+ xMax = aPoint[0].cx;
433
+ yMin = aPoint[0].cy;
434
+ yMax = aPoint[0].cy;
435
+ for (const p of aPoint) {
436
+ if (p.cx !== Number.NEGATIVE_INFINITY) {
437
+ xMin = Math.min(xMin, p.cx);
438
+ }
439
+ if (p.cx !== Number.POSITIVE_INFINITY) {
440
+ xMax = Math.max(xMax, p.cx);
441
+ }
442
+ if (p.cy !== Number.NEGATIVE_INFINITY) {
443
+ yMin = Math.min(yMin, p.cy);
444
+ }
445
+ if (p.cy !== Number.POSITIVE_INFINITY) {
446
+ yMax = Math.max(yMax, p.cy);
447
+ }
448
+ }
449
+ }
450
+ return [xMin, xMax, yMin, yMax];
451
+ }
452
+
453
+ // src/line.ts
454
+ var Line = class _Line {
455
+ cx;
456
+ cy;
457
+ ca;
458
+ constructor(ix, iy, ia) {
459
+ this.cx = ix;
460
+ this.cy = iy;
461
+ this.ca = ia;
462
+ }
463
+ draw(ctx, cAdjust, color = colors.line) {
464
+ const display_length = ctx.canvas.width * 2;
465
+ const [cx1, cy1] = point2canvas(
466
+ this.cx - display_length * Math.cos(this.ca),
467
+ this.cy - display_length * Math.sin(this.ca),
468
+ cAdjust
469
+ );
470
+ const [cx2, cy2] = point2canvas(
471
+ this.cx + 2 * display_length * Math.cos(this.ca),
472
+ this.cy + 2 * display_length * Math.sin(this.ca),
473
+ cAdjust
474
+ );
475
+ ctx.beginPath();
476
+ ctx.moveTo(cx1, cy1);
477
+ ctx.lineTo(cx2, cy2);
478
+ ctx.strokeStyle = color;
479
+ ctx.stroke();
480
+ }
481
+ setFromPoints(p1, p2) {
482
+ this.cx = p1.cx;
483
+ this.cy = p1.cy;
484
+ this.ca = p1.angleToPoint(p2);
485
+ return this;
486
+ }
487
+ getAffine() {
488
+ const rAffine = { quasiVertical: false, ha: 0, hb: 0, va: 0, vb: 0 };
489
+ const angleZeroHPi = Math.abs(withinHPiHPi(this.ca));
490
+ if (angleZeroHPi > Math.PI / 4) {
491
+ rAffine.quasiVertical = true;
492
+ rAffine.va = -1 * Math.tan(withinHPiHPi(this.ca - Math.PI / 2));
493
+ rAffine.vb = this.cx - rAffine.va * this.cy;
494
+ } else {
495
+ rAffine.ha = Math.tan(withinHPiHPi(this.ca));
496
+ rAffine.hb = this.cy - rAffine.ha * this.cx;
497
+ }
498
+ return rAffine;
499
+ }
500
+ setAffine(iAffine) {
501
+ const rLine = new _Line(0, 0, 0);
502
+ if (iAffine.quasiVertical) {
503
+ rLine.ca = Math.PI / 2 - Math.atan(iAffine.va);
504
+ rLine.cx = iAffine.vb;
505
+ rLine.cy = 0;
506
+ } else {
507
+ rLine.ca = Math.atan(iAffine.ha);
508
+ rLine.cx = 0;
509
+ rLine.cy = iAffine.hb;
510
+ }
511
+ return rLine;
512
+ }
513
+ // intersection
514
+ intersection(il) {
515
+ if (this.isParallel(il)) {
516
+ throw `err902: no intersection, lines are parallel ca1: ${this.ca} ca2: ${il.ca}`;
517
+ }
518
+ let rx = 0;
519
+ let ry = 0;
520
+ const affin1 = this.getAffine();
521
+ const affin2 = il.getAffine();
522
+ if (affin1.quasiVertical) {
523
+ if (affin2.quasiVertical) {
524
+ ry = (affin1.vb - affin2.vb) / (affin2.va - affin1.va);
525
+ rx = affin1.va * ry + affin1.vb;
526
+ } else {
527
+ rx = (affin1.va * affin2.hb + affin1.vb) / (1 - affin1.va * affin2.ha);
528
+ ry = affin2.ha * rx + affin2.hb;
529
+ }
530
+ } else {
531
+ if (affin2.quasiVertical) {
532
+ ry = (affin1.ha * affin2.vb + affin1.hb) / (1 - affin1.ha * affin2.va);
533
+ rx = affin2.va * ry + affin2.vb;
534
+ } else {
535
+ rx = (affin1.hb - affin2.hb) / (affin2.ha - affin1.ha);
536
+ ry = affin1.ha * rx + affin1.hb;
537
+ }
538
+ }
539
+ const rp = point(rx, ry);
540
+ return rp;
541
+ }
542
+ getAxisXIntersection() {
543
+ const c_axisX = new _Line(0, 0, 0);
544
+ const rp = this.intersection(c_axisX);
545
+ return rp.cx;
546
+ }
547
+ getAxisYIntersection() {
548
+ const c_axisY = new _Line(0, 0, Math.PI / 2);
549
+ const rp = this.intersection(c_axisY);
550
+ return rp.cy;
551
+ }
552
+ getAxisXIntersecTri() {
553
+ let rX = Infinity;
554
+ if (roundZero(withinHPiHPi(this.ca)) !== 0) {
555
+ const p1 = new Point(this.cx, this.cy);
556
+ const l1ca = withinZeroPi(this.ca);
557
+ const aC = p1.angleOrig();
558
+ const la = p1.distanceOrig();
559
+ if (roundZero(la) === 0) {
560
+ rX = 0;
561
+ } else if (roundZero(withinHPiHPi(l1ca - aC)) === 0) {
562
+ rX = 0;
563
+ } else {
564
+ const aA = Math.min(l1ca, Math.PI - l1ca);
565
+ const aB = withinPiPi(l1ca - aC);
566
+ const aB2 = Math.min(Math.abs(aB), Math.PI - Math.abs(aB));
567
+ rX = Math.sign(aB) * lbFromLaAaAb(la, aA, aB2);
568
+ }
569
+ }
570
+ return rX;
571
+ }
572
+ getAxisYIntersecTri() {
573
+ let rY = Infinity;
574
+ if (roundZero(withinHPiHPi(this.ca - Math.PI / 2)) !== 0) {
575
+ const p1 = new Point(this.cx, this.cy);
576
+ const l1ca = withinHPiHPi(this.ca);
577
+ const aC = p1.angleOrig();
578
+ const la = p1.distanceOrig();
579
+ const angleDiff = withinHPiHPi(l1ca - aC);
580
+ if (roundZero(la) === 0) {
581
+ rY = 0;
582
+ } else if (roundZero(angleDiff) === 0) {
583
+ rY = 0;
584
+ } else {
585
+ const aA = withinZeroPi(l1ca - Math.PI / 2);
586
+ const aB = -1 * withinPiPi(l1ca - aC);
587
+ const aA2 = Math.min(aA, Math.PI - aA);
588
+ const aB2 = Math.min(Math.abs(aB), Math.PI - Math.abs(aB));
589
+ rY = Math.sign(aB) * lbFromLaAaAb(la, aA2, aB2);
590
+ }
591
+ }
592
+ return rY;
593
+ }
594
+ angleOrig() {
595
+ const p1 = new Point(this.cx, this.cy);
596
+ const aC = p1.angleOrig();
597
+ const l1ca = withinHPiHPi(this.ca);
598
+ const aB = -1 * withinPiPi(l1ca - aC);
599
+ let direction = 0;
600
+ if (aB < 0) {
601
+ direction = -Math.PI;
602
+ }
603
+ const ra = withinZeroPi(Math.PI / 2 + this.ca) + direction;
604
+ return ra;
605
+ }
606
+ distanceOrig() {
607
+ const a1 = this.angleOrig();
608
+ const p1 = new Point(this.cx, this.cy);
609
+ const a2 = p1.angleOrig();
610
+ const la = p1.distanceOrig();
611
+ const a12 = withinHPiHPi(a2 - a1);
612
+ const rd = la * Math.cos(a12);
613
+ return rd;
614
+ }
615
+ projectOrig() {
616
+ const pa = this.angleOrig();
617
+ const pl = this.distanceOrig();
618
+ return point(0, 0).setPolar(pa, pl);
619
+ }
620
+ // methods inherited from point
621
+ translate(ix, iy) {
622
+ return new _Line(this.cx + ix, this.cy + iy, this.ca);
623
+ }
624
+ rotateOrig(ia) {
625
+ const lPoint2 = new Point(this.cx, this.cy).rotateOrig(ia);
626
+ return new _Line(lPoint2.cx, lPoint2.cy, withinPiPi(this.ca + ia));
627
+ }
628
+ scaleOrig(ir) {
629
+ const lPoint2 = new Point(this.cx, this.cy).scaleOrig(ir);
630
+ return new _Line(lPoint2.cx, lPoint2.cy, this.ca);
631
+ }
632
+ rotate(ic, ia) {
633
+ const lPoint2 = new Point(this.cx, this.cy).rotate(ic, ia);
634
+ return new _Line(lPoint2.cx, lPoint2.cy, withinPiPi(this.ca + ia));
635
+ }
636
+ scale(ic, ir) {
637
+ const lPoint2 = new Point(this.cx, this.cy).scale(ic, ir);
638
+ return new _Line(lPoint2.cx, lPoint2.cy, this.ca);
639
+ }
640
+ clone() {
641
+ const lPoint2 = new Point(this.cx, this.cy);
642
+ return new _Line(lPoint2.cx, lPoint2.cy, this.ca);
643
+ }
644
+ // end of methods from point
645
+ // line creation
646
+ lineOrthogonal(ic) {
647
+ return new _Line(ic.cx, ic.cy, this.ca + Math.PI / 2);
648
+ }
649
+ lineParallel(ic) {
650
+ return new _Line(ic.cx, ic.cy, this.ca);
651
+ }
652
+ // orthogonal projection
653
+ distanceToPoint(ic) {
654
+ let rd = 0;
655
+ const p1 = new Point(this.cx, this.cy);
656
+ const lp1ic = p1.distanceToPoint(ic);
657
+ if (roundZero(lp1ic) !== 0) {
658
+ const aC = p1.angleToPoint(ic);
659
+ const aB = withinHPiHPi(aC - this.ca);
660
+ rd = lp1ic * Math.abs(Math.sin(aB));
661
+ }
662
+ return rd;
663
+ }
664
+ projectPoint(ic) {
665
+ let rd = 0;
666
+ const p1 = new Point(this.cx, this.cy);
667
+ const lp1ic = p1.distanceToPoint(ic);
668
+ if (roundZero(lp1ic) !== 0) {
669
+ const aC = p1.angleToPoint(ic);
670
+ const aB = withinPiPi(aC - this.ca);
671
+ rd = lp1ic * Math.cos(aB);
672
+ }
673
+ const rp = p1.translatePolar(this.ca, rd);
674
+ return rp;
675
+ }
676
+ // line comparison
677
+ isParallel(il) {
678
+ const rb = roundZero(withinHPiHPi(this.ca - il.ca)) === 0;
679
+ return rb;
680
+ }
681
+ isOrthogonal(il) {
682
+ const rb = roundZero(withinHPiHPi(Math.PI / 2 + this.ca - il.ca)) === 0;
683
+ return rb;
684
+ }
685
+ isEqual(il) {
686
+ const p2 = point(il.cx, il.cy);
687
+ const dist = this.distanceToPoint(p2);
688
+ const rb = roundZero(dist) === 0 && this.isParallel(il);
689
+ return rb;
690
+ }
691
+ // bisector
692
+ bisector(il, ip) {
693
+ const pInter = this.intersection(il);
694
+ const a1t = withinZeroPi(this.ca);
695
+ const a2t = withinZeroPi(il.ca);
696
+ const a1 = Math.min(a1t, a2t);
697
+ const a2 = Math.max(a1t, a2t);
698
+ const aList = [a1, a2, a1 + Math.PI, a2 + Math.PI, a1];
699
+ const aRef = pInter.angleToPoint(ip);
700
+ let idx = 0;
701
+ for (let i = 0; i < 4; i++) {
702
+ const aDiff1 = withinPiPi(aList[i] - aRef);
703
+ const aDiff2 = withinPiPi(aList[i + 1] - aRef);
704
+ if (aDiff1 === 0 || aDiff2 === 0) {
705
+ throw `err419: bad reference point for bisecor ${ip.cx} ${ip.cy}`;
706
+ }
707
+ if (aDiff1 < 0 && aDiff2 > 0) {
708
+ idx = i;
709
+ }
710
+ }
711
+ const a0 = withinZeroPi((a1 + a2) / 2);
712
+ const ca = a0 + idx * Math.PI / 2;
713
+ return new _Line(pInter.cx, pInter.cy, ca);
714
+ }
715
+ // parallel distance
716
+ lineParallelDistance(iDist, ipMagnet, ipMagnet2) {
717
+ const p1 = point(this.cx, this.cy);
718
+ const p2a = p1.translatePolar(this.ca + Math.PI / 2, iDist);
719
+ const p2b = p1.translatePolar(this.ca - Math.PI / 2, iDist);
720
+ let p2 = p2b;
721
+ let pMagnet = ipMagnet;
722
+ if (roundZero(this.distanceToPoint(pMagnet)) === 0) {
723
+ pMagnet = ipMagnet2;
724
+ }
725
+ if (pMagnet.distanceToPoint(p2a) < pMagnet.distanceToPoint(p2b)) {
726
+ p2 = p2a;
727
+ }
728
+ return new _Line(p2.cx, p2.cy, this.ca);
729
+ }
730
+ };
731
+ function line(ix, iy, ia) {
732
+ return new Line(ix, iy, ia);
733
+ }
734
+ function linePP(ip1, ip2) {
735
+ const rline = line(0, 0, 0).setFromPoints(ip1, ip2);
736
+ return rline;
737
+ }
738
+ function bisector(ip1, ip2) {
739
+ if (ip1.isEqual(ip2)) {
740
+ throw `err546: no bisector with two same points cx: ${ip1.cx} cy: ${ip1.cy}`;
741
+ }
742
+ const pbi = ip1.middlePoint(ip2);
743
+ const abi = withinZeroPi(ip1.angleToPoint(ip2) + Math.PI / 2);
744
+ return line(pbi.cx, pbi.cy, abi);
745
+ }
746
+ function circleCenter(ip1, ip2, ip3) {
747
+ if (ip1.isEqual(ip2) || ip2.isEqual(ip3) || ip1.isEqual(ip3)) {
748
+ throw `err833: no bisector with two same points cx: ${ip1.cx} cy: ${ip1.cy}`;
749
+ }
750
+ const bisec1 = bisector(ip1, ip2);
751
+ const bisec2 = bisector(ip2, ip3);
752
+ const rp = bisec1.intersection(bisec2);
753
+ return rp;
754
+ }
755
+
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
+ // src/segment.ts
843
+ function isSeg(iSegEnum) {
844
+ let rIsSeg = false;
845
+ if (iSegEnum === 0 /* eStroke */ || iSegEnum === 1 /* eArc */) {
846
+ rIsSeg = true;
847
+ }
848
+ return rIsSeg;
849
+ }
850
+ function isAddPoint(iSegEnum) {
851
+ let rIsOther = false;
852
+ if (isSeg(iSegEnum) || iSegEnum === 6 /* eStart */) {
853
+ rIsOther = true;
854
+ }
855
+ return rIsOther;
856
+ }
857
+ function isActiveCorner(iSegEnum) {
858
+ let rIsActiveCorner = false;
859
+ if (iSegEnum === 3 /* eRounded */ || iSegEnum === 4 /* eWidened */ || iSegEnum === 5 /* eWideAcc */) {
860
+ rIsActiveCorner = true;
861
+ }
862
+ return rIsActiveCorner;
863
+ }
864
+ function isCorner(iSegEnum) {
865
+ let rIsCorner = false;
866
+ if (iSegEnum === 2 /* ePointed */ || isActiveCorner(iSegEnum)) {
867
+ rIsCorner = true;
868
+ }
869
+ return rIsCorner;
870
+ }
871
+ var Segment1 = class _Segment1 {
872
+ sType;
873
+ px;
874
+ py;
875
+ radius;
876
+ arcLarge;
877
+ arcCcw;
878
+ constructor(iType, ix, iy, iRadius, iArcLarge = false, iArcCcw = false) {
879
+ this.sType = iType;
880
+ this.px = ix;
881
+ this.py = iy;
882
+ this.radius = iRadius;
883
+ this.arcLarge = iArcLarge;
884
+ this.arcCcw = iArcCcw;
885
+ }
886
+ clone() {
887
+ const rseg1 = new _Segment1(
888
+ this.sType,
889
+ this.px,
890
+ this.py,
891
+ this.radius,
892
+ this.arcLarge,
893
+ this.arcCcw
894
+ );
895
+ return rseg1;
896
+ }
897
+ };
898
+ var Segment2 = class {
899
+ sType;
900
+ p1;
901
+ p2;
902
+ pc;
903
+ radius;
904
+ a1;
905
+ a2;
906
+ arcCcw;
907
+ constructor(iType, ip1, ip2, ipc, iRadius, ia1, ia2, iArcCcw = false) {
908
+ this.sType = iType;
909
+ this.p1 = ip1;
910
+ this.p2 = ip2;
911
+ this.pc = ipc;
912
+ this.radius = iRadius;
913
+ this.a1 = ia1;
914
+ this.a2 = ia2;
915
+ this.arcCcw = iArcCcw;
916
+ }
917
+ };
918
+ var SegDbg = class {
919
+ debugPoints;
920
+ debugLines;
921
+ logMessage;
922
+ constructor() {
923
+ this.debugPoints = [];
924
+ this.debugLines = [];
925
+ this.logMessage = "";
926
+ }
927
+ addPoint(ip) {
928
+ this.debugPoints.push(ip);
929
+ }
930
+ getPoints() {
931
+ return this.debugPoints;
932
+ }
933
+ clearPoints() {
934
+ this.debugPoints = [];
935
+ }
936
+ addLine(il) {
937
+ this.debugLines.push(il);
938
+ }
939
+ getLines() {
940
+ return this.debugLines;
941
+ }
942
+ clearLines() {
943
+ this.debugLines = [];
944
+ }
945
+ addMsg(iMsg) {
946
+ this.logMessage += iMsg;
947
+ }
948
+ getMsg() {
949
+ return this.logMessage;
950
+ }
951
+ clearMsg() {
952
+ this.logMessage = "";
953
+ }
954
+ };
955
+ var gSegDbg = new SegDbg();
956
+ function arcSeg1To2(px1, py1, iSeg1) {
957
+ if (iSeg1.sType !== 1 /* eArc */) {
958
+ throw `err202: arcSeg1To2 has unexpected type ${iSeg1.sType}`;
959
+ }
960
+ const p1 = point(px1, py1);
961
+ const p2 = point(iSeg1.px, iSeg1.py);
962
+ const lp1p2h = p1.distanceToPoint(p2) / 2;
963
+ if (p1.isEqual(p2)) {
964
+ throw `err638: no equidistance because identical point ${p1.cx} ${p2.cy}`;
965
+ }
966
+ let oppos = 0;
967
+ if (roundZero(iSeg1.radius - lp1p2h) === 0) {
968
+ oppos = 0;
969
+ } else if (iSeg1.radius < lp1p2h) {
970
+ throw `err399: radius ${iSeg1.radius} smaller than lp1p2h ${lp1p2h}`;
971
+ } else {
972
+ oppos = rightTriLbFromLaLc(iSeg1.radius, lp1p2h);
973
+ }
974
+ const pbi = p1.middlePoint(p2);
975
+ const abi = p1.angleToPoint(p2) + Math.PI / 2;
976
+ const rp1 = pbi.translatePolar(abi, oppos);
977
+ const rp2 = pbi.translatePolar(abi + Math.PI, oppos);
978
+ let rp3 = rp1;
979
+ if (!iSeg1.arcLarge && !iSeg1.arcCcw || iSeg1.arcLarge && iSeg1.arcCcw) {
980
+ rp3 = rp2;
981
+ }
982
+ const a1 = rp3.angleToPoint(p1);
983
+ const a2 = rp3.angleToPoint(p2);
984
+ const rSeg2 = new Segment2(1 /* eArc */, p1, p2, rp3, iSeg1.radius, a1, a2, iSeg1.arcCcw);
985
+ return rSeg2;
986
+ }
987
+ function arcSeg2To1(iSeg2) {
988
+ let a12 = withinZero2Pi(iSeg2.a2 - iSeg2.a1);
989
+ if (!iSeg2.arcCcw) {
990
+ a12 = 2 * Math.PI - a12;
991
+ }
992
+ let large = false;
993
+ if (a12 > Math.PI) {
994
+ large = true;
995
+ }
996
+ const rSeg1 = new Segment1(
997
+ 1 /* eArc */,
998
+ iSeg2.p2.cx,
999
+ iSeg2.p2.cy,
1000
+ iSeg2.radius,
1001
+ large,
1002
+ iSeg2.arcCcw
1003
+ );
1004
+ return rSeg1;
1005
+ }
1006
+ function prepare(s1, s2, s3) {
1007
+ const p1 = s1.p1;
1008
+ const p2 = s1.p2;
1009
+ const p2b = s3.p1;
1010
+ const p3 = s3.p2;
1011
+ if (!p2.isEqual(p2b)) {
1012
+ throw `err309: makeCorner-prepare p2 and p2b differ px ${p2.cx} ${p2b.cx} py ${p2.cy} ${p2b.cy}`;
1013
+ }
1014
+ let aTangent1 = p2.angleToPoint(p1);
1015
+ if (s1.sType === 1 /* eArc */) {
1016
+ const sign = s1.arcCcw ? 1 : -1;
1017
+ aTangent1 = s1.a2 - sign * Math.PI / 2;
1018
+ }
1019
+ let aTangent3 = p2.angleToPoint(p3);
1020
+ if (s3.sType === 1 /* eArc */) {
1021
+ const sign = s3.arcCcw ? 1 : -1;
1022
+ aTangent3 = s3.a1 + sign * Math.PI / 2;
1023
+ }
1024
+ const a123 = aTangent3 - aTangent1;
1025
+ const a123b = withinPiPi(a123);
1026
+ let aPeakHalf = a123b / 2;
1027
+ if (roundZero(aPeakHalf) === 0) {
1028
+ const tolerance2 = tolerance * 10 ** -2;
1029
+ if (s1.sType === 0 /* eStroke */ && s3.sType === 1 /* eArc */) {
1030
+ aPeakHalf = s3.arcCcw ? tolerance2 : -tolerance2;
1031
+ } else if (s1.sType === 1 /* eArc */ && s3.sType === 0 /* eStroke */) {
1032
+ aPeakHalf = s1.arcCcw ? tolerance2 : -tolerance2;
1033
+ } else if (s1.sType === 0 /* eStroke */ && s3.sType === 0 /* eStroke */) {
1034
+ throw `err402: prepare aPeakHalf too closed to zero ${aPeakHalf}`;
1035
+ }
1036
+ }
1037
+ const aBisector = aTangent1 + aPeakHalf;
1038
+ const p6 = p2.translatePolar(aBisector, s2.radius);
1039
+ const rPre = {
1040
+ s1,
1041
+ s2,
1042
+ s3,
1043
+ ra: s2.radius,
1044
+ p1,
1045
+ p2,
1046
+ p3,
1047
+ p4: s1.pc,
1048
+ p5: s3.pc,
1049
+ p6,
1050
+ at1: aTangent1,
1051
+ at3: aTangent3,
1052
+ abi: aBisector,
1053
+ aph: aPeakHalf
1054
+ };
1055
+ return rPre;
1056
+ }
1057
+ function modifRadius(iaph, iseg, iradius) {
1058
+ if (iseg.sType !== 1 /* eArc */) {
1059
+ throw `err510: modifRadius with wrong type ${iseg.sType}`;
1060
+ }
1061
+ const bisector2 = iaph > 0 ? 1 : -1;
1062
+ const arcCcw = iseg.arcCcw ? 1 : -1;
1063
+ const sign = roundZero(iaph) === 0 ? 1 : bisector2 * arcCcw;
1064
+ const rmr = iseg.radius + sign * iradius;
1065
+ if (rmr <= 0) {
1066
+ throw `err621: modifRadius with negative modified lenght ${rmr}`;
1067
+ }
1068
+ return rmr;
1069
+ }
1070
+ function closestPoint(ica, dist, pB, p6) {
1071
+ const p7a = pB.translatePolar(ica, dist);
1072
+ const p7b = pB.translatePolar(ica + Math.PI, dist);
1073
+ const d67a = p6.distanceToPoint(p7a);
1074
+ const d67b = p6.distanceToPoint(p7b);
1075
+ const rp7 = d67a < d67b ? p7a : p7b;
1076
+ return rp7;
1077
+ }
1078
+ function closestPoint2(p4, a45, a547, dist, p6) {
1079
+ const p7a = p4.translatePolar(a45 - a547, dist);
1080
+ const p7b = p4.translatePolar(a45 + a547, dist);
1081
+ const d67a = p6.distanceToPoint(p7a);
1082
+ const d67b = p6.distanceToPoint(p7b);
1083
+ const sign = d67a < d67b ? -1 : 1;
1084
+ return sign;
1085
+ }
1086
+ function newStrokeFirst(iseg, ip) {
1087
+ const p8 = ip.clone();
1088
+ const p1 = iseg.p1.clone();
1089
+ const p2 = iseg.p2;
1090
+ if (iseg.sType !== 0 /* eStroke */) {
1091
+ throw `err103: newStrokeFirst unexpected sType ${iseg.sType}`;
1092
+ }
1093
+ const distLine = linePP(p1, p2).distanceToPoint(p8);
1094
+ if (roundZero(distLine) !== 0) {
1095
+ throw `err104: newStrokeFirst new point not aligned ${distLine} ${p8.cx} ${p8.cy}`;
1096
+ }
1097
+ const a2 = p1.angleToPoint(p2);
1098
+ const a8 = p1.angleToPoint(p8);
1099
+ if (roundZero(withinPiPi(a8 - a2)) !== 0) {
1100
+ throw `err105: newStrokeFirst new point miss aligned ${a2} ${a8} ${p8.cx} ${p8.cy}`;
1101
+ }
1102
+ const l18 = p1.distanceToPoint(p8);
1103
+ const l12 = p1.distanceToPoint(p2);
1104
+ if (l12 < l18) {
1105
+ throw `err106: newStrokeFirst new point out of scope ${l12} ${l18} ${p8.cx} ${p8.cy}`;
1106
+ }
1107
+ const p0 = point(0, 0);
1108
+ const rNewSeg = new Segment2(0 /* eStroke */, p1, p8, p0, 0, 0, 0, false);
1109
+ return rNewSeg;
1110
+ }
1111
+ function newStrokeSecond(iseg, ip) {
1112
+ const p9 = ip.clone();
1113
+ const p3 = iseg.p2.clone();
1114
+ const p2 = iseg.p1;
1115
+ if (iseg.sType !== 0 /* eStroke */) {
1116
+ throw `err203: newStrokeSecond unexpected sType ${iseg.sType}`;
1117
+ }
1118
+ const distLine = linePP(p3, p2).distanceToPoint(p9);
1119
+ if (roundZero(distLine) !== 0) {
1120
+ throw `err204: newStrokeSecond new point not aligned ${distLine} ${p9.cx} ${p9.cy}`;
1121
+ }
1122
+ const a2 = p3.angleToPoint(p2);
1123
+ const a9 = p3.angleToPoint(p9);
1124
+ if (roundZero(withinPiPi(a9 - a2)) !== 0) {
1125
+ throw `err205: newStrokeSecond new point miss aligned ${a2} ${a9} ${p9.cx} ${p9.cy}`;
1126
+ }
1127
+ const l39 = p3.distanceToPoint(p9);
1128
+ const l32 = p3.distanceToPoint(p2);
1129
+ if (l32 < l39) {
1130
+ throw `err206: newStrokeSecond new point out of scope ${l32} ${l39} ${p9.cx} ${p9.cy}`;
1131
+ }
1132
+ const p0 = point(0, 0);
1133
+ const rNewSeg = new Segment2(0 /* eStroke */, p9, p3, p0, 0, 0, 0, false);
1134
+ return rNewSeg;
1135
+ }
1136
+ function newArcFirst(iseg, ip) {
1137
+ if (iseg.sType !== 1 /* eArc */) {
1138
+ throw `err203: newArcFirst unexpected sType ${iseg.sType}`;
1139
+ }
1140
+ const p1 = iseg.p1.clone();
1141
+ const p4 = iseg.pc.clone();
1142
+ const p8 = ip.clone();
1143
+ const a48 = p4.angleToPoint(p8);
1144
+ if (!isWithin(a48, iseg.a1, iseg.a2, iseg.arcCcw)) {
1145
+ throw `err908: newArcFirst a48 out of scope ${a48} ${iseg.a1} ${iseg.a2} ${iseg.arcCcw}`;
1146
+ }
1147
+ const rNewSeg = new Segment2(1 /* eArc */, p1, p8, p4, iseg.radius, iseg.a1, a48, iseg.arcCcw);
1148
+ return rNewSeg;
1149
+ }
1150
+ function newArcSecond(iseg, ip) {
1151
+ if (iseg.sType !== 1 /* eArc */) {
1152
+ throw `err204: newArcSecond unexpected sType ${iseg.sType}`;
1153
+ }
1154
+ const p3 = iseg.p2.clone();
1155
+ const p5 = iseg.pc.clone();
1156
+ const p9 = ip.clone();
1157
+ const a59 = p5.angleToPoint(p9);
1158
+ if (!isWithin(a59, iseg.a1, iseg.a2, iseg.arcCcw)) {
1159
+ throw `err907: newArcSecond a59 out of scope ${a59} ${iseg.a1} ${iseg.a2} ${iseg.arcCcw}`;
1160
+ }
1161
+ const rNewSeg = new Segment2(1 /* eArc */, p9, p3, p5, iseg.radius, a59, iseg.a2, iseg.arcCcw);
1162
+ return rNewSeg;
1163
+ }
1164
+ function newRounded(ip8, ip9, ip7, ra, aph, abi) {
1165
+ const p8 = ip8.clone();
1166
+ const p9 = ip9.clone();
1167
+ const p7 = ip7.clone();
1168
+ const l78 = p7.distanceToPoint(p8);
1169
+ const l79 = p7.distanceToPoint(p9);
1170
+ if (roundZero(l78 - ra) !== 0 || roundZero(l79 - ra) !== 0) {
1171
+ throw `err610: newRounded not on circle ${ra} ${l78} ${l79}`;
1172
+ }
1173
+ const a78 = p7.angleToPoint(p8);
1174
+ const a79 = p7.angleToPoint(p9);
1175
+ const a873 = withinPiPi(a78 - abi + Math.PI);
1176
+ const a973 = withinPiPi(a79 - abi + Math.PI);
1177
+ if (Math.abs(a973 - a873) > Math.PI + tolerance) {
1178
+ gSegDbg.addMsg(
1179
+ `warn882: newRounded a873 or a972 larger than PI/2 ${ffix(a873)} ${ffix(a973)} at ${ffix(p7.cx)} ${ffix(p7.cy)}
1180
+ `
1181
+ );
1182
+ }
1183
+ const ccw2 = aph > 0 ? false : true;
1184
+ const rNewSeg = new Segment2(1 /* eArc */, p8, p9, p7, ra, a78, a79, ccw2);
1185
+ return rNewSeg;
1186
+ }
1187
+ function roundStrokeStroke(ag) {
1188
+ const l7 = Math.abs(ag.ra / Math.sin(ag.aph));
1189
+ const l7b = l7 * Math.cos(ag.aph);
1190
+ const p7 = ag.p2.translatePolar(ag.abi, l7);
1191
+ const p8 = ag.p2.translatePolar(ag.at1, l7b);
1192
+ const p9 = ag.p2.translatePolar(ag.at3, l7b);
1193
+ const rsegs = [];
1194
+ rsegs.push(newStrokeFirst(ag.s1, p8));
1195
+ rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
1196
+ rsegs.push(newStrokeSecond(ag.s3, p9));
1197
+ return rsegs;
1198
+ }
1199
+ function roundStrokeArc(ag) {
1200
+ const lStroke = linePP(ag.p1, ag.p2);
1201
+ const lStrokep = lStroke.lineParallelDistance(ag.ra, ag.p6, ag.p5);
1202
+ const pB = lStrokep.projectPoint(ag.p5);
1203
+ const lB5 = pB.distanceToPoint(ag.p5);
1204
+ const ml = modifRadius(ag.aph, ag.s3, ag.ra);
1205
+ const lB7 = rightTriLbFromLaLc(ml, lB5);
1206
+ const p7 = closestPoint(lStrokep.ca, lB7, pB, ag.p6);
1207
+ const a57 = ag.p5.angleToPoint(p7);
1208
+ const p9 = ag.p5.translatePolar(a57, ag.s3.radius);
1209
+ const a127 = ag.p2.angleFromToPoints(ag.p1, p7);
1210
+ const l27 = Math.abs(ag.ra / Math.sin(a127));
1211
+ const l28 = l27 * Math.cos(a127);
1212
+ const a28 = ag.p2.angleToPoint(ag.p1);
1213
+ const p8 = ag.p2.translatePolar(a28, l28);
1214
+ const rsegs = [];
1215
+ rsegs.push(newStrokeFirst(ag.s1, p8));
1216
+ rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
1217
+ rsegs.push(newArcSecond(ag.s3, p9));
1218
+ return rsegs;
1219
+ }
1220
+ function roundArcStroke(ag) {
1221
+ const lStroke = linePP(ag.p3, ag.p2);
1222
+ const lStrokep = lStroke.lineParallelDistance(ag.ra, ag.p6, ag.p4);
1223
+ const pB = lStrokep.projectPoint(ag.p4);
1224
+ const lB4 = pB.distanceToPoint(ag.p4);
1225
+ const ml = modifRadius(ag.aph, ag.s1, ag.ra);
1226
+ const lB7 = rightTriLbFromLaLc(ml, lB4);
1227
+ const p7 = closestPoint(lStrokep.ca, lB7, pB, ag.p6);
1228
+ const a47 = ag.p4.angleToPoint(p7);
1229
+ const p8 = ag.p4.translatePolar(a47, ag.s1.radius);
1230
+ const a327 = ag.p2.angleFromToPoints(ag.p3, p7);
1231
+ const l27 = Math.abs(ag.ra / Math.sin(a327));
1232
+ const l29 = l27 * Math.cos(a327);
1233
+ const a29 = ag.p2.angleToPoint(ag.p3);
1234
+ const p9 = ag.p2.translatePolar(a29, l29);
1235
+ const rsegs = [];
1236
+ rsegs.push(newArcFirst(ag.s1, p8));
1237
+ rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
1238
+ rsegs.push(newStrokeSecond(ag.s3, p9));
1239
+ return rsegs;
1240
+ }
1241
+ function roundArcArc(ag) {
1242
+ const mr1 = modifRadius(ag.aph, ag.s1, ag.ra);
1243
+ const mr3 = modifRadius(ag.aph, ag.s3, ag.ra);
1244
+ const lp4p5 = ag.p4.distanceToPoint(ag.p5);
1245
+ const a45 = ag.p4.angleToPoint(ag.p5);
1246
+ const a547 = aCFromLaLbLc(lp4p5, mr1, mr3);
1247
+ const sign1 = closestPoint2(ag.p4, a45, a547, mr1, ag.p6);
1248
+ const a47 = a45 + sign1 * a547;
1249
+ const p7 = ag.p4.translatePolar(a47, mr1);
1250
+ const p8 = ag.p4.translatePolar(a47, ag.s1.radius);
1251
+ const a54 = Math.PI + a45;
1252
+ const a457 = aCFromLaLbLc(lp4p5, mr3, mr1);
1253
+ const sign2 = closestPoint2(ag.p5, a54, a457, mr3, ag.p6);
1254
+ const a57 = a54 + sign2 * a457;
1255
+ const p7b = ag.p5.translatePolar(a57, mr3);
1256
+ if (!p7b.isEqual(p7)) {
1257
+ throw `err909: roundArcArc p7 anf p7b differ ${p7.cx} ${p7b.cx} ${p7.cy} ${p7b.cy} ${0 /* eDefault */}`;
1258
+ }
1259
+ const p9 = ag.p5.translatePolar(a57, ag.s3.radius);
1260
+ const rsegs = [];
1261
+ rsegs.push(newArcFirst(ag.s1, p8));
1262
+ rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
1263
+ rsegs.push(newArcSecond(ag.s3, p9));
1264
+ return rsegs;
1265
+ }
1266
+ function widenCorner(ag) {
1267
+ const a68 = ag.abi - 2 * ag.aph;
1268
+ const a69 = ag.abi + 2 * ag.aph;
1269
+ let p8 = ag.p6.translatePolar(a68, ag.ra);
1270
+ let p9 = ag.p6.translatePolar(a69, ag.ra);
1271
+ if (ag.s1.sType === 1 /* eArc */) {
1272
+ const a246 = ag.p4.angleFromToPoints(ag.p2, ag.p6);
1273
+ const a42 = ag.p4.angleToPoint(ag.p2);
1274
+ const a46 = a42 + 2 * a246;
1275
+ p8 = ag.p4.translatePolar(a46, ag.s1.radius);
1276
+ }
1277
+ if (ag.s3.sType === 1 /* eArc */) {
1278
+ const a256 = ag.p5.angleFromToPoints(ag.p2, ag.p6);
1279
+ const a52 = ag.p5.angleToPoint(ag.p2);
1280
+ const a56 = a52 + 2 * a256;
1281
+ p9 = ag.p5.translatePolar(a56, ag.s3.radius);
1282
+ }
1283
+ const ccw2 = ag.aph > 0 ? false : true;
1284
+ const segCorner = new Segment2(1 /* eArc */, p8, p9, ag.p6, ag.ra, a68, a69, ccw2);
1285
+ const rsegs = [];
1286
+ if (ag.s1.sType === 0 /* eStroke */) {
1287
+ rsegs.push(newStrokeFirst(ag.s1, p8));
1288
+ } else if (ag.s1.sType === 1 /* eArc */) {
1289
+ rsegs.push(newArcFirst(ag.s1, p8));
1290
+ }
1291
+ rsegs.push(segCorner);
1292
+ if (ag.s3.sType === 0 /* eStroke */) {
1293
+ rsegs.push(newStrokeSecond(ag.s3, p9));
1294
+ } else if (ag.s3.sType === 1 /* eArc */) {
1295
+ rsegs.push(newArcSecond(ag.s3, p9));
1296
+ }
1297
+ return rsegs;
1298
+ }
1299
+ function wideAccessSide(sign, one, p8one, ag) {
1300
+ let p8a = p8one;
1301
+ let p8b = p8one;
1302
+ const a268 = ag.p6.angleFromToPoints(ag.p2, p8one);
1303
+ if (Math.abs(a268) > Math.PI / 2) {
1304
+ p8b = ag.p6.translatePolar(ag.abi + sign * Math.PI / 2, ag.ra);
1305
+ const l2 = line(p8b.cx, p8b.cy, ag.abi);
1306
+ if (one.sType === 0 /* eStroke */) {
1307
+ const l1 = linePP(one.p1, one.p2);
1308
+ p8a = l1.intersection(l2);
1309
+ } else if (one.sType === 1 /* eArc */) {
1310
+ const ph = l2.projectPoint(one.pc);
1311
+ const lh4 = ph.distanceToPoint(one.pc);
1312
+ if (lh4 < one.radius) {
1313
+ const lh8a = rightTriLbFromLaLc(one.radius, lh4);
1314
+ p8a = closestPoint(ag.abi, lh8a, ph, p8one);
1315
+ } else {
1316
+ gSegDbg.addMsg(
1317
+ `warn222: wideAccess not possible on arc ${ffix(one.radius)} ${ffix(lh4)} at ${ffix(p8one.cx)} ${ffix(p8one.cy)}
1318
+ `
1319
+ );
1320
+ p8a = p8one;
1321
+ p8b = p8one;
1322
+ }
1323
+ }
1324
+ }
1325
+ return [p8a, p8b];
1326
+ }
1327
+ function wideAccessCorner(ag) {
1328
+ const ones = widenCorner(ag);
1329
+ const sign1 = ones[1].arcCcw ? 1 : -1;
1330
+ const [p8a, p8b] = wideAccessSide(sign1, ag.s1, ones[1].p1, ag);
1331
+ const [p9a, p9b] = wideAccessSide(-sign1, ag.s3, ones[1].p2, ag);
1332
+ const rsegs = [];
1333
+ if (p8a.isEqual(p8b)) {
1334
+ rsegs.push(ones[0]);
1335
+ } else {
1336
+ if (ag.s1.sType === 0 /* eStroke */) {
1337
+ rsegs.push(newStrokeFirst(ag.s1, p8a));
1338
+ } else if (ag.s1.sType === 1 /* eArc */) {
1339
+ rsegs.push(newArcFirst(ag.s1, p8a));
1340
+ }
1341
+ const p0 = point(0, 0);
1342
+ const newStroke = new Segment2(0 /* eStroke */, p8a, p8b, p0, 0, 0, 0, false);
1343
+ rsegs.push(newStroke);
1344
+ }
1345
+ rsegs.push(newRounded(p8b, p9b, ag.p6, ag.ra, ag.aph, ag.abi));
1346
+ if (p9a.isEqual(p9b)) {
1347
+ rsegs.push(ones[2]);
1348
+ } else {
1349
+ const p0 = point(0, 0);
1350
+ const newStroke = new Segment2(0 /* eStroke */, p9b, p9a, p0, 0, 0, 0, false);
1351
+ rsegs.push(newStroke);
1352
+ if (ag.s3.sType === 0 /* eStroke */) {
1353
+ rsegs.push(newStrokeSecond(ag.s3, p9a));
1354
+ } else if (ag.s3.sType === 1 /* eArc */) {
1355
+ rsegs.push(newArcSecond(ag.s3, p9a));
1356
+ }
1357
+ }
1358
+ return rsegs;
1359
+ }
1360
+ function makeCorner(s1, s2, s3) {
1361
+ const preArg = prepare(s1, s2, s3);
1362
+ const rsegs = [];
1363
+ if (s2.sType === 3 /* eRounded */) {
1364
+ if (s1.sType === 0 /* eStroke */ && s3.sType === 0 /* eStroke */) {
1365
+ rsegs.push(...roundStrokeStroke(preArg));
1366
+ } else if (s1.sType === 0 /* eStroke */ && s3.sType === 1 /* eArc */) {
1367
+ rsegs.push(...roundStrokeArc(preArg));
1368
+ } else if (s1.sType === 1 /* eArc */ && s3.sType === 0 /* eStroke */) {
1369
+ rsegs.push(...roundArcStroke(preArg));
1370
+ } else if (s1.sType === 1 /* eArc */ && s3.sType === 1 /* eArc */) {
1371
+ rsegs.push(...roundArcArc(preArg));
1372
+ } else {
1373
+ throw `err123: makeCorner unexpected s1s3.sType ${s1.sType} ${s3.sType}`;
1374
+ }
1375
+ } else if (s2.sType === 4 /* eWidened */) {
1376
+ rsegs.push(...widenCorner(preArg));
1377
+ } else if (s2.sType === 5 /* eWideAcc */) {
1378
+ rsegs.push(...wideAccessCorner(preArg));
1379
+ } else {
1380
+ throw `err723: makeCorner unexpected s2.sType ${s2.sType}`;
1381
+ }
1382
+ return rsegs;
1383
+ }
1384
+
1385
+ // src/write_svg.ts
1386
+ function ff(ifloat) {
1387
+ return ifloat.toFixed(4);
1388
+ }
1389
+ function svgCircleString(cx, cy, radius, color = "") {
1390
+ let sColor = color;
1391
+ if (sColor === "") {
1392
+ sColor = "black";
1393
+ }
1394
+ const rSvg = `<circle cx="${ff(cx)}" cy="${ff(cy)}" r="${ff(
1395
+ radius
1396
+ )}" stroke="${sColor}" stroke-width="1" fill="none" />`;
1397
+ return rSvg;
1398
+ }
1399
+ var SvgPath = class {
1400
+ pathD;
1401
+ constructor() {
1402
+ this.pathD = "";
1403
+ }
1404
+ addStart(px, py) {
1405
+ this.pathD = `M ${ff(px)} ${ff(py)}`;
1406
+ }
1407
+ addStroke(px, py) {
1408
+ this.pathD += ` L ${ff(px)} ${ff(py)}`;
1409
+ }
1410
+ addArc(px, py, radius, large, ccw) {
1411
+ const aRadius = ff(radius);
1412
+ const aLarge = large ? 1 : 0;
1413
+ const aCcw = ccw ? 1 : 0;
1414
+ this.pathD += ` A ${aRadius} ${aRadius} 0 ${aLarge} ${aCcw} ${ff(px)} ${ff(py)}`;
1415
+ }
1416
+ stringify(color = "") {
1417
+ let sColor = color;
1418
+ if (sColor === "") {
1419
+ sColor = "black";
1420
+ }
1421
+ const rSvg = `<path d="${this.pathD} Z" stroke="${sColor}" stroke-width="1" fill="none" />`;
1422
+ return rSvg;
1423
+ }
1424
+ };
1425
+ function svgPath() {
1426
+ const rSvgPath = new SvgPath();
1427
+ return rSvgPath;
1428
+ }
1429
+ var SvgWriter = class {
1430
+ svgStr;
1431
+ payloadStr;
1432
+ groupActive;
1433
+ constructor() {
1434
+ this.payloadStr = "";
1435
+ this.svgStr = "";
1436
+ this.groupActive = false;
1437
+ }
1438
+ addHeader(xMin, xWidth, yMin, yHeight) {
1439
+ const viewBoxValues = `${xMin} ${yMin} ${xWidth} ${yHeight}`;
1440
+ this.svgStr = `<svg width="${xWidth}" height="${yHeight}" viewBox="${viewBoxValues}" xmlns="http://www.w3.org/2000/svg">`;
1441
+ }
1442
+ addSvgString(svgString) {
1443
+ this.payloadStr += svgString;
1444
+ }
1445
+ addGroup(groupId) {
1446
+ if (this.groupActive) {
1447
+ throw `err321: group must be closed before opening a new one`;
1448
+ }
1449
+ this.groupActive = true;
1450
+ this.payloadStr += `<g id="${groupId}">`;
1451
+ }
1452
+ closeGroup() {
1453
+ if (!this.groupActive) {
1454
+ throw `err331: group is not active so can not be closed`;
1455
+ }
1456
+ this.groupActive = false;
1457
+ this.payloadStr += `</g>`;
1458
+ }
1459
+ closeSvg() {
1460
+ if (this.svgStr === "") {
1461
+ throw `err301: no header set for the svg`;
1462
+ }
1463
+ if (this.groupActive) {
1464
+ throw `err311: group is not closed`;
1465
+ }
1466
+ this.svgStr += this.payloadStr;
1467
+ this.svgStr += "</svg>";
1468
+ }
1469
+ stringify() {
1470
+ this.closeSvg();
1471
+ return this.svgStr;
1472
+ }
1473
+ };
1474
+ function svgWriter() {
1475
+ const rSvgWrite = new SvgWriter();
1476
+ return rSvgWrite;
1477
+ }
1478
+
1479
+ // src/write_dxf.ts
1480
+ function ff2(ifloat) {
1481
+ return ifloat.toFixed(4);
1482
+ }
1483
+ var DxfSeg = class {
1484
+ arc;
1485
+ p1x;
1486
+ p1y;
1487
+ radius;
1488
+ a1;
1489
+ a2;
1490
+ p2x;
1491
+ p2y;
1492
+ constructor(arc, p1x, p1y, radius, a1, a2, p2x, p2y) {
1493
+ this.arc = arc;
1494
+ this.p1x = p1x;
1495
+ this.p1y = p1y;
1496
+ this.radius = radius;
1497
+ this.a1 = a1;
1498
+ this.a2 = a2;
1499
+ this.p2x = p2x;
1500
+ this.p2y = p2y;
1501
+ }
1502
+ };
1503
+ function dxfSegLine(p1x, p1y, p2x, p2y) {
1504
+ const rDxfSeg = new DxfSeg(false, p1x, p1y, 0, 0, 0, p2x, p2y);
1505
+ return rDxfSeg;
1506
+ }
1507
+ function dxfSegArc(p1x, p1y, radius, aa1, aa2, arcCcw) {
1508
+ const a1 = arcCcw ? aa1 : aa2;
1509
+ const a2 = arcCcw ? aa2 : aa1;
1510
+ const b1 = radToDeg(withinZero2Pi(a1));
1511
+ const b2 = radToDeg(withinZero2Pi(a2));
1512
+ const rDxfSeg = new DxfSeg(true, p1x, p1y, radius, b1, b2, 0, 0);
1513
+ return rDxfSeg;
1514
+ }
1515
+ function dxfSegCircle(p1x, p1y, radius) {
1516
+ const rDxfSeg = new DxfSeg(false, p1x, p1y, radius, 0, 0, 0, 0);
1517
+ return rDxfSeg;
1518
+ }
1519
+ var DxfWrite = class {
1520
+ dxfStr;
1521
+ constructor() {
1522
+ this.dxfStr = "0\nSECTION\n2\nENTITIES\n";
1523
+ }
1524
+ addCircle(cx, cy, radius) {
1525
+ this.dxfStr += "0\nCIRCLE\n8\nPARAMETRIX\n";
1526
+ this.dxfStr += `10
1527
+ ${ff2(cx)}
1528
+ 20
1529
+ ${ff2(cy)}
1530
+ 40
1531
+ ${ff2(radius)}
1532
+ `;
1533
+ }
1534
+ addLine(p1x, p1y, p2x, p2y) {
1535
+ this.dxfStr += "0\nLINE\n8\nPARAMETRIX\n";
1536
+ this.dxfStr += `10
1537
+ ${ff2(p1x)}
1538
+ 20
1539
+ ${ff2(p1y)}
1540
+ 11
1541
+ ${ff2(p2x)}
1542
+ 21
1543
+ ${ff2(p2y)}
1544
+ `;
1545
+ }
1546
+ addArc(cx, cy, ra, a1, a2) {
1547
+ this.dxfStr += "0\nARC\n8\nPARAMETRIX\n";
1548
+ this.dxfStr += `10
1549
+ ${ff2(cx)}
1550
+ 20
1551
+ ${ff2(cy)}
1552
+ 40
1553
+ ${ff2(ra)}
1554
+ 50
1555
+ ${ff2(a1)}
1556
+ 51
1557
+ ${ff2(
1558
+ a2
1559
+ )}
1560
+ `;
1561
+ }
1562
+ close() {
1563
+ this.dxfStr += "0\nENDSEC\n0\nEOF\n";
1564
+ }
1565
+ stringify() {
1566
+ this.close();
1567
+ return this.dxfStr;
1568
+ }
1569
+ };
1570
+ function dxfWriter() {
1571
+ const rDxfWrite = new DxfWrite();
1572
+ return rDxfWrite;
1573
+ }
1574
+
1575
+ // src/prepare_pax.ts
1576
+ function ff3(ifloat) {
1577
+ const rFloat = ifloat;
1578
+ return rFloat;
1579
+ }
1580
+ function paxCircle(cx, cy, radius) {
1581
+ const rPax = {
1582
+ circle: true,
1583
+ cx: ff3(cx),
1584
+ cy: ff3(cy),
1585
+ radius: ff3(radius)
1586
+ };
1587
+ return rPax;
1588
+ }
1589
+ var PaxPath = class {
1590
+ seg;
1591
+ constructor() {
1592
+ this.seg = [];
1593
+ }
1594
+ addStart(px, py) {
1595
+ this.seg = [];
1596
+ const one = {
1597
+ typ: 0 /* eStart */,
1598
+ px,
1599
+ py
1600
+ };
1601
+ this.seg.push(one);
1602
+ }
1603
+ addStroke(px, py) {
1604
+ const one = {
1605
+ typ: 1 /* eStroke */,
1606
+ px,
1607
+ py
1608
+ };
1609
+ this.seg.push(one);
1610
+ }
1611
+ addArc(cx, cy, radius, large, ccw) {
1612
+ const one = {
1613
+ typ: 2 /* eArc */,
1614
+ px: cx,
1615
+ py: cy,
1616
+ radius,
1617
+ large,
1618
+ ccw
1619
+ };
1620
+ this.seg.push(one);
1621
+ }
1622
+ toJson() {
1623
+ const rPaxC = {
1624
+ circle: false,
1625
+ seg: this.seg
1626
+ };
1627
+ return rPaxC;
1628
+ }
1629
+ };
1630
+ function paxPath() {
1631
+ const rPaxPath = new PaxPath();
1632
+ return rPaxPath;
1633
+ }
1634
+
1635
+ // src/contour.ts
1636
+ var AContour = class {
1637
+ };
1638
+ var Contour = class _Contour extends AContour {
1639
+ circle = false;
1640
+ segments;
1641
+ points;
1642
+ debugPoints;
1643
+ debugLines;
1644
+ lastPoint;
1645
+ imposedColor;
1646
+ constructor(ix, iy, icolor = "") {
1647
+ super();
1648
+ this.segments = [new Segment1(6 /* eStart */, ix, iy, 0)];
1649
+ this.points = [];
1650
+ this.debugPoints = [];
1651
+ this.debugLines = [];
1652
+ this.lastPoint = point(ix, iy);
1653
+ this.imposedColor = icolor;
1654
+ }
1655
+ setLastPoint(ix, iy) {
1656
+ this.lastPoint = point(ix, iy);
1657
+ }
1658
+ getLastPoint() {
1659
+ return this.lastPoint;
1660
+ }
1661
+ addPointA(ax, ay) {
1662
+ if (this.points.length > 2) {
1663
+ throw `err311: contour add too much point ${ax} ${ay}`;
1664
+ }
1665
+ this.points.push(point(ax, ay));
1666
+ return this;
1667
+ }
1668
+ addPointAP(aa, al) {
1669
+ const p1 = point(0, 0).translatePolar(aa, al);
1670
+ this.addPointA(p1.cx, p1.cy);
1671
+ return this;
1672
+ }
1673
+ addPointR(rx, ry) {
1674
+ const plast = this.getLastPoint();
1675
+ const p1 = plast.translate(rx, ry);
1676
+ this.addPointA(p1.cx, p1.cy);
1677
+ return this;
1678
+ }
1679
+ addPointRP(ra, rl) {
1680
+ const plast = this.getLastPoint();
1681
+ const p1 = plast.translatePolar(ra, rl);
1682
+ this.addPointA(p1.cx, p1.cy);
1683
+ return this;
1684
+ }
1685
+ addSeg(iSeg) {
1686
+ this.segments.push(iSeg);
1687
+ return this;
1688
+ }
1689
+ addSegStroke() {
1690
+ if (this.points.length !== 1) {
1691
+ throw `err554: contour addSegStroke with unexpected points.length ${this.points.length}`;
1692
+ }
1693
+ const p1 = this.points.pop();
1694
+ if (p1 !== void 0) {
1695
+ const seg = new Segment1(0 /* eStroke */, p1.cx, p1.cy, 0);
1696
+ if (!p1.isEqual(this.getLastPoint())) {
1697
+ this.addSeg(seg);
1698
+ this.setLastPoint(p1.cx, p1.cy);
1699
+ }
1700
+ } else {
1701
+ throw `err284: contour p1 is undefined`;
1702
+ }
1703
+ return this;
1704
+ }
1705
+ addSegStrokeA(ax, ay) {
1706
+ this.addPointA(ax, ay).addSegStroke();
1707
+ return this;
1708
+ }
1709
+ addSegStrokeAP(aa, al) {
1710
+ this.addPointAP(aa, al).addSegStroke();
1711
+ return this;
1712
+ }
1713
+ addSegStrokeR(rx, ry) {
1714
+ this.addPointR(rx, ry).addSegStroke();
1715
+ return this;
1716
+ }
1717
+ addSegStrokeRP(ra, rl) {
1718
+ this.addPointRP(ra, rl).addSegStroke();
1719
+ return this;
1720
+ }
1721
+ addSegArc(iRadius, iLarge, iCcw) {
1722
+ if (this.points.length !== 1) {
1723
+ throw `err954: contour addSegArc with unexpected points.length ${this.points.length}`;
1724
+ }
1725
+ const p1 = this.points.pop();
1726
+ if (p1 !== void 0) {
1727
+ const seg = new Segment1(
1728
+ 1 /* eArc */,
1729
+ p1.cx,
1730
+ p1.cy,
1731
+ iRadius,
1732
+ iLarge,
1733
+ iCcw
1734
+ );
1735
+ if (!p1.isEqual(this.getLastPoint())) {
1736
+ this.addSeg(seg);
1737
+ this.setLastPoint(p1.cx, p1.cy);
1738
+ } else {
1739
+ console.log(
1740
+ `warn144: addSegArc last and new point identical ${ffix(p1.cx)} ${ffix(p1.cy)}`
1741
+ );
1742
+ }
1743
+ } else {
1744
+ throw `err482: contour p1 is undefined`;
1745
+ }
1746
+ return this;
1747
+ }
1748
+ addSegArc2() {
1749
+ if (this.points.length !== 2) {
1750
+ throw `err958: contour addSegArc2 with unexpected points.length ${this.points.length}`;
1751
+ }
1752
+ const p2 = this.points.pop();
1753
+ const p1 = this.points.pop();
1754
+ if (p1 !== void 0 && p2 !== void 0) {
1755
+ const p0 = this.getLastPoint();
1756
+ const p3 = circleCenter(p0, p1, p2);
1757
+ const radius = p3.distanceToPoint(p0);
1758
+ const p0p2middle = p0.middlePoint(p2);
1759
+ const a0 = p0p2middle.angleToPoint(p0);
1760
+ const a1 = p0p2middle.angleToPoint(p1);
1761
+ const a3 = p0p2middle.angleToPoint(p3);
1762
+ const a01 = withinPiPi(a1 - a0);
1763
+ const a03 = withinPiPi(a3 - a0);
1764
+ let large = false;
1765
+ let ccw = false;
1766
+ if (Math.sign(a03) * Math.sign(a01) > 0) {
1767
+ large = true;
1768
+ }
1769
+ if (Math.sign(a01) > 0) {
1770
+ ccw = true;
1771
+ }
1772
+ this.addPointA(p2.cx, p2.cy).addSegArc(radius, large, ccw);
1773
+ this.debugPoints.push(p1);
1774
+ } else {
1775
+ throw `err488: contour p1 or p2 or seg is undefined`;
1776
+ }
1777
+ return this;
1778
+ }
1779
+ addSegArc3(iTangentAngle1, firstNlast) {
1780
+ if (this.points.length !== 1) {
1781
+ throw `err914: contour addSegArc3 with unexpected points.length ${this.points.length}`;
1782
+ }
1783
+ const p1 = this.points.pop();
1784
+ if (p1 !== void 0) {
1785
+ const p0 = this.getLastPoint();
1786
+ const lbi = bisector(p0, p1);
1787
+ let pref = p1;
1788
+ if (firstNlast) {
1789
+ pref = p0;
1790
+ }
1791
+ const lradial = line(pref.cx, pref.cy, iTangentAngle1 + Math.PI / 2);
1792
+ const pArcCenter = lbi.intersection(lradial);
1793
+ const radius = pArcCenter.distanceToPoint(p0);
1794
+ const pmid = p0.middlePoint(p1);
1795
+ const amid = pref.angleToPoint(pmid);
1796
+ const aref = withinPiPi(iTangentAngle1 - amid);
1797
+ let large = false;
1798
+ if (Math.abs(aref) > Math.PI / 2) {
1799
+ large = true;
1800
+ }
1801
+ let ccw = false;
1802
+ if (aref < 0) {
1803
+ ccw = true;
1804
+ }
1805
+ if (!firstNlast) {
1806
+ ccw = !ccw;
1807
+ }
1808
+ this.addPointA(p1.cx, p1.cy).addSegArc(radius, large, ccw);
1809
+ this.debugPoints.push(pmid);
1810
+ this.debugPoints.push(pArcCenter);
1811
+ } else {
1812
+ throw `err282: contour p1 is undefined`;
1813
+ }
1814
+ return this;
1815
+ }
1816
+ addSeg2Arcs(ita1, ita2) {
1817
+ if (this.points.length !== 1) {
1818
+ throw `err214: contour addSeg2Arcs with unexpected points.length ${this.points.length}`;
1819
+ }
1820
+ const p1 = this.points.pop();
1821
+ if (p1 !== void 0) {
1822
+ const p0 = this.getLastPoint();
1823
+ const l01 = p0.distanceToPoint(p1);
1824
+ const a01 = p0.angleToPoint(p1);
1825
+ const a10 = p1.angleToPoint(p0);
1826
+ const au = withinPiPi(ita1 - a01);
1827
+ const av = -1 * withinPiPi(ita2 - a10);
1828
+ if (Math.abs(au) >= Math.PI / 2) {
1829
+ throw `err545: addSeg2Arcs with too large au ${au}`;
1830
+ }
1831
+ if (Math.abs(av) >= Math.PI / 2) {
1832
+ throw `err546: addSeg2Arcs with too large av ${av}`;
1833
+ }
1834
+ if (roundZero(au) === 0) {
1835
+ throw `err765: addSeg2Arcs with almost zero au ${au}`;
1836
+ }
1837
+ if (roundZero(av) === 0) {
1838
+ throw `err766: addSeg2Arcs with almost zero av ${av}`;
1839
+ }
1840
+ if (Math.sign(au) * Math.sign(av) < 1) {
1841
+ throw `err767: addSeg2Arcs with au/av bad orientation ${au} ${av}`;
1842
+ }
1843
+ const tanu2 = Math.tan(au / 2);
1844
+ const tanv2 = Math.tan(av / 2);
1845
+ const lBH = l01 * tanv2 / (tanv2 + tanu2);
1846
+ const lJB = Math.abs(lBH / Math.sin(au));
1847
+ const lBG = lBH / Math.cos(au / 2);
1848
+ const lHC = l01 * tanu2 / (tanv2 + tanu2);
1849
+ const lIC = Math.abs(lHC / Math.sin(av));
1850
+ const p2 = p0.translatePolar(a01 + au / 2, lBG);
1851
+ let ccw = false;
1852
+ if (Math.sign(au) < 0) {
1853
+ ccw = true;
1854
+ }
1855
+ this.addPointA(p2.cx, p2.cy).addSegArc(lJB, false, ccw);
1856
+ this.addPointA(p1.cx, p1.cy).addSegArc(lIC, false, ccw);
1857
+ this.debugPoints.push(p0.translatePolar(a01, lBH));
1858
+ this.debugPoints.push(p0.translatePolar(a01 + au - Math.sign(au) * Math.PI / 2, lJB));
1859
+ this.debugPoints.push(p1.translatePolar(a10 - av + Math.sign(au) * Math.PI / 2, lIC));
1860
+ } else {
1861
+ throw `err182: contour p1 is undefined`;
1862
+ }
1863
+ return this;
1864
+ }
1865
+ addCornerPointed() {
1866
+ const seg = new Segment1(2 /* ePointed */, 0, 0, 0);
1867
+ this.addSeg(seg);
1868
+ return this;
1869
+ }
1870
+ addCornerRounded(iRadius) {
1871
+ const seg = new Segment1(3 /* eRounded */, 0, 0, iRadius);
1872
+ this.addSeg(seg);
1873
+ return this;
1874
+ }
1875
+ addCornerWidened(iRadius) {
1876
+ const seg = new Segment1(4 /* eWidened */, 0, 0, iRadius);
1877
+ this.addSeg(seg);
1878
+ return this;
1879
+ }
1880
+ addCornerWideAcc(iRadius) {
1881
+ const seg = new Segment1(5 /* eWideAcc */, 0, 0, iRadius);
1882
+ this.addSeg(seg);
1883
+ return this;
1884
+ }
1885
+ closeSegStroke() {
1886
+ const px = this.segments[0].px;
1887
+ const py = this.segments[0].py;
1888
+ this.addSegStrokeA(px, py);
1889
+ return this;
1890
+ }
1891
+ closeSegArc(iRadius, iLarge, iCcw) {
1892
+ const px = this.segments[0].px;
1893
+ const py = this.segments[0].py;
1894
+ this.addPointA(px, py).addSegArc(iRadius, iLarge, iCcw);
1895
+ return this;
1896
+ }
1897
+ clone() {
1898
+ const rctr = new _Contour(this.segments[0].px, this.segments[0].py);
1899
+ for (const seg of this.segments) {
1900
+ const nseg = seg.clone();
1901
+ if (nseg.sType !== 6 /* eStart */) {
1902
+ rctr.addSeg(nseg);
1903
+ if (isSeg(nseg.sType)) {
1904
+ rctr.setLastPoint(nseg.px, nseg.py);
1905
+ }
1906
+ }
1907
+ }
1908
+ return rctr;
1909
+ }
1910
+ translate(ix, iy) {
1911
+ const p0x = this.segments[0].px + ix;
1912
+ const p0y = this.segments[0].py + iy;
1913
+ const rctr = new _Contour(p0x, p0y);
1914
+ for (const seg of this.segments) {
1915
+ const nseg = seg.clone();
1916
+ if (isSeg(seg.sType)) {
1917
+ nseg.px += ix;
1918
+ nseg.py += iy;
1919
+ }
1920
+ if (nseg.sType !== 6 /* eStart */) {
1921
+ rctr.addSeg(nseg);
1922
+ if (isSeg(nseg.sType)) {
1923
+ rctr.setLastPoint(nseg.px, nseg.py);
1924
+ }
1925
+ }
1926
+ }
1927
+ return rctr;
1928
+ }
1929
+ translatePolar(ia, il) {
1930
+ return this.translate(il * Math.cos(ia), il * Math.sin(ia));
1931
+ }
1932
+ rotate(ix, iy, ia) {
1933
+ const ic = point(ix, iy);
1934
+ const pStart = point(this.segments[0].px, this.segments[0].py);
1935
+ const pStartRot = pStart.rotate(ic, ia);
1936
+ const rctr = new _Contour(pStartRot.cx, pStartRot.cy);
1937
+ for (const seg of this.segments) {
1938
+ const nseg = seg.clone();
1939
+ if (isSeg(seg.sType)) {
1940
+ const pt = point(nseg.px, nseg.py);
1941
+ const ptRot = pt.rotate(ic, ia);
1942
+ nseg.px = ptRot.cx;
1943
+ nseg.py = ptRot.cy;
1944
+ }
1945
+ if (nseg.sType !== 6 /* eStart */) {
1946
+ rctr.addSeg(nseg);
1947
+ if (isSeg(nseg.sType)) {
1948
+ rctr.setLastPoint(nseg.px, nseg.py);
1949
+ }
1950
+ }
1951
+ }
1952
+ return rctr;
1953
+ }
1954
+ scale(ix, iy, ir, scaleCorner = false) {
1955
+ const ic = point(ix, iy);
1956
+ const pStart = point(this.segments[0].px, this.segments[0].py);
1957
+ const pStartScale = pStart.scale(ic, ir);
1958
+ const rctr = new _Contour(pStartScale.cx, pStartScale.cy);
1959
+ for (const seg of this.segments) {
1960
+ const nseg = seg.clone();
1961
+ if (isSeg(seg.sType)) {
1962
+ const pt = point(nseg.px, nseg.py);
1963
+ const ptScale = pt.scale(ic, ir);
1964
+ nseg.px = ptScale.cx;
1965
+ nseg.py = ptScale.cy;
1966
+ }
1967
+ if (seg.sType === 1 /* eArc */) {
1968
+ nseg.radius *= ir;
1969
+ }
1970
+ if (isActiveCorner(seg.sType) && scaleCorner) {
1971
+ nseg.radius *= ir;
1972
+ }
1973
+ if (nseg.sType !== 6 /* eStart */) {
1974
+ rctr.addSeg(nseg);
1975
+ if (isSeg(nseg.sType)) {
1976
+ rctr.setLastPoint(nseg.px, nseg.py);
1977
+ }
1978
+ }
1979
+ }
1980
+ return rctr;
1981
+ }
1982
+ addPartial(iContour) {
1983
+ if (this.points.length > 0) {
1984
+ throw `err911: addPartial, points should be used ${this.points.length}`;
1985
+ }
1986
+ for (const seg of iContour.segments) {
1987
+ if (seg.sType !== 6 /* eStart */) {
1988
+ this.addSeg(seg);
1989
+ if (isSeg(seg.sType)) {
1990
+ this.setLastPoint(seg.px, seg.py);
1991
+ }
1992
+ }
1993
+ }
1994
+ return this;
1995
+ }
1996
+ draw(ctx, cAdjust, color = colors.contour) {
1997
+ const theColor = this.imposedColor === "" ? color : this.imposedColor;
1998
+ let px1 = 0;
1999
+ let py1 = 0;
2000
+ for (const seg of this.segments) {
2001
+ if (seg.sType === 0 /* eStroke */) {
2002
+ const [cx1, cy1] = point2canvas(px1, py1, cAdjust);
2003
+ const [cx2, cy2] = point2canvas(seg.px, seg.py, cAdjust);
2004
+ ctx.beginPath();
2005
+ ctx.moveTo(cx1, cy1);
2006
+ ctx.lineTo(cx2, cy2);
2007
+ ctx.strokeStyle = theColor;
2008
+ ctx.stroke();
2009
+ }
2010
+ if (seg.sType === 1 /* eArc */) {
2011
+ try {
2012
+ const seg2 = arcSeg1To2(px1, py1, seg);
2013
+ const [cx3, cy3] = point2canvas(seg2.pc.cx, seg2.pc.cy, cAdjust);
2014
+ const cRadius = radius2canvas(seg.radius, cAdjust);
2015
+ ctx.beginPath();
2016
+ ctx.arc(cx3, cy3, cRadius, -seg2.a1, -seg2.a2, seg.arcCcw);
2017
+ ctx.strokeStyle = theColor;
2018
+ ctx.stroke();
2019
+ } catch (emsg) {
2020
+ console.log("err413: " + emsg);
2021
+ }
2022
+ }
2023
+ if (isAddPoint(seg.sType)) {
2024
+ px1 = seg.px;
2025
+ py1 = seg.py;
2026
+ }
2027
+ }
2028
+ }
2029
+ extractSkeleton() {
2030
+ const seg0 = this.segments[0];
2031
+ const rContour = new _Contour(seg0.px, seg0.py);
2032
+ for (const seg of this.segments) {
2033
+ if (isSeg(seg.sType)) {
2034
+ rContour.addSeg(seg);
2035
+ }
2036
+ }
2037
+ return rContour;
2038
+ }
2039
+ generateContour() {
2040
+ gSegDbg.clearPoints();
2041
+ gSegDbg.clearLines();
2042
+ const segStack = [];
2043
+ const segStackEnd = [];
2044
+ let coType = 0;
2045
+ let px1 = 0;
2046
+ let py1 = 0;
2047
+ for (const seg of this.segments) {
2048
+ if (seg.sType === 0 /* eStroke */) {
2049
+ const p1 = point(px1, py1);
2050
+ const p2 = point(seg.px, seg.py);
2051
+ const p0 = point(0, 0);
2052
+ segStack.push(new Segment2(seg.sType, p1, p2, p0, 0, 0, 0, false));
2053
+ coType = 1;
2054
+ }
2055
+ if (seg.sType === 1 /* eArc */) {
2056
+ const seg2 = arcSeg1To2(px1, py1, seg);
2057
+ segStack.push(seg2);
2058
+ coType = 1;
2059
+ }
2060
+ const segz12 = segStack.at(-1);
2061
+ const segz2 = segStack.at(-2);
2062
+ if (segz12 !== void 0 && segz2 !== void 0) {
2063
+ if (isSeg(segz12.sType) && isCorner(segz2.sType)) {
2064
+ const s3 = segStack.pop();
2065
+ const s2 = segStack.pop();
2066
+ const s1 = segStack.pop();
2067
+ if (s1 !== void 0 && s2 !== void 0 && s3 !== void 0) {
2068
+ const segs = makeCorner(s1, s2, s3);
2069
+ segStack.push(...segs);
2070
+ } else {
2071
+ throw `err603: contour generateContour internal error`;
2072
+ }
2073
+ }
2074
+ }
2075
+ if (isCorner(seg.sType)) {
2076
+ if (coType === 2) {
2077
+ throw `err419: generateContour with two consecutive corners ${seg.sType}`;
2078
+ }
2079
+ if (coType === 0 && isActiveCorner(seg.sType) && seg.radius > 0) {
2080
+ const p0 = point(0, 0);
2081
+ segStackEnd.push(
2082
+ new Segment2(seg.sType, p0, p0, p0, seg.radius, 0, 0, false)
2083
+ );
2084
+ }
2085
+ if (coType === 1 && isActiveCorner(seg.sType) && seg.radius > 0) {
2086
+ const p0 = point(0, 0);
2087
+ segStack.push(
2088
+ new Segment2(seg.sType, p0, p0, p0, seg.radius, 0, 0, false)
2089
+ );
2090
+ }
2091
+ coType = 2;
2092
+ }
2093
+ if (isAddPoint(seg.sType)) {
2094
+ px1 = seg.px;
2095
+ py1 = seg.py;
2096
+ }
2097
+ }
2098
+ if (segStackEnd.length > 0) {
2099
+ if (coType === 1) {
2100
+ segStack.push(...segStackEnd);
2101
+ } else {
2102
+ throw `err397: contour generateContour Corners defined at end and begining`;
2103
+ }
2104
+ }
2105
+ const segz1 = segStack.at(-1);
2106
+ if (segz1 !== void 0) {
2107
+ if (isCorner(segz1.sType)) {
2108
+ const s3 = segStack[0];
2109
+ const s2 = segStack.pop();
2110
+ const s1 = segStack.pop();
2111
+ if (s1 !== void 0 && s2 !== void 0 && s3 !== void 0) {
2112
+ const segs = makeCorner(s1, s2, s3);
2113
+ segStack.push(...segs.slice(0, -1));
2114
+ const s4 = segs.at(-1);
2115
+ if (s4 !== void 0) {
2116
+ segStack[0] = s4;
2117
+ } else {
2118
+ throw `err606: contour generateContour internal error`;
2119
+ }
2120
+ } else {
2121
+ throw `err602: contour generateContour internal error`;
2122
+ }
2123
+ }
2124
+ }
2125
+ const seg0 = segStack[0];
2126
+ const rContour = new _Contour(seg0.p1.cx, seg0.p1.cy, this.imposedColor);
2127
+ rContour.debugPoints.push(...gSegDbg.getPoints());
2128
+ rContour.debugLines.push(...gSegDbg.getLines());
2129
+ for (const seg2 of segStack) {
2130
+ if (seg2.sType === 0 /* eStroke */) {
2131
+ rContour.addSegStrokeA(seg2.p2.cx, seg2.p2.cy);
2132
+ } else if (seg2.sType === 1 /* eArc */) {
2133
+ const seg1 = arcSeg2To1(seg2);
2134
+ rContour.addPointA(seg2.p2.cx, seg2.p2.cy).addSegArc(seg1.radius, seg1.arcLarge, seg1.arcCcw);
2135
+ } else {
2136
+ throw `err986: contour generateContour unexpected in seg2 Enum ${seg2.sType}`;
2137
+ }
2138
+ }
2139
+ return rContour;
2140
+ }
2141
+ generatePoints() {
2142
+ const rPoints = [];
2143
+ rPoints.push(...this.debugPoints);
2144
+ const seg0 = this.segments[0];
2145
+ rPoints.push(point(seg0.px, seg0.py));
2146
+ let px1 = 0;
2147
+ let py1 = 0;
2148
+ for (const seg of this.segments) {
2149
+ if (seg.sType === 1 /* eArc */) {
2150
+ try {
2151
+ const seg2 = arcSeg1To2(px1, py1, seg);
2152
+ const p3 = point(seg2.pc.cx, seg2.pc.cy);
2153
+ const a12h = withinPiPi((seg2.a2 - seg2.a1) / 2);
2154
+ let a3 = seg2.a1 + a12h;
2155
+ if (Math.sign(a12h) > 0 && !seg.arcCcw || Math.sign(a12h) < 0 && seg.arcCcw) {
2156
+ a3 += Math.PI;
2157
+ }
2158
+ const p4 = p3.translatePolar(a3, seg.radius);
2159
+ rPoints.push(p4);
2160
+ } catch (emsg) {
2161
+ console.log("err453: " + emsg);
2162
+ }
2163
+ }
2164
+ if (isAddPoint(seg.sType)) {
2165
+ px1 = seg.px;
2166
+ py1 = seg.py;
2167
+ rPoints.push(point(px1, py1));
2168
+ }
2169
+ }
2170
+ return rPoints;
2171
+ }
2172
+ generateLines() {
2173
+ const rLines = [];
2174
+ rLines.push(...this.debugLines);
2175
+ return rLines;
2176
+ }
2177
+ checkContour(ctr) {
2178
+ if (ctr.segments[0].sType !== 6 /* eStart */) {
2179
+ throw `err412: contour check first seg is not eStart ${ctr.segments[0].sType}`;
2180
+ }
2181
+ let px1 = 0;
2182
+ let py1 = 0;
2183
+ for (const seg of ctr.segments) {
2184
+ if (seg.sType === 1 /* eArc */) {
2185
+ try {
2186
+ arcSeg1To2(px1, py1, seg);
2187
+ } catch (emsg) {
2188
+ throw `err778: ${emsg}`;
2189
+ }
2190
+ }
2191
+ if (isAddPoint(seg.sType)) {
2192
+ px1 = seg.px;
2193
+ py1 = seg.py;
2194
+ }
2195
+ }
2196
+ const px0 = ctr.segments[0].px;
2197
+ const py0 = ctr.segments[0].py;
2198
+ if (roundZero(px1 - px0) !== 0 || roundZero(py1 - py0) !== 0) {
2199
+ throw `err414: contour check, contour is not closed px ${px0} ${px1} py ${px0} ${py0}`;
2200
+ }
2201
+ }
2202
+ check() {
2203
+ gSegDbg.clearMsg();
2204
+ this.checkContour(this);
2205
+ const ctrG = this.generateContour();
2206
+ this.checkContour(ctrG);
2207
+ return gSegDbg.getMsg();
2208
+ }
2209
+ toSvg(yCeiling, color = "") {
2210
+ const sPath = svgPath();
2211
+ for (const seg of this.segments) {
2212
+ if (seg.sType === 6 /* eStart */) {
2213
+ sPath.addStart(seg.px, yCeiling - seg.py);
2214
+ } else if (seg.sType === 0 /* eStroke */) {
2215
+ sPath.addStroke(seg.px, yCeiling - seg.py);
2216
+ } else if (seg.sType === 1 /* eArc */) {
2217
+ sPath.addArc(seg.px, yCeiling - seg.py, seg.radius, seg.arcLarge, !seg.arcCcw);
2218
+ } else {
2219
+ console.log(`err631: contour.toSvg has unknown segment type ${seg.sType}`);
2220
+ }
2221
+ }
2222
+ const rSvg = sPath.stringify(color);
2223
+ return rSvg;
2224
+ }
2225
+ toDxfSeg() {
2226
+ const rDxfSeg = [];
2227
+ let px1 = 0;
2228
+ let py1 = 0;
2229
+ for (const seg of this.segments) {
2230
+ if (seg.sType === 0 /* eStroke */) {
2231
+ rDxfSeg.push(dxfSegLine(px1, py1, seg.px, seg.py));
2232
+ } else if (seg.sType === 1 /* eArc */) {
2233
+ try {
2234
+ const seg2 = arcSeg1To2(px1, py1, seg);
2235
+ rDxfSeg.push(
2236
+ dxfSegArc(seg2.pc.cx, seg2.pc.cy, seg.radius, seg2.a1, seg2.a2, seg2.arcCcw)
2237
+ );
2238
+ } catch (emsg) {
2239
+ console.log("err413: " + emsg);
2240
+ }
2241
+ }
2242
+ if (isAddPoint(seg.sType)) {
2243
+ px1 = seg.px;
2244
+ py1 = seg.py;
2245
+ }
2246
+ }
2247
+ return rDxfSeg;
2248
+ }
2249
+ toPax() {
2250
+ const pPath = paxPath();
2251
+ for (const seg of this.segments) {
2252
+ if (seg.sType === 6 /* eStart */) {
2253
+ pPath.addStart(seg.px, seg.py);
2254
+ } else if (seg.sType === 0 /* eStroke */) {
2255
+ pPath.addStroke(seg.px, seg.py);
2256
+ } else if (seg.sType === 1 /* eArc */) {
2257
+ pPath.addArc(seg.px, seg.py, seg.radius, seg.arcLarge, seg.arcCcw);
2258
+ } else {
2259
+ console.log(`err709: contour.toPax has unknown segment type ${seg.sType}`);
2260
+ }
2261
+ }
2262
+ const rPaxC = pPath.toJson();
2263
+ return rPaxC;
2264
+ }
2265
+ };
2266
+ var ContourCircle = class _ContourCircle extends AContour {
2267
+ circle = true;
2268
+ px;
2269
+ py;
2270
+ radius;
2271
+ imposedColor;
2272
+ constructor(ix, iy, iRadius, icolor = "") {
2273
+ super();
2274
+ this.px = ix;
2275
+ this.py = iy;
2276
+ this.radius = iRadius;
2277
+ this.imposedColor = icolor;
2278
+ }
2279
+ clone() {
2280
+ const rctr = new _ContourCircle(this.px, this.py, this.radius, this.imposedColor);
2281
+ return rctr;
2282
+ }
2283
+ translate(ix, iy) {
2284
+ const rctr = new _ContourCircle(this.px + ix, this.py + iy, this.radius, this.imposedColor);
2285
+ return rctr;
2286
+ }
2287
+ translatePolar(ia, il) {
2288
+ return this.translate(il * Math.cos(ia), il * Math.sin(ia));
2289
+ }
2290
+ rotate(ix, iy, ia) {
2291
+ const ic = point(ix, iy);
2292
+ const nCenter = point(this.px, this.py).rotate(ic, ia);
2293
+ const rctr = new _ContourCircle(nCenter.cx, nCenter.cy, this.radius, this.imposedColor);
2294
+ return rctr;
2295
+ }
2296
+ draw(ctx, cAdjust, color = colors.contour) {
2297
+ const [cx3, cy3] = point2canvas(this.px, this.py, cAdjust);
2298
+ const cRadius = radius2canvas(this.radius, cAdjust);
2299
+ const theColor = this.imposedColor === "" ? color : this.imposedColor;
2300
+ ctx.beginPath();
2301
+ ctx.arc(cx3, cy3, cRadius, 0, 2 * Math.PI, true);
2302
+ ctx.strokeStyle = theColor;
2303
+ ctx.stroke();
2304
+ }
2305
+ extractSkeleton() {
2306
+ const rContour = new _ContourCircle(this.px, this.py, this.radius);
2307
+ return rContour;
2308
+ }
2309
+ generateContour() {
2310
+ const rContour = new _ContourCircle(this.px, this.py, this.radius, this.imposedColor);
2311
+ return rContour;
2312
+ }
2313
+ generatePoints() {
2314
+ const rPoints = [];
2315
+ const p1 = point(this.px, this.py);
2316
+ rPoints.push(p1);
2317
+ for (let i = 0; i < 4; i++) {
2318
+ const p2 = p1.translatePolar(i * Math.PI / 2, this.radius);
2319
+ rPoints.push(p2);
2320
+ }
2321
+ return rPoints;
2322
+ }
2323
+ generateLines() {
2324
+ return [];
2325
+ }
2326
+ check() {
2327
+ return "";
2328
+ }
2329
+ toSvg(yCeiling, color = "") {
2330
+ const rSvg = svgCircleString(this.px, yCeiling - this.py, this.radius, color);
2331
+ return rSvg;
2332
+ }
2333
+ toDxfSeg() {
2334
+ const rDxfSeg = [];
2335
+ rDxfSeg.push(dxfSegCircle(this.px, this.py, this.radius));
2336
+ return rDxfSeg;
2337
+ }
2338
+ toPax() {
2339
+ const rPaxC = paxCircle(this.px, this.py, this.radius);
2340
+ return rPaxC;
2341
+ }
2342
+ };
2343
+ function contour(ix, iy, icolor = "") {
2344
+ return new Contour(ix, iy, icolor);
2345
+ }
2346
+ function contourCircle(ix, iy, iRadius, icolor = "") {
2347
+ return new ContourCircle(ix, iy, iRadius, icolor);
2348
+ }
2349
+
2350
+ // src/figure.ts
2351
+ var Figure = class _Figure {
2352
+ pointList;
2353
+ lineList;
2354
+ vectorList;
2355
+ mainList;
2356
+ mainBList;
2357
+ secondList;
2358
+ secondBList;
2359
+ dynamicsList;
2360
+ xMin;
2361
+ xMax;
2362
+ yMin;
2363
+ yMax;
2364
+ constructor() {
2365
+ this.pointList = [];
2366
+ this.lineList = [];
2367
+ this.vectorList = [];
2368
+ this.mainList = [];
2369
+ this.mainBList = [];
2370
+ this.secondList = [];
2371
+ this.secondBList = [];
2372
+ this.dynamicsList = [];
2373
+ this.xMin = 0;
2374
+ this.xMax = 0;
2375
+ this.yMin = 0;
2376
+ this.yMax = 0;
2377
+ }
2378
+ addPoint(ipoint) {
2379
+ this.pointList.push(ipoint);
2380
+ }
2381
+ addPoints(ipoints) {
2382
+ this.pointList.push(...ipoints);
2383
+ }
2384
+ addLine(iline) {
2385
+ this.lineList.push(iline);
2386
+ }
2387
+ addLines(ilines) {
2388
+ for (const iline of ilines) {
2389
+ this.lineList.push(iline);
2390
+ }
2391
+ }
2392
+ addVector(ivector) {
2393
+ this.vectorList.push(ivector);
2394
+ }
2395
+ addMain(icontour) {
2396
+ const roundedContour = icontour.generateContour();
2397
+ this.addPoints(roundedContour.generatePoints());
2398
+ this.addLines(roundedContour.generateLines());
2399
+ this.mainList.push(roundedContour);
2400
+ this.mainBList.push(icontour.extractSkeleton());
2401
+ }
2402
+ addSecond(icontour) {
2403
+ const roundedContour = icontour.generateContour();
2404
+ this.addPoints(roundedContour.generatePoints());
2405
+ this.addLines(roundedContour.generateLines());
2406
+ this.secondList.push(roundedContour);
2407
+ this.secondBList.push(icontour.extractSkeleton());
2408
+ }
2409
+ addDynamics(icontour) {
2410
+ this.addPoints(icontour.generatePoints());
2411
+ this.addLines(icontour.generateLines());
2412
+ this.dynamicsList.push(icontour);
2413
+ }
2414
+ translate(ix, iy) {
2415
+ const rfig = new _Figure();
2416
+ for (const pt of this.pointList) {
2417
+ rfig.addPoint(pt.translate(ix, iy));
2418
+ }
2419
+ for (const li of this.lineList) {
2420
+ rfig.addLine(li.translate(ix, iy));
2421
+ }
2422
+ for (const vec of this.vectorList) {
2423
+ rfig.addVector(vec.translate(ix, iy));
2424
+ }
2425
+ for (const ctr of this.mainList) {
2426
+ rfig.addMain(ctr.translate(ix, iy));
2427
+ }
2428
+ for (const ctr of this.secondList) {
2429
+ rfig.addSecond(ctr.translate(ix, iy));
2430
+ }
2431
+ for (const ctr of this.dynamicsList) {
2432
+ rfig.addDynamics(ctr.translate(ix, iy));
2433
+ }
2434
+ return rfig;
2435
+ }
2436
+ translatePolar(ia, il) {
2437
+ return this.translate(il * Math.cos(ia), il * Math.sin(ia));
2438
+ }
2439
+ rotate(ix, iy, ia) {
2440
+ const rfig = new _Figure();
2441
+ const pt0 = point(ix, iy);
2442
+ for (const pt of this.pointList) {
2443
+ rfig.addPoint(pt.rotate(pt0, ia));
2444
+ }
2445
+ for (const li of this.lineList) {
2446
+ rfig.addLine(li.rotate(pt0, ia));
2447
+ }
2448
+ for (const vec of this.vectorList) {
2449
+ rfig.addVector(vec.rotate(pt0, ia));
2450
+ }
2451
+ for (const ctr of this.mainList) {
2452
+ rfig.addMain(ctr.rotate(ix, iy, ia));
2453
+ }
2454
+ for (const ctr of this.secondList) {
2455
+ rfig.addSecond(ctr.rotate(ix, iy, ia));
2456
+ }
2457
+ for (const ctr of this.dynamicsList) {
2458
+ rfig.addDynamics(ctr.rotate(ix, iy, ia));
2459
+ }
2460
+ return rfig;
2461
+ }
2462
+ mergeFigure(ifig, mainToSecond = false) {
2463
+ for (const pt of ifig.pointList) {
2464
+ this.addPoint(pt.clone());
2465
+ }
2466
+ for (const li of ifig.lineList) {
2467
+ this.addLine(li.clone());
2468
+ }
2469
+ for (const vec of ifig.vectorList) {
2470
+ this.addVector(vec.clone());
2471
+ }
2472
+ for (const ctr of ifig.mainList) {
2473
+ if (mainToSecond) {
2474
+ this.addSecond(ctr.clone());
2475
+ } else {
2476
+ this.addMain(ctr.clone());
2477
+ }
2478
+ }
2479
+ for (const ctr of ifig.secondList) {
2480
+ this.addSecond(ctr.clone());
2481
+ }
2482
+ for (const ctr of ifig.dynamicsList) {
2483
+ this.addDynamics(ctr.clone());
2484
+ }
2485
+ }
2486
+ clear() {
2487
+ this.pointList = [];
2488
+ this.lineList = [];
2489
+ this.vectorList = [];
2490
+ this.mainList = [];
2491
+ this.mainBList = [];
2492
+ this.secondList = [];
2493
+ this.secondBList = [];
2494
+ this.dynamicsList = [];
2495
+ }
2496
+ getMinMax() {
2497
+ [this.xMin, this.xMax, this.yMin, this.yMax] = pointMinMax(this.pointList);
2498
+ }
2499
+ getAdjustFull(iCanvasWidth, iCanvasHeight) {
2500
+ let rCanvasAdjust = adjustZero();
2501
+ if (this.pointList.length > 0) {
2502
+ this.getMinMax();
2503
+ rCanvasAdjust = adjustInit(
2504
+ this.xMin,
2505
+ this.xMax,
2506
+ this.yMin,
2507
+ this.yMax,
2508
+ iCanvasWidth,
2509
+ iCanvasHeight
2510
+ );
2511
+ }
2512
+ return rCanvasAdjust;
2513
+ }
2514
+ getAdjustZoom(iCanvasWidth, iCanvasHeight) {
2515
+ let rCanvasAdjust = adjustZero();
2516
+ if (this.pointList.length > 0) {
2517
+ this.getMinMax();
2518
+ const xMin = (this.xMin + this.xMax) / 2;
2519
+ const yMin = (this.yMin + this.yMax) / 2;
2520
+ rCanvasAdjust = adjustInit(
2521
+ xMin,
2522
+ this.xMax,
2523
+ yMin,
2524
+ this.yMax,
2525
+ iCanvasWidth,
2526
+ iCanvasHeight
2527
+ );
2528
+ }
2529
+ return rCanvasAdjust;
2530
+ }
2531
+ quantifyRuler(canvasWidth, adjust) {
2532
+ const minWidth = canvasWidth / 10;
2533
+ const lsizep = minWidth / adjust.scaleX;
2534
+ let lref = 1e-4;
2535
+ while (lref < lsizep) {
2536
+ lref *= 10;
2537
+ }
2538
+ if (lref / 5 > lsizep) {
2539
+ lref /= 5;
2540
+ } else if (lref / 2 > lsizep) {
2541
+ lref /= 2;
2542
+ }
2543
+ const lsize = lref * adjust.scaleX;
2544
+ return [lref, lsize];
2545
+ }
2546
+ drawRuler(ctx, adjust, color) {
2547
+ const [lref, lsize] = this.quantifyRuler(ctx.canvas.width, adjust);
2548
+ const xpos = ctx.canvas.width - 10 - lsize;
2549
+ ctx.font = "15px Arial";
2550
+ ctx.fillStyle = color;
2551
+ ctx.fillText(`${lref.toFixed(4)}`, xpos, 20);
2552
+ ctx.beginPath();
2553
+ ctx.moveTo(xpos, 25);
2554
+ ctx.lineTo(xpos + lsize, 25);
2555
+ ctx.lineTo(xpos + lsize, 25 + lsize);
2556
+ ctx.strokeStyle = color;
2557
+ ctx.stroke();
2558
+ }
2559
+ draw(ctx, adjust, layers) {
2560
+ if (layers.points) {
2561
+ for (const p of this.pointList) {
2562
+ p.draw(ctx, adjust);
2563
+ }
2564
+ }
2565
+ if (layers.lines) {
2566
+ for (const li of this.lineList) {
2567
+ li.draw(ctx, adjust);
2568
+ }
2569
+ }
2570
+ if (layers.vectors) {
2571
+ for (const li of this.vectorList) {
2572
+ li.draw(ctx, adjust);
2573
+ }
2574
+ }
2575
+ if (layers.main) {
2576
+ for (const li of this.mainList) {
2577
+ li.draw(ctx, adjust, colors.main);
2578
+ }
2579
+ }
2580
+ if (layers.mainB) {
2581
+ for (const li of this.mainBList) {
2582
+ li.draw(ctx, adjust, colors.mainB);
2583
+ }
2584
+ }
2585
+ if (layers.second) {
2586
+ for (const li of this.secondList) {
2587
+ li.draw(ctx, adjust, colors.second);
2588
+ }
2589
+ }
2590
+ if (layers.secondB) {
2591
+ for (const li of this.secondBList) {
2592
+ li.draw(ctx, adjust, colors.secondB);
2593
+ }
2594
+ }
2595
+ if (layers.dynamics) {
2596
+ for (const li of this.dynamicsList) {
2597
+ li.draw(ctx, adjust, colors.dynamics);
2598
+ }
2599
+ }
2600
+ if (layers.ruler) {
2601
+ this.drawRuler(ctx, adjust, colors.ruler);
2602
+ }
2603
+ if (layers.refframe) {
2604
+ for (const i of [10, 100, 200]) {
2605
+ point(i, 0).draw(ctx, adjust, colors.reference, 2 /* eCross */);
2606
+ point(-i, 0).draw(ctx, adjust, colors.reference, 2 /* eCross */);
2607
+ point(0, i).draw(ctx, adjust, colors.reference, 2 /* eCross */);
2608
+ point(0, -i).draw(ctx, adjust, colors.reference, 2 /* eCross */);
2609
+ }
2610
+ point(0, 0).draw(ctx, adjust, colors.origin, 2 /* eCross */);
2611
+ }
2612
+ }
2613
+ };
2614
+ function figure() {
2615
+ return new Figure();
2616
+ }
2617
+ function mergeFaces(iFaces) {
2618
+ const rfig = figure();
2619
+ for (const face in iFaces) {
2620
+ const fig = iFaces[face];
2621
+ for (const ipoint of fig.pointList) {
2622
+ rfig.pointList.push(ipoint);
2623
+ }
2624
+ for (const iline of fig.lineList) {
2625
+ rfig.lineList.push(iline);
2626
+ }
2627
+ for (const ivector of fig.vectorList) {
2628
+ rfig.vectorList.push(ivector);
2629
+ }
2630
+ for (const ctr of fig.mainList) {
2631
+ rfig.mainList.push(ctr);
2632
+ }
2633
+ for (const ctr of fig.mainBList) {
2634
+ rfig.mainBList.push(ctr);
2635
+ }
2636
+ for (const ctr of fig.secondList) {
2637
+ rfig.secondList.push(ctr);
2638
+ }
2639
+ for (const ctr of fig.secondBList) {
2640
+ rfig.secondBList.push(ctr);
2641
+ }
2642
+ for (const ctr of fig.dynamicsList) {
2643
+ rfig.dynamicsList.push(ctr);
2644
+ }
2645
+ }
2646
+ return rfig;
2647
+ }
2648
+ function initLayers() {
2649
+ const layers = {
2650
+ points: false,
2651
+ lines: false,
2652
+ vectors: false,
2653
+ main: true,
2654
+ mainB: false,
2655
+ second: true,
2656
+ secondB: false,
2657
+ dynamics: false,
2658
+ ruler: true,
2659
+ refframe: false
2660
+ };
2661
+ return layers;
2662
+ }
2663
+ function copyLayers(iLayers) {
2664
+ const layers = {
2665
+ points: iLayers.points,
2666
+ lines: iLayers.lines,
2667
+ vectors: iLayers.vectors,
2668
+ main: iLayers.main,
2669
+ mainB: iLayers.mainB,
2670
+ second: iLayers.second,
2671
+ secondB: iLayers.secondB,
2672
+ dynamics: iLayers.dynamics,
2673
+ ruler: iLayers.ruler,
2674
+ refframe: iLayers.refframe
2675
+ };
2676
+ return layers;
2677
+ }
2678
+
2679
+ // src/designParams.ts
2680
+ var PType = /* @__PURE__ */ ((PType2) => {
2681
+ PType2[PType2["eNumber"] = 0] = "eNumber";
2682
+ PType2[PType2["eCheckbox"] = 1] = "eCheckbox";
2683
+ PType2[PType2["eDropdown"] = 2] = "eDropdown";
2684
+ return PType2;
2685
+ })(PType || {});
2686
+ function oneDesignParam(iVal, iInit, iChg) {
2687
+ const oneDP = { val: iVal, init: iInit, chg: iChg };
2688
+ return oneDP;
2689
+ }
2690
+ function paramListToVal(dpList) {
2691
+ const rParamVal = {};
2692
+ for (const pa of Object.keys(dpList)) {
2693
+ rParamVal[pa] = dpList[pa].val;
2694
+ }
2695
+ return rParamVal;
2696
+ }
2697
+ var DesignParam = class {
2698
+ paramVal = {};
2699
+ paramInit = {};
2700
+ paramChanged = {};
2701
+ partName;
2702
+ paramNames;
2703
+ getParamName() {
2704
+ const rNames = [];
2705
+ for (const pName of Object.keys(this.paramVal)) {
2706
+ rNames.push(pName);
2707
+ }
2708
+ return rNames;
2709
+ }
2710
+ constructor(iparamDef) {
2711
+ for (const pi of iparamDef.params) {
2712
+ this.paramVal[pi.name] = pi.init;
2713
+ this.paramInit[pi.name] = pi.init;
2714
+ this.paramChanged[pi.name] = false;
2715
+ }
2716
+ this.partName = iparamDef.partName;
2717
+ this.paramNames = this.getParamName();
2718
+ }
2719
+ getPartName() {
2720
+ return this.partName;
2721
+ }
2722
+ getParamVal() {
2723
+ return this.paramVal;
2724
+ }
2725
+ getVal(iname) {
2726
+ if (this.paramNames.includes(iname)) {
2727
+ return this.paramVal[iname];
2728
+ } else {
2729
+ throw `err140: parameter ${iname} does not exist in design ${this.partName}`;
2730
+ }
2731
+ }
2732
+ getInit(iname) {
2733
+ if (this.paramNames.includes(iname)) {
2734
+ return this.paramInit[iname];
2735
+ } else {
2736
+ throw `err149: parameter ${iname} does not exist in design ${this.partName}`;
2737
+ }
2738
+ }
2739
+ getChanged(iname) {
2740
+ if (this.paramNames.includes(iname)) {
2741
+ return this.paramChanged[iname];
2742
+ } else {
2743
+ throw `err156: parameter ${iname} does not exist in design ${this.partName}`;
2744
+ }
2745
+ }
2746
+ setVal(iname, ival) {
2747
+ if (this.paramNames.includes(iname)) {
2748
+ this.paramVal[iname] = ival;
2749
+ this.paramChanged[iname] = true;
2750
+ } else {
2751
+ throw `err163: parameter ${iname} does not exist in design ${this.partName}`;
2752
+ }
2753
+ }
2754
+ applyParamVal(iValues) {
2755
+ let rlog = "";
2756
+ for (const pa of Object.keys(iValues)) {
2757
+ this.setVal(pa, iValues[pa]);
2758
+ }
2759
+ rlog += `info104: apply ${Object.keys(iValues).length} parameters on ${this.partName}
2760
+ `;
2761
+ return rlog;
2762
+ }
2763
+ applyParamList(iValues) {
2764
+ const rlog = this.applyParamVal(paramListToVal(iValues));
2765
+ return rlog;
2766
+ }
2767
+ getDesignParamList() {
2768
+ const rDPList = {};
2769
+ for (const pi of this.paramNames) {
2770
+ rDPList[pi] = oneDesignParam(this.getVal(pi), this.getInit(pi), this.getChanged(pi));
2771
+ }
2772
+ return rDPList;
2773
+ }
2774
+ };
2775
+ function designParam(iparamDef) {
2776
+ return new DesignParam(iparamDef);
2777
+ }
2778
+ function pNumber(name, unit, init, min = 0, max = 100, step = 1) {
2779
+ const rParam = {
2780
+ name,
2781
+ unit,
2782
+ init,
2783
+ min,
2784
+ max,
2785
+ step,
2786
+ dropdown: [],
2787
+ pType: 0 /* eNumber */
2788
+ };
2789
+ return rParam;
2790
+ }
2791
+ function pCheckbox(name, init) {
2792
+ const rParam = {
2793
+ name,
2794
+ unit: "checkbox",
2795
+ init: init ? 1 : 0,
2796
+ min: 0,
2797
+ max: 1,
2798
+ step: 1,
2799
+ dropdown: [],
2800
+ pType: 1 /* eCheckbox */
2801
+ };
2802
+ return rParam;
2803
+ }
2804
+ function pDropdown(name, values) {
2805
+ const rParam = {
2806
+ name,
2807
+ unit: "dropdown",
2808
+ init: 0,
2809
+ min: 0,
2810
+ max: values.length - 1,
2811
+ step: 1,
2812
+ dropdown: values,
2813
+ pType: 2 /* eDropdown */
2814
+ };
2815
+ return rParam;
2816
+ }
2817
+
2818
+ // src/volume.ts
2819
+ var EExtrude = /* @__PURE__ */ ((EExtrude2) => {
2820
+ EExtrude2[EExtrude2["eLinearOrtho"] = 0] = "eLinearOrtho";
2821
+ EExtrude2[EExtrude2["eRotate"] = 1] = "eRotate";
2822
+ return EExtrude2;
2823
+ })(EExtrude || {});
2824
+ var EBVolume = /* @__PURE__ */ ((EBVolume2) => {
2825
+ EBVolume2[EBVolume2["eIdentity"] = 0] = "eIdentity";
2826
+ EBVolume2[EBVolume2["eIntersection"] = 1] = "eIntersection";
2827
+ EBVolume2[EBVolume2["eUnion"] = 2] = "eUnion";
2828
+ EBVolume2[EBVolume2["eSubstraction"] = 3] = "eSubstraction";
2829
+ return EBVolume2;
2830
+ })(EBVolume || {});
2831
+
2832
+ // src/aaParamGeom.ts
2833
+ function fround(ireal, iprecision = 1e3) {
2834
+ return Math.floor(ireal * iprecision) / iprecision;
2835
+ }
2836
+ function initGeom(partName) {
2837
+ const rGeom = {
2838
+ partName,
2839
+ calcErr: true,
2840
+ logstr: "",
2841
+ fig: {},
2842
+ vol: { extrudes: [], volumes: [] },
2843
+ sub: {}
2844
+ };
2845
+ return rGeom;
2846
+ }
2847
+ function checkGeom(iGeom) {
2848
+ if (iGeom.calcErr) {
2849
+ let errMsg = `err182: Error in sub-design ${iGeom.partName}
2850
+ `;
2851
+ errMsg += prefixLog(iGeom.logstr, iGeom.partName);
2852
+ throw errMsg;
2853
+ }
2854
+ }
2855
+ function prefixLog(iLog, iPartName) {
2856
+ let rLog = "";
2857
+ for (const oneline of iLog.split("\n")) {
2858
+ if (oneline !== "") {
2859
+ rLog += `[${iPartName}]: ${oneline}
2860
+ `;
2861
+ }
2862
+ }
2863
+ return rLog;
2864
+ }
2865
+
2866
+ // src/write_pax.ts
2867
+ var PaxWrite = class {
2868
+ //constructor() {}
2869
+ figureToPaxF(aCtr) {
2870
+ const rPaxF = [];
2871
+ for (const ctr of aCtr) {
2872
+ rPaxF.push(ctr.toPax());
2873
+ }
2874
+ return rPaxF;
2875
+ }
2876
+ getFigures(figs) {
2877
+ const figFaces = {};
2878
+ for (const face in figs) {
2879
+ const figu = this.figureToPaxF(figs[face].mainList);
2880
+ figFaces[face] = figu;
2881
+ }
2882
+ return figFaces;
2883
+ }
2884
+ getPaxJson(paramVal, geome0) {
2885
+ const rPaxJson = {
2886
+ partName: geome0.partName,
2887
+ params: paramVal,
2888
+ faces: this.getFigures(geome0.fig),
2889
+ volume: geome0.vol,
2890
+ subs: geome0.sub,
2891
+ log: geome0.logstr
2892
+ };
2893
+ return rPaxJson;
2894
+ }
2895
+ getPaxStr(paramVal, geome0) {
2896
+ const paxJson = this.getPaxJson(paramVal, geome0);
2897
+ const rStr = JSON.stringify(paxJson, null, 2);
2898
+ return rStr;
2899
+ }
2900
+ };
2901
+ function paxWrite() {
2902
+ const rPaxWrite = new PaxWrite();
2903
+ return rPaxWrite;
2904
+ }
2905
+ function convTypePaxToSeg1(paxType) {
2906
+ let rType = 6 /* eStart */;
2907
+ if (paxType === 1 /* eStroke */) {
2908
+ rType = 0 /* eStroke */;
2909
+ } else if (paxType === 2 /* eArc */) {
2910
+ rType = 1 /* eArc */;
2911
+ }
2912
+ return rType;
2913
+ }
2914
+
2915
+ // src/arc_to_stroke.ts
2916
+ function calcAngleStep(max_angle, max_length, radius, arc_angle) {
2917
+ let max_angle2 = Math.PI / 2;
2918
+ if (max_length < 2 * radius) {
2919
+ max_angle2 = 2 * Math.asin(max_length / (2 * radius));
2920
+ }
2921
+ const angleStepMax = Math.min(max_angle, max_angle2);
2922
+ const angleNb = Math.ceil(arc_angle / angleStepMax);
2923
+ const angleStep = arc_angle / angleNb;
2924
+ return [angleNb, angleStep];
2925
+ }
2926
+ function circle_to_stroke(cx, cy, radius, max_angle = Math.PI / 6, max_length = 2) {
2927
+ const [angleNb, angleStep] = calcAngleStep(max_angle, max_length, radius, 2 * Math.PI);
2928
+ const rPoints = [];
2929
+ for (let i = 0; i < angleNb; i++) {
2930
+ const px = cx + radius * Math.cos(i * angleStep);
2931
+ const py = cy + radius * Math.sin(i * angleStep);
2932
+ rPoints.push([px, py]);
2933
+ }
2934
+ const p0x = rPoints[0][0];
2935
+ const p0y = rPoints[0][1];
2936
+ rPoints.push([p0x, p0y]);
2937
+ return rPoints;
2938
+ }
2939
+ function arc_to_stroke(cx, cy, radius, a1, a2, ccw, max_angle = Math.PI / 6, max_length = 2) {
2940
+ const arc_angle = orientedArc(a1, a2, ccw);
2941
+ const [angleNb, angleStep] = calcAngleStep(max_angle, max_length, radius, Math.abs(arc_angle));
2942
+ const angleStepSigned = ccw ? angleStep : -angleStep;
2943
+ const angleNb2 = angleNb + 1;
2944
+ const rPoints = [];
2945
+ for (let i = 1; i < angleNb2; i++) {
2946
+ const angle = a1 + i * angleStepSigned;
2947
+ const px = cx + radius * Math.cos(angle);
2948
+ const py = cy + radius * Math.sin(angle);
2949
+ rPoints.push([px, py]);
2950
+ }
2951
+ return rPoints;
2952
+ }
2953
+
2954
+ // src/write_openscad.ts
2955
+ var approxMaxAngle = Math.PI / 8;
2956
+ var approxMaxLength = 20;
2957
+ function oscadSegLine(p2x, p2y) {
2958
+ const rSeg = [[p2x, p2y]];
2959
+ return rSeg;
2960
+ }
2961
+ function oscadSegArc(cx, cy, radius, aa1, aa2, arcCcw) {
2962
+ const rSeg = arc_to_stroke(cx, cy, radius, aa1, aa2, arcCcw, approxMaxAngle, approxMaxLength);
2963
+ return rSeg;
2964
+ }
2965
+ function oscadSegCircle(cx, cy, radius) {
2966
+ const rSeg = circle_to_stroke(cx, cy, radius, approxMaxAngle, approxMaxLength);
2967
+ return rSeg;
2968
+ }
2969
+ function toOpenscadSeg(paxCtr) {
2970
+ const rOscadSeg = [];
2971
+ let px1 = 0;
2972
+ let py1 = 0;
2973
+ for (const seg of paxCtr) {
2974
+ if (seg.typ === 0 /* eStart */) {
2975
+ rOscadSeg.push(...oscadSegLine(seg.px, seg.py));
2976
+ } else if (seg.typ === 1 /* eStroke */) {
2977
+ rOscadSeg.push(...oscadSegLine(seg.px, seg.py));
2978
+ } else if (seg.typ === 2 /* eArc */) {
2979
+ try {
2980
+ const sega = seg;
2981
+ const seg1 = new Segment1(
2982
+ convTypePaxToSeg1(sega.typ),
2983
+ sega.px,
2984
+ sega.py,
2985
+ sega.radius,
2986
+ sega.large,
2987
+ sega.ccw
2988
+ );
2989
+ const seg2 = arcSeg1To2(px1, py1, seg1);
2990
+ rOscadSeg.push(
2991
+ ...oscadSegArc(
2992
+ seg2.pc.cx,
2993
+ seg2.pc.cy,
2994
+ seg1.radius,
2995
+ seg2.a1,
2996
+ seg2.a2,
2997
+ seg2.arcCcw
2998
+ )
2999
+ );
3000
+ } catch (emsg) {
3001
+ console.log("err730: " + emsg);
3002
+ }
3003
+ }
3004
+ px1 = seg.px;
3005
+ py1 = seg.py;
3006
+ }
3007
+ return rOscadSeg;
3008
+ }
3009
+ function ff4(ifloat) {
3010
+ return ifloat.toFixed(4);
3011
+ }
3012
+ var OpenscadWriteFigure = class {
3013
+ pts;
3014
+ ptIdx;
3015
+ idx;
3016
+ constructor() {
3017
+ this.pts = [];
3018
+ this.ptIdx = [];
3019
+ this.idx = 0;
3020
+ }
3021
+ addContour(ictr) {
3022
+ const pts2 = [];
3023
+ const ptIdx2 = [];
3024
+ for (const pt of ictr) {
3025
+ const [px, py] = pt;
3026
+ pts2.push(`[ ${ff4(px)}, ${ff4(py)} ]`);
3027
+ ptIdx2.push(` ${this.idx}`);
3028
+ this.idx += 1;
3029
+ }
3030
+ const ptStr = `[ ${pts2.join(",")} ]`;
3031
+ const ptIdxStr = `[ ${ptIdx2.join(",")} ]`;
3032
+ this.pts.push(ptStr);
3033
+ this.ptIdx.push(ptIdxStr);
3034
+ }
3035
+ getFigure(faceId) {
3036
+ let rStr = "";
3037
+ const aList = [];
3038
+ const bList = [];
3039
+ for (const idx of this.pts.keys()) {
3040
+ const aId = `ca_${faceId}_${idx}`;
3041
+ const bId = `cb_${faceId}_${idx}`;
3042
+ rStr += `${aId} = ${this.pts[idx]};
3043
+ `;
3044
+ rStr += `${bId} = ${this.ptIdx[idx]};
3045
+ `;
3046
+ aList.push(aId);
3047
+ bList.push(bId);
3048
+ }
3049
+ const aListStr = aList.join(", ");
3050
+ const bListStr = bList.join(", ");
3051
+ rStr += `a_${faceId} = concat(${aListStr});
3052
+ `;
3053
+ rStr += `b_${faceId} = [${bListStr}];
3054
+ `;
3055
+ return rStr;
3056
+ }
3057
+ };
3058
+ var OpenscadWrite = class {
3059
+ //constructor() {}
3060
+ getHeader() {
3061
+ const rStr = "// Generated by Parametrix\n";
3062
+ return rStr;
3063
+ }
3064
+ getOneFigure(aCtr, faceId) {
3065
+ const oscadWF = new OpenscadWriteFigure();
3066
+ for (const paxCtr of aCtr) {
3067
+ if (paxCtr.circle === true) {
3068
+ const paxCircle2 = paxCtr;
3069
+ const oscadSeg = oscadSegCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius);
3070
+ oscadWF.addContour(oscadSeg);
3071
+ } else {
3072
+ const paxPath2 = paxCtr;
3073
+ const oscadSeg = toOpenscadSeg(paxPath2.seg);
3074
+ oscadWF.addContour(oscadSeg);
3075
+ }
3076
+ }
3077
+ const rOscadF = oscadWF.getFigure(faceId);
3078
+ return rOscadF;
3079
+ }
3080
+ getAllFigures(faces, partName) {
3081
+ let rStr = "";
3082
+ for (const face in faces) {
3083
+ const figu = this.getOneFigure(faces[face], `${partName}_${face}`);
3084
+ rStr += figu;
3085
+ }
3086
+ return rStr;
3087
+ }
3088
+ getOneExtrude(extrud) {
3089
+ let extrudMethod = "rotate_extrude";
3090
+ let extrudOption = "";
3091
+ if (extrud.extrudeMethod === 0 /* eLinearOrtho */) {
3092
+ if (extrud.length === void 0) {
3093
+ console.log("err103: design error: scad-linear_extrude length undefined!");
3094
+ }
3095
+ extrudMethod = "linear_extrude";
3096
+ extrudOption = `height = ${extrud.length}`;
3097
+ }
3098
+ const rStr = `
3099
+ module ${extrud.outName} () {
3100
+ translate( [ ${extrud.translate[0]}, ${extrud.translate[1]}, ${extrud.translate[2]} ])
3101
+ rotate( [ ${radToDeg(extrud.rotate[0])}, ${radToDeg(extrud.rotate[1])}, ${radToDeg(
3102
+ extrud.rotate[2]
3103
+ )} ])
3104
+ ${extrudMethod}(${extrudOption}) polygon(a_${extrud.face}, b_${extrud.face});
3105
+ }
3106
+ `;
3107
+ return rStr;
3108
+ }
3109
+ getAllExtrudes(extrudes) {
3110
+ let rStr = "";
3111
+ for (const extrud of extrudes) {
3112
+ const subp = this.getOneExtrude(extrud);
3113
+ rStr += subp;
3114
+ }
3115
+ return rStr;
3116
+ }
3117
+ getOneVolume(volum) {
3118
+ let vMethod = "identity";
3119
+ switch (volum.boolMethod) {
3120
+ case 1 /* eIntersection */:
3121
+ vMethod = "intersection";
3122
+ break;
3123
+ case 2 /* eUnion */:
3124
+ vMethod = "union";
3125
+ break;
3126
+ case 3 /* eSubstraction */:
3127
+ vMethod = "difference";
3128
+ break;
3129
+ }
3130
+ const inList2 = [];
3131
+ for (const elem of volum.inList) {
3132
+ inList2.push(`${elem}();`);
3133
+ }
3134
+ const inList3 = inList2.join("\n");
3135
+ let rStr = `
3136
+ module ${volum.outName} () {
3137
+ ${vMethod} () {
3138
+ ${inList3}
3139
+ }
3140
+ }
3141
+ `;
3142
+ if (volum.boolMethod === 0 /* eIdentity */) {
3143
+ rStr = `
3144
+ module ${volum.outName} () {
3145
+ ${inList3}
3146
+ }
3147
+ `;
3148
+ }
3149
+ return rStr;
3150
+ }
3151
+ getAllVolumes(volumes) {
3152
+ let rStr = "";
3153
+ for (const volum of volumes) {
3154
+ const subp = this.getOneVolume(volum);
3155
+ rStr += subp;
3156
+ }
3157
+ return rStr;
3158
+ }
3159
+ getAllSubGeoms(inherits) {
3160
+ const rGeoms = [];
3161
+ for (const inher of inherits) {
3162
+ if (!rGeoms.includes(inher.subgeom)) {
3163
+ rGeoms.push(inher.subgeom);
3164
+ }
3165
+ }
3166
+ return rGeoms;
3167
+ }
3168
+ getOneInherit(inherit) {
3169
+ const rStr = `
3170
+ module ${inherit.outName} () {
3171
+ translate( [ ${inherit.translate[0]}, ${inherit.translate[1]}, ${inherit.translate[2]} ])
3172
+ rotate( [ ${radToDeg(inherit.rotate[0])}, ${radToDeg(inherit.rotate[1])}, ${radToDeg(
3173
+ inherit.rotate[2]
3174
+ )} ])
3175
+ ${inherit.subdesign}();
3176
+ }
3177
+ `;
3178
+ return rStr;
3179
+ }
3180
+ getAllInherits(inherits) {
3181
+ let rStr = "";
3182
+ for (const inher of inherits) {
3183
+ const subinhe = this.getOneInherit(inher);
3184
+ rStr += subinhe;
3185
+ }
3186
+ return rStr;
3187
+ }
3188
+ getVolume(vol) {
3189
+ let rStr = "";
3190
+ if (vol.inherits !== void 0) {
3191
+ const subGeoms = this.getAllSubGeoms(vol.inherits);
3192
+ for (const oneGeom of subGeoms) {
3193
+ const paxJson = paxWrite().getPaxJson({}, oneGeom);
3194
+ rStr += this.getAllFigures(paxJson.faces, paxJson.partName);
3195
+ rStr += this.getVolume(oneGeom.vol);
3196
+ }
3197
+ rStr += this.getAllInherits(vol.inherits);
3198
+ }
3199
+ rStr += this.getAllExtrudes(vol.extrudes);
3200
+ rStr += this.getAllVolumes(vol.volumes);
3201
+ return rStr;
3202
+ }
3203
+ getFooter(partName) {
3204
+ const rStr = `
3205
+ pax_${partName}();
3206
+ `;
3207
+ return rStr;
3208
+ }
3209
+ getExportFile(pax) {
3210
+ let rStr = this.getHeader();
3211
+ rStr += this.getAllFigures(pax.faces, pax.partName);
3212
+ rStr += this.getVolume(pax.volume);
3213
+ rStr += this.getFooter(pax.partName);
3214
+ return rStr;
3215
+ }
3216
+ };
3217
+ function oscadWrite() {
3218
+ const rOscadWrite = new OpenscadWrite();
3219
+ return rOscadWrite;
3220
+ }
3221
+
3222
+ // src/write_openjscad.ts
3223
+ var approxMaxAngle2 = Math.PI / 8;
3224
+ var approxMaxLength2 = 20;
3225
+ function ojscadSegLine(p2x, p2y) {
3226
+ const rSeg = [[p2x, p2y]];
3227
+ return rSeg;
3228
+ }
3229
+ function ojscadSegArc(cx, cy, radius, aa1, aa2, arcCcw) {
3230
+ const rSeg = arc_to_stroke(cx, cy, radius, aa1, aa2, arcCcw, approxMaxAngle2, approxMaxLength2);
3231
+ return rSeg;
3232
+ }
3233
+ function toOpenjscadSeg(paxCtr) {
3234
+ const rOjscadSeg = [];
3235
+ let px1 = 0;
3236
+ let py1 = 0;
3237
+ for (const seg of paxCtr) {
3238
+ if (seg.typ === 0 /* eStart */) {
3239
+ rOjscadSeg.push(...ojscadSegLine(seg.px, seg.py));
3240
+ } else if (seg.typ === 1 /* eStroke */) {
3241
+ rOjscadSeg.push(...ojscadSegLine(seg.px, seg.py));
3242
+ } else if (seg.typ === 2 /* eArc */) {
3243
+ try {
3244
+ const sega = seg;
3245
+ const seg1 = new Segment1(
3246
+ convTypePaxToSeg1(sega.typ),
3247
+ sega.px,
3248
+ sega.py,
3249
+ sega.radius,
3250
+ sega.large,
3251
+ sega.ccw
3252
+ );
3253
+ const seg2 = arcSeg1To2(px1, py1, seg1);
3254
+ rOjscadSeg.push(
3255
+ ...ojscadSegArc(
3256
+ seg2.pc.cx,
3257
+ seg2.pc.cy,
3258
+ seg1.radius,
3259
+ seg2.a1,
3260
+ seg2.a2,
3261
+ seg2.arcCcw
3262
+ )
3263
+ );
3264
+ } catch (emsg) {
3265
+ console.log("err730: " + emsg);
3266
+ }
3267
+ }
3268
+ px1 = seg.px;
3269
+ py1 = seg.py;
3270
+ }
3271
+ return rOjscadSeg;
3272
+ }
3273
+ function ojscadSegCircle(cx, cy, radius) {
3274
+ const rSeg = circle_to_stroke(cx, cy, radius, approxMaxAngle2, approxMaxLength2);
3275
+ return rSeg;
3276
+ }
3277
+ function ff5(ifloat) {
3278
+ return ifloat.toFixed(4);
3279
+ }
3280
+ var OjscadWriteFigure = class {
3281
+ pts;
3282
+ constructor() {
3283
+ this.pts = [];
3284
+ }
3285
+ addContour(ictr) {
3286
+ const pts2 = [];
3287
+ for (const pt of ictr) {
3288
+ const [px, py] = pt;
3289
+ pts2.push(`[ ${ff5(px)}, ${ff5(py)} ]`);
3290
+ }
3291
+ const ptStr = `[ ${pts2.join(",")} ]`;
3292
+ this.pts.push(ptStr);
3293
+ }
3294
+ getFigure(faceId) {
3295
+ let rStr = "";
3296
+ const aList = [];
3297
+ for (const idx of this.pts.keys()) {
3298
+ const aId = `ctr_${faceId}_${idx}`;
3299
+ rStr += `const ${aId} = polygon({ points: ${this.pts[idx]} });
3300
+ `;
3301
+ aList.push(aId);
3302
+ }
3303
+ if (aList.length === 1) {
3304
+ rStr += `const face_${faceId} = ${aList[0]};
3305
+ `;
3306
+ } else if (aList.length > 1) {
3307
+ const ctrList = aList.join(", ");
3308
+ rStr += `const face_${faceId} = subtract( ${ctrList} )
3309
+ `;
3310
+ }
3311
+ return rStr;
3312
+ }
3313
+ };
3314
+ var OpenjscadWrite = class {
3315
+ //constructor() {}
3316
+ getHeader() {
3317
+ const rStr = `// Generated by Parametrix
3318
+ const { polygon } = require('@jscad/modeling').primitives
3319
+ //const { subtract } = require('@jscad/modeling').booleans;
3320
+ const { union, intersect, scission, subtract } = require('@jscad/modeling').booleans
3321
+ const { extrudeLinear, extrudeRotate } = require('@jscad/modeling').extrusions;
3322
+ const { translate, rotate } = require('@jscad/modeling').transforms
3323
+ const main = () => {
3324
+ `;
3325
+ return rStr;
3326
+ }
3327
+ getOneFigure(aCtr, faceId) {
3328
+ const ojscadWF = new OjscadWriteFigure();
3329
+ for (const paxCtr of aCtr) {
3330
+ if (paxCtr.circle === true) {
3331
+ const paxCircle2 = paxCtr;
3332
+ const ojscadSeg = ojscadSegCircle(paxCircle2.cx, paxCircle2.cy, paxCircle2.radius);
3333
+ ojscadWF.addContour(ojscadSeg);
3334
+ } else {
3335
+ const paxPath2 = paxCtr;
3336
+ const ojscadSeg = toOpenjscadSeg(paxPath2.seg);
3337
+ ojscadWF.addContour(ojscadSeg);
3338
+ }
3339
+ }
3340
+ const rOjscadF = ojscadWF.getFigure(faceId);
3341
+ return rOjscadF;
3342
+ }
3343
+ getAllFigures(faces, partName) {
3344
+ let rStr = "";
3345
+ for (const face in faces) {
3346
+ const figu = this.getOneFigure(faces[face], `${partName}_${face}`);
3347
+ rStr += figu;
3348
+ }
3349
+ return rStr;
3350
+ }
3351
+ getOneExtrude(extrud) {
3352
+ let extrudMethod = "extrudeRotate";
3353
+ let extrudOption = "{segments: 32}";
3354
+ if (extrud.extrudeMethod === 0 /* eLinearOrtho */) {
3355
+ if (extrud.length === void 0) {
3356
+ console.log("err079: design error: extrudeLinear length undefined!");
3357
+ }
3358
+ extrudMethod = "extrudeLinear";
3359
+ extrudOption = `{height: ${extrud.length}}`;
3360
+ }
3361
+ const rStr = `
3362
+ const ${extrud.outName} =
3363
+ translate( [ ${extrud.translate[0]}, ${extrud.translate[1]}, ${extrud.translate[2]}, ],
3364
+ rotate( [ ${extrud.rotate[0]}, ${extrud.rotate[1]}, ${extrud.rotate[2]}, ],
3365
+ ${extrudMethod}( ${extrudOption}, face_${extrud.face} )
3366
+ )
3367
+ );
3368
+ `;
3369
+ return rStr;
3370
+ }
3371
+ getAllExtrudes(extrudes) {
3372
+ let rStr = "";
3373
+ for (const extrud of extrudes) {
3374
+ const subp = this.getOneExtrude(extrud);
3375
+ rStr += subp;
3376
+ }
3377
+ return rStr;
3378
+ }
3379
+ getOneVolume(volum) {
3380
+ let vMethod = "identity";
3381
+ switch (volum.boolMethod) {
3382
+ case 1 /* eIntersection */:
3383
+ vMethod = "intersect";
3384
+ break;
3385
+ case 2 /* eUnion */:
3386
+ vMethod = "union";
3387
+ break;
3388
+ case 3 /* eSubstraction */:
3389
+ vMethod = "subtract";
3390
+ break;
3391
+ }
3392
+ const inList2 = volum.inList.join(", ");
3393
+ let rStr = `const ${volum.outName} = ${vMethod}( ${inList2} );
3394
+ `;
3395
+ if (volum.boolMethod === 0 /* eIdentity */) {
3396
+ rStr = `const ${volum.outName} = ${volum.inList[0]};
3397
+ `;
3398
+ }
3399
+ return rStr;
3400
+ }
3401
+ getAllVolumes(volumes) {
3402
+ let rStr = "";
3403
+ for (const volum of volumes) {
3404
+ const subp = this.getOneVolume(volum);
3405
+ rStr += subp;
3406
+ }
3407
+ return rStr;
3408
+ }
3409
+ getAllSubGeoms(inherits) {
3410
+ const rGeoms = [];
3411
+ for (const inher of inherits) {
3412
+ if (!rGeoms.includes(inher.subgeom)) {
3413
+ rGeoms.push(inher.subgeom);
3414
+ }
3415
+ }
3416
+ return rGeoms;
3417
+ }
3418
+ getOneInherit(inherit) {
3419
+ const rStr = `
3420
+ const ${inherit.outName} =
3421
+ translate( [ ${inherit.translate[0]}, ${inherit.translate[1]}, ${inherit.translate[2]}, ],
3422
+ rotate( [ ${inherit.rotate[0]}, ${inherit.rotate[1]}, ${inherit.rotate[2]}, ],
3423
+ ${inherit.subdesign}
3424
+ )
3425
+ );
3426
+ `;
3427
+ return rStr;
3428
+ }
3429
+ getAllInherits(inherits) {
3430
+ let rStr = "";
3431
+ for (const inher of inherits) {
3432
+ const subinhe = this.getOneInherit(inher);
3433
+ rStr += subinhe;
3434
+ }
3435
+ return rStr;
3436
+ }
3437
+ getVolume(vol) {
3438
+ let rStr = "";
3439
+ if (vol.inherits !== void 0) {
3440
+ const subGeoms = this.getAllSubGeoms(vol.inherits);
3441
+ for (const oneGeom of subGeoms) {
3442
+ const paxJson = paxWrite().getPaxJson({}, oneGeom);
3443
+ rStr += this.getAllFigures(paxJson.faces, paxJson.partName);
3444
+ rStr += this.getVolume(oneGeom.vol);
3445
+ }
3446
+ rStr += this.getAllInherits(vol.inherits);
3447
+ }
3448
+ rStr += this.getAllExtrudes(vol.extrudes);
3449
+ rStr += this.getAllVolumes(vol.volumes);
3450
+ return rStr;
3451
+ }
3452
+ getFooter(partName) {
3453
+ const rStr = `
3454
+ return pax_${partName};
3455
+ }
3456
+ module.exports = { main };
3457
+ `;
3458
+ return rStr;
3459
+ }
3460
+ getExportFile(pax) {
3461
+ let rStr = this.getHeader();
3462
+ rStr += this.getAllFigures(pax.faces, pax.partName);
3463
+ rStr += this.getVolume(pax.volume);
3464
+ rStr += this.getFooter(pax.partName);
3465
+ return rStr;
3466
+ }
3467
+ };
3468
+ function ojscadWrite() {
3469
+ const rOjscadWrite = new OpenjscadWrite();
3470
+ return rOjscadWrite;
3471
+ }
3472
+
3473
+ // src/aaExportContent.ts
3474
+ import * as zip from "@zip.js/zip.js";
3475
+ var MinMaxPoint = class {
3476
+ xMin;
3477
+ xMax;
3478
+ yMin;
3479
+ yMax;
3480
+ firstDone;
3481
+ constructor() {
3482
+ this.firstDone = false;
3483
+ this.xMin = 0;
3484
+ this.xMax = 0;
3485
+ this.yMin = 0;
3486
+ this.yMax = 0;
3487
+ }
3488
+ addAContour(aCtr) {
3489
+ if (aCtr.length > 0) {
3490
+ const pts = [];
3491
+ if (this.firstDone) {
3492
+ pts.push(point(this.xMin, this.yMin));
3493
+ pts.push(point(this.xMax, this.yMax));
3494
+ }
3495
+ for (const ctr of aCtr) {
3496
+ pts.push(...ctr.generatePoints());
3497
+ }
3498
+ const [Xmin, Xmax, Ymin, Ymax] = pointMinMax(pts);
3499
+ this.xMin = Xmin;
3500
+ this.xMax = Xmax;
3501
+ this.yMin = Ymin;
3502
+ this.yMax = Ymax;
3503
+ }
3504
+ }
3505
+ getViewBox() {
3506
+ const Xdelta = Math.round((this.xMax - this.xMin) * 1.1) + 10;
3507
+ const Ydelta = Math.round((this.yMax - this.yMin) * 1.1) + 10;
3508
+ const Xmin2 = Math.round(this.xMin - Xdelta * 0.05);
3509
+ const Ymin2 = Math.round(this.yMin - Ydelta * 0.05);
3510
+ return [Xmin2, Xdelta, Ymin2, Ydelta];
3511
+ }
3512
+ };
3513
+ var SvgWriter2 = class {
3514
+ minMax;
3515
+ groups;
3516
+ svg;
3517
+ constructor() {
3518
+ this.minMax = new MinMaxPoint();
3519
+ this.groups = [];
3520
+ this.svg = svgWriter();
3521
+ }
3522
+ addAContour(aCtrs, groupId = "", icolor = colors.contour) {
3523
+ this.minMax.addAContour(aCtrs);
3524
+ const grp = { gpName: groupId, gpColor: icolor, ctrs: aCtrs };
3525
+ this.groups.push(grp);
3526
+ }
3527
+ makeSvg(yCeiling) {
3528
+ for (const grp of this.groups) {
3529
+ if (grp.gpName !== "") {
3530
+ this.svg.addGroup(grp.gpName);
3531
+ }
3532
+ for (const ctr of grp.ctrs) {
3533
+ let ctrColor = ctr.imposedColor;
3534
+ if (ctrColor === "") {
3535
+ ctrColor = grp.gpColor;
3536
+ }
3537
+ this.svg.addSvgString(ctr.toSvg(yCeiling, ctrColor));
3538
+ }
3539
+ if (grp.gpName !== "") {
3540
+ this.svg.closeGroup();
3541
+ }
3542
+ }
3543
+ }
3544
+ stringify() {
3545
+ const [Xmin2, Xdelta, Ymin2, Ydelta] = this.minMax.getViewBox();
3546
+ this.svg.addHeader(Xmin2, Xdelta, Ymin2, Ydelta);
3547
+ this.makeSvg(this.minMax.yMax + this.minMax.yMin);
3548
+ return this.svg.stringify();
3549
+ }
3550
+ };
3551
+ function svgWriter2() {
3552
+ const rSvgWriter2 = new SvgWriter2();
3553
+ return rSvgWriter2;
3554
+ }
3555
+ function figureToSvg(aCtr) {
3556
+ const sw2 = svgWriter2();
3557
+ sw2.addAContour(aCtr);
3558
+ return sw2.stringify();
3559
+ }
3560
+ function figureToSvgDeco(fig) {
3561
+ const sw2 = svgWriter2();
3562
+ sw2.addAContour(fig.mainList, "main", colors.main);
3563
+ sw2.addAContour(fig.mainBList, "mainB", colors.mainB);
3564
+ sw2.addAContour(fig.secondList, "second", colors.second);
3565
+ sw2.addAContour(fig.secondBList, "secondB", colors.secondB);
3566
+ sw2.addAContour(fig.dynamicsList, "dynamics", colors.dynamics);
3567
+ const rSvgDeco = sw2.stringify();
3568
+ return rSvgDeco;
3569
+ }
3570
+ function figureToDxf(aCtr) {
3571
+ const dxf = dxfWriter();
3572
+ for (const ctr of aCtr) {
3573
+ if (ctr.circle) {
3574
+ const seg = ctr.toDxfSeg()[0];
3575
+ dxf.addCircle(seg.p1x, seg.p1y, seg.radius);
3576
+ } else {
3577
+ for (const seg of ctr.toDxfSeg()) {
3578
+ if (seg.arc) {
3579
+ dxf.addArc(seg.p1x, seg.p1y, seg.radius, seg.a1, seg.a2);
3580
+ } else {
3581
+ dxf.addLine(seg.p1x, seg.p1y, seg.p2x, seg.p2y);
3582
+ }
3583
+ }
3584
+ }
3585
+ }
3586
+ const rDxf = dxf.stringify();
3587
+ return rDxf;
3588
+ }
3589
+ function makePax(paramVal, geome0) {
3590
+ const rStr = paxWrite().getPaxStr(paramVal, geome0);
3591
+ return rStr;
3592
+ }
3593
+ function makeOpenscad(geome0) {
3594
+ const paxJson = paxWrite().getPaxJson({}, geome0);
3595
+ const rStr = oscadWrite().getExportFile(paxJson);
3596
+ return rStr;
3597
+ }
3598
+ function makeOpenjscad(geome0) {
3599
+ const paxJson = paxWrite().getPaxJson({}, geome0);
3600
+ const rStr = ojscadWrite().getExportFile(paxJson);
3601
+ return rStr;
3602
+ }
3603
+ async function makeZip(paramVal, geome0, tSim, geome1) {
3604
+ const zipFileWriter = new zip.BlobWriter("application/zip");
3605
+ const zipWriter = new zip.ZipWriter(zipFileWriter);
3606
+ const partName = geome0.partName;
3607
+ const zParam = new zip.TextReader(JSON.stringify(paramVal, null, 2));
3608
+ await zipWriter.add(`param_${partName}.json`, zParam);
3609
+ const zLog0 = new zip.TextReader(geome0.logstr);
3610
+ await zipWriter.add(`geom_${partName}_log.txt`, zLog0);
3611
+ const zLog1 = new zip.TextReader(geome1.logstr);
3612
+ await zipWriter.add(`geom_${partName}_t${tSim}_log.txt`, zLog1);
3613
+ for (const face in geome0.fig) {
3614
+ const svgOne = new zip.TextReader(figureToSvg(geome0.fig[face].mainList));
3615
+ await zipWriter.add(`face_${partName}_${face}.svg`, svgOne);
3616
+ const dxfOne = new zip.TextReader(figureToDxf(geome0.fig[face].mainList));
3617
+ await zipWriter.add(`face_${partName}_${face}.dxf`, dxfOne);
3618
+ const svgOneDeco = new zip.TextReader(figureToSvgDeco(geome0.fig[face]));
3619
+ await zipWriter.add(`deco_${partName}_${face}.svg`, svgOneDeco);
3620
+ const svgOneDecoT = new zip.TextReader(figureToSvgDeco(geome1.fig[face]));
3621
+ await zipWriter.add(`deco_${partName}_${face}_t${tSim}.svg`, svgOneDecoT);
3622
+ }
3623
+ const mergedFace = mergeFaces(geome0.fig);
3624
+ const svgMerged = new zip.TextReader(figureToSvg(mergedFace.mainList));
3625
+ await zipWriter.add(`face_${partName}_all_merged.svg`, svgMerged);
3626
+ const dxfMerged = new zip.TextReader(figureToDxf(mergedFace.mainList));
3627
+ await zipWriter.add(`face_${partName}_all_merged.dxf`, dxfMerged);
3628
+ const svgMergedDeco = new zip.TextReader(figureToSvgDeco(mergedFace));
3629
+ await zipWriter.add(`deco_${partName}_all_merged.svg`, svgMergedDeco);
3630
+ const svgMergedDecoT = new zip.TextReader(figureToSvgDeco(mergedFace));
3631
+ await zipWriter.add(`deco_${partName}_all_merged_t${tSim}.svg`, svgMergedDecoT);
3632
+ const zPax = new zip.TextReader(makePax(paramVal, geome0));
3633
+ await zipWriter.add(`${partName}.pax.json`, zPax);
3634
+ const zSCad = new zip.TextReader(makeOpenscad(geome0));
3635
+ await zipWriter.add(`${partName}_noarc_openscad.scad`, zSCad);
3636
+ const zJScad = new zip.TextReader(makeOpenjscad(geome0));
3637
+ await zipWriter.add(`${partName}_noarc_jscad.js`, zJScad);
3638
+ await zipWriter.close();
3639
+ const rFileContent = await zipFileWriter.getData();
3640
+ return rFileContent;
3641
+ }
3642
+
3643
+ // src/aaExportFile.ts
3644
+ var EFormat = /* @__PURE__ */ ((EFormat2) => {
3645
+ EFormat2[EFormat2["eSVG"] = 0] = "eSVG";
3646
+ EFormat2[EFormat2["eSVGALL"] = 1] = "eSVGALL";
3647
+ EFormat2[EFormat2["eDXF"] = 2] = "eDXF";
3648
+ EFormat2[EFormat2["eDXFALL"] = 3] = "eDXFALL";
3649
+ EFormat2[EFormat2["ePAX"] = 4] = "ePAX";
3650
+ EFormat2[EFormat2["eOPENSCAD"] = 5] = "eOPENSCAD";
3651
+ EFormat2[EFormat2["eJSCAD"] = 6] = "eJSCAD";
3652
+ EFormat2[EFormat2["eZIP"] = 7] = "eZIP";
3653
+ return EFormat2;
3654
+ })(EFormat || {});
3655
+ function fileTextContent(fgeom, paramVal, eFace, exportFormat) {
3656
+ const geome0 = fgeom(0, paramVal);
3657
+ let rFileContent = "";
3658
+ if (!geome0.calcErr) {
3659
+ const figList = Object.keys(geome0.fig);
3660
+ if (exportFormat === 0 /* eSVG */) {
3661
+ if (figList.includes(eFace)) {
3662
+ const figu = geome0.fig[eFace];
3663
+ rFileContent = figureToSvg(figu.mainList);
3664
+ } else {
3665
+ console.log(`err749: fileTextContent eFace ${eFace} invalid`);
3666
+ }
3667
+ } else if (exportFormat === 1 /* eSVGALL */) {
3668
+ const figu = mergeFaces(geome0.fig);
3669
+ rFileContent = figureToSvg(figu.mainList);
3670
+ } else if (exportFormat === 2 /* eDXF */) {
3671
+ if (figList.includes(eFace)) {
3672
+ const figu = geome0.fig[eFace];
3673
+ rFileContent = figureToDxf(figu.mainList);
3674
+ } else {
3675
+ console.log(`err759: fileTextContent eFace ${eFace} invalid`);
3676
+ }
3677
+ } else if (exportFormat === 3 /* eDXFALL */) {
3678
+ const figu = mergeFaces(geome0.fig);
3679
+ rFileContent = figureToDxf(figu.mainList);
3680
+ } else if (exportFormat === 4 /* ePAX */) {
3681
+ rFileContent = makePax(paramVal, geome0);
3682
+ } else if (exportFormat === 5 /* eOPENSCAD */) {
3683
+ rFileContent = makeOpenscad(geome0);
3684
+ } else if (exportFormat === 6 /* eJSCAD */) {
3685
+ rFileContent = makeOpenjscad(geome0);
3686
+ } else {
3687
+ console.log(`err912: unknown exportFormat ${exportFormat}`);
3688
+ }
3689
+ } else {
3690
+ console.log("err931: error by calling geome ${geome0.calcErr}");
3691
+ }
3692
+ return rFileContent;
3693
+ }
3694
+ async function fileBinContent(fgeom, tSim, paramVal, exportFormat) {
3695
+ const geome0 = fgeom(0, paramVal);
3696
+ const geome1 = fgeom(tSim, paramVal);
3697
+ let rFileContent = new Blob();
3698
+ if (!geome0.calcErr && !geome1.calcErr) {
3699
+ if (exportFormat === 7 /* eZIP */) {
3700
+ rFileContent = await makeZip(paramVal, geome0, tSim, geome1);
3701
+ } else {
3702
+ console.log(`err913: unknown exportFormat ${exportFormat}`);
3703
+ }
3704
+ } else {
3705
+ console.log("err932: error by calling geome ${geome0.calcErr} ${geome1.calcErr}");
3706
+ }
3707
+ return rFileContent;
3708
+ }
3709
+ function fileMime(exportFormat) {
3710
+ let rMime = "";
3711
+ if (exportFormat === 0 /* eSVG */ || exportFormat === 1 /* eSVGALL */) {
3712
+ rMime = "image/svg+xml";
3713
+ } else if (exportFormat === 2 /* eDXF */ || exportFormat === 3 /* eDXFALL */) {
3714
+ rMime = "application/dxf";
3715
+ } else if (exportFormat === 4 /* ePAX */) {
3716
+ rMime = "application/json";
3717
+ } else if (exportFormat === 5 /* eOPENSCAD */) {
3718
+ rMime = "text/plain";
3719
+ } else if (exportFormat === 6 /* eJSCAD */) {
3720
+ rMime = "text/plain";
3721
+ } else if (exportFormat === 7 /* eZIP */) {
3722
+ rMime = "application/zip";
3723
+ }
3724
+ return rMime;
3725
+ }
3726
+ function fileSuffix(exportFormat) {
3727
+ let rSuffix = "";
3728
+ if (exportFormat === 0 /* eSVG */ || exportFormat === 1 /* eSVGALL */) {
3729
+ rSuffix = ".svg";
3730
+ } else if (exportFormat === 2 /* eDXF */ || exportFormat === 3 /* eDXFALL */) {
3731
+ rSuffix = ".dxf";
3732
+ } else if (exportFormat === 4 /* ePAX */) {
3733
+ rSuffix = ".pax.json";
3734
+ } else if (exportFormat === 5 /* eOPENSCAD */) {
3735
+ rSuffix = "_noarc_openscad.scad";
3736
+ } else if (exportFormat === 6 /* eJSCAD */) {
3737
+ rSuffix = "_noarc_jscad.js";
3738
+ } else if (exportFormat === 7 /* eZIP */) {
3739
+ rSuffix = ".zip";
3740
+ }
3741
+ return rSuffix;
3742
+ }
3743
+ function fileBin(exportFormat) {
3744
+ let rBin = false;
3745
+ if (exportFormat === 7 /* eZIP */) {
3746
+ rBin = true;
3747
+ }
3748
+ return rBin;
3749
+ }
3750
+
3751
+ // src/paramFile.ts
3752
+ function createParamFile(lastModif, idparams, comment) {
3753
+ const allVal = {
3754
+ lastModif,
3755
+ pVal: idparams,
3756
+ comment
3757
+ };
3758
+ const fContentStr = JSON.stringify(allVal, null, " ");
3759
+ return fContentStr;
3760
+ }
3761
+ function parseParamFile(fContentStr) {
3762
+ const wholeJson = JSON.parse(fContentStr);
3763
+ const lastModifKey = "lastModif";
3764
+ const pValKey = "pVal";
3765
+ const commentKey = "comment";
3766
+ let rlog = "";
3767
+ const rObj = { lastModif: "", pVal: {}, comment: "" };
3768
+ if (Object.hasOwn(wholeJson, lastModifKey)) {
3769
+ rObj[lastModifKey] = wholeJson[lastModifKey];
3770
+ }
3771
+ if (Object.hasOwn(wholeJson, pValKey)) {
3772
+ const paNaVa = wholeJson[pValKey];
3773
+ for (const paNa of Object.keys(paNaVa)) {
3774
+ const paVa = paNaVa[paNa];
3775
+ if (isNaN(paVa)) {
3776
+ throw `err905: ${paVa} is not a number!`;
3777
+ }
3778
+ rObj[pValKey][paNa] = paVa;
3779
+ }
3780
+ rlog += `info398: parsing file has found ${Object.keys(rObj[pValKey]).length} parameters
3781
+ `;
3782
+ } else {
3783
+ throw `err489: parameter-json-file has no key ${pValKey}
3784
+ `;
3785
+ }
3786
+ if (Object.hasOwn(wholeJson, commentKey)) {
3787
+ rObj[commentKey] = wholeJson[commentKey];
3788
+ }
3789
+ return [rObj, rlog];
3790
+ }
3791
+ export {
3792
+ EBVolume,
3793
+ EExtrude,
3794
+ EFormat,
3795
+ PType,
3796
+ ShapePoint,
3797
+ aBFromLaLbAa,
3798
+ aCFromLaLbLc,
3799
+ adjustCenter,
3800
+ adjustInit,
3801
+ adjustRect,
3802
+ adjustScale,
3803
+ adjustTranslate,
3804
+ adjustZero,
3805
+ bisector,
3806
+ canvas2point,
3807
+ canvasTranslatePolar,
3808
+ checkGeom,
3809
+ circleCenter,
3810
+ colors,
3811
+ contour,
3812
+ contourCircle,
3813
+ copyLayers,
3814
+ createParamFile,
3815
+ degToRad,
3816
+ designParam,
3817
+ ffix,
3818
+ figure,
3819
+ fileBin,
3820
+ fileBinContent,
3821
+ fileMime,
3822
+ fileSuffix,
3823
+ fileTextContent,
3824
+ fround,
3825
+ initGeom,
3826
+ initLayers,
3827
+ lbFromLaAaAb,
3828
+ lcFromLaLbAc,
3829
+ line,
3830
+ linePP,
3831
+ mergeFaces,
3832
+ oneDesignParam,
3833
+ pCheckbox,
3834
+ pDropdown,
3835
+ pNumber,
3836
+ paramListToVal,
3837
+ parseParamFile,
3838
+ point,
3839
+ point2canvas,
3840
+ prefixLog,
3841
+ radToDeg,
3842
+ radius2canvas,
3843
+ roundZero,
3844
+ vector,
3845
+ withinPiPi,
3846
+ withinZero2Pi
3847
+ };
3848
+ //# sourceMappingURL=index.js.map