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.
- package/dist/index.d.ts +505 -0
- package/dist/index.js +3848 -0
- package/package.json +7 -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
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
//import { roundZero } from './angle_utils';
|
|
3
|
-
import {
|
|
4
|
-
rightTriLaFromLbLc,
|
|
5
|
-
rightTriLbFromLaLc,
|
|
6
|
-
lcFromLaLbAc,
|
|
7
|
-
aCFromLaLbLc,
|
|
8
|
-
aCFromAaAb,
|
|
9
|
-
lbFromLaAaAb,
|
|
10
|
-
aBFromLaLbAa
|
|
11
|
-
} from './triangle_utils';
|
|
12
|
-
|
|
13
|
-
describe('triangle suit', () => {
|
|
14
|
-
it('right triangle hypothenuse 1', () => {
|
|
15
|
-
expect(rightTriLaFromLbLc(3, 4)).toBeCloseTo(5, 5);
|
|
16
|
-
});
|
|
17
|
-
it('right triangle hypothenuse 2', () => {
|
|
18
|
-
expect(rightTriLaFromLbLc(2, 2)).toBeCloseTo(2.828427, 5);
|
|
19
|
-
});
|
|
20
|
-
it('right triangle side 1', () => {
|
|
21
|
-
expect(rightTriLbFromLaLc(5, 4)).toBeCloseTo(3, 5);
|
|
22
|
-
});
|
|
23
|
-
it('any triangle lc 1', () => {
|
|
24
|
-
expect(lcFromLaLbAc(3, 4, Math.PI / 2)).toBeCloseTo(5, 5);
|
|
25
|
-
});
|
|
26
|
-
it('any triangle aC 1', () => {
|
|
27
|
-
expect(aCFromLaLbLc(3, 4, 5)).toBeCloseTo(Math.PI / 2, 5);
|
|
28
|
-
});
|
|
29
|
-
it('any triangle aC angle only 1', () => {
|
|
30
|
-
expect(aCFromAaAb(Math.PI / 7, (4 * Math.PI) / 7)).toBeCloseTo((2 * Math.PI) / 7, 5);
|
|
31
|
-
});
|
|
32
|
-
it('any triangle lb 1', () => {
|
|
33
|
-
expect(lbFromLaAaAb(1, Math.PI / 2, Math.PI / 6)).toBeCloseTo(0.5, 5);
|
|
34
|
-
});
|
|
35
|
-
it('any triangle aB 1', () => {
|
|
36
|
-
expect(aBFromLaLbAa(2, 1, Math.PI / 2)).toBeCloseTo(Math.PI / 6, 5);
|
|
37
|
-
});
|
|
38
|
-
});
|
package/src/triangle_utils.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// triangle_utils.ts
|
|
2
|
-
// some functions around triangle
|
|
3
|
-
// triangle_utils.ts dependences on angle_utils.ts
|
|
4
|
-
|
|
5
|
-
//import { degToRad, radToDeg, roundZero, withinZero2Pi, withinPiPi, withinZeroPi, withinHPiHPi } from './angle_utils';
|
|
6
|
-
import { roundZero, withinZeroPi, withinPiPi } from './angle_utils';
|
|
7
|
-
|
|
8
|
-
/* right triangle
|
|
9
|
-
* sides: la [hypothenuse], lb, lc
|
|
10
|
-
* angles: aA [right angle], aB, aC
|
|
11
|
-
* */
|
|
12
|
-
|
|
13
|
-
function rightTriLaFromLbLc(ilb: number, ilc: number): number {
|
|
14
|
-
return Math.sqrt(ilb ** 2 + ilc ** 2);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rightTriLbFromLaLc(ila: number, ilc: number): number {
|
|
18
|
-
let rlb = 0;
|
|
19
|
-
if (ilc > ila) {
|
|
20
|
-
throw `err539: ila < ilc ${ila} ${ilc}`;
|
|
21
|
-
} else {
|
|
22
|
-
rlb = Math.sqrt(ila ** 2 - ilc ** 2);
|
|
23
|
-
}
|
|
24
|
-
return rlb;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/* any triangle
|
|
28
|
-
* sides: la, lb, lc
|
|
29
|
-
* angles: aA, aB, aC
|
|
30
|
-
* */
|
|
31
|
-
|
|
32
|
-
function lcFromLaLbAc(la: number, lb: number, ac: number) {
|
|
33
|
-
const rlc = Math.sqrt(la ** 2 + lb ** 2 - 2 * la * lb * Math.cos(ac));
|
|
34
|
-
return rlc;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function aCFromLaLbLc(la: number, lb: number, lc: number) {
|
|
38
|
-
let rac = 0;
|
|
39
|
-
const l3 = [la, lb, lc];
|
|
40
|
-
for (let i = 0; i < l3.length; i++) {
|
|
41
|
-
if (l3[i] < 0) {
|
|
42
|
-
throw `err209: l3[${i}] = ${l3[i]}`;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const l3s = l3.sort(function (a, b) {
|
|
46
|
-
return b - a;
|
|
47
|
-
});
|
|
48
|
-
//console.log(l3s);
|
|
49
|
-
if (l3s[0] > l3s[1] + l3s[2]) {
|
|
50
|
-
throw `err839: impossible triangle with length ${la}, ${lb} and ${lc}`;
|
|
51
|
-
} else {
|
|
52
|
-
rac = Math.acos((la ** 2 + lb ** 2 - lc ** 2) / (2 * la * lb));
|
|
53
|
-
}
|
|
54
|
-
return rac;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function aCFromAaAb(iaA: number, iaB: number) {
|
|
58
|
-
let rac = 0;
|
|
59
|
-
const aA = Math.abs(withinPiPi(iaA));
|
|
60
|
-
const aB = Math.abs(withinPiPi(iaB));
|
|
61
|
-
const sum = aA + aB;
|
|
62
|
-
if (sum > Math.PI) {
|
|
63
|
-
throw `err739: impossible triangle with angles ${iaA} and ${iaB}`;
|
|
64
|
-
} else {
|
|
65
|
-
rac = Math.PI - sum;
|
|
66
|
-
}
|
|
67
|
-
return rac;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function lbFromLaAaAb(ila: number, iaA: number, iaB: number) {
|
|
71
|
-
let rlb = 0;
|
|
72
|
-
const args = [ila, iaA, iaB];
|
|
73
|
-
for (let i = 0; i < args.length; i++) {
|
|
74
|
-
if (roundZero(args[i]) === 0 || args[i] < 0) {
|
|
75
|
-
throw `err329: negative or zero triangle-args ${i} : ${args[i]}`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const aA = withinZeroPi(iaA);
|
|
79
|
-
const aB = withinZeroPi(iaB);
|
|
80
|
-
const sum = aA + aB;
|
|
81
|
-
if (sum > Math.PI) {
|
|
82
|
-
throw `err939: impossible triangle with angles ${iaA} and ${iaB}`;
|
|
83
|
-
} else {
|
|
84
|
-
rlb = (ila * Math.sin(iaB)) / Math.sin(iaA);
|
|
85
|
-
}
|
|
86
|
-
return rlb;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// it works only with angle within -PI/2 and PI/2 because arcsinus()
|
|
90
|
-
function aBFromLaLbAa(ila: number, ilb: number, iaA: number) {
|
|
91
|
-
let rab = 0;
|
|
92
|
-
const args = [ila, ilb, iaA];
|
|
93
|
-
for (let i = 0; i < args.length; i++) {
|
|
94
|
-
if (args[i] <= 0) {
|
|
95
|
-
throw `err429: negative or zero triangle-args ${i} : ${args[i]}`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
rab = Math.asin((ilb * Math.sin(iaA)) / ila);
|
|
99
|
-
return rab;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/* export */
|
|
103
|
-
|
|
104
|
-
export {
|
|
105
|
-
rightTriLaFromLbLc,
|
|
106
|
-
rightTriLbFromLaLc,
|
|
107
|
-
lcFromLaLbAc,
|
|
108
|
-
aCFromLaLbLc,
|
|
109
|
-
aCFromAaAb,
|
|
110
|
-
lbFromLaAaAb,
|
|
111
|
-
aBFromLaLbAa
|
|
112
|
-
};
|
package/src/vector.test.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
//import type { tPolar } from './point';
|
|
3
|
-
import { point } from './point';
|
|
4
|
-
//import type { tCartesian } from './vector';
|
|
5
|
-
import { vector } from './vector';
|
|
6
|
-
import { degToRad } from './angle_utils';
|
|
7
|
-
|
|
8
|
-
describe('vector module', () => {
|
|
9
|
-
const p1 = point(50, 50);
|
|
10
|
-
const p2 = point(30, -15);
|
|
11
|
-
const p3 = point(80, -25);
|
|
12
|
-
const v1 = vector(degToRad(0), 100, p1);
|
|
13
|
-
const v2 = vector(degToRad(-90), 20, p1);
|
|
14
|
-
const v3 = vector(degToRad(135), 20, p1);
|
|
15
|
-
it('Vector translate', () => {
|
|
16
|
-
expect(v1.translatePoint(p1).isEqual(point(150, 50))).toBeTruthy();
|
|
17
|
-
expect(v2.translatePoint(p2).isEqual(point(30, -35))).toBeTruthy();
|
|
18
|
-
expect(v3.translatePoint(p3).isEqual(point(65.8578643, -10.857864))).toBeTruthy();
|
|
19
|
-
});
|
|
20
|
-
it('Vector dot product', () => {
|
|
21
|
-
expect(v1.dotProduct(v2)).toBeCloseTo(0, 5);
|
|
22
|
-
expect(v1.dotProduct(v3)).toBeCloseTo(-1414.213562, 5);
|
|
23
|
-
});
|
|
24
|
-
it('Vector cross product', () => {
|
|
25
|
-
expect(v1.crossProduct(v2)).toBeCloseTo(-2000, 5);
|
|
26
|
-
expect(v1.crossProduct(v3)).toBeCloseTo(1414.213562, 5);
|
|
27
|
-
});
|
|
28
|
-
});
|
package/src/vector.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// vector.ts
|
|
2
|
-
// vector.ts deals with vectors
|
|
3
|
-
// vector.ts depends on canvas_utils.ts, angle_utils.ts, points.ts and line.ts
|
|
4
|
-
// vector.ts id used by figure.ts
|
|
5
|
-
|
|
6
|
-
import type { tCanvasAdjust } from './canvas_utils';
|
|
7
|
-
//import { colorCanvasPoint } from '$lib/style/colors.scss';
|
|
8
|
-
import { colors, point2canvas, canvasTranslatePolar } from './canvas_utils';
|
|
9
|
-
import {
|
|
10
|
-
//degToRad,
|
|
11
|
-
//radToDeg,
|
|
12
|
-
roundZero,
|
|
13
|
-
//withinZero2Pi,
|
|
14
|
-
withinPiPi
|
|
15
|
-
//withinZeroPi,
|
|
16
|
-
//withinHPiHPi
|
|
17
|
-
} from './angle_utils';
|
|
18
|
-
//import {
|
|
19
|
-
//rightTriLaFromLbLc,
|
|
20
|
-
//rightTriLbFromLaLc,
|
|
21
|
-
//lcFromLaLbAc,
|
|
22
|
-
//aCFromLaLbLc,
|
|
23
|
-
//aCFromAaAb,
|
|
24
|
-
//lbFromLaAaAb,
|
|
25
|
-
//aBFromLaLbAa
|
|
26
|
-
//} from './triangle_utils';
|
|
27
|
-
//import type { tPolar } from './point';
|
|
28
|
-
import type { Point } from './point';
|
|
29
|
-
|
|
30
|
-
type tCartesian = [number, number]; // angle, distance
|
|
31
|
-
|
|
32
|
-
/* Base classes */
|
|
33
|
-
class Vector {
|
|
34
|
-
ca: number;
|
|
35
|
-
cl: number;
|
|
36
|
-
drawPoint: Point;
|
|
37
|
-
constructor(ia: number, il: number, iDrawPoint: Point) {
|
|
38
|
-
this.ca = ia;
|
|
39
|
-
this.cl = il;
|
|
40
|
-
this.drawPoint = iDrawPoint;
|
|
41
|
-
}
|
|
42
|
-
draw(ctx: CanvasRenderingContext2D, cAdjust: tCanvasAdjust, color: string = colors.vector) {
|
|
43
|
-
const radius = ctx.canvas.width * (0.7 / 100);
|
|
44
|
-
const [cx2, cy2] = point2canvas(this.drawPoint.cx, this.drawPoint.cy, cAdjust);
|
|
45
|
-
const [cx3, cy3] = canvasTranslatePolar(cx2, cy2, this.ca + Math.PI / 2, 2 * radius);
|
|
46
|
-
const [cx4, cy4] = canvasTranslatePolar(cx2, cy2, this.ca - Math.PI / 2, 2 * radius);
|
|
47
|
-
const p3 = this.drawPoint.translatePolar(this.ca, this.cl);
|
|
48
|
-
const [cx5, cy5] = point2canvas(p3.cx, p3.cy, cAdjust);
|
|
49
|
-
const [cx6, cy6] = canvasTranslatePolar(cx5, cy5, this.ca + (3 * Math.PI) / 4, 4 * radius);
|
|
50
|
-
const [cx7, cy7] = canvasTranslatePolar(cx5, cy5, this.ca + (5 * Math.PI) / 4, 4 * radius);
|
|
51
|
-
ctx.beginPath();
|
|
52
|
-
ctx.moveTo(cx3, cy3);
|
|
53
|
-
ctx.lineTo(cx4, cy4);
|
|
54
|
-
ctx.moveTo(cx2, cy2);
|
|
55
|
-
ctx.lineTo(cx5, cy5);
|
|
56
|
-
ctx.lineTo(cx6, cy6);
|
|
57
|
-
ctx.moveTo(cx5, cy5);
|
|
58
|
-
ctx.lineTo(cx7, cy7);
|
|
59
|
-
ctx.strokeStyle = color;
|
|
60
|
-
ctx.stroke();
|
|
61
|
-
}
|
|
62
|
-
getCartesian(): tCartesian {
|
|
63
|
-
return [this.cl * Math.cos(this.ca), this.cl * Math.sin(this.ca)];
|
|
64
|
-
}
|
|
65
|
-
setCartesian(ix: number, iy: number): Vector {
|
|
66
|
-
return new Vector(Math.atan2(iy, ix), Math.sqrt(ix ** 2 + iy ** 2), this.drawPoint);
|
|
67
|
-
}
|
|
68
|
-
translatePoint(ip: Point): Point {
|
|
69
|
-
const [x1, y1] = this.getCartesian();
|
|
70
|
-
return ip.translate(x1, y1);
|
|
71
|
-
}
|
|
72
|
-
add(iVect: Vector): Vector {
|
|
73
|
-
const [x1, y1] = this.getCartesian();
|
|
74
|
-
const [x2, y2] = iVect.getCartesian();
|
|
75
|
-
const rVect = this.setCartesian(x1 + x2, y1 + y2);
|
|
76
|
-
return rVect;
|
|
77
|
-
}
|
|
78
|
-
addCart(ix: number, iy: number): Vector {
|
|
79
|
-
const [x1, y1] = this.getCartesian();
|
|
80
|
-
const rVect = this.setCartesian(x1 + ix, y1 + iy);
|
|
81
|
-
return rVect;
|
|
82
|
-
}
|
|
83
|
-
// transforms
|
|
84
|
-
translate(ix: number, iy: number): Vector {
|
|
85
|
-
const rVec = new Vector(this.ca, this.cl, this.drawPoint.translate(ix, iy));
|
|
86
|
-
return rVec;
|
|
87
|
-
}
|
|
88
|
-
rotate(ic: Point, ia: number): Vector {
|
|
89
|
-
const rVec = new Vector(this.ca + ia, this.cl, this.drawPoint.rotate(ic, ia));
|
|
90
|
-
return rVec;
|
|
91
|
-
}
|
|
92
|
-
clone(): Vector {
|
|
93
|
-
const rVec = new Vector(this.ca, this.cl, this.drawPoint.clone());
|
|
94
|
-
return rVec;
|
|
95
|
-
}
|
|
96
|
-
// point comparison
|
|
97
|
-
isEqual(iVect: Vector): boolean {
|
|
98
|
-
const [x1, y1] = this.getCartesian();
|
|
99
|
-
const [x2, y2] = iVect.getCartesian();
|
|
100
|
-
const rb = roundZero(x2 - x1) === 0 && roundZero(y2 - y1) === 0;
|
|
101
|
-
return rb;
|
|
102
|
-
}
|
|
103
|
-
// dot product
|
|
104
|
-
dotProduct(iVect: Vector): number {
|
|
105
|
-
const angle = withinPiPi(iVect.ca - this.ca);
|
|
106
|
-
return this.cl * iVect.cl * Math.cos(angle);
|
|
107
|
-
}
|
|
108
|
-
// cross product
|
|
109
|
-
crossProduct(iVect: Vector): number {
|
|
110
|
-
const angle = withinPiPi(iVect.ca - this.ca);
|
|
111
|
-
return this.cl * iVect.cl * Math.sin(angle);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function vector(ia: number, il: number, iDrawPoint: Point) {
|
|
116
|
-
return new Vector(ia, il, iDrawPoint);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* export */
|
|
120
|
-
|
|
121
|
-
export type { tCartesian };
|
|
122
|
-
export { Vector, vector };
|
package/src/volume.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// volume.ts
|
|
2
|
-
|
|
3
|
-
import type { tGeom } from './aaParamGeom';
|
|
4
|
-
|
|
5
|
-
interface tInherit {
|
|
6
|
-
outName: string;
|
|
7
|
-
subdesign: string;
|
|
8
|
-
subgeom: tGeom;
|
|
9
|
-
rotate: [number, number, number];
|
|
10
|
-
translate: [number, number, number];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
enum EExtrude {
|
|
14
|
-
eLinearOrtho,
|
|
15
|
-
//eLinear,
|
|
16
|
-
//eAlongPath,
|
|
17
|
-
//eTwisted,
|
|
18
|
-
eRotate
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface tExtrude {
|
|
22
|
-
outName: string;
|
|
23
|
-
face: string;
|
|
24
|
-
extrudeMethod: EExtrude;
|
|
25
|
-
length?: number;
|
|
26
|
-
rotate: [number, number, number];
|
|
27
|
-
translate: [number, number, number];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
enum EBVolume {
|
|
31
|
-
eIdentity,
|
|
32
|
-
eIntersection,
|
|
33
|
-
eUnion,
|
|
34
|
-
eSubstraction
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface tBVolume {
|
|
38
|
-
outName: string;
|
|
39
|
-
boolMethod: EBVolume;
|
|
40
|
-
inList: string[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface tVolume {
|
|
44
|
-
inherits?: tInherit[];
|
|
45
|
-
extrudes: tExtrude[];
|
|
46
|
-
volumes: tBVolume[];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type { tVolume, tInherit, tExtrude, tBVolume };
|
|
50
|
-
export { EExtrude, EBVolume };
|
package/src/write_dxf.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// write_dxf.ts
|
|
2
|
-
|
|
3
|
-
import { radToDeg, withinZero2Pi } from './angle_utils';
|
|
4
|
-
|
|
5
|
-
// floating precision for dxf export
|
|
6
|
-
function ff(ifloat: number): string {
|
|
7
|
-
return ifloat.toFixed(4);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
class DxfSeg {
|
|
11
|
-
arc: boolean;
|
|
12
|
-
p1x: number;
|
|
13
|
-
p1y: number;
|
|
14
|
-
radius: number;
|
|
15
|
-
a1: number;
|
|
16
|
-
a2: number;
|
|
17
|
-
p2x: number;
|
|
18
|
-
p2y: number;
|
|
19
|
-
constructor(
|
|
20
|
-
arc: boolean,
|
|
21
|
-
p1x: number,
|
|
22
|
-
p1y: number,
|
|
23
|
-
radius: number,
|
|
24
|
-
a1: number,
|
|
25
|
-
a2: number,
|
|
26
|
-
p2x: number,
|
|
27
|
-
p2y: number
|
|
28
|
-
) {
|
|
29
|
-
this.arc = arc;
|
|
30
|
-
this.p1x = p1x;
|
|
31
|
-
this.p1y = p1y;
|
|
32
|
-
this.radius = radius;
|
|
33
|
-
this.a1 = a1;
|
|
34
|
-
this.a2 = a2;
|
|
35
|
-
this.p2x = p2x;
|
|
36
|
-
this.p2y = p2y;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function dxfSegLine(p1x: number, p1y: number, p2x: number, p2y: number): DxfSeg {
|
|
40
|
-
const rDxfSeg = new DxfSeg(false, p1x, p1y, 0, 0, 0, p2x, p2y);
|
|
41
|
-
return rDxfSeg;
|
|
42
|
-
}
|
|
43
|
-
function dxfSegArc(
|
|
44
|
-
p1x: number,
|
|
45
|
-
p1y: number,
|
|
46
|
-
radius: number,
|
|
47
|
-
aa1: number,
|
|
48
|
-
aa2: number,
|
|
49
|
-
arcCcw: boolean
|
|
50
|
-
): DxfSeg {
|
|
51
|
-
//const a1 = aa1;
|
|
52
|
-
//const a2 = aa2;
|
|
53
|
-
const a1 = arcCcw ? aa1 : aa2;
|
|
54
|
-
const a2 = arcCcw ? aa2 : aa1;
|
|
55
|
-
// DXF angles are in degree and preferably positive
|
|
56
|
-
const b1 = radToDeg(withinZero2Pi(a1));
|
|
57
|
-
const b2 = radToDeg(withinZero2Pi(a2));
|
|
58
|
-
const rDxfSeg = new DxfSeg(true, p1x, p1y, radius, b1, b2, 0, 0);
|
|
59
|
-
return rDxfSeg;
|
|
60
|
-
}
|
|
61
|
-
function dxfSegCircle(p1x: number, p1y: number, radius: number): DxfSeg {
|
|
62
|
-
const rDxfSeg = new DxfSeg(false, p1x, p1y, radius, 0, 0, 0, 0);
|
|
63
|
-
return rDxfSeg;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
class DxfWrite {
|
|
67
|
-
dxfStr: string;
|
|
68
|
-
constructor() {
|
|
69
|
-
this.dxfStr = '0\nSECTION\n2\nENTITIES\n';
|
|
70
|
-
}
|
|
71
|
-
addCircle(cx: number, cy: number, radius: number) {
|
|
72
|
-
this.dxfStr += '0\nCIRCLE\n8\nPARAMETRIX\n';
|
|
73
|
-
this.dxfStr += `10\n${ff(cx)}\n20\n${ff(cy)}\n40\n${ff(radius)}\n`;
|
|
74
|
-
}
|
|
75
|
-
addLine(p1x: number, p1y: number, p2x: number, p2y: number) {
|
|
76
|
-
this.dxfStr += '0\nLINE\n8\nPARAMETRIX\n';
|
|
77
|
-
this.dxfStr += `10\n${ff(p1x)}\n20\n${ff(p1y)}\n11\n${ff(p2x)}\n21\n${ff(p2y)}\n`;
|
|
78
|
-
}
|
|
79
|
-
addArc(cx: number, cy: number, ra: number, a1: number, a2: number) {
|
|
80
|
-
this.dxfStr += '0\nARC\n8\nPARAMETRIX\n';
|
|
81
|
-
this.dxfStr += `10\n${ff(cx)}\n20\n${ff(cy)}\n40\n${ff(ra)}\n50\n${ff(a1)}\n51\n${ff(
|
|
82
|
-
a2
|
|
83
|
-
)}\n`;
|
|
84
|
-
}
|
|
85
|
-
close() {
|
|
86
|
-
this.dxfStr += '0\nENDSEC\n0\nEOF\n';
|
|
87
|
-
}
|
|
88
|
-
stringify(): string {
|
|
89
|
-
this.close();
|
|
90
|
-
return this.dxfStr;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function dxfWriter() {
|
|
95
|
-
const rDxfWrite = new DxfWrite();
|
|
96
|
-
return rDxfWrite;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export type { DxfSeg };
|
|
100
|
-
export { dxfSegLine, dxfSegArc, dxfSegCircle, dxfWriter };
|