@bitbybit-dev/base 1.6.2 → 1.8.0
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/NOTICE +24 -0
- package/README.md +3 -1
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +40 -7
- package/lib/api/inputs/base-inputs.js +32 -0
- package/lib/api/inputs/io-inputs.d.ts +927 -59
- package/lib/api/inputs/io-inputs.js +769 -40
- package/lib/api/inputs/line-inputs.d.ts +17 -0
- package/lib/api/inputs/line-inputs.js +15 -0
- package/lib/api/inputs/mesh-inputs.d.ts +20 -1
- package/lib/api/inputs/mesh-inputs.js +23 -0
- package/lib/api/inputs/recipes-inputs.d.ts +13 -5
- package/lib/api/inputs/recipes-inputs.js +10 -5
- package/lib/api/kernel-calls/index.d.ts +2 -0
- package/lib/api/kernel-calls/index.js +2 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +3 -1
- package/lib/api/kernel-calls/resolve-dto.js +7 -2
- package/lib/api/kernel-calls/settings.d.ts +101 -0
- package/lib/api/kernel-calls/settings.js +123 -0
- package/lib/api/kernel-calls/up-axis-aliases.d.ts +25 -0
- package/lib/api/kernel-calls/up-axis-aliases.js +70 -0
- package/lib/api/models/simplex.d.ts +2 -0
- package/lib/api/models/simplex.js +10 -1
- package/lib/api/recipes/surface-mesh.d.ts +2 -1
- package/lib/api/recipes/surface-mesh.js +5 -3
- package/lib/api/resolved-inputs/index.d.ts +32 -3
- package/lib/api/services/base-bitbybit.d.ts +12 -0
- package/lib/api/services/base-bitbybit.js +19 -3
- package/lib/api/services/color.js +2 -3
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +3 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +1 -0
- package/lib/api/services/helpers/color/color-forms.js +4 -1
- package/lib/api/services/helpers/color/css-colors.constants.d.ts +9 -0
- package/lib/api/services/helpers/color/css-colors.constants.js +158 -0
- package/lib/api/services/helpers/color/css-colors.d.ts +1 -0
- package/lib/api/services/helpers/color/css-colors.js +61 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.js +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.d.ts +24 -0
- package/lib/api/services/helpers/curves/bezier-pieces.js +149 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.js +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +26 -0
- package/lib/api/services/helpers/curves/conic-arcs.js +87 -0
- package/lib/api/services/helpers/curves/nurbs-forms.d.ts +20 -0
- package/lib/api/services/helpers/curves/nurbs-forms.js +112 -0
- package/lib/api/services/helpers/curves/nurbs.d.ts +4 -0
- package/lib/api/services/helpers/curves/nurbs.js +10 -9
- package/lib/api/services/helpers/files/drawing/drawing-budget.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +34 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.js +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.d.ts +4 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.js +271 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +101 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.js +123 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.js +91 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.js +336 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.d.ts +2 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.js +47 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.d.ts +9 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.js +25 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +117 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.js +1 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +41 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +46 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.js +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.js +45 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +196 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.d.ts +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.js +50 -0
- package/lib/api/services/helpers/files/dxf/dxf-generator.d.ts +2 -36
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +97 -523
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.js +312 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.d.ts +6 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +115 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.js +67 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.js +151 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.js +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +134 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +95 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +446 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +29 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +248 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.d.ts +26 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.js +97 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +11 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +89 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +43 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +47 -1
- package/lib/api/services/helpers/files/file-bytes.d.ts +1 -0
- package/lib/api/services/helpers/files/file-bytes.js +15 -0
- package/lib/api/services/helpers/files/ground-axes.d.ts +2 -0
- package/lib/api/services/helpers/files/ground-axes.js +4 -0
- package/lib/api/services/helpers/files/mesh-file-axes.d.ts +7 -0
- package/lib/api/services/helpers/files/mesh-file-axes.js +17 -0
- package/lib/api/services/helpers/files/stl-axes.d.ts +4 -0
- package/lib/api/services/helpers/files/stl-axes.js +22 -0
- package/lib/api/services/helpers/files/stl-types.d.ts +7 -0
- package/lib/api/services/helpers/files/stl-types.js +1 -0
- package/lib/api/services/helpers/files/stl.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/stl.constants.js +11 -0
- package/lib/api/services/helpers/files/stl.d.ts +3 -0
- package/lib/api/services/helpers/files/stl.js +93 -0
- package/lib/api/services/helpers/files/svg/svg-css.d.ts +48 -0
- package/lib/api/services/helpers/files/svg/svg-css.js +444 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-document.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-document.js +89 -0
- package/lib/api/services/helpers/files/svg/svg-memo.d.ts +1 -0
- package/lib/api/services/helpers/files/svg/svg-memo.js +8 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.js +433 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.d.ts +15 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.js +61 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.d.ts +8 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.js +10 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.js +203 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.d.ts +33 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.d.ts +35 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.js +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-reading.js +233 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.d.ts +54 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.js +102 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +38 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.js +132 -0
- package/lib/api/services/helpers/files/svg/svg-style.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-style.js +211 -0
- package/lib/api/services/helpers/files/svg/svg-transform.d.ts +10 -0
- package/lib/api/services/helpers/files/svg/svg-transform.js +76 -0
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +18 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +230 -0
- package/lib/api/services/helpers/files/svg/svg-xml.d.ts +11 -0
- package/lib/api/services/helpers/files/svg/svg-xml.js +322 -0
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/svg/svg.constants.js +14 -0
- package/lib/api/services/helpers/files/work-budget.d.ts +11 -0
- package/lib/api/services/helpers/files/work-budget.js +26 -0
- package/lib/api/services/helpers/geometry/affine2.d.ts +8 -0
- package/lib/api/services/helpers/geometry/affine2.js +18 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.d.ts +14 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.js +96 -0
- package/lib/api/services/helpers/geometry/frame-axes.d.ts +3 -1
- package/lib/api/services/helpers/geometry/loop-fill.d.ts +2 -0
- package/lib/api/services/helpers/geometry/loop-fill.js +37 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.d.ts +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.js +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.d.ts +31 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.js +251 -0
- package/lib/api/services/helpers/geometry/vectors.d.ts +1 -0
- package/lib/api/services/helpers/geometry/vectors.js +6 -0
- package/lib/api/services/helpers/helper-types.d.ts +33 -0
- package/lib/api/services/helpers/text/stroke-font.d.ts +6 -0
- package/lib/api/services/helpers/text/stroke-font.js +177 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.d.ts +2 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.js +18 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.d.ts +14 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.js +34 -0
- package/lib/api/services/io/drawing.d.ts +368 -0
- package/lib/api/services/io/drawing.js +454 -0
- package/lib/api/services/io/dxf.d.ts +134 -0
- package/lib/api/services/io/dxf.js +167 -0
- package/lib/api/services/io/index.d.ts +4 -0
- package/lib/api/services/io/index.js +4 -0
- package/lib/api/services/io/io.d.ts +14 -0
- package/lib/api/services/io/io.js +15 -0
- package/lib/api/services/io/svg.d.ts +66 -0
- package/lib/api/services/io/svg.js +105 -0
- package/lib/api/services/line.d.ts +17 -0
- package/lib/api/services/line.js +20 -1
- package/lib/api/services/mesh.d.ts +19 -0
- package/lib/api/services/mesh.js +40 -0
- package/lib/api/services/point.d.ts +4 -1
- package/lib/api/services/point.js +9 -4
- package/lib/api/services/recipes.d.ts +3 -0
- package/lib/api/services/recipes.js +6 -2
- package/lib/api/services/text.d.ts +7 -4
- package/lib/api/services/text.js +14 -27
- package/package.json +1 -1
- package/lib/api/services/helpers/files/dxf/dxf.d.ts +0 -87
- package/lib/api/services/helpers/files/dxf/dxf.js +0 -111
- package/lib/api/services/io.d.ts +0 -9
- package/lib/api/services/io.js +0 -10
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import * as Inputs from "../../inputs";
|
|
2
|
+
import { DxfGenerator } from "../helpers/files/dxf/dxf-generator";
|
|
3
|
+
import { resolveDto } from "../../kernel-calls";
|
|
4
|
+
import { readDxfDrawing } from "../helpers/files/dxf/dxf-reader";
|
|
5
|
+
import { dxfTextOf } from "../helpers/files/dxf/dxf-file-text";
|
|
6
|
+
import { drawingDtoOf } from "../helpers/files/dxf/dxf-reader-dtos";
|
|
7
|
+
/**
|
|
8
|
+
* Writes a drawing as a DXF file and reads a DXF file back into one. The drawing itself is built with
|
|
9
|
+
* `io.drawing`; the builders here are its former DXF-named copies.
|
|
10
|
+
*/
|
|
11
|
+
export class Dxf {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.dxfGenerator = new DxfGenerator();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Makes a straight segment for a drawing, under its former DXF name.
|
|
17
|
+
* @param inputs - The line segment definition
|
|
18
|
+
* @returns The line segment
|
|
19
|
+
* @group dxf
|
|
20
|
+
* @shortname line segment
|
|
21
|
+
* @drawable false
|
|
22
|
+
* @deprecated Use `io.drawing.lineSegment`, the same builder under the drawing's own name; this one is
|
|
23
|
+
* removed in the next major version.
|
|
24
|
+
*/
|
|
25
|
+
lineSegment(inputs) {
|
|
26
|
+
return inputs;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Makes a circular arc for a drawing, under its former DXF name.
|
|
30
|
+
* @param inputs - The arc segment definition
|
|
31
|
+
* @returns The arc segment
|
|
32
|
+
* @group dxf
|
|
33
|
+
* @shortname arc segment
|
|
34
|
+
* @drawable false
|
|
35
|
+
* @deprecated Use `io.drawing.arcSegment`, the same builder under the drawing's own name; this one is
|
|
36
|
+
* removed in the next major version.
|
|
37
|
+
*/
|
|
38
|
+
arcSegment(inputs) {
|
|
39
|
+
return inputs;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Makes a whole circle for a drawing, under its former DXF name.
|
|
43
|
+
* @param inputs - The circle segment definition
|
|
44
|
+
* @returns The circle segment
|
|
45
|
+
* @group dxf
|
|
46
|
+
* @shortname circle segment
|
|
47
|
+
* @drawable false
|
|
48
|
+
* @deprecated Use `io.drawing.circleSegment`, the same builder under the drawing's own name; this one is
|
|
49
|
+
* removed in the next major version.
|
|
50
|
+
*/
|
|
51
|
+
circleSegment(inputs) {
|
|
52
|
+
return inputs;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Makes connected straight segments for a drawing, under its former DXF name.
|
|
56
|
+
* @param inputs - The polyline segment definition
|
|
57
|
+
* @returns The polyline segment
|
|
58
|
+
* @group dxf
|
|
59
|
+
* @shortname polyline segment
|
|
60
|
+
* @drawable false
|
|
61
|
+
* @deprecated Use `io.drawing.polylineSegment`, the same builder under the drawing's own name; this one is
|
|
62
|
+
* removed in the next major version.
|
|
63
|
+
*/
|
|
64
|
+
polylineSegment(inputs) {
|
|
65
|
+
const resolved = resolveDto(Inputs.IO.DxfPolylineSegmentDto, inputs);
|
|
66
|
+
return resolved;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Makes a B-spline or NURBS curve for a drawing, under its former DXF name.
|
|
70
|
+
* @param inputs - The spline segment definition
|
|
71
|
+
* @returns The spline segment
|
|
72
|
+
* @group dxf
|
|
73
|
+
* @shortname spline segment
|
|
74
|
+
* @drawable false
|
|
75
|
+
* @deprecated Use `io.drawing.splineSegment`, the same builder under the drawing's own name; this one is
|
|
76
|
+
* removed in the next major version.
|
|
77
|
+
*/
|
|
78
|
+
splineSegment(inputs) {
|
|
79
|
+
const resolved = resolveDto(Inputs.IO.DxfSplineSegmentDto, inputs);
|
|
80
|
+
return resolved;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Makes an ellipse or an arc of one for a drawing, under its former DXF name.
|
|
84
|
+
* @param inputs - The ellipse segment definition
|
|
85
|
+
* @returns The ellipse segment
|
|
86
|
+
* @group dxf
|
|
87
|
+
* @shortname ellipse segment
|
|
88
|
+
* @drawable false
|
|
89
|
+
* @deprecated Use `io.drawing.ellipseSegment`, the same builder under the drawing's own name; this one is
|
|
90
|
+
* removed in the next major version.
|
|
91
|
+
*/
|
|
92
|
+
ellipseSegment(inputs) {
|
|
93
|
+
const resolved = resolveDto(Inputs.IO.DxfEllipseSegmentDto, inputs);
|
|
94
|
+
return resolved;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Makes a path joined from segments for a drawing, under its former DXF name.
|
|
98
|
+
* @param inputs - The path definition
|
|
99
|
+
* @returns The path
|
|
100
|
+
* @group dxf
|
|
101
|
+
* @shortname path
|
|
102
|
+
* @drawable false
|
|
103
|
+
* @deprecated Use `io.drawing.path`, the same builder under the drawing's own name; this one is
|
|
104
|
+
* removed in the next major version.
|
|
105
|
+
*/
|
|
106
|
+
path(inputs) {
|
|
107
|
+
return inputs;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Makes a part of a drawing on one layer for a drawing, under its former DXF name.
|
|
111
|
+
* @param inputs - The paths part definition
|
|
112
|
+
* @returns The paths part
|
|
113
|
+
* @group dxf
|
|
114
|
+
* @shortname paths part
|
|
115
|
+
* @drawable false
|
|
116
|
+
* @deprecated Use `io.drawing.part`, the same builder under the drawing's own name; this one is
|
|
117
|
+
* removed in the next major version.
|
|
118
|
+
*/
|
|
119
|
+
pathsPart(inputs) {
|
|
120
|
+
const resolved = resolveDto(Inputs.IO.DxfPathsPartDto, inputs);
|
|
121
|
+
return resolved;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Writes a DXF file from path parts, each on its layer with its color and line type.
|
|
125
|
+
*
|
|
126
|
+
* `AC1015` keeps every curve exact. `AC1009` (R12) writes splines and ellipses as polylines
|
|
127
|
+
* within `curveTolerance`, never finer than a millionth of the drawing. Points off one Z make a
|
|
128
|
+
* 3D polyline; a drawing too large to write throws.
|
|
129
|
+
* @param inputs DXF model definition
|
|
130
|
+
* @returns DXF file content as string
|
|
131
|
+
* @group dxf
|
|
132
|
+
* @shortname dxf create
|
|
133
|
+
* @drawable false
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
137
|
+
* const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
138
|
+
* const part = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [outline] }, { segments: [hole] }] });
|
|
139
|
+
* const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: [part], unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
dxfCreate(inputs) {
|
|
143
|
+
const resolved = resolveDto(Inputs.IO.DxfModelDto, inputs);
|
|
144
|
+
return this.dxfGenerator.generateDxf(resolved);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Reads a DXF file into path parts by layer, color and line type, the model `dxfCreate` writes.
|
|
148
|
+
*
|
|
149
|
+
* Lines, arcs, circles, ellipses, polylines and splines are read exactly, block inserts
|
|
150
|
+
* expanded, with single-line texts and hatches. Multi-line text and dimensions are named in
|
|
151
|
+
* `warnings`; `occt.io.loadDxf` reads splines given only by fit points.
|
|
152
|
+
* @param inputs - The DXF file, as text or bytes, and whether hidden layers are read
|
|
153
|
+
* @returns The drawing's parts, unit, version and warnings
|
|
154
|
+
* @group dxf
|
|
155
|
+
* @shortname dxf read
|
|
156
|
+
* @drawable false
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const drawing = bitbybit.io.dxf.dxfRead({ dxf: dxfText });
|
|
160
|
+
* const svg = bitbybit.io.svg.svgCreate({ parts: drawing.parts, unit: drawing.unit });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
dxfRead(inputs) {
|
|
164
|
+
const resolved = resolveDto(Inputs.IO.DxfReadDto, inputs);
|
|
165
|
+
return drawingDtoOf(readDxfDrawing(dxfTextOf(resolved.dxf, "dxf"), resolved.includeHiddenLayers, true));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Drawing } from "./drawing";
|
|
2
|
+
import { Dxf } from "./dxf";
|
|
3
|
+
import { Svg } from "./svg";
|
|
4
|
+
/**
|
|
5
|
+
* Drawings as data, with no kernel: `drawing` builds one from segments, paths and layered parts and
|
|
6
|
+
* converts SVG files to DXF and back, `dxf` writes it as a DXF file and reads one back, and `svg` does
|
|
7
|
+
* the same for SVG.
|
|
8
|
+
*/
|
|
9
|
+
export declare class IoBitByBit {
|
|
10
|
+
drawing: Drawing;
|
|
11
|
+
dxf: Dxf;
|
|
12
|
+
svg: Svg;
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Drawing } from "./drawing";
|
|
2
|
+
import { Dxf } from "./dxf";
|
|
3
|
+
import { Svg } from "./svg";
|
|
4
|
+
/**
|
|
5
|
+
* Drawings as data, with no kernel: `drawing` builds one from segments, paths and layered parts and
|
|
6
|
+
* converts SVG files to DXF and back, `dxf` writes it as a DXF file and reads one back, and `svg` does
|
|
7
|
+
* the same for SVG.
|
|
8
|
+
*/
|
|
9
|
+
export class IoBitByBit {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.dxf = new Dxf();
|
|
12
|
+
this.svg = new Svg();
|
|
13
|
+
this.drawing = new Drawing(() => this.dxf, () => this.svg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as Inputs from "../../inputs";
|
|
2
|
+
/**
|
|
3
|
+
* Writes SVG drawings from the same path parts DXF files are made of: lines, arcs, circles, bulged
|
|
4
|
+
* polylines, splines and ellipses, kept exact wherever SVG can draw them, with texts drawn as the
|
|
5
|
+
* strokes of their letters and hatches filled with patterns. Reads SVG files back into those parts,
|
|
6
|
+
* by layer, color and line type.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Svg {
|
|
9
|
+
/**
|
|
10
|
+
* Writes an SVG file from path parts, each layer an Inkscape layer.
|
|
11
|
+
*
|
|
12
|
+
* Arcs, circles, ellipses and bulges stay exact arcs, unweighted splines up to degree 3 exact
|
|
13
|
+
* Beziers, others cubics within `tolerance`. Texts become letter strokes, hatches patterned
|
|
14
|
+
* regions. Y points up, Z is dropped and `unit` gives the true size. A drawing too large to
|
|
15
|
+
* write throws.
|
|
16
|
+
* @param inputs - The path parts with their texts, hatches and line weights, the unit, the line width, the border, the dash scale and the curve tolerance
|
|
17
|
+
* @returns The SVG file as text
|
|
18
|
+
* @group svg
|
|
19
|
+
* @shortname svg create
|
|
20
|
+
* @drawable false
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
24
|
+
* const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
25
|
+
* const part = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }, { segments: [hole] }] });
|
|
26
|
+
* const svg = bitbybit.io.svg.svgCreate({ parts: [part], unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
svgCreate(inputs: Inputs.IO.SvgModelDto): string;
|
|
30
|
+
/**
|
|
31
|
+
* Writes one drawing path as SVG path data, the text of a `path` element's `d` attribute.
|
|
32
|
+
*
|
|
33
|
+
* Segments that meet are drawn as one stroke, reversed where a segment ends where the stroke is,
|
|
34
|
+
* and a stroke that returns to its start is closed. Curves stay exact as in `svgCreate`, or with
|
|
35
|
+
* `cubicsOnly` become cubic Beziers within `tolerance`.
|
|
36
|
+
* @param inputs - The path, whether Y is negated, the curve tolerance and whether only cubics are written
|
|
37
|
+
* @returns SVG path data
|
|
38
|
+
* @group svg
|
|
39
|
+
* @shortname path data
|
|
40
|
+
* @drawable false
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
|
|
44
|
+
* const data = bitbybit.io.svg.pathData({ path: { segments: [slot] }, flipY: false });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
pathData(inputs: Inputs.IO.SvgPathDataDto): string;
|
|
48
|
+
/**
|
|
49
|
+
* Reads an SVG file into path parts by layer, color and line type.
|
|
50
|
+
*
|
|
51
|
+
* Lines, arcs and Bezier curves are read exactly, transforms applied, Y up. Inkscape
|
|
52
|
+
* layers are layers, each stroke color (else fill) a color, each dash pattern a line type. Text
|
|
53
|
+
* and images are left out, named in `warnings`; `svgCreate`'s texts and hatches return as paths.
|
|
54
|
+
* @param inputs - The SVG text, the unit to read it in and whether hidden elements are read
|
|
55
|
+
* @returns The drawing's parts, unit, view box and warnings
|
|
56
|
+
* @group svg
|
|
57
|
+
* @shortname svg read
|
|
58
|
+
* @drawable false
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const drawing = bitbybit.io.svg.svgRead({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
62
|
+
* const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: drawing.parts, unit: drawing.unit });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
svgRead(inputs: Inputs.IO.SvgReadDto): Inputs.IO.SvgDrawingDto;
|
|
66
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as Inputs from "../../inputs";
|
|
2
|
+
import { InputError, resolveDto } from "../../kernel-calls";
|
|
3
|
+
import { checkedUnitOfLength } from "../helpers/geometry/lengths";
|
|
4
|
+
import { drawingPartsOf, drawingPathOf, positiveNumber } from "../helpers/files/drawing/drawing-model";
|
|
5
|
+
import { readSvgDrawing } from "../helpers/files/svg/svg-reading";
|
|
6
|
+
import { pathDataOf, svgDocumentOf } from "../helpers/files/svg/svg-writer";
|
|
7
|
+
const marginOf = (value) => {
|
|
8
|
+
if (value === undefined) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
12
|
+
throw new InputError("`margin` must be a finite number of 0 or more.", "margin");
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Writes SVG drawings from the same path parts DXF files are made of: lines, arcs, circles, bulged
|
|
18
|
+
* polylines, splines and ellipses, kept exact wherever SVG can draw them, with texts drawn as the
|
|
19
|
+
* strokes of their letters and hatches filled with patterns. Reads SVG files back into those parts,
|
|
20
|
+
* by layer, color and line type.
|
|
21
|
+
*/
|
|
22
|
+
export class Svg {
|
|
23
|
+
/**
|
|
24
|
+
* Writes an SVG file from path parts, each layer an Inkscape layer.
|
|
25
|
+
*
|
|
26
|
+
* Arcs, circles, ellipses and bulges stay exact arcs, unweighted splines up to degree 3 exact
|
|
27
|
+
* Beziers, others cubics within `tolerance`. Texts become letter strokes, hatches patterned
|
|
28
|
+
* regions. Y points up, Z is dropped and `unit` gives the true size. A drawing too large to
|
|
29
|
+
* write throws.
|
|
30
|
+
* @param inputs - The path parts with their texts, hatches and line weights, the unit, the line width, the border, the dash scale and the curve tolerance
|
|
31
|
+
* @returns The SVG file as text
|
|
32
|
+
* @group svg
|
|
33
|
+
* @shortname svg create
|
|
34
|
+
* @drawable false
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
38
|
+
* const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
39
|
+
* const part = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }, { segments: [hole] }] });
|
|
40
|
+
* const svg = bitbybit.io.svg.svgCreate({ parts: [part], unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
svgCreate(inputs) {
|
|
44
|
+
const resolved = resolveDto(Inputs.IO.SvgModelDto, inputs);
|
|
45
|
+
const tolerance = positiveNumber(resolved.tolerance, "tolerance");
|
|
46
|
+
const unit = resolved.unit === undefined ? undefined : checkedUnitOfLength(resolved.unit, "unit");
|
|
47
|
+
return svgDocumentOf(drawingPartsOf(resolved.parts, "parts"), {
|
|
48
|
+
unit,
|
|
49
|
+
strokeWidth: resolved.strokeWidth === undefined ? undefined : positiveNumber(resolved.strokeWidth, "strokeWidth"),
|
|
50
|
+
margin: marginOf(resolved.margin),
|
|
51
|
+
lineTypeScale: resolved.lineTypeScale === undefined ? undefined : positiveNumber(resolved.lineTypeScale, "lineTypeScale"),
|
|
52
|
+
tolerance,
|
|
53
|
+
property: "parts",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Writes one drawing path as SVG path data, the text of a `path` element's `d` attribute.
|
|
58
|
+
*
|
|
59
|
+
* Segments that meet are drawn as one stroke, reversed where a segment ends where the stroke is,
|
|
60
|
+
* and a stroke that returns to its start is closed. Curves stay exact as in `svgCreate`, or with
|
|
61
|
+
* `cubicsOnly` become cubic Beziers within `tolerance`.
|
|
62
|
+
* @param inputs - The path, whether Y is negated, the curve tolerance and whether only cubics are written
|
|
63
|
+
* @returns SVG path data
|
|
64
|
+
* @group svg
|
|
65
|
+
* @shortname path data
|
|
66
|
+
* @drawable false
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
|
|
70
|
+
* const data = bitbybit.io.svg.pathData({ path: { segments: [slot] }, flipY: false });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
pathData(inputs) {
|
|
74
|
+
const resolved = resolveDto(Inputs.IO.SvgPathDataDto, inputs);
|
|
75
|
+
const tolerance = positiveNumber(resolved.tolerance, "tolerance");
|
|
76
|
+
return pathDataOf(drawingPathOf(resolved.path, "path"), { flipY: resolved.flipY, cubicsOnly: resolved.cubicsOnly, tolerance, property: "path" });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reads an SVG file into path parts by layer, color and line type.
|
|
80
|
+
*
|
|
81
|
+
* Lines, arcs and Bezier curves are read exactly, transforms applied, Y up. Inkscape
|
|
82
|
+
* layers are layers, each stroke color (else fill) a color, each dash pattern a line type. Text
|
|
83
|
+
* and images are left out, named in `warnings`; `svgCreate`'s texts and hatches return as paths.
|
|
84
|
+
* @param inputs - The SVG text, the unit to read it in and whether hidden elements are read
|
|
85
|
+
* @returns The drawing's parts, unit, view box and warnings
|
|
86
|
+
* @group svg
|
|
87
|
+
* @shortname svg read
|
|
88
|
+
* @drawable false
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const drawing = bitbybit.io.svg.svgRead({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
92
|
+
* const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: drawing.parts, unit: drawing.unit });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
svgRead(inputs) {
|
|
96
|
+
const resolved = resolveDto(Inputs.IO.SvgReadDto, inputs);
|
|
97
|
+
if (typeof resolved.svg !== "string") {
|
|
98
|
+
throw new InputError(`\`svg\` must be the text of an SVG file; it is ${typeof resolved.svg}.`, "svg");
|
|
99
|
+
}
|
|
100
|
+
if (resolved.unit !== undefined) {
|
|
101
|
+
checkedUnitOfLength(resolved.unit, "unit");
|
|
102
|
+
}
|
|
103
|
+
return readSvgDrawing(resolved.svg, { unit: resolved.unit, includeInvisible: resolved.includeInvisible === true });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -46,6 +46,23 @@ export declare class Line {
|
|
|
46
46
|
* @drawable false
|
|
47
47
|
*/
|
|
48
48
|
length(inputs: Inputs.Line.LineDto): number;
|
|
49
|
+
/**
|
|
50
|
+
* Measures how far a point lies from a line, to the nearest point between its start and end.
|
|
51
|
+
*
|
|
52
|
+
* A point beside the line is measured square to it, and one past either end to that end. A line
|
|
53
|
+
* whose ends meet is measured to that one point.
|
|
54
|
+
* @param inputs - The line and the point
|
|
55
|
+
* @returns Distance in model units
|
|
56
|
+
* @group get
|
|
57
|
+
* @shortname distance to point
|
|
58
|
+
* @drawable false
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const beside = bitbybit.line.distanceToPoint({ line: { start: [0, 0, 0], end: [10, 0, 0] }, point: [4, 3, 0] });
|
|
62
|
+
* const pastTheEnd = bitbybit.line.distanceToPoint({ line: { start: [0, 0, 0], end: [10, 0, 0] }, point: [13, 4, 0] });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
distanceToPoint(inputs: Inputs.Line.LinePointDistanceDto): number;
|
|
49
66
|
/**
|
|
50
67
|
* Swaps the start and end of a line, so it runs the other way.
|
|
51
68
|
*
|
package/lib/api/services/line.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { resolveDto } from "../kernel-calls";
|
|
3
|
-
import { add3, scale3, subtract3 } from "./helpers/geometry/vectors";
|
|
3
|
+
import { add3, distanceToSegment3, scale3, subtract3 } from "./helpers/geometry/vectors";
|
|
4
4
|
/**
|
|
5
5
|
* Straight lines between two points, held as plain objects of the form `{ start, end }`, and the
|
|
6
6
|
* segment form `[start, end]` of the same thing. The methods here build lines, measure and
|
|
@@ -52,6 +52,25 @@ export class Line {
|
|
|
52
52
|
length(inputs) {
|
|
53
53
|
return this.point.distance({ startPoint: inputs.line.start, endPoint: inputs.line.end });
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Measures how far a point lies from a line, to the nearest point between its start and end.
|
|
57
|
+
*
|
|
58
|
+
* A point beside the line is measured square to it, and one past either end to that end. A line
|
|
59
|
+
* whose ends meet is measured to that one point.
|
|
60
|
+
* @param inputs - The line and the point
|
|
61
|
+
* @returns Distance in model units
|
|
62
|
+
* @group get
|
|
63
|
+
* @shortname distance to point
|
|
64
|
+
* @drawable false
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const beside = bitbybit.line.distanceToPoint({ line: { start: [0, 0, 0], end: [10, 0, 0] }, point: [4, 3, 0] });
|
|
68
|
+
* const pastTheEnd = bitbybit.line.distanceToPoint({ line: { start: [0, 0, 0], end: [10, 0, 0] }, point: [13, 4, 0] });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
distanceToPoint(inputs) {
|
|
72
|
+
return distanceToSegment3(inputs.point, inputs.line.start, inputs.line.end);
|
|
73
|
+
}
|
|
55
74
|
/**
|
|
56
75
|
* Swaps the start and end of a line, so it runs the other way.
|
|
57
76
|
*
|
|
@@ -154,6 +154,25 @@ export declare class MeshBitByBit {
|
|
|
154
154
|
* ```
|
|
155
155
|
*/
|
|
156
156
|
triangulatePolygon(inputs: Inputs.Mesh.PolygonWithHolesDto): Inputs.Base.Mesh3;
|
|
157
|
+
/**
|
|
158
|
+
* Fills closed loops lying in one plane with triangles, as letters are filled.
|
|
159
|
+
*
|
|
160
|
+
* Outlines and holes come from how the loops nest, in any order or direction; under the default
|
|
161
|
+
* even-odd rule the middle of an `O` stays open.
|
|
162
|
+
* Example: a 4 by 4 square around a 2 by 2 square -> a ring of area 12
|
|
163
|
+
* @param inputs - The loops and the fill rule
|
|
164
|
+
* @returns The triangles, each three points
|
|
165
|
+
* @group polygon
|
|
166
|
+
* @shortname triangulate loops
|
|
167
|
+
* @drawable false
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const outer = [[-2, -2, 0], [2, -2, 0], [2, 2, 0], [-2, 2, 0]];
|
|
171
|
+
* const inner = [[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]];
|
|
172
|
+
* const ring = bitbybit.mesh.triangulateLoops({ loops: [outer, inner], fillRule: Bit.Inputs.Base.loopFillRuleEnum.evenOdd });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
triangulateLoops(inputs: Inputs.Mesh.TriangulateLoopsDto): Inputs.Base.Mesh3;
|
|
157
176
|
/**
|
|
158
177
|
* Measures the volume a closed triangle mesh encloses, with a sign: positive when its triangles
|
|
159
178
|
* face outwards by the right-hand rule, negative when they all face inwards.
|
package/lib/api/services/mesh.js
CHANGED
|
@@ -3,6 +3,7 @@ import { InputError, resolveDto } from "../kernel-calls";
|
|
|
3
3
|
import { signedVolumeOf } from "./helpers/mesh/mesh-measures";
|
|
4
4
|
import { closestOnTriangle, pointInTree, treesNested, treesWithin, triangleTree } from "./helpers/mesh/mesh-proximity";
|
|
5
5
|
import { triangulateFace } from "./helpers/geometry/triangulation";
|
|
6
|
+
import { filledLoopTriangles } from "./helpers/geometry/loop-fill";
|
|
6
7
|
import { frustum, icosphere } from "./helpers/mesh/mesh-primitives";
|
|
7
8
|
import { axesAlong, isTriple, pointToWorld } from "./helpers/geometry/frame-axes";
|
|
8
9
|
import { add3, scale3 } from "./helpers/geometry/vectors";
|
|
@@ -10,6 +11,10 @@ import { computeVertexNormals, creasedVertices } from "./helpers/mesh/mesh-norma
|
|
|
10
11
|
import { windingComponents, windingRepairs } from "./helpers/mesh/mesh-orientation";
|
|
11
12
|
import { uniqueVectors } from "./helpers/geometry/vector-grid";
|
|
12
13
|
const TRIANGLE_CORNERS = 3;
|
|
14
|
+
const LOOP_FILL_RULES = {
|
|
15
|
+
[Inputs.Base.loopFillRuleEnum.evenOdd]: "evenOdd",
|
|
16
|
+
[Inputs.Base.loopFillRuleEnum.nonZero]: "nonzero",
|
|
17
|
+
};
|
|
13
18
|
const MAX_ICOSPHERE_DETAIL = 6;
|
|
14
19
|
const MIN_FRUSTUM_SIDES = 3;
|
|
15
20
|
const POINT_SIZE = 3;
|
|
@@ -385,6 +390,41 @@ export class MeshBitByBit {
|
|
|
385
390
|
}
|
|
386
391
|
return mesh;
|
|
387
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Fills closed loops lying in one plane with triangles, as letters are filled.
|
|
395
|
+
*
|
|
396
|
+
* Outlines and holes come from how the loops nest, in any order or direction; under the default
|
|
397
|
+
* even-odd rule the middle of an `O` stays open.
|
|
398
|
+
* Example: a 4 by 4 square around a 2 by 2 square -> a ring of area 12
|
|
399
|
+
* @param inputs - The loops and the fill rule
|
|
400
|
+
* @returns The triangles, each three points
|
|
401
|
+
* @group polygon
|
|
402
|
+
* @shortname triangulate loops
|
|
403
|
+
* @drawable false
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const outer = [[-2, -2, 0], [2, -2, 0], [2, 2, 0], [-2, 2, 0]];
|
|
407
|
+
* const inner = [[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]];
|
|
408
|
+
* const ring = bitbybit.mesh.triangulateLoops({ loops: [outer, inner], fillRule: Bit.Inputs.Base.loopFillRuleEnum.evenOdd });
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
triangulateLoops(inputs) {
|
|
412
|
+
const resolved = resolveDto(Inputs.Mesh.TriangulateLoopsDto, inputs);
|
|
413
|
+
const corners = resolved.loops.flat();
|
|
414
|
+
const positions = corners.flat();
|
|
415
|
+
let next = 0;
|
|
416
|
+
const loops = resolved.loops.map((loop) => loop.map(() => next++));
|
|
417
|
+
const rule = LOOP_FILL_RULES[resolved.fillRule];
|
|
418
|
+
if (rule === undefined) {
|
|
419
|
+
throw new InputError(`\`fillRule\` is ${String(resolved.fillRule)}, which is none of ${Object.keys(LOOP_FILL_RULES).join(", ")}.`, "fillRule");
|
|
420
|
+
}
|
|
421
|
+
const triangles = filledLoopTriangles(positions, loops, rule);
|
|
422
|
+
const mesh = [];
|
|
423
|
+
for (let at = 0; at + 2 < triangles.length; at += TRIANGLE_CORNERS) {
|
|
424
|
+
mesh.push([[...corners[triangles[at]]], [...corners[triangles[at + 1]]], [...corners[triangles[at + 2]]]]);
|
|
425
|
+
}
|
|
426
|
+
return mesh;
|
|
427
|
+
}
|
|
388
428
|
/**
|
|
389
429
|
* Measures the volume a closed triangle mesh encloses, with a sign: positive when its triangles
|
|
390
430
|
* face outwards by the right-hand rule, negative when they all face inwards.
|
|
@@ -4,6 +4,7 @@ import type { Transforms } from "./transforms";
|
|
|
4
4
|
import type { Vector } from "./vector";
|
|
5
5
|
import type * as Models from "../models";
|
|
6
6
|
import type { Lists } from "./lists";
|
|
7
|
+
import type { BitbybitSettings } from "../kernel-calls/settings";
|
|
7
8
|
/**
|
|
8
9
|
* Points as plain number arrays. A point is `[x, y, z]` with Y pointing up, the same shape as a
|
|
9
10
|
* vector, so the two can be passed to each other's methods; a 2D point is `[x, y]`. Every method
|
|
@@ -15,7 +16,9 @@ export declare class Point {
|
|
|
15
16
|
private readonly transforms;
|
|
16
17
|
private readonly vector;
|
|
17
18
|
private readonly lists;
|
|
18
|
-
|
|
19
|
+
private readonly settings;
|
|
20
|
+
constructor(geometryHelper: GeometryHelper, transforms: Transforms, vector: Vector, lists: Lists, settings?: () => BitbybitSettings);
|
|
21
|
+
private onGround;
|
|
19
22
|
/**
|
|
20
23
|
* Applies a transformation matrix, or a list of them in order, to one point.
|
|
21
24
|
*
|
|
@@ -2,6 +2,7 @@ import * as Inputs from "../inputs";
|
|
|
2
2
|
import { InputError, resolveDto } from "../kernel-calls";
|
|
3
3
|
import { arcThroughThreePoints, pointsOnArc } from "./helpers/geometry/arcs";
|
|
4
4
|
import { add3, length3, scale3, subtract3 } from "./helpers/geometry/vectors";
|
|
5
|
+
import { pointOnGround } from "./helpers/files/ground-axes";
|
|
5
6
|
/**
|
|
6
7
|
* Points as plain number arrays. A point is `[x, y, z]` with Y pointing up, the same shape as a
|
|
7
8
|
* vector, so the two can be passed to each other's methods; a 2D point is `[x, y]`. Every method
|
|
@@ -9,11 +10,15 @@ import { add3, length3, scale3, subtract3 } from "./helpers/geometry/vectors";
|
|
|
9
10
|
* model units.
|
|
10
11
|
*/
|
|
11
12
|
export class Point {
|
|
12
|
-
constructor(geometryHelper, transforms, vector, lists) {
|
|
13
|
+
constructor(geometryHelper, transforms, vector, lists, settings = () => ({})) {
|
|
13
14
|
this.geometryHelper = geometryHelper;
|
|
14
15
|
this.transforms = transforms;
|
|
15
16
|
this.vector = vector;
|
|
16
17
|
this.lists = lists;
|
|
18
|
+
this.settings = settings;
|
|
19
|
+
}
|
|
20
|
+
onGround(x, y) {
|
|
21
|
+
return pointOnGround(x, y, this.settings().coordinateSystem);
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* Applies a transformation matrix, or a list of them in order, to one point.
|
|
@@ -541,7 +546,7 @@ export class Point {
|
|
|
541
546
|
}
|
|
542
547
|
if (resolved.pointsOnGround) {
|
|
543
548
|
points.forEach((p, index) => {
|
|
544
|
-
points[index] =
|
|
549
|
+
points[index] = this.onGround(p[0], p[1]);
|
|
545
550
|
});
|
|
546
551
|
}
|
|
547
552
|
return points;
|
|
@@ -799,11 +804,11 @@ export class Point {
|
|
|
799
804
|
}
|
|
800
805
|
if (pointsOnGround) {
|
|
801
806
|
for (let i = 0; i < scaledCenters.length; i++) {
|
|
802
|
-
scaledCenters[i] =
|
|
807
|
+
scaledCenters[i] = this.onGround(scaledCenters[i][0], scaledCenters[i][1]);
|
|
803
808
|
}
|
|
804
809
|
for (let i = 0; i < scaledHexagons.length; i++) {
|
|
805
810
|
for (let j = 0; j < scaledHexagons[i].length; j++) {
|
|
806
|
-
scaledHexagons[i][j] =
|
|
811
|
+
scaledHexagons[i][j] = this.onGround(scaledHexagons[i][j][0], scaledHexagons[i][j][1]);
|
|
807
812
|
}
|
|
808
813
|
}
|
|
809
814
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
|
+
import type { BitbybitSettings } from "../kernel-calls/settings";
|
|
2
3
|
import type { RecipeIssue, RecipeSource, RecipeSurfaceMesh } from "../recipes/recipe-types";
|
|
3
4
|
/**
|
|
4
5
|
* Recipes with no CAD kernel needed: solids described as a list of steps that `occt.recipes` and
|
|
@@ -8,6 +9,8 @@ import type { RecipeIssue, RecipeSource, RecipeSurfaceMesh } from "../recipes/re
|
|
|
8
9
|
* @beta
|
|
9
10
|
*/
|
|
10
11
|
export declare class Recipes {
|
|
12
|
+
private readonly settings;
|
|
13
|
+
constructor(settings?: () => BitbybitSettings);
|
|
11
14
|
/**
|
|
12
15
|
* Checks a value against the recipe format and lists what is wrong with it: steps that refer
|
|
13
16
|
* forward or out of range, ranges outside their buffers, coordinates that are not finite or
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
|
-
import { InputError, resolveDto } from "../kernel-calls";
|
|
2
|
+
import { InputError, checkedUpAxis, resolveDto } from "../kernel-calls";
|
|
3
3
|
import { checkRecipe, toRecipe } from "../recipes/validate";
|
|
4
4
|
import { recipeSurfaceMeshes } from "../recipes/surface-mesh";
|
|
5
5
|
import { recipeSourceOf } from "../recipes/sources";
|
|
@@ -13,6 +13,9 @@ import { isTransformMatrix } from "./helpers/geometry/matrices";
|
|
|
13
13
|
* @beta
|
|
14
14
|
*/
|
|
15
15
|
export class Recipes {
|
|
16
|
+
constructor(settings = () => ({})) {
|
|
17
|
+
this.settings = settings;
|
|
18
|
+
}
|
|
16
19
|
/**
|
|
17
20
|
* Checks a value against the recipe format and lists what is wrong with it: steps that refer
|
|
18
21
|
* forward or out of range, ranges outside their buffers, coordinates that are not finite or
|
|
@@ -71,7 +74,8 @@ export class Recipes {
|
|
|
71
74
|
*/
|
|
72
75
|
surfaceMeshes(inputs) {
|
|
73
76
|
const resolved = resolveDto(Inputs.Recipes.RecipeSurfaceMeshesDto, inputs);
|
|
74
|
-
|
|
77
|
+
const upAxis = checkedUpAxis(resolved.upAxis, [Inputs.Base.upAxisConversionEnum.keep, Inputs.Base.upAxisConversionEnum.zUpToYUp]);
|
|
78
|
+
return recipeSurfaceMeshes(resolved.recipe, resolved.roots, upAxis === Inputs.Base.upAxisConversionEnum.zUpToYUp, this.settings().coordinateSystem);
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
81
|
* Follows a node through the transforms that only turn and move to the step it places, folding
|