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/src/segment.ts DELETED
@@ -1,701 +0,0 @@
1
- // segment.ts
2
- // segment.ts deals with segments and arcs for helping the module contour.ts
3
- // segment.ts depends on point.ts, line.ts and vector.ts
4
- // segment.ts is used by contour.ts
5
-
6
- //import type { tCanvasAdjust } from './canvas_utils';
7
- //import type { tPolar } from './point';
8
- //import { colorCanvasPoint } from '$lib/style/colors.scss';
9
- import {
10
- tolerance,
11
- //degToRad,
12
- //radToDeg,
13
- roundZero,
14
- withinZero2Pi,
15
- withinPiPi,
16
- //withinZeroPi,
17
- //withinHPiHPi,
18
- isWithin,
19
- ffix
20
- } from './angle_utils';
21
- //import { colors, point2canvas, radius2canvas } from './canvas_utils';
22
- import {
23
- //rightTriLaFromLbLc,
24
- rightTriLbFromLaLc,
25
- //lcFromLaLbAc,
26
- aCFromLaLbLc
27
- //aCFromAaAb,
28
- //lbFromLaAaAb,
29
- //aBFromLaLbAa
30
- } from './triangle_utils';
31
- import { ShapePoint, point, Point } from './point';
32
- //import { line, linePP, bisector, circleCenter } from './line';
33
- import { line, linePP, Line } from './line';
34
- //import { vector, Vector } from './vector';
35
-
36
- enum SegEnum {
37
- eStroke,
38
- eArc,
39
- ePointed,
40
- eRounded,
41
- eWidened,
42
- eWideAcc, // Widened Access
43
- eStart
44
- }
45
-
46
- function isSeg(iSegEnum: SegEnum) {
47
- let rIsSeg = false;
48
- if (iSegEnum === SegEnum.eStroke || iSegEnum === SegEnum.eArc) {
49
- rIsSeg = true;
50
- }
51
- return rIsSeg;
52
- }
53
- function isAddPoint(iSegEnum: SegEnum) {
54
- let rIsOther = false;
55
- if (isSeg(iSegEnum) || iSegEnum === SegEnum.eStart) {
56
- rIsOther = true;
57
- }
58
- return rIsOther;
59
- }
60
- function isActiveCorner(iSegEnum: SegEnum) {
61
- let rIsActiveCorner = false;
62
- if (
63
- iSegEnum === SegEnum.eRounded ||
64
- iSegEnum === SegEnum.eWidened ||
65
- iSegEnum === SegEnum.eWideAcc
66
- ) {
67
- rIsActiveCorner = true;
68
- }
69
- return rIsActiveCorner;
70
- }
71
- function isCorner(iSegEnum: SegEnum) {
72
- let rIsCorner = false;
73
- if (iSegEnum === SegEnum.ePointed || isActiveCorner(iSegEnum)) {
74
- rIsCorner = true;
75
- }
76
- return rIsCorner;
77
- }
78
-
79
- /* Segment class */
80
-
81
- class Segment1 {
82
- sType: SegEnum;
83
- px: number;
84
- py: number;
85
- radius: number;
86
- arcLarge: boolean;
87
- arcCcw: boolean;
88
- constructor(
89
- iType: SegEnum,
90
- ix: number,
91
- iy: number,
92
- iRadius: number,
93
- iArcLarge = false,
94
- iArcCcw = false
95
- ) {
96
- this.sType = iType;
97
- this.px = ix;
98
- this.py = iy;
99
- this.radius = iRadius;
100
- this.arcLarge = iArcLarge;
101
- this.arcCcw = iArcCcw;
102
- }
103
- clone(): Segment1 {
104
- const rseg1 = new Segment1(
105
- this.sType,
106
- this.px,
107
- this.py,
108
- this.radius,
109
- this.arcLarge,
110
- this.arcCcw
111
- );
112
- return rseg1;
113
- }
114
- }
115
- class Segment2 {
116
- sType: SegEnum;
117
- p1: Point;
118
- p2: Point;
119
- pc: Point;
120
- radius: number;
121
- a1: number;
122
- a2: number;
123
- arcCcw: boolean;
124
- constructor(
125
- iType: SegEnum,
126
- ip1: Point,
127
- ip2: Point,
128
- ipc: Point,
129
- iRadius: number,
130
- ia1: number,
131
- ia2: number,
132
- iArcCcw = false
133
- ) {
134
- this.sType = iType;
135
- this.p1 = ip1;
136
- this.p2 = ip2;
137
- this.pc = ipc;
138
- this.radius = iRadius;
139
- this.a1 = ia1;
140
- this.a2 = ia2;
141
- this.arcCcw = iArcCcw;
142
- }
143
- }
144
-
145
- class SegDbg {
146
- debugPoints: Point[];
147
- debugLines: Line[];
148
- logMessage: string;
149
- constructor() {
150
- this.debugPoints = [];
151
- this.debugLines = [];
152
- this.logMessage = '';
153
- }
154
- addPoint(ip: Point) {
155
- this.debugPoints.push(ip);
156
- }
157
- getPoints(): Point[] {
158
- return this.debugPoints;
159
- }
160
- clearPoints() {
161
- this.debugPoints = [];
162
- }
163
- addLine(il: Line) {
164
- this.debugLines.push(il);
165
- }
166
- getLines(): Line[] {
167
- return this.debugLines;
168
- }
169
- clearLines() {
170
- this.debugLines = [];
171
- }
172
- addMsg(iMsg: string) {
173
- this.logMessage += iMsg;
174
- }
175
- getMsg(): string {
176
- return this.logMessage;
177
- }
178
- clearMsg() {
179
- this.logMessage = '';
180
- }
181
- }
182
- const gSegDbg = new SegDbg();
183
-
184
- function arcSeg1To2(px1: number, py1: number, iSeg1: Segment1): Segment2 {
185
- if (iSeg1.sType !== SegEnum.eArc) {
186
- throw `err202: arcSeg1To2 has unexpected type ${iSeg1.sType}`;
187
- }
188
- const p1 = point(px1, py1);
189
- const p2 = point(iSeg1.px, iSeg1.py);
190
- const lp1p2h = p1.distanceToPoint(p2) / 2;
191
- if (p1.isEqual(p2)) {
192
- throw `err638: no equidistance because identical point ${p1.cx} ${p2.cy}`;
193
- }
194
- let oppos = 0;
195
- if (roundZero(iSeg1.radius - lp1p2h) === 0) {
196
- oppos = 0;
197
- } else if (iSeg1.radius < lp1p2h) {
198
- //console.log(`dbg398: ${p1.cx} ${p1.cy} ${iSeg1.px} ${iSeg1.py}`);
199
- throw `err399: radius ${iSeg1.radius} smaller than lp1p2h ${lp1p2h}`;
200
- } else {
201
- oppos = rightTriLbFromLaLc(iSeg1.radius, lp1p2h);
202
- }
203
- const pbi = p1.middlePoint(p2);
204
- const abi = p1.angleToPoint(p2) + Math.PI / 2;
205
- const rp1 = pbi.translatePolar(abi, oppos);
206
- const rp2 = pbi.translatePolar(abi + Math.PI, oppos);
207
- let rp3 = rp1;
208
- if ((!iSeg1.arcLarge && !iSeg1.arcCcw) || (iSeg1.arcLarge && iSeg1.arcCcw)) {
209
- rp3 = rp2;
210
- }
211
- const a1 = rp3.angleToPoint(p1);
212
- const a2 = rp3.angleToPoint(p2);
213
- const rSeg2 = new Segment2(SegEnum.eArc, p1, p2, rp3, iSeg1.radius, a1, a2, iSeg1.arcCcw);
214
- return rSeg2;
215
- }
216
- function arcSeg2To1(iSeg2: Segment2): Segment1 {
217
- let a12 = withinZero2Pi(iSeg2.a2 - iSeg2.a1);
218
- if (!iSeg2.arcCcw) {
219
- a12 = 2 * Math.PI - a12;
220
- }
221
- let large = false;
222
- if (a12 > Math.PI) {
223
- large = true;
224
- }
225
- const rSeg1 = new Segment1(
226
- SegEnum.eArc,
227
- iSeg2.p2.cx,
228
- iSeg2.p2.cy,
229
- iSeg2.radius,
230
- large,
231
- iSeg2.arcCcw
232
- );
233
- return rSeg1;
234
- }
235
-
236
- interface tPrepare {
237
- s1: Segment2;
238
- s2: Segment2;
239
- s3: Segment2;
240
- ra: number;
241
- p1: Point;
242
- p2: Point;
243
- p3: Point;
244
- p4: Point;
245
- p5: Point;
246
- p6: Point;
247
- at1: number;
248
- at3: number;
249
- abi: number;
250
- aph: number;
251
- }
252
- function prepare(s1: Segment2, s2: Segment2, s3: Segment2): tPrepare {
253
- const p1 = s1.p1;
254
- const p2 = s1.p2;
255
- const p2b = s3.p1;
256
- const p3 = s3.p2;
257
- if (!p2.isEqual(p2b)) {
258
- throw `err309: makeCorner-prepare p2 and p2b differ px ${p2.cx} ${p2b.cx} py ${p2.cy} ${p2b.cy}`;
259
- }
260
- let aTangent1 = p2.angleToPoint(p1);
261
- if (s1.sType === SegEnum.eArc) {
262
- const sign = s1.arcCcw ? 1 : -1;
263
- aTangent1 = s1.a2 - (sign * Math.PI) / 2;
264
- }
265
- let aTangent3 = p2.angleToPoint(p3);
266
- if (s3.sType === SegEnum.eArc) {
267
- const sign = s3.arcCcw ? 1 : -1;
268
- aTangent3 = s3.a1 + (sign * Math.PI) / 2;
269
- }
270
- const a123 = aTangent3 - aTangent1;
271
- const a123b = withinPiPi(a123); // the sign might change
272
- let aPeakHalf = a123b / 2;
273
- if (roundZero(aPeakHalf) === 0) {
274
- const tolerance2 = tolerance * 10 ** -2;
275
- if (s1.sType === SegEnum.eStroke && s3.sType === SegEnum.eArc) {
276
- aPeakHalf = s3.arcCcw ? tolerance2 : -tolerance2;
277
- } else if (s1.sType === SegEnum.eArc && s3.sType === SegEnum.eStroke) {
278
- aPeakHalf = s1.arcCcw ? tolerance2 : -tolerance2;
279
- } else if (s1.sType === SegEnum.eStroke && s3.sType === SegEnum.eStroke) {
280
- throw `err402: prepare aPeakHalf too closed to zero ${aPeakHalf}`;
281
- }
282
- // eArc && eArc : nothing special
283
- }
284
- const aBisector = aTangent1 + aPeakHalf;
285
- const p6 = p2.translatePolar(aBisector, s2.radius);
286
- const rPre: tPrepare = {
287
- s1: s1,
288
- s2: s2,
289
- s3: s3,
290
- ra: s2.radius,
291
- p1: p1,
292
- p2: p2,
293
- p3: p3,
294
- p4: s1.pc,
295
- p5: s3.pc,
296
- p6: p6,
297
- at1: aTangent1,
298
- at3: aTangent3,
299
- abi: aBisector,
300
- aph: aPeakHalf
301
- };
302
- return rPre;
303
- }
304
-
305
- function modifRadius(iaph: number, iseg: Segment2, iradius: number): number {
306
- if (iseg.sType !== SegEnum.eArc) {
307
- throw `err510: modifRadius with wrong type ${iseg.sType}`;
308
- }
309
- const bisector = iaph > 0 ? 1 : -1;
310
- const arcCcw = iseg.arcCcw ? 1 : -1;
311
- const sign = roundZero(iaph) === 0 ? 1 : bisector * arcCcw;
312
- const rmr = iseg.radius + sign * iradius;
313
- if (rmr <= 0) {
314
- throw `err621: modifRadius with negative modified lenght ${rmr}`;
315
- }
316
- return rmr;
317
- }
318
- function closestPoint(ica: number, dist: number, pB: Point, p6: Point): Point {
319
- const p7a = pB.translatePolar(ica, dist);
320
- const p7b = pB.translatePolar(ica + Math.PI, dist);
321
- const d67a = p6.distanceToPoint(p7a);
322
- const d67b = p6.distanceToPoint(p7b);
323
- const rp7 = d67a < d67b ? p7a : p7b;
324
- return rp7;
325
- }
326
- function closestPoint2(p4: Point, a45: number, a547: number, dist: number, p6: Point): number {
327
- const p7a = p4.translatePolar(a45 - a547, dist);
328
- const p7b = p4.translatePolar(a45 + a547, dist);
329
- const d67a = p6.distanceToPoint(p7a);
330
- const d67b = p6.distanceToPoint(p7b);
331
- const sign = d67a < d67b ? -1 : 1;
332
- return sign;
333
- }
334
- function newStrokeFirst(iseg: Segment2, ip: Point): Segment2 {
335
- const p8 = ip.clone();
336
- const p1 = iseg.p1.clone();
337
- const p2 = iseg.p2;
338
- // few checks
339
- if (iseg.sType !== SegEnum.eStroke) {
340
- throw `err103: newStrokeFirst unexpected sType ${iseg.sType}`;
341
- }
342
- const distLine = linePP(p1, p2).distanceToPoint(p8);
343
- if (roundZero(distLine) !== 0) {
344
- throw `err104: newStrokeFirst new point not aligned ${distLine} ${p8.cx} ${p8.cy}`;
345
- }
346
- const a2 = p1.angleToPoint(p2);
347
- const a8 = p1.angleToPoint(p8);
348
- if (roundZero(withinPiPi(a8 - a2)) !== 0) {
349
- throw `err105: newStrokeFirst new point miss aligned ${a2} ${a8} ${p8.cx} ${p8.cy}`;
350
- }
351
- const l18 = p1.distanceToPoint(p8);
352
- const l12 = p1.distanceToPoint(p2);
353
- if (l12 < l18) {
354
- throw `err106: newStrokeFirst new point out of scope ${l12} ${l18} ${p8.cx} ${p8.cy}`;
355
- }
356
- // end of few checks
357
- const p0 = point(0, 0);
358
- const rNewSeg = new Segment2(SegEnum.eStroke, p1, p8, p0, 0, 0, 0, false);
359
- return rNewSeg;
360
- }
361
- function newStrokeSecond(iseg: Segment2, ip: Point): Segment2 {
362
- const p9 = ip.clone();
363
- const p3 = iseg.p2.clone();
364
- const p2 = iseg.p1;
365
- // few checks
366
- if (iseg.sType !== SegEnum.eStroke) {
367
- throw `err203: newStrokeSecond unexpected sType ${iseg.sType}`;
368
- }
369
- const distLine = linePP(p3, p2).distanceToPoint(p9);
370
- if (roundZero(distLine) !== 0) {
371
- throw `err204: newStrokeSecond new point not aligned ${distLine} ${p9.cx} ${p9.cy}`;
372
- }
373
- const a2 = p3.angleToPoint(p2);
374
- const a9 = p3.angleToPoint(p9);
375
- if (roundZero(withinPiPi(a9 - a2)) !== 0) {
376
- throw `err205: newStrokeSecond new point miss aligned ${a2} ${a9} ${p9.cx} ${p9.cy}`;
377
- }
378
- const l39 = p3.distanceToPoint(p9);
379
- const l32 = p3.distanceToPoint(p2);
380
- if (l32 < l39) {
381
- throw `err206: newStrokeSecond new point out of scope ${l32} ${l39} ${p9.cx} ${p9.cy}`;
382
- }
383
- // end of few checks
384
- const p0 = point(0, 0);
385
- const rNewSeg = new Segment2(SegEnum.eStroke, p9, p3, p0, 0, 0, 0, false);
386
- return rNewSeg;
387
- }
388
- function newArcFirst(iseg: Segment2, ip: Point): Segment2 {
389
- if (iseg.sType !== SegEnum.eArc) {
390
- throw `err203: newArcFirst unexpected sType ${iseg.sType}`;
391
- }
392
- const p1 = iseg.p1.clone();
393
- const p4 = iseg.pc.clone();
394
- const p8 = ip.clone();
395
- const a48 = p4.angleToPoint(p8);
396
- // check arc angle are properly reduced
397
- if (!isWithin(a48, iseg.a1, iseg.a2, iseg.arcCcw)) {
398
- throw `err908: newArcFirst a48 out of scope ${a48} ${iseg.a1} ${iseg.a2} ${iseg.arcCcw}`;
399
- }
400
- const rNewSeg = new Segment2(SegEnum.eArc, p1, p8, p4, iseg.radius, iseg.a1, a48, iseg.arcCcw);
401
- return rNewSeg;
402
- }
403
- function newArcSecond(iseg: Segment2, ip: Point): Segment2 {
404
- if (iseg.sType !== SegEnum.eArc) {
405
- throw `err204: newArcSecond unexpected sType ${iseg.sType}`;
406
- }
407
- const p3 = iseg.p2.clone();
408
- const p5 = iseg.pc.clone();
409
- const p9 = ip.clone();
410
- const a59 = p5.angleToPoint(p9);
411
- // check arc angle are properly reduced
412
- if (!isWithin(a59, iseg.a1, iseg.a2, iseg.arcCcw)) {
413
- throw `err907: newArcSecond a59 out of scope ${a59} ${iseg.a1} ${iseg.a2} ${iseg.arcCcw}`;
414
- }
415
- const rNewSeg = new Segment2(SegEnum.eArc, p9, p3, p5, iseg.radius, a59, iseg.a2, iseg.arcCcw);
416
- return rNewSeg;
417
- }
418
- function newRounded(
419
- ip8: Point,
420
- ip9: Point,
421
- ip7: Point,
422
- ra: number,
423
- aph: number,
424
- abi: number
425
- ): Segment2 {
426
- const p8 = ip8.clone();
427
- const p9 = ip9.clone();
428
- const p7 = ip7.clone();
429
- // few checks
430
- const l78 = p7.distanceToPoint(p8);
431
- const l79 = p7.distanceToPoint(p9);
432
- if (roundZero(l78 - ra) !== 0 || roundZero(l79 - ra) !== 0) {
433
- throw `err610: newRounded not on circle ${ra} ${l78} ${l79}`;
434
- }
435
- const a78 = p7.angleToPoint(p8);
436
- const a79 = p7.angleToPoint(p9);
437
- const a873 = withinPiPi(a78 - abi + Math.PI);
438
- const a973 = withinPiPi(a79 - abi + Math.PI);
439
- if (Math.abs(a973 - a873) > Math.PI + tolerance) {
440
- gSegDbg.addMsg(
441
- `warn882: newRounded a873 or a972 larger than PI/2 ` +
442
- `${ffix(a873)} ${ffix(a973)} at ${ffix(p7.cx)} ${ffix(p7.cy)}\n`
443
- );
444
- }
445
- // end of few checks
446
- const ccw2 = aph > 0 ? false : true;
447
- const rNewSeg = new Segment2(SegEnum.eArc, p8, p9, p7, ra, a78, a79, ccw2);
448
- return rNewSeg;
449
- }
450
- function roundStrokeStroke(ag: tPrepare): Segment2[] {
451
- const l7 = Math.abs(ag.ra / Math.sin(ag.aph));
452
- const l7b = l7 * Math.cos(ag.aph);
453
- const p7 = ag.p2.translatePolar(ag.abi, l7);
454
- //const p8 = linePP(ag.p1, ag.p2).projectPoint(p7);
455
- //const p9 = linePP(ag.p2, ag.p3).projectPoint(p7);
456
- //const p8 = p7.translatePolar(a78, ag.ra);
457
- //const p9 = p7.translatePolar(a79, ag.ra);
458
- const p8 = ag.p2.translatePolar(ag.at1, l7b);
459
- const p9 = ag.p2.translatePolar(ag.at3, l7b);
460
- const rsegs: Segment2[] = [];
461
- rsegs.push(newStrokeFirst(ag.s1, p8));
462
- rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
463
- rsegs.push(newStrokeSecond(ag.s3, p9));
464
- return rsegs;
465
- }
466
- function roundStrokeArc(ag: tPrepare): Segment2[] {
467
- const lStroke = linePP(ag.p1, ag.p2);
468
- const lStrokep = lStroke.lineParallelDistance(ag.ra, ag.p6, ag.p5);
469
- const pB = lStrokep.projectPoint(ag.p5);
470
- //gSegDbg.addPoint(ag.p6.clone(ShapePoint.eTwoTri));
471
- //gSegDbg.addPoint(ag.p5.clone(ShapePoint.eTri1));
472
- //gSegDbg.addPoint(pB.clone(ShapePoint.eTri2));
473
- const lB5 = pB.distanceToPoint(ag.p5);
474
- const ml = modifRadius(ag.aph, ag.s3, ag.ra);
475
- const lB7 = rightTriLbFromLaLc(ml, lB5);
476
- //console.log(`dbg678: ${lB5} ${ml} ${lB7}`);
477
- const p7 = closestPoint(lStrokep.ca, lB7, pB, ag.p6);
478
- const a57 = ag.p5.angleToPoint(p7);
479
- const p9 = ag.p5.translatePolar(a57, ag.s3.radius);
480
- const a127 = ag.p2.angleFromToPoints(ag.p1, p7);
481
- const l27 = Math.abs(ag.ra / Math.sin(a127));
482
- const l28 = l27 * Math.cos(a127);
483
- const a28 = ag.p2.angleToPoint(ag.p1);
484
- const p8 = ag.p2.translatePolar(a28, l28);
485
- //gSegDbg.addPoint(p7.clone(ShapePoint.eTri3));
486
- //gSegDbg.addPoint(p8.clone(ShapePoint.eTri4));
487
- //gSegDbg.addPoint(p9.clone(ShapePoint.eCross));
488
- const rsegs: Segment2[] = [];
489
- rsegs.push(newStrokeFirst(ag.s1, p8));
490
- rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
491
- rsegs.push(newArcSecond(ag.s3, p9));
492
- //rsegs.push(newStrokeFirst(ag.s1, ag.p2));
493
- //rsegs.push(newArcSecond(ag.s3, ag.p2));
494
- return rsegs;
495
- }
496
- function roundArcStroke(ag: tPrepare): Segment2[] {
497
- const lStroke = linePP(ag.p3, ag.p2);
498
- const lStrokep = lStroke.lineParallelDistance(ag.ra, ag.p6, ag.p4);
499
- const pB = lStrokep.projectPoint(ag.p4);
500
- const lB4 = pB.distanceToPoint(ag.p4);
501
- const ml = modifRadius(ag.aph, ag.s1, ag.ra);
502
- const lB7 = rightTriLbFromLaLc(ml, lB4);
503
- const p7 = closestPoint(lStrokep.ca, lB7, pB, ag.p6);
504
- const a47 = ag.p4.angleToPoint(p7);
505
- const p8 = ag.p4.translatePolar(a47, ag.s1.radius);
506
- const a327 = ag.p2.angleFromToPoints(ag.p3, p7);
507
- const l27 = Math.abs(ag.ra / Math.sin(a327));
508
- const l29 = l27 * Math.cos(a327);
509
- const a29 = ag.p2.angleToPoint(ag.p3);
510
- const p9 = ag.p2.translatePolar(a29, l29);
511
- //gSegDbg.addPoint(p7.clone(ShapePoint.eTri3));
512
- //gSegDbg.addPoint(p8.clone(ShapePoint.eTri4));
513
- //gSegDbg.addPoint(p9.clone(ShapePoint.eCross));
514
- const rsegs: Segment2[] = [];
515
- rsegs.push(newArcFirst(ag.s1, p8));
516
- rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
517
- rsegs.push(newStrokeSecond(ag.s3, p9));
518
- //rsegs.push(newArcFirst(ag.s1, ag.p2));
519
- //rsegs.push(newStrokeSecond(ag.s3, ag.p2));
520
- return rsegs;
521
- }
522
- function roundArcArc(ag: tPrepare): Segment2[] {
523
- const mr1 = modifRadius(ag.aph, ag.s1, ag.ra);
524
- const mr3 = modifRadius(ag.aph, ag.s3, ag.ra);
525
- const lp4p5 = ag.p4.distanceToPoint(ag.p5);
526
- const a45 = ag.p4.angleToPoint(ag.p5);
527
- const a547 = aCFromLaLbLc(lp4p5, mr1, mr3);
528
- const sign1 = closestPoint2(ag.p4, a45, a547, mr1, ag.p6);
529
- const a47 = a45 + sign1 * a547;
530
- const p7 = ag.p4.translatePolar(a47, mr1);
531
- const p8 = ag.p4.translatePolar(a47, ag.s1.radius);
532
- const a54 = Math.PI + a45;
533
- const a457 = aCFromLaLbLc(lp4p5, mr3, mr1);
534
- //const a457b = aBFromLaLbAa(mr3, mr1, a547); // a bad alternative using arcsinus!
535
- //if (roundZero(a457 - a457b) !== 0) {
536
- // gSegDbg.addMsg(`dbg356: ${a457b} ${a457} ${mr3} ${mr1} ${a547}\n`);
537
- //}
538
- const sign2 = closestPoint2(ag.p5, a54, a457, mr3, ag.p6);
539
- const a57 = a54 + sign2 * a457;
540
- const p7b = ag.p5.translatePolar(a57, mr3);
541
- if (!p7b.isEqual(p7)) {
542
- throw `err909: roundArcArc p7 anf p7b differ ${p7.cx} ${p7b.cx} ${p7.cy} ${p7b.cy} ${ShapePoint.eDefault}`;
543
- }
544
- const p9 = ag.p5.translatePolar(a57, ag.s3.radius);
545
- //gSegDbg.addPoint(p7.clone(ShapePoint.eTri1));
546
- //gSegDbg.addPoint(p7b.clone(ShapePoint.eSquare));
547
- //gSegDbg.addPoint(p8.clone(ShapePoint.eTri3));
548
- //gSegDbg.addPoint(p9.clone(ShapePoint.eTri4));
549
- const rsegs: Segment2[] = [];
550
- rsegs.push(newArcFirst(ag.s1, p8));
551
- rsegs.push(newRounded(p8, p9, p7, ag.ra, ag.aph, ag.abi));
552
- rsegs.push(newArcSecond(ag.s3, p9));
553
- //rsegs.push(newArcFirst(ag.s1, ag.p2));
554
- //rsegs.push(newArcSecond(ag.s3, ag.p2));
555
- return rsegs;
556
- }
557
- function widenCorner(ag: tPrepare): Segment2[] {
558
- const a68 = ag.abi - 2 * ag.aph;
559
- const a69 = ag.abi + 2 * ag.aph;
560
- let p8 = ag.p6.translatePolar(a68, ag.ra);
561
- let p9 = ag.p6.translatePolar(a69, ag.ra);
562
- if (ag.s1.sType === SegEnum.eArc) {
563
- const a246 = ag.p4.angleFromToPoints(ag.p2, ag.p6);
564
- const a42 = ag.p4.angleToPoint(ag.p2);
565
- const a46 = a42 + 2 * a246;
566
- p8 = ag.p4.translatePolar(a46, ag.s1.radius);
567
- }
568
- if (ag.s3.sType === SegEnum.eArc) {
569
- const a256 = ag.p5.angleFromToPoints(ag.p2, ag.p6);
570
- const a52 = ag.p5.angleToPoint(ag.p2);
571
- const a56 = a52 + 2 * a256;
572
- p9 = ag.p5.translatePolar(a56, ag.s3.radius);
573
- }
574
- const ccw2 = ag.aph > 0 ? false : true;
575
- const segCorner = new Segment2(SegEnum.eArc, p8, p9, ag.p6, ag.ra, a68, a69, ccw2);
576
- //gSegDbg.addPoint(ag.p6.clone(ShapePoint.eTwoTri));
577
- const rsegs: Segment2[] = [];
578
- if (ag.s1.sType === SegEnum.eStroke) {
579
- rsegs.push(newStrokeFirst(ag.s1, p8));
580
- } else if (ag.s1.sType === SegEnum.eArc) {
581
- rsegs.push(newArcFirst(ag.s1, p8));
582
- }
583
- rsegs.push(segCorner);
584
- if (ag.s3.sType === SegEnum.eStroke) {
585
- rsegs.push(newStrokeSecond(ag.s3, p9));
586
- } else if (ag.s3.sType === SegEnum.eArc) {
587
- rsegs.push(newArcSecond(ag.s3, p9));
588
- }
589
- return rsegs;
590
- }
591
- function wideAccessSide(sign: number, one: Segment2, p8one: Point, ag: tPrepare): Point[] {
592
- let p8a = p8one;
593
- let p8b = p8one;
594
- const a268 = ag.p6.angleFromToPoints(ag.p2, p8one);
595
- if (Math.abs(a268) > Math.PI / 2) {
596
- p8b = ag.p6.translatePolar(ag.abi + (sign * Math.PI) / 2, ag.ra);
597
- //gSegDbg.addPoint(p8b.clone(ShapePoint.eSquare));
598
- const l2 = line(p8b.cx, p8b.cy, ag.abi);
599
- //gSegDbg.addLine(l2);
600
- if (one.sType === SegEnum.eStroke) {
601
- const l1 = linePP(one.p1, one.p2);
602
- p8a = l1.intersection(l2);
603
- } else if (one.sType === SegEnum.eArc) {
604
- const ph = l2.projectPoint(one.pc);
605
- //gSegDbg.addPoint(ph.clone(ShapePoint.eSquare));
606
- //gSegDbg.addPoint(one.pc.clone(ShapePoint.eSquare));
607
- //gSegDbg.addLine(linePP(one.pc, ph));
608
- const lh4 = ph.distanceToPoint(one.pc);
609
- if (lh4 < one.radius) {
610
- const lh8a = rightTriLbFromLaLc(one.radius, lh4);
611
- p8a = closestPoint(ag.abi, lh8a, ph, p8one);
612
- } else {
613
- gSegDbg.addMsg(
614
- `warn222: wideAccess not possible on arc ` +
615
- `${ffix(one.radius)} ${ffix(lh4)} at ${ffix(p8one.cx)} ${ffix(p8one.cy)}\n`
616
- );
617
- p8a = p8one;
618
- p8b = p8one;
619
- }
620
- }
621
- }
622
- return [p8a, p8b];
623
- }
624
- function wideAccessCorner(ag: tPrepare): Segment2[] {
625
- const ones = widenCorner(ag);
626
- const sign1 = ones[1].arcCcw ? 1 : -1;
627
- const [p8a, p8b] = wideAccessSide(sign1, ag.s1, ones[1].p1, ag);
628
- const [p9a, p9b] = wideAccessSide(-sign1, ag.s3, ones[1].p2, ag);
629
- //gSegDbg.addPoint(p8a.clone(ShapePoint.eTri1));
630
- //gSegDbg.addPoint(p8b.clone(ShapePoint.eTri2));
631
- //gSegDbg.addPoint(p9b.clone(ShapePoint.eTri3));
632
- //gSegDbg.addPoint(p9a.clone(ShapePoint.eTri4));
633
- const rsegs: Segment2[] = [];
634
- if (p8a.isEqual(p8b)) {
635
- rsegs.push(ones[0]);
636
- } else {
637
- if (ag.s1.sType === SegEnum.eStroke) {
638
- rsegs.push(newStrokeFirst(ag.s1, p8a));
639
- } else if (ag.s1.sType === SegEnum.eArc) {
640
- rsegs.push(newArcFirst(ag.s1, p8a));
641
- }
642
- const p0 = point(0, 0);
643
- const newStroke = new Segment2(SegEnum.eStroke, p8a, p8b, p0, 0, 0, 0, false);
644
- rsegs.push(newStroke);
645
- }
646
- rsegs.push(newRounded(p8b, p9b, ag.p6, ag.ra, ag.aph, ag.abi));
647
- if (p9a.isEqual(p9b)) {
648
- rsegs.push(ones[2]);
649
- } else {
650
- const p0 = point(0, 0);
651
- const newStroke = new Segment2(SegEnum.eStroke, p9b, p9a, p0, 0, 0, 0, false);
652
- rsegs.push(newStroke);
653
- if (ag.s3.sType === SegEnum.eStroke) {
654
- rsegs.push(newStrokeSecond(ag.s3, p9a));
655
- } else if (ag.s3.sType === SegEnum.eArc) {
656
- rsegs.push(newArcSecond(ag.s3, p9a));
657
- }
658
- }
659
- //rsegs.push(ones[0]);
660
- //rsegs.push(ones[1]);
661
- //rsegs.push(ones[2]);
662
- return rsegs;
663
- }
664
- function makeCorner(s1: Segment2, s2: Segment2, s3: Segment2): Segment2[] {
665
- const preArg = prepare(s1, s2, s3);
666
- const rsegs: Segment2[] = [];
667
- if (s2.sType === SegEnum.eRounded) {
668
- if (s1.sType === SegEnum.eStroke && s3.sType === SegEnum.eStroke) {
669
- rsegs.push(...roundStrokeStroke(preArg));
670
- } else if (s1.sType === SegEnum.eStroke && s3.sType === SegEnum.eArc) {
671
- rsegs.push(...roundStrokeArc(preArg));
672
- } else if (s1.sType === SegEnum.eArc && s3.sType === SegEnum.eStroke) {
673
- rsegs.push(...roundArcStroke(preArg));
674
- } else if (s1.sType === SegEnum.eArc && s3.sType === SegEnum.eArc) {
675
- rsegs.push(...roundArcArc(preArg));
676
- } else {
677
- throw `err123: makeCorner unexpected s1s3.sType ${s1.sType} ${s3.sType}`;
678
- }
679
- } else if (s2.sType === SegEnum.eWidened) {
680
- rsegs.push(...widenCorner(preArg));
681
- } else if (s2.sType === SegEnum.eWideAcc) {
682
- rsegs.push(...wideAccessCorner(preArg));
683
- } else {
684
- throw `err723: makeCorner unexpected s2.sType ${s2.sType}`;
685
- }
686
- return rsegs;
687
- }
688
-
689
- export {
690
- SegEnum,
691
- isSeg,
692
- isAddPoint,
693
- isActiveCorner,
694
- isCorner,
695
- Segment1,
696
- Segment2,
697
- gSegDbg,
698
- arcSeg1To2,
699
- arcSeg2To1,
700
- makeCorner
701
- };
package/src/sub_design.ts DELETED
@@ -1,16 +0,0 @@
1
- // sub_design.ts
2
-
3
- import type { tDesignParamList } from './designParams';
4
-
5
- type tPosiOrien = [number, number, number];
6
-
7
- interface tSubInst {
8
- partName: string;
9
- dparam: tDesignParamList;
10
- orientation: tPosiOrien;
11
- position: tPosiOrien;
12
- }
13
-
14
- type tSubDesign = Record<string, tSubInst>;
15
-
16
- export type { tPosiOrien, tSubInst, tSubDesign };