geometrix 0.5.10 → 0.5.12

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 (89) hide show
  1. package/dist/index.d.ts +505 -0
  2. package/dist/index.js +3848 -0
  3. package/package.json +7 -1
  4. package/.eslintignore +0 -17
  5. package/.eslintrc.cjs +0 -24
  6. package/.prettierignore +0 -15
  7. package/.prettierrc +0 -8
  8. package/src/aaExportContent.ts +0 -213
  9. package/src/aaExportFile.ts +0 -141
  10. package/src/aaParamGeom.ts +0 -62
  11. package/src/angle_utils.test.ts +0 -83
  12. package/src/angle_utils.ts +0 -98
  13. package/src/arc_to_stroke.ts +0 -73
  14. package/src/canvas_utils.test.ts +0 -28
  15. package/src/canvas_utils.ts +0 -159
  16. package/src/contour.test.ts +0 -37
  17. package/src/contour.ts +0 -806
  18. package/src/designParams.ts +0 -178
  19. package/src/figure.test.ts +0 -21
  20. package/src/figure.ts +0 -400
  21. package/src/index.ts +0 -16
  22. package/src/line.test.ts +0 -78
  23. package/src/line.ts +0 -359
  24. package/src/paramFile.ts +0 -52
  25. package/src/point.test.ts +0 -36
  26. package/src/point.ts +0 -246
  27. package/src/prepare_pax.ts +0 -102
  28. package/src/segment.test.ts +0 -26
  29. package/src/segment.ts +0 -701
  30. package/src/sub_design.ts +0 -16
  31. package/src/triangle_utils.test.ts +0 -38
  32. package/src/triangle_utils.ts +0 -112
  33. package/src/vector.test.ts +0 -28
  34. package/src/vector.ts +0 -122
  35. package/src/volume.ts +0 -50
  36. package/src/write_dxf.ts +0 -100
  37. package/src/write_openjscad.ts +0 -284
  38. package/src/write_openscad.ts +0 -305
  39. package/src/write_pax.ts +0 -73
  40. package/src/write_svg.ts +0 -101
  41. package/svg/any_triangle.svg +0 -156
  42. package/svg/arc_definition.svg +0 -506
  43. package/svg/construct_corner_rounded_ext_arc_ext_arc.svg +0 -378
  44. package/svg/construct_corner_rounded_int_arc_ext_arc.svg +0 -359
  45. package/svg/construct_corner_rounded_int_arc_int_arc.svg +0 -356
  46. package/svg/construct_corner_rounded_stroke_ext_arc.svg +0 -374
  47. package/svg/construct_corner_rounded_stroke_ext_arc_obtuse.svg +0 -370
  48. package/svg/construct_corner_rounded_stroke_ext_arc_obtuse_method2.svg +0 -311
  49. package/svg/construct_corner_rounded_stroke_int_arc.svg +0 -364
  50. package/svg/construct_corner_rounded_stroke_int_arc_obtuse.svg +0 -358
  51. package/svg/construct_corner_rounded_stroke_int_arc_obtuse_method2.svg +0 -237
  52. package/svg/construct_corner_rounded_stroke_stroke.svg +0 -280
  53. package/svg/construct_corner_wideacc.svg +0 -286
  54. package/svg/construct_corner_widened.svg +0 -278
  55. package/svg/construction_of_line_intersection_1.svg +0 -187
  56. package/svg/construction_of_line_intersection_2.svg +0 -189
  57. package/svg/contour_arc_definition_options.svg +0 -324
  58. package/svg/contour_point_absolute_relative.svg +0 -258
  59. package/svg/contour_tangential_two_arcs.svg +0 -531
  60. package/svg/contour_tangential_two_arcs_impossible_case.svg +0 -175
  61. package/svg/contour_tangential_two_arcs_requirements.svg +0 -364
  62. package/svg/corner_rounded_ext_arc_ext_arc.svg +0 -281
  63. package/svg/corner_rounded_int_arc_ext_arc.svg +0 -281
  64. package/svg/corner_rounded_int_arc_int_arc.svg +0 -279
  65. package/svg/corner_rounded_stroke_ext_arc.svg +0 -218
  66. package/svg/corner_rounded_stroke_int_arc.svg +0 -225
  67. package/svg/corner_rounded_stroke_stroke.svg +0 -174
  68. package/svg/geom_dev.svg +0 -14708
  69. package/svg/geom_modules.svg +0 -246
  70. package/svg/geom_user.svg +0 -58
  71. package/svg/line_axis_x_cases.svg +0 -1408
  72. package/svg/line_axis_y_cases.svg +0 -1369
  73. package/svg/line_distanceOrig.svg +0 -318
  74. package/svg/line_getAxisXIntersection.svg +0 -262
  75. package/svg/line_getAxisXIntersection_2.svg +0 -244
  76. package/svg/line_getAxisYIntersection.svg +0 -304
  77. package/svg/line_getAxisYIntersection_2.svg +0 -285
  78. package/svg/line_getAxisYIntersection_3.svg +0 -277
  79. package/svg/line_intersection.svg +0 -346
  80. package/svg/line_projectPoint.svg +0 -311
  81. package/svg/point_1.svg +0 -243
  82. package/svg/point_2.svg +0 -409
  83. package/svg/point_3.svg +0 -298
  84. package/svg/point_4.svg +0 -272
  85. package/svg/point_5.svg +0 -356
  86. package/svg/right_triangle.svg +0 -194
  87. package/svg/vector_definition.svg +0 -130
  88. package/tsconfig.json +0 -13
  89. package/vitest.config.ts +0 -7
@@ -1,73 +0,0 @@
1
- // arc_to_stroke.ts
2
-
3
- import { orientedArc } from './angle_utils';
4
-
5
- type tAtsPoints = [number, number][];
6
-
7
- function calcAngleStep(
8
- max_angle: number,
9
- max_length: number,
10
- radius: number,
11
- arc_angle: number
12
- ): [number, number] {
13
- let max_angle2 = Math.PI / 2;
14
- if (max_length < 2 * radius) {
15
- max_angle2 = 2 * Math.asin(max_length / (2 * radius));
16
- }
17
- const angleStepMax = Math.min(max_angle, max_angle2);
18
- //const angleNb = Math.floor(arc_angle / angleStepMax) + 1;
19
- const angleNb = Math.ceil(arc_angle / angleStepMax);
20
- const angleStep = arc_angle / angleNb;
21
- //console.log(`dbg783: ${arc_angle} ${angleStepMax} ${angleNb}`);
22
- return [angleNb, angleStep];
23
- }
24
-
25
- function circle_to_stroke(
26
- cx: number,
27
- cy: number,
28
- radius: number,
29
- max_angle = Math.PI / 6,
30
- max_length = 2.0
31
- ): tAtsPoints {
32
- const [angleNb, angleStep] = calcAngleStep(max_angle, max_length, radius, 2 * Math.PI);
33
- const rPoints: tAtsPoints = [];
34
- for (let i = 0; i < angleNb; i++) {
35
- const px = cx + radius * Math.cos(i * angleStep);
36
- const py = cy + radius * Math.sin(i * angleStep);
37
- rPoints.push([px, py]);
38
- }
39
- // close the contour
40
- const p0x = rPoints[0][0];
41
- const p0y = rPoints[0][1];
42
- rPoints.push([p0x, p0y]);
43
- return rPoints;
44
- }
45
-
46
- function arc_to_stroke(
47
- cx: number,
48
- cy: number,
49
- radius: number,
50
- a1: number,
51
- a2: number,
52
- ccw: boolean,
53
- max_angle = Math.PI / 6,
54
- max_length = 2.0
55
- ): tAtsPoints {
56
- const arc_angle = orientedArc(a1, a2, ccw);
57
- const [angleNb, angleStep] = calcAngleStep(max_angle, max_length, radius, Math.abs(arc_angle));
58
- //console.log(`dbg054: ${angleNb} ${angleStep}`);
59
- const angleStepSigned = ccw ? angleStep : -angleStep;
60
- const angleNb2 = angleNb + 1; // pole and fence
61
- const rPoints: tAtsPoints = [];
62
- // skip first point
63
- for (let i = 1; i < angleNb2; i++) {
64
- const angle = a1 + i * angleStepSigned;
65
- const px = cx + radius * Math.cos(angle);
66
- const py = cy + radius * Math.sin(angle);
67
- rPoints.push([px, py]);
68
- }
69
- return rPoints;
70
- }
71
-
72
- export type { tAtsPoints };
73
- export { circle_to_stroke, arc_to_stroke };
@@ -1,28 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- //import type { tCanvasAdjust };
3
- import {
4
- colors,
5
- point2canvas,
6
- canvas2point,
7
- //adjustZero,
8
- adjustInit
9
- //adjustCenter,
10
- //adjustRect,
11
- //adjustScale,
12
- //adjustTranslate
13
- } from './canvas_utils';
14
-
15
- const cAdjust = adjustInit(0, 200, 0, 200, 200, 200);
16
-
17
- describe('canvas_utils', () => {
18
- it('colors object', () => {
19
- expect(colors).toHaveProperty('point');
20
- expect(colors).not.toHaveProperty('blabla');
21
- });
22
- it('point2canvas function', () => {
23
- expect(point2canvas(10, 20, cAdjust)).toEqual([19, 172]);
24
- });
25
- it('canvas2point function', () => {
26
- expect(canvas2point(19, 172, cAdjust)).toEqual([10, 20]);
27
- });
28
- });
@@ -1,159 +0,0 @@
1
- // canvas_utils.ts
2
- // helper interfaces and functions to work with HtmlCanvas
3
- // used by point.ts, line.ts, vector.ts, contour.ts and figure.ts
4
-
5
- import { roundZero } from './angle_utils';
6
-
7
- const colors = {
8
- point: 'grey',
9
- line: 'grey',
10
- vector: 'DarkTurquoise',
11
- contour: 'green',
12
- main: 'SteelBlue',
13
- mainB: 'SlateGrey',
14
- second: 'Violet',
15
- secondB: 'SlateGrey',
16
- dynamics: 'Tomato',
17
- ruler: 'blue',
18
- origin: 'red',
19
- reference: 'blue',
20
- mouse: 'yellow'
21
- };
22
-
23
- interface tCanvasAdjust {
24
- init: number;
25
- xMin: number;
26
- yMin: number;
27
- xyDiff: number;
28
- shiftX: number;
29
- shiftY: number;
30
- scaleX: number;
31
- scaleY: number;
32
- }
33
-
34
- function point2canvas(px: number, py: number, iAdjust: tCanvasAdjust): [number, number] {
35
- const cx2 = iAdjust.shiftX + (px - iAdjust.xMin) * iAdjust.scaleX;
36
- const cy2 = iAdjust.shiftY + (py - iAdjust.yMin) * iAdjust.scaleY;
37
- return [cx2, cy2];
38
- }
39
- function canvas2point(cx: number, cy: number, iAdjust: tCanvasAdjust): [number, number] {
40
- const px2 = (cx - iAdjust.shiftX) / iAdjust.scaleX + iAdjust.xMin;
41
- const py2 = (cy - iAdjust.shiftY) / iAdjust.scaleY + iAdjust.yMin;
42
- return [px2, py2];
43
- }
44
- function canvasTranslatePolar(cx: number, cy: number, ia: number, il: number): [number, number] {
45
- const cx2 = cx + il * Math.cos(ia);
46
- const cy2 = cy - il * Math.sin(ia);
47
- return [cx2, cy2];
48
- }
49
- function radius2canvas(iRadius: number, iAdjust: tCanvasAdjust): number {
50
- if (roundZero(iAdjust.scaleX - Math.abs(iAdjust.scaleY)) !== 0) {
51
- throw `err683: iAdjust.scaleX and scaleY differ ${iAdjust.scaleX} ${iAdjust.scaleY}`;
52
- }
53
- const rRadius = iRadius * iAdjust.scaleX;
54
- return rRadius;
55
- }
56
-
57
- function adjustZero(): tCanvasAdjust {
58
- const rAdjustZero = {
59
- init: 0,
60
- xMin: 0,
61
- yMin: 0,
62
- xyDiff: 1,
63
- shiftX: 0,
64
- shiftY: 0,
65
- scaleX: 1,
66
- scaleY: 1
67
- };
68
- return rAdjustZero;
69
- }
70
- function adjustInit(
71
- xMin: number,
72
- xMax: number,
73
- yMin: number,
74
- yMax: number,
75
- cWidth: number,
76
- cHeight: number
77
- ): tCanvasAdjust {
78
- const rAdjust: tCanvasAdjust = adjustZero();
79
- const xDiff = Math.max(xMax - xMin, 1);
80
- const yDiff = Math.max(yMax - yMin, 1);
81
- const xScale = cWidth / xDiff;
82
- const yScale = cHeight / yDiff;
83
- let xyScale = 0.9 * xScale;
84
- let xyDiff = xDiff;
85
- if (yScale < xScale) {
86
- xyScale = 0.9 * yScale;
87
- xyDiff = yDiff;
88
- }
89
- rAdjust.init = 1;
90
- rAdjust.xMin = xMin;
91
- rAdjust.yMin = yMin;
92
- rAdjust.xyDiff = xyDiff;
93
- rAdjust.shiftX = 0.05 * cWidth;
94
- rAdjust.scaleX = xyScale;
95
- rAdjust.shiftY = cHeight - 0.05 * cHeight;
96
- rAdjust.scaleY = -1 * xyScale;
97
- return rAdjust;
98
- }
99
- function adjustCenter(px: number, py: number, iAdjust: tCanvasAdjust): tCanvasAdjust {
100
- const rAdjust: tCanvasAdjust = structuredClone(iAdjust);
101
- rAdjust.xMin = px - rAdjust.xyDiff / 2;
102
- rAdjust.yMin = py - rAdjust.xyDiff / 2;
103
- return rAdjust;
104
- }
105
- function adjustRect(
106
- p1x: number,
107
- p1y: number,
108
- p2x: number,
109
- p2y: number,
110
- cWidth: number,
111
- cHeight: number
112
- ): tCanvasAdjust {
113
- const xMin = Math.min(p1x, p2x);
114
- const xMax = Math.max(p1x, p2x);
115
- const yMin = Math.min(p1y, p2y);
116
- const yMax = Math.max(p1y, p2y);
117
- const rAdjust = adjustInit(xMin, xMax, yMin, yMax, cWidth, cHeight);
118
- return rAdjust;
119
- }
120
- function adjustScale(iFactor: number, iAdjust: tCanvasAdjust): tCanvasAdjust {
121
- const rAdjust: tCanvasAdjust = structuredClone(iAdjust);
122
- const shift = (1 - iFactor) / 2;
123
- rAdjust.xMin += shift * iAdjust.xyDiff;
124
- rAdjust.yMin += shift * iAdjust.xyDiff;
125
- rAdjust.xyDiff *= iFactor;
126
- rAdjust.scaleX *= 1.0 / iFactor;
127
- rAdjust.scaleY *= 1.0 / iFactor;
128
- return rAdjust;
129
- }
130
- function adjustTranslate(
131
- p1x: number,
132
- p1y: number,
133
- p2x: number,
134
- p2y: number,
135
- iAdjust: tCanvasAdjust
136
- ): tCanvasAdjust {
137
- const rAdjust: tCanvasAdjust = structuredClone(iAdjust);
138
- const xDiff = p2x - p1x;
139
- const yDiff = p2y - p1y;
140
- //console.log(`dbg118: ${xDiff} ${yDiff}`);
141
- rAdjust.xMin += -xDiff;
142
- rAdjust.yMin += -yDiff;
143
- return rAdjust;
144
- }
145
-
146
- export type { tCanvasAdjust };
147
- export {
148
- colors,
149
- point2canvas,
150
- canvas2point,
151
- canvasTranslatePolar,
152
- radius2canvas,
153
- adjustZero,
154
- adjustInit,
155
- adjustCenter,
156
- adjustRect,
157
- adjustScale,
158
- adjustTranslate
159
- };
@@ -1,37 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { point } from './point';
3
- import { contour, contourCircle } from './contour';
4
-
5
- describe('Contour suit', () => {
6
- const ctr1 = contour(10, 10);
7
- ctr1.addPointA(20, 20).addSegStroke();
8
- ctr1.addPointA(20, 0).addSegStroke();
9
- ctr1.closeSegStroke();
10
- it('extractPoints', () => {
11
- expect(ctr1.generatePoints()[0].isEqual(point(10, 10))).toBeTruthy();
12
- });
13
- it('generateContour', () => {
14
- const ctr2 = ctr1.generateContour();
15
- expect(ctr2.generatePoints()[0].isEqual(point(10, 10))).toBeTruthy();
16
- });
17
- });
18
-
19
- describe('Contour suit 2', () => {
20
- const ctr1 = contour(10, 10);
21
- ctr1.addSegStrokeR(30, 30);
22
- ctr1.addCornerPointed();
23
- ctr1.addCornerPointed();
24
- ctr1.addSegStrokeR(30, -30);
25
- ctr1.closeSegStroke();
26
- it('generateContour', () => {
27
- expect(() => ctr1.generateContour()).toThrowError(/err419/);
28
- });
29
- });
30
-
31
- describe('ContourCircle suit', () => {
32
- const ctr3 = contourCircle(50, 50, 20);
33
- it('extractPoints', () => {
34
- expect(ctr3.generatePoints()[0].isEqual(point(50, 50))).toBeTruthy();
35
- expect(ctr3.generatePoints()[1].isEqual(point(70, 50))).toBeTruthy();
36
- });
37
- });