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.
- package/dist/index.d.ts +505 -0
- package/dist/index.js +3848 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -1
- package/.eslintignore +0 -17
- package/.eslintrc.cjs +0 -24
- package/.prettierignore +0 -15
- package/.prettierrc +0 -8
- package/src/aaExportContent.ts +0 -213
- package/src/aaExportFile.ts +0 -141
- package/src/aaParamGeom.ts +0 -62
- package/src/angle_utils.test.ts +0 -83
- package/src/angle_utils.ts +0 -98
- package/src/arc_to_stroke.ts +0 -73
- package/src/canvas_utils.test.ts +0 -28
- package/src/canvas_utils.ts +0 -159
- package/src/contour.test.ts +0 -37
- package/src/contour.ts +0 -806
- package/src/designParams.ts +0 -178
- package/src/figure.test.ts +0 -21
- package/src/figure.ts +0 -400
- package/src/index.ts +0 -16
- package/src/line.test.ts +0 -78
- package/src/line.ts +0 -359
- package/src/paramFile.ts +0 -52
- package/src/point.test.ts +0 -36
- package/src/point.ts +0 -246
- package/src/prepare_pax.ts +0 -102
- package/src/segment.test.ts +0 -26
- package/src/segment.ts +0 -701
- package/src/sub_design.ts +0 -16
- package/src/triangle_utils.test.ts +0 -38
- package/src/triangle_utils.ts +0 -112
- package/src/vector.test.ts +0 -28
- package/src/vector.ts +0 -122
- package/src/volume.ts +0 -50
- package/src/write_dxf.ts +0 -100
- package/src/write_openjscad.ts +0 -284
- package/src/write_openscad.ts +0 -305
- package/src/write_pax.ts +0 -73
- package/src/write_svg.ts +0 -101
- package/svg/any_triangle.svg +0 -156
- package/svg/arc_definition.svg +0 -506
- package/svg/construct_corner_rounded_ext_arc_ext_arc.svg +0 -378
- package/svg/construct_corner_rounded_int_arc_ext_arc.svg +0 -359
- package/svg/construct_corner_rounded_int_arc_int_arc.svg +0 -356
- package/svg/construct_corner_rounded_stroke_ext_arc.svg +0 -374
- package/svg/construct_corner_rounded_stroke_ext_arc_obtuse.svg +0 -370
- package/svg/construct_corner_rounded_stroke_ext_arc_obtuse_method2.svg +0 -311
- package/svg/construct_corner_rounded_stroke_int_arc.svg +0 -364
- package/svg/construct_corner_rounded_stroke_int_arc_obtuse.svg +0 -358
- package/svg/construct_corner_rounded_stroke_int_arc_obtuse_method2.svg +0 -237
- package/svg/construct_corner_rounded_stroke_stroke.svg +0 -280
- package/svg/construct_corner_wideacc.svg +0 -286
- package/svg/construct_corner_widened.svg +0 -278
- package/svg/construction_of_line_intersection_1.svg +0 -187
- package/svg/construction_of_line_intersection_2.svg +0 -189
- package/svg/contour_arc_definition_options.svg +0 -324
- package/svg/contour_point_absolute_relative.svg +0 -258
- package/svg/contour_tangential_two_arcs.svg +0 -531
- package/svg/contour_tangential_two_arcs_impossible_case.svg +0 -175
- package/svg/contour_tangential_two_arcs_requirements.svg +0 -364
- package/svg/corner_rounded_ext_arc_ext_arc.svg +0 -281
- package/svg/corner_rounded_int_arc_ext_arc.svg +0 -281
- package/svg/corner_rounded_int_arc_int_arc.svg +0 -279
- package/svg/corner_rounded_stroke_ext_arc.svg +0 -218
- package/svg/corner_rounded_stroke_int_arc.svg +0 -225
- package/svg/corner_rounded_stroke_stroke.svg +0 -174
- package/svg/geom_dev.svg +0 -14708
- package/svg/geom_modules.svg +0 -246
- package/svg/geom_user.svg +0 -58
- package/svg/line_axis_x_cases.svg +0 -1408
- package/svg/line_axis_y_cases.svg +0 -1369
- package/svg/line_distanceOrig.svg +0 -318
- package/svg/line_getAxisXIntersection.svg +0 -262
- package/svg/line_getAxisXIntersection_2.svg +0 -244
- package/svg/line_getAxisYIntersection.svg +0 -304
- package/svg/line_getAxisYIntersection_2.svg +0 -285
- package/svg/line_getAxisYIntersection_3.svg +0 -277
- package/svg/line_intersection.svg +0 -346
- package/svg/line_projectPoint.svg +0 -311
- package/svg/point_1.svg +0 -243
- package/svg/point_2.svg +0 -409
- package/svg/point_3.svg +0 -298
- package/svg/point_4.svg +0 -272
- package/svg/point_5.svg +0 -356
- package/svg/right_triangle.svg +0 -194
- package/svg/vector_definition.svg +0 -130
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -7
package/src/write_openjscad.ts
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
// write_openjscad.ts
|
|
2
|
-
|
|
3
|
-
import * as segLib from './segment';
|
|
4
|
-
import type {
|
|
5
|
-
tPaxContour,
|
|
6
|
-
tPaxContourCircle,
|
|
7
|
-
tPaxContourPath,
|
|
8
|
-
tPaxSeg,
|
|
9
|
-
tPaxSegArc
|
|
10
|
-
} from './prepare_pax';
|
|
11
|
-
import { PSeg } from './prepare_pax';
|
|
12
|
-
import type { tPaxFaces, tPaxJson } from './write_pax';
|
|
13
|
-
import { convTypePaxToSeg1, paxWrite } from './write_pax';
|
|
14
|
-
import type { tVolume, tInherit, tExtrude, tBVolume } from './volume';
|
|
15
|
-
import { EExtrude, EBVolume } from './volume';
|
|
16
|
-
import type { tGeom } from './aaParamGeom';
|
|
17
|
-
//import { withinZero2Pi } from './angle_utils';
|
|
18
|
-
import type { tAtsPoints } from './arc_to_stroke';
|
|
19
|
-
import { circle_to_stroke, arc_to_stroke } from './arc_to_stroke';
|
|
20
|
-
|
|
21
|
-
type tOpenjscadSeg = tAtsPoints;
|
|
22
|
-
|
|
23
|
-
const approxMaxAngle = Math.PI / 8;
|
|
24
|
-
const approxMaxLength = 20.0;
|
|
25
|
-
|
|
26
|
-
function ojscadSegLine(p2x: number, p2y: number): tOpenjscadSeg {
|
|
27
|
-
const rSeg: tOpenjscadSeg = [[p2x, p2y]];
|
|
28
|
-
return rSeg;
|
|
29
|
-
}
|
|
30
|
-
function ojscadSegArc(
|
|
31
|
-
cx: number,
|
|
32
|
-
cy: number,
|
|
33
|
-
radius: number,
|
|
34
|
-
aa1: number,
|
|
35
|
-
aa2: number,
|
|
36
|
-
arcCcw: boolean
|
|
37
|
-
): tOpenjscadSeg {
|
|
38
|
-
const rSeg = arc_to_stroke(cx, cy, radius, aa1, aa2, arcCcw, approxMaxAngle, approxMaxLength);
|
|
39
|
-
return rSeg;
|
|
40
|
-
}
|
|
41
|
-
function toOpenjscadSeg(paxCtr: tPaxSeg[]): tOpenjscadSeg {
|
|
42
|
-
const rOjscadSeg: tOpenjscadSeg = [];
|
|
43
|
-
let px1 = 0;
|
|
44
|
-
let py1 = 0;
|
|
45
|
-
for (const seg of paxCtr) {
|
|
46
|
-
if (seg.typ === PSeg.eStart) {
|
|
47
|
-
rOjscadSeg.push(...ojscadSegLine(seg.px, seg.py));
|
|
48
|
-
} else if (seg.typ === PSeg.eStroke) {
|
|
49
|
-
rOjscadSeg.push(...ojscadSegLine(seg.px, seg.py));
|
|
50
|
-
} else if (seg.typ === PSeg.eArc) {
|
|
51
|
-
try {
|
|
52
|
-
const sega = seg as tPaxSegArc;
|
|
53
|
-
const seg1 = new segLib.Segment1(
|
|
54
|
-
convTypePaxToSeg1(sega.typ),
|
|
55
|
-
sega.px,
|
|
56
|
-
sega.py,
|
|
57
|
-
sega.radius,
|
|
58
|
-
sega.large,
|
|
59
|
-
sega.ccw
|
|
60
|
-
);
|
|
61
|
-
const seg2 = segLib.arcSeg1To2(px1, py1, seg1);
|
|
62
|
-
rOjscadSeg.push(
|
|
63
|
-
...ojscadSegArc(
|
|
64
|
-
seg2.pc.cx,
|
|
65
|
-
seg2.pc.cy,
|
|
66
|
-
seg1.radius,
|
|
67
|
-
seg2.a1,
|
|
68
|
-
seg2.a2,
|
|
69
|
-
seg2.arcCcw
|
|
70
|
-
)
|
|
71
|
-
);
|
|
72
|
-
} catch (emsg) {
|
|
73
|
-
console.log('err730: ' + (emsg as string));
|
|
74
|
-
}
|
|
75
|
-
//} else {
|
|
76
|
-
// console.log(
|
|
77
|
-
// `err778: write_openjscad toOpenjscadSeg has unknown segment type ${seg.typ}`
|
|
78
|
-
// );
|
|
79
|
-
}
|
|
80
|
-
// all segements of Pax must update the last point
|
|
81
|
-
px1 = seg.px;
|
|
82
|
-
py1 = seg.py;
|
|
83
|
-
}
|
|
84
|
-
return rOjscadSeg;
|
|
85
|
-
}
|
|
86
|
-
function ojscadSegCircle(cx: number, cy: number, radius: number): tOpenjscadSeg {
|
|
87
|
-
const rSeg = circle_to_stroke(cx, cy, radius, approxMaxAngle, approxMaxLength);
|
|
88
|
-
return rSeg;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// floating precision for OpenScad export
|
|
92
|
-
function ff(ifloat: number): string {
|
|
93
|
-
return ifloat.toFixed(4);
|
|
94
|
-
}
|
|
95
|
-
class OjscadWriteFigure {
|
|
96
|
-
pts: string[];
|
|
97
|
-
constructor() {
|
|
98
|
-
this.pts = [];
|
|
99
|
-
}
|
|
100
|
-
addContour(ictr: tOpenjscadSeg) {
|
|
101
|
-
const pts2: string[] = [];
|
|
102
|
-
for (const pt of ictr) {
|
|
103
|
-
const [px, py] = pt;
|
|
104
|
-
pts2.push(`[ ${ff(px)}, ${ff(py)} ]`);
|
|
105
|
-
}
|
|
106
|
-
const ptStr = `[ ${pts2.join(',')} ]`;
|
|
107
|
-
this.pts.push(ptStr);
|
|
108
|
-
}
|
|
109
|
-
getFigure(faceId: string): string {
|
|
110
|
-
let rStr = '';
|
|
111
|
-
const aList: string[] = [];
|
|
112
|
-
for (const idx of this.pts.keys()) {
|
|
113
|
-
const aId = `ctr_${faceId}_${idx}`;
|
|
114
|
-
rStr += `const ${aId} = polygon({ points: ${this.pts[idx]} });\n`;
|
|
115
|
-
aList.push(aId);
|
|
116
|
-
}
|
|
117
|
-
if (aList.length === 1) {
|
|
118
|
-
rStr += `const face_${faceId} = ${aList[0]};\n`;
|
|
119
|
-
} else if (aList.length > 1) {
|
|
120
|
-
const ctrList = aList.join(', ');
|
|
121
|
-
rStr += `const face_${faceId} = subtract( ${ctrList} )\n`;
|
|
122
|
-
}
|
|
123
|
-
return rStr;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
class OpenjscadWrite {
|
|
128
|
-
//constructor() {}
|
|
129
|
-
getHeader(): string {
|
|
130
|
-
const rStr = `// Generated by Parametrix
|
|
131
|
-
const { polygon } = require('@jscad/modeling').primitives
|
|
132
|
-
//const { subtract } = require('@jscad/modeling').booleans;
|
|
133
|
-
const { union, intersect, scission, subtract } = require('@jscad/modeling').booleans
|
|
134
|
-
const { extrudeLinear, extrudeRotate } = require('@jscad/modeling').extrusions;
|
|
135
|
-
const { translate, rotate } = require('@jscad/modeling').transforms
|
|
136
|
-
const main = () => {
|
|
137
|
-
`;
|
|
138
|
-
return rStr;
|
|
139
|
-
}
|
|
140
|
-
getOneFigure(aCtr: tPaxContour[], faceId: string): string {
|
|
141
|
-
const ojscadWF = new OjscadWriteFigure();
|
|
142
|
-
for (const paxCtr of aCtr) {
|
|
143
|
-
if (paxCtr.circle === true) {
|
|
144
|
-
const paxCircle = paxCtr as tPaxContourCircle;
|
|
145
|
-
const ojscadSeg = ojscadSegCircle(paxCircle.cx, paxCircle.cy, paxCircle.radius);
|
|
146
|
-
ojscadWF.addContour(ojscadSeg);
|
|
147
|
-
} else {
|
|
148
|
-
const paxPath = paxCtr as tPaxContourPath;
|
|
149
|
-
const ojscadSeg = toOpenjscadSeg(paxPath.seg);
|
|
150
|
-
ojscadWF.addContour(ojscadSeg);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const rOjscadF = ojscadWF.getFigure(faceId);
|
|
154
|
-
return rOjscadF;
|
|
155
|
-
}
|
|
156
|
-
getAllFigures(faces: tPaxFaces, partName: string): string {
|
|
157
|
-
let rStr = '';
|
|
158
|
-
for (const face in faces) {
|
|
159
|
-
const figu = this.getOneFigure(faces[face], `${partName}_${face}`);
|
|
160
|
-
rStr += figu;
|
|
161
|
-
}
|
|
162
|
-
return rStr;
|
|
163
|
-
}
|
|
164
|
-
getOneExtrude(extrud: tExtrude): string {
|
|
165
|
-
let extrudMethod = 'extrudeRotate';
|
|
166
|
-
let extrudOption = '{segments: 32}';
|
|
167
|
-
if (extrud.extrudeMethod === EExtrude.eLinearOrtho) {
|
|
168
|
-
if (extrud.length === undefined) {
|
|
169
|
-
console.log('err079: design error: extrudeLinear length undefined!');
|
|
170
|
-
}
|
|
171
|
-
extrudMethod = 'extrudeLinear';
|
|
172
|
-
extrudOption = `{height: ${extrud.length}}`;
|
|
173
|
-
}
|
|
174
|
-
const rStr = `
|
|
175
|
-
const ${extrud.outName} =
|
|
176
|
-
translate( [ ${extrud.translate[0]}, ${extrud.translate[1]}, ${extrud.translate[2]}, ],
|
|
177
|
-
rotate( [ ${extrud.rotate[0]}, ${extrud.rotate[1]}, ${extrud.rotate[2]}, ],
|
|
178
|
-
${extrudMethod}( ${extrudOption}, face_${extrud.face} )
|
|
179
|
-
)
|
|
180
|
-
);
|
|
181
|
-
`;
|
|
182
|
-
return rStr;
|
|
183
|
-
}
|
|
184
|
-
getAllExtrudes(extrudes: tExtrude[]): string {
|
|
185
|
-
let rStr = '';
|
|
186
|
-
for (const extrud of extrudes) {
|
|
187
|
-
const subp = this.getOneExtrude(extrud);
|
|
188
|
-
rStr += subp;
|
|
189
|
-
}
|
|
190
|
-
return rStr;
|
|
191
|
-
}
|
|
192
|
-
getOneVolume(volum: tBVolume): string {
|
|
193
|
-
let vMethod = 'identity';
|
|
194
|
-
switch (volum.boolMethod) {
|
|
195
|
-
case EBVolume.eIntersection:
|
|
196
|
-
vMethod = 'intersect';
|
|
197
|
-
break;
|
|
198
|
-
case EBVolume.eUnion:
|
|
199
|
-
vMethod = 'union';
|
|
200
|
-
break;
|
|
201
|
-
case EBVolume.eSubstraction:
|
|
202
|
-
vMethod = 'subtract';
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
const inList2 = volum.inList.join(', ');
|
|
206
|
-
let rStr = `const ${volum.outName} = ${vMethod}( ${inList2} );\n`;
|
|
207
|
-
if (volum.boolMethod === EBVolume.eIdentity) {
|
|
208
|
-
rStr = `const ${volum.outName} = ${volum.inList[0]};\n`;
|
|
209
|
-
}
|
|
210
|
-
return rStr;
|
|
211
|
-
}
|
|
212
|
-
getAllVolumes(volumes: tBVolume[]): string {
|
|
213
|
-
let rStr = '';
|
|
214
|
-
for (const volum of volumes) {
|
|
215
|
-
const subp = this.getOneVolume(volum);
|
|
216
|
-
rStr += subp;
|
|
217
|
-
}
|
|
218
|
-
return rStr;
|
|
219
|
-
}
|
|
220
|
-
getAllSubGeoms(inherits: tInherit[]): tGeom[] {
|
|
221
|
-
const rGeoms: tGeom[] = [];
|
|
222
|
-
for (const inher of inherits) {
|
|
223
|
-
if (!rGeoms.includes(inher.subgeom)) {
|
|
224
|
-
rGeoms.push(inher.subgeom);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return rGeoms;
|
|
228
|
-
}
|
|
229
|
-
getOneInherit(inherit: tInherit): string {
|
|
230
|
-
const rStr = `
|
|
231
|
-
const ${inherit.outName} =
|
|
232
|
-
translate( [ ${inherit.translate[0]}, ${inherit.translate[1]}, ${inherit.translate[2]}, ],
|
|
233
|
-
rotate( [ ${inherit.rotate[0]}, ${inherit.rotate[1]}, ${inherit.rotate[2]}, ],
|
|
234
|
-
${inherit.subdesign}
|
|
235
|
-
)
|
|
236
|
-
);
|
|
237
|
-
`;
|
|
238
|
-
return rStr;
|
|
239
|
-
}
|
|
240
|
-
getAllInherits(inherits: tInherit[]): string {
|
|
241
|
-
let rStr = '';
|
|
242
|
-
for (const inher of inherits) {
|
|
243
|
-
const subinhe = this.getOneInherit(inher);
|
|
244
|
-
rStr += subinhe;
|
|
245
|
-
}
|
|
246
|
-
return rStr;
|
|
247
|
-
}
|
|
248
|
-
getVolume(vol: tVolume): string {
|
|
249
|
-
let rStr = '';
|
|
250
|
-
if (vol.inherits !== undefined) {
|
|
251
|
-
const subGeoms = this.getAllSubGeoms(vol.inherits);
|
|
252
|
-
for (const oneGeom of subGeoms) {
|
|
253
|
-
const paxJson = paxWrite().getPaxJson({}, oneGeom);
|
|
254
|
-
rStr += this.getAllFigures(paxJson.faces, paxJson.partName);
|
|
255
|
-
rStr += this.getVolume(oneGeom.vol);
|
|
256
|
-
}
|
|
257
|
-
rStr += this.getAllInherits(vol.inherits);
|
|
258
|
-
}
|
|
259
|
-
rStr += this.getAllExtrudes(vol.extrudes);
|
|
260
|
-
rStr += this.getAllVolumes(vol.volumes);
|
|
261
|
-
return rStr;
|
|
262
|
-
}
|
|
263
|
-
getFooter(partName: string): string {
|
|
264
|
-
const rStr = `
|
|
265
|
-
return pax_${partName};
|
|
266
|
-
}
|
|
267
|
-
module.exports = { main };
|
|
268
|
-
`;
|
|
269
|
-
return rStr;
|
|
270
|
-
}
|
|
271
|
-
getExportFile(pax: tPaxJson) {
|
|
272
|
-
let rStr = this.getHeader();
|
|
273
|
-
rStr += this.getAllFigures(pax.faces, pax.partName);
|
|
274
|
-
rStr += this.getVolume(pax.volume);
|
|
275
|
-
rStr += this.getFooter(pax.partName);
|
|
276
|
-
return rStr;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
function ojscadWrite() {
|
|
280
|
-
const rOjscadWrite = new OpenjscadWrite();
|
|
281
|
-
return rOjscadWrite;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export { ojscadWrite };
|
package/src/write_openscad.ts
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
// write_openscad.ts
|
|
2
|
-
|
|
3
|
-
//import type { tContour } from './contour';
|
|
4
|
-
//import type { tFaces } from './figure';
|
|
5
|
-
import * as segLib from './segment';
|
|
6
|
-
import type {
|
|
7
|
-
tPaxContour,
|
|
8
|
-
tPaxContourCircle,
|
|
9
|
-
tPaxContourPath,
|
|
10
|
-
tPaxSeg,
|
|
11
|
-
tPaxSegArc
|
|
12
|
-
} from './prepare_pax';
|
|
13
|
-
import { PSeg } from './prepare_pax';
|
|
14
|
-
import type { tPaxFaces, tPaxJson } from './write_pax';
|
|
15
|
-
import { convTypePaxToSeg1, paxWrite } from './write_pax';
|
|
16
|
-
import type { tGeom } from './aaParamGeom';
|
|
17
|
-
import type { tVolume, tInherit, tExtrude, tBVolume } from './volume';
|
|
18
|
-
import { EExtrude, EBVolume } from './volume';
|
|
19
|
-
//import { withinZero2Pi, radToDeg } from './angle_utils';
|
|
20
|
-
import { radToDeg } from './angle_utils';
|
|
21
|
-
import type { tAtsPoints } from './arc_to_stroke';
|
|
22
|
-
import { circle_to_stroke, arc_to_stroke } from './arc_to_stroke';
|
|
23
|
-
|
|
24
|
-
type tOpenscadSeg = tAtsPoints;
|
|
25
|
-
|
|
26
|
-
const approxMaxAngle = Math.PI / 8;
|
|
27
|
-
const approxMaxLength = 20.0;
|
|
28
|
-
|
|
29
|
-
function oscadSegLine(p2x: number, p2y: number): tOpenscadSeg {
|
|
30
|
-
const rSeg: tOpenscadSeg = [[p2x, p2y]];
|
|
31
|
-
return rSeg;
|
|
32
|
-
}
|
|
33
|
-
function oscadSegArc(
|
|
34
|
-
cx: number,
|
|
35
|
-
cy: number,
|
|
36
|
-
radius: number,
|
|
37
|
-
aa1: number,
|
|
38
|
-
aa2: number,
|
|
39
|
-
arcCcw: boolean
|
|
40
|
-
): tOpenscadSeg {
|
|
41
|
-
const rSeg = arc_to_stroke(cx, cy, radius, aa1, aa2, arcCcw, approxMaxAngle, approxMaxLength);
|
|
42
|
-
return rSeg;
|
|
43
|
-
}
|
|
44
|
-
function oscadSegCircle(cx: number, cy: number, radius: number): tOpenscadSeg {
|
|
45
|
-
const rSeg = circle_to_stroke(cx, cy, radius, approxMaxAngle, approxMaxLength);
|
|
46
|
-
return rSeg;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function toOpenscadSeg(paxCtr: tPaxSeg[]): tOpenscadSeg {
|
|
50
|
-
const rOscadSeg: tOpenscadSeg = [];
|
|
51
|
-
let px1 = 0;
|
|
52
|
-
let py1 = 0;
|
|
53
|
-
for (const seg of paxCtr) {
|
|
54
|
-
if (seg.typ === PSeg.eStart) {
|
|
55
|
-
rOscadSeg.push(...oscadSegLine(seg.px, seg.py));
|
|
56
|
-
} else if (seg.typ === PSeg.eStroke) {
|
|
57
|
-
rOscadSeg.push(...oscadSegLine(seg.px, seg.py));
|
|
58
|
-
} else if (seg.typ === PSeg.eArc) {
|
|
59
|
-
try {
|
|
60
|
-
const sega = seg as tPaxSegArc;
|
|
61
|
-
const seg1 = new segLib.Segment1(
|
|
62
|
-
convTypePaxToSeg1(sega.typ),
|
|
63
|
-
sega.px,
|
|
64
|
-
sega.py,
|
|
65
|
-
sega.radius,
|
|
66
|
-
sega.large,
|
|
67
|
-
sega.ccw
|
|
68
|
-
);
|
|
69
|
-
const seg2 = segLib.arcSeg1To2(px1, py1, seg1);
|
|
70
|
-
rOscadSeg.push(
|
|
71
|
-
...oscadSegArc(
|
|
72
|
-
seg2.pc.cx,
|
|
73
|
-
seg2.pc.cy,
|
|
74
|
-
seg1.radius,
|
|
75
|
-
seg2.a1,
|
|
76
|
-
seg2.a2,
|
|
77
|
-
seg2.arcCcw
|
|
78
|
-
)
|
|
79
|
-
);
|
|
80
|
-
} catch (emsg) {
|
|
81
|
-
console.log('err730: ' + (emsg as string));
|
|
82
|
-
}
|
|
83
|
-
//} else {
|
|
84
|
-
// console.log(`err725: write_openscad toOpenscadSeg has unknown segment type ${seg.typ}`);
|
|
85
|
-
}
|
|
86
|
-
// all segements of Pax must update the last point
|
|
87
|
-
px1 = seg.px;
|
|
88
|
-
py1 = seg.py;
|
|
89
|
-
}
|
|
90
|
-
return rOscadSeg;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// floating precision for OpenScad export
|
|
94
|
-
function ff(ifloat: number): string {
|
|
95
|
-
return ifloat.toFixed(4);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
class OpenscadWriteFigure {
|
|
99
|
-
pts: string[];
|
|
100
|
-
ptIdx: string[];
|
|
101
|
-
idx: number;
|
|
102
|
-
constructor() {
|
|
103
|
-
this.pts = [];
|
|
104
|
-
this.ptIdx = [];
|
|
105
|
-
this.idx = 0;
|
|
106
|
-
}
|
|
107
|
-
addContour(ictr: tOpenscadSeg) {
|
|
108
|
-
const pts2: string[] = [];
|
|
109
|
-
const ptIdx2: string[] = [];
|
|
110
|
-
for (const pt of ictr) {
|
|
111
|
-
const [px, py] = pt;
|
|
112
|
-
pts2.push(`[ ${ff(px)}, ${ff(py)} ]`);
|
|
113
|
-
ptIdx2.push(` ${this.idx}`);
|
|
114
|
-
this.idx += 1;
|
|
115
|
-
}
|
|
116
|
-
const ptStr = `[ ${pts2.join(',')} ]`;
|
|
117
|
-
const ptIdxStr = `[ ${ptIdx2.join(',')} ]`;
|
|
118
|
-
this.pts.push(ptStr);
|
|
119
|
-
this.ptIdx.push(ptIdxStr);
|
|
120
|
-
}
|
|
121
|
-
getFigure(faceId: string): string {
|
|
122
|
-
let rStr = '';
|
|
123
|
-
const aList: string[] = [];
|
|
124
|
-
const bList: string[] = [];
|
|
125
|
-
for (const idx of this.pts.keys()) {
|
|
126
|
-
const aId = `ca_${faceId}_${idx}`;
|
|
127
|
-
const bId = `cb_${faceId}_${idx}`;
|
|
128
|
-
rStr += `${aId} = ${this.pts[idx]};\n`;
|
|
129
|
-
rStr += `${bId} = ${this.ptIdx[idx]};\n`;
|
|
130
|
-
aList.push(aId);
|
|
131
|
-
bList.push(bId);
|
|
132
|
-
}
|
|
133
|
-
const aListStr = aList.join(', ');
|
|
134
|
-
const bListStr = bList.join(', ');
|
|
135
|
-
rStr += `a_${faceId} = concat(${aListStr});\n`;
|
|
136
|
-
rStr += `b_${faceId} = [${bListStr}];\n`;
|
|
137
|
-
return rStr;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
class OpenscadWrite {
|
|
142
|
-
//constructor() {}
|
|
143
|
-
getHeader(): string {
|
|
144
|
-
const rStr = '// Generated by Parametrix\n';
|
|
145
|
-
return rStr;
|
|
146
|
-
}
|
|
147
|
-
getOneFigure(aCtr: tPaxContour[], faceId: string): string {
|
|
148
|
-
const oscadWF = new OpenscadWriteFigure();
|
|
149
|
-
for (const paxCtr of aCtr) {
|
|
150
|
-
if (paxCtr.circle === true) {
|
|
151
|
-
const paxCircle = paxCtr as tPaxContourCircle;
|
|
152
|
-
const oscadSeg = oscadSegCircle(paxCircle.cx, paxCircle.cy, paxCircle.radius);
|
|
153
|
-
oscadWF.addContour(oscadSeg);
|
|
154
|
-
} else {
|
|
155
|
-
const paxPath = paxCtr as tPaxContourPath;
|
|
156
|
-
const oscadSeg = toOpenscadSeg(paxPath.seg);
|
|
157
|
-
oscadWF.addContour(oscadSeg);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const rOscadF = oscadWF.getFigure(faceId);
|
|
161
|
-
return rOscadF;
|
|
162
|
-
}
|
|
163
|
-
getAllFigures(faces: tPaxFaces, partName: string): string {
|
|
164
|
-
let rStr = '';
|
|
165
|
-
for (const face in faces) {
|
|
166
|
-
const figu = this.getOneFigure(faces[face], `${partName}_${face}`);
|
|
167
|
-
rStr += figu;
|
|
168
|
-
}
|
|
169
|
-
return rStr;
|
|
170
|
-
}
|
|
171
|
-
getOneExtrude(extrud: tExtrude): string {
|
|
172
|
-
let extrudMethod = 'rotate_extrude';
|
|
173
|
-
let extrudOption = '';
|
|
174
|
-
if (extrud.extrudeMethod === EExtrude.eLinearOrtho) {
|
|
175
|
-
if (extrud.length === undefined) {
|
|
176
|
-
console.log('err103: design error: scad-linear_extrude length undefined!');
|
|
177
|
-
}
|
|
178
|
-
extrudMethod = 'linear_extrude';
|
|
179
|
-
extrudOption = `height = ${extrud.length}`;
|
|
180
|
-
}
|
|
181
|
-
const rStr = `
|
|
182
|
-
module ${extrud.outName} () {
|
|
183
|
-
translate( [ ${extrud.translate[0]}, ${extrud.translate[1]}, ${extrud.translate[2]} ])
|
|
184
|
-
rotate( [ ${radToDeg(extrud.rotate[0])}, ${radToDeg(extrud.rotate[1])}, ${radToDeg(
|
|
185
|
-
extrud.rotate[2]
|
|
186
|
-
)} ])
|
|
187
|
-
${extrudMethod}(${extrudOption}) polygon(a_${extrud.face}, b_${extrud.face});
|
|
188
|
-
}
|
|
189
|
-
`;
|
|
190
|
-
return rStr;
|
|
191
|
-
}
|
|
192
|
-
getAllExtrudes(extrudes: tExtrude[]): string {
|
|
193
|
-
let rStr = '';
|
|
194
|
-
for (const extrud of extrudes) {
|
|
195
|
-
const subp = this.getOneExtrude(extrud);
|
|
196
|
-
rStr += subp;
|
|
197
|
-
}
|
|
198
|
-
return rStr;
|
|
199
|
-
}
|
|
200
|
-
getOneVolume(volum: tBVolume): string {
|
|
201
|
-
let vMethod = 'identity';
|
|
202
|
-
switch (volum.boolMethod) {
|
|
203
|
-
case EBVolume.eIntersection:
|
|
204
|
-
vMethod = 'intersection';
|
|
205
|
-
break;
|
|
206
|
-
case EBVolume.eUnion:
|
|
207
|
-
vMethod = 'union';
|
|
208
|
-
break;
|
|
209
|
-
case EBVolume.eSubstraction:
|
|
210
|
-
vMethod = 'difference';
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
const inList2 = [];
|
|
214
|
-
for (const elem of volum.inList) {
|
|
215
|
-
inList2.push(`${elem}();`);
|
|
216
|
-
}
|
|
217
|
-
const inList3 = inList2.join('\n');
|
|
218
|
-
let rStr = `
|
|
219
|
-
module ${volum.outName} () {
|
|
220
|
-
${vMethod} () {
|
|
221
|
-
${inList3}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
`;
|
|
225
|
-
if (volum.boolMethod === EBVolume.eIdentity) {
|
|
226
|
-
rStr = `
|
|
227
|
-
module ${volum.outName} () {
|
|
228
|
-
${inList3}
|
|
229
|
-
}
|
|
230
|
-
`;
|
|
231
|
-
}
|
|
232
|
-
return rStr;
|
|
233
|
-
}
|
|
234
|
-
getAllVolumes(volumes: tBVolume[]): string {
|
|
235
|
-
let rStr = '';
|
|
236
|
-
for (const volum of volumes) {
|
|
237
|
-
const subp = this.getOneVolume(volum);
|
|
238
|
-
rStr += subp;
|
|
239
|
-
}
|
|
240
|
-
return rStr;
|
|
241
|
-
}
|
|
242
|
-
getAllSubGeoms(inherits: tInherit[]): tGeom[] {
|
|
243
|
-
const rGeoms: tGeom[] = [];
|
|
244
|
-
for (const inher of inherits) {
|
|
245
|
-
if (!rGeoms.includes(inher.subgeom)) {
|
|
246
|
-
rGeoms.push(inher.subgeom);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return rGeoms;
|
|
250
|
-
}
|
|
251
|
-
getOneInherit(inherit: tInherit): string {
|
|
252
|
-
const rStr = `
|
|
253
|
-
module ${inherit.outName} () {
|
|
254
|
-
translate( [ ${inherit.translate[0]}, ${inherit.translate[1]}, ${inherit.translate[2]} ])
|
|
255
|
-
rotate( [ ${radToDeg(inherit.rotate[0])}, ${radToDeg(inherit.rotate[1])}, ${radToDeg(
|
|
256
|
-
inherit.rotate[2]
|
|
257
|
-
)} ])
|
|
258
|
-
${inherit.subdesign}();
|
|
259
|
-
}
|
|
260
|
-
`;
|
|
261
|
-
return rStr;
|
|
262
|
-
}
|
|
263
|
-
getAllInherits(inherits: tInherit[]): string {
|
|
264
|
-
let rStr = '';
|
|
265
|
-
for (const inher of inherits) {
|
|
266
|
-
const subinhe = this.getOneInherit(inher);
|
|
267
|
-
rStr += subinhe;
|
|
268
|
-
}
|
|
269
|
-
return rStr;
|
|
270
|
-
}
|
|
271
|
-
getVolume(vol: tVolume): string {
|
|
272
|
-
let rStr = '';
|
|
273
|
-
if (vol.inherits !== undefined) {
|
|
274
|
-
const subGeoms = this.getAllSubGeoms(vol.inherits);
|
|
275
|
-
for (const oneGeom of subGeoms) {
|
|
276
|
-
const paxJson = paxWrite().getPaxJson({}, oneGeom);
|
|
277
|
-
rStr += this.getAllFigures(paxJson.faces, paxJson.partName);
|
|
278
|
-
rStr += this.getVolume(oneGeom.vol);
|
|
279
|
-
}
|
|
280
|
-
rStr += this.getAllInherits(vol.inherits);
|
|
281
|
-
}
|
|
282
|
-
rStr += this.getAllExtrudes(vol.extrudes);
|
|
283
|
-
rStr += this.getAllVolumes(vol.volumes);
|
|
284
|
-
return rStr;
|
|
285
|
-
}
|
|
286
|
-
getFooter(partName: string): string {
|
|
287
|
-
const rStr = `
|
|
288
|
-
pax_${partName}();
|
|
289
|
-
`;
|
|
290
|
-
return rStr;
|
|
291
|
-
}
|
|
292
|
-
getExportFile(pax: tPaxJson) {
|
|
293
|
-
let rStr = this.getHeader();
|
|
294
|
-
rStr += this.getAllFigures(pax.faces, pax.partName);
|
|
295
|
-
rStr += this.getVolume(pax.volume);
|
|
296
|
-
rStr += this.getFooter(pax.partName);
|
|
297
|
-
return rStr;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function oscadWrite() {
|
|
301
|
-
const rOscadWrite = new OpenscadWrite();
|
|
302
|
-
return rOscadWrite;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export { oscadWrite };
|
package/src/write_pax.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// write_pax.ts
|
|
2
|
-
|
|
3
|
-
import * as segLib from './segment';
|
|
4
|
-
import type { tFaces } from './figure';
|
|
5
|
-
import type { tVolume } from './volume';
|
|
6
|
-
import type { tSubDesign } from './sub_design';
|
|
7
|
-
import type { tParamVal } from './designParams';
|
|
8
|
-
import type { tGeom } from './aaParamGeom';
|
|
9
|
-
import type { tPaxContour } from './prepare_pax';
|
|
10
|
-
import { PSeg } from './prepare_pax';
|
|
11
|
-
import type { tContour } from './contour';
|
|
12
|
-
|
|
13
|
-
type tPaxFaces = Record<string, tPaxContour[]>;
|
|
14
|
-
interface tPaxJson {
|
|
15
|
-
partName: string;
|
|
16
|
-
params: tParamVal;
|
|
17
|
-
faces: tPaxFaces;
|
|
18
|
-
volume: tVolume;
|
|
19
|
-
subs: tSubDesign;
|
|
20
|
-
log: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class PaxWrite {
|
|
24
|
-
//constructor() {}
|
|
25
|
-
figureToPaxF(aCtr: tContour[]): tPaxContour[] {
|
|
26
|
-
const rPaxF: tPaxContour[] = [];
|
|
27
|
-
for (const ctr of aCtr) {
|
|
28
|
-
rPaxF.push(ctr.toPax());
|
|
29
|
-
}
|
|
30
|
-
return rPaxF;
|
|
31
|
-
}
|
|
32
|
-
getFigures(figs: tFaces): tPaxFaces {
|
|
33
|
-
const figFaces: tPaxFaces = {};
|
|
34
|
-
for (const face in figs) {
|
|
35
|
-
const figu = this.figureToPaxF(figs[face].mainList);
|
|
36
|
-
figFaces[face] = figu;
|
|
37
|
-
}
|
|
38
|
-
return figFaces;
|
|
39
|
-
}
|
|
40
|
-
getPaxJson(paramVal: tParamVal, geome0: tGeom): tPaxJson {
|
|
41
|
-
const rPaxJson = {
|
|
42
|
-
partName: geome0.partName,
|
|
43
|
-
params: paramVal,
|
|
44
|
-
faces: this.getFigures(geome0.fig),
|
|
45
|
-
volume: geome0.vol,
|
|
46
|
-
subs: geome0.sub,
|
|
47
|
-
log: geome0.logstr
|
|
48
|
-
};
|
|
49
|
-
return rPaxJson;
|
|
50
|
-
}
|
|
51
|
-
getPaxStr(paramVal: tParamVal, geome0: tGeom): string {
|
|
52
|
-
const paxJson = this.getPaxJson(paramVal, geome0);
|
|
53
|
-
const rStr = JSON.stringify(paxJson, null, 2);
|
|
54
|
-
return rStr;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function paxWrite(): PaxWrite {
|
|
58
|
-
const rPaxWrite = new PaxWrite();
|
|
59
|
-
return rPaxWrite;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function convTypePaxToSeg1(paxType: PSeg): segLib.SegEnum {
|
|
63
|
-
let rType: segLib.SegEnum = segLib.SegEnum.eStart;
|
|
64
|
-
if (paxType === PSeg.eStroke) {
|
|
65
|
-
rType = segLib.SegEnum.eStroke;
|
|
66
|
-
} else if (paxType === PSeg.eArc) {
|
|
67
|
-
rType = segLib.SegEnum.eArc;
|
|
68
|
-
}
|
|
69
|
-
return rType;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export type { tPaxFaces, tPaxJson };
|
|
73
|
-
export { paxWrite, convTypePaxToSeg1 };
|