@bitbybit-dev/base 1.6.1 → 1.7.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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +36 -7
- package/lib/api/inputs/base-inputs.js +10 -0
- package/lib/api/inputs/color-inputs.d.ts +54 -1
- package/lib/api/inputs/color-inputs.js +73 -1
- package/lib/api/inputs/frame-inputs.d.ts +2 -1
- package/lib/api/inputs/frame-inputs.js +2 -1
- package/lib/api/inputs/io-inputs.d.ts +527 -59
- package/lib/api/inputs/io-inputs.js +432 -40
- package/lib/api/inputs/line-inputs.d.ts +17 -0
- package/lib/api/inputs/line-inputs.js +15 -0
- package/lib/api/inputs/math-inputs.d.ts +62 -0
- package/lib/api/inputs/math-inputs.js +82 -0
- package/lib/api/inputs/mesh-inputs.d.ts +16 -0
- package/lib/api/inputs/mesh-inputs.js +14 -0
- package/lib/api/inputs/transforms-inputs.d.ts +76 -0
- package/lib/api/inputs/transforms-inputs.js +85 -0
- package/lib/api/kernel-calls/index.d.ts +1 -0
- package/lib/api/kernel-calls/index.js +1 -0
- package/lib/api/kernel-calls/settings.d.ts +82 -0
- package/lib/api/kernel-calls/settings.js +123 -0
- 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 -2
- package/lib/api/services/base-bitbybit.d.ts +12 -0
- package/lib/api/services/base-bitbybit.js +19 -3
- package/lib/api/services/color.d.ts +36 -2
- package/lib/api/services/color.js +60 -11
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +10 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +10 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.js +27 -0
- 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 +24 -0
- package/lib/api/services/helpers/curves/conic-arcs.js +85 -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 +24 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +18 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +84 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +5 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.js +252 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +60 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.js +1 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +28 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +29 -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 +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +193 -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 +81 -523
- 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 +81 -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-types.d.ts +69 -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 +71 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +78 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +556 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +27 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +247 -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 +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +65 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +32 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +34 -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 +108 -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 +16 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +153 -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 +13 -0
- package/lib/api/services/helpers/files/svg/svg.constants.js +13 -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/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/quaternions.constants.d.ts +3 -0
- package/lib/api/services/helpers/geometry/quaternions.constants.js +3 -0
- package/lib/api/services/helpers/geometry/quaternions.d.ts +14 -0
- package/lib/api/services/helpers/geometry/quaternions.js +71 -0
- package/lib/api/services/helpers/geometry/scalars.constants.d.ts +1 -0
- package/lib/api/services/helpers/geometry/scalars.constants.js +1 -0
- package/lib/api/services/helpers/geometry/scalars.d.ts +3 -0
- package/lib/api/services/helpers/geometry/scalars.js +29 -1
- 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/mesh/mesh-proximity.constants.d.ts +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.js +40 -40
- package/lib/api/services/io/drawing.d.ts +170 -0
- package/lib/api/services/io/drawing.js +212 -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 +64 -0
- package/lib/api/services/io/svg.js +102 -0
- package/lib/api/services/line.d.ts +17 -0
- package/lib/api/services/line.js +20 -1
- package/lib/api/services/math.d.ts +35 -0
- package/lib/api/services/math.js +56 -1
- package/lib/api/services/mesh.d.ts +17 -0
- package/lib/api/services/mesh.js +27 -1
- 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 +4 -1
- package/lib/api/services/text.d.ts +4 -1
- package/lib/api/services/text.js +8 -3
- package/lib/api/services/transforms.d.ts +119 -1
- package/lib/api/services/transforms.js +158 -30
- 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 in the file's
|
|
150
|
+
* coordinates, block inserts expanded. Text, dimensions and hatches are left out and named in
|
|
151
|
+
* `warnings`; splines given only by fit points are read by `occt.io.loadDxf`.
|
|
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));
|
|
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,64 @@
|
|
|
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. Reads SVG files back into
|
|
5
|
+
* those parts, by layer, color and line type.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Svg {
|
|
8
|
+
/**
|
|
9
|
+
* Writes an SVG file from path parts, each layer an Inkscape layer.
|
|
10
|
+
*
|
|
11
|
+
* Arcs, circles, ellipses and bulges stay exact arcs, unweighted splines up to degree 3 exact
|
|
12
|
+
* Beziers, others cubics within `tolerance` (at least a millionth of the drawing). Y points up, Z
|
|
13
|
+
* is dropped and `unit` gives the true size. A drawing too large to write throws.
|
|
14
|
+
* @param inputs - The path parts, the unit, the line width, the border and the curve tolerance
|
|
15
|
+
* @returns The SVG file as text
|
|
16
|
+
* @group svg
|
|
17
|
+
* @shortname svg create
|
|
18
|
+
* @drawable false
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
22
|
+
* const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
23
|
+
* const part = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }, { segments: [hole] }] });
|
|
24
|
+
* const svg = bitbybit.io.svg.svgCreate({ parts: [part], unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
svgCreate(inputs: Inputs.IO.SvgModelDto): string;
|
|
28
|
+
/**
|
|
29
|
+
* Writes one drawing path as SVG path data, the text of a `path` element's `d` attribute.
|
|
30
|
+
*
|
|
31
|
+
* Segments that meet are drawn as one stroke, reversed where a segment ends where the stroke is,
|
|
32
|
+
* and a stroke that returns to its start is closed. Curves are kept exact as `svgCreate` keeps
|
|
33
|
+
* them.
|
|
34
|
+
* @param inputs - The path, whether Y is negated, and the curve tolerance
|
|
35
|
+
* @returns SVG path data
|
|
36
|
+
* @group svg
|
|
37
|
+
* @shortname path data
|
|
38
|
+
* @drawable false
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
|
|
42
|
+
* const data = bitbybit.io.svg.pathData({ path: { segments: [slot] }, flipY: false });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
pathData(inputs: Inputs.IO.SvgPathDataDto): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reads an SVG file into path parts by layer, color and line type, the model `svgCreate` writes.
|
|
48
|
+
*
|
|
49
|
+
* Lines, arcs and Bezier curves are read exactly, transforms applied and Y turned up. Inkscape
|
|
50
|
+
* layers are layers, each stroke color (else fill) a color, each dash pattern a line type. Text
|
|
51
|
+
* and images are left out and named in `warnings`.
|
|
52
|
+
* @param inputs - The SVG text, the unit to read it in and whether hidden elements are read
|
|
53
|
+
* @returns The drawing's parts, unit, view box and warnings
|
|
54
|
+
* @group svg
|
|
55
|
+
* @shortname svg read
|
|
56
|
+
* @drawable false
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const drawing = bitbybit.io.svg.svgRead({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
60
|
+
* const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: drawing.parts, unit: drawing.unit });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
svgRead(inputs: Inputs.IO.SvgReadDto): Inputs.IO.SvgDrawingDto;
|
|
64
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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. Reads SVG files back into
|
|
19
|
+
* those parts, by layer, color and line type.
|
|
20
|
+
*/
|
|
21
|
+
export class Svg {
|
|
22
|
+
/**
|
|
23
|
+
* Writes an SVG file from path parts, each layer an Inkscape layer.
|
|
24
|
+
*
|
|
25
|
+
* Arcs, circles, ellipses and bulges stay exact arcs, unweighted splines up to degree 3 exact
|
|
26
|
+
* Beziers, others cubics within `tolerance` (at least a millionth of the drawing). Y points up, Z
|
|
27
|
+
* is dropped and `unit` gives the true size. A drawing too large to write throws.
|
|
28
|
+
* @param inputs - The path parts, the unit, the line width, the border and the curve tolerance
|
|
29
|
+
* @returns The SVG file as text
|
|
30
|
+
* @group svg
|
|
31
|
+
* @shortname svg create
|
|
32
|
+
* @drawable false
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
36
|
+
* const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
37
|
+
* const part = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }, { segments: [hole] }] });
|
|
38
|
+
* const svg = bitbybit.io.svg.svgCreate({ parts: [part], unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
svgCreate(inputs) {
|
|
42
|
+
const resolved = resolveDto(Inputs.IO.SvgModelDto, inputs);
|
|
43
|
+
const tolerance = positiveNumber(resolved.tolerance, "tolerance");
|
|
44
|
+
const unit = resolved.unit === undefined ? undefined : checkedUnitOfLength(resolved.unit, "unit");
|
|
45
|
+
return svgDocumentOf(drawingPartsOf(resolved.parts, "parts"), {
|
|
46
|
+
unit,
|
|
47
|
+
strokeWidth: resolved.strokeWidth === undefined ? undefined : positiveNumber(resolved.strokeWidth, "strokeWidth"),
|
|
48
|
+
margin: marginOf(resolved.margin),
|
|
49
|
+
tolerance,
|
|
50
|
+
property: "parts",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Writes one drawing path as SVG path data, the text of a `path` element's `d` attribute.
|
|
55
|
+
*
|
|
56
|
+
* Segments that meet are drawn as one stroke, reversed where a segment ends where the stroke is,
|
|
57
|
+
* and a stroke that returns to its start is closed. Curves are kept exact as `svgCreate` keeps
|
|
58
|
+
* them.
|
|
59
|
+
* @param inputs - The path, whether Y is negated, and the curve tolerance
|
|
60
|
+
* @returns SVG path data
|
|
61
|
+
* @group svg
|
|
62
|
+
* @shortname path data
|
|
63
|
+
* @drawable false
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
|
|
67
|
+
* const data = bitbybit.io.svg.pathData({ path: { segments: [slot] }, flipY: false });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
pathData(inputs) {
|
|
71
|
+
const resolved = resolveDto(Inputs.IO.SvgPathDataDto, inputs);
|
|
72
|
+
const tolerance = positiveNumber(resolved.tolerance, "tolerance");
|
|
73
|
+
return pathDataOf(drawingPathOf(resolved.path, "path"), { flipY: resolved.flipY, tolerance, property: "path" });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Reads an SVG file into path parts by layer, color and line type, the model `svgCreate` writes.
|
|
77
|
+
*
|
|
78
|
+
* Lines, arcs and Bezier curves are read exactly, transforms applied and Y turned up. Inkscape
|
|
79
|
+
* layers are layers, each stroke color (else fill) a color, each dash pattern a line type. Text
|
|
80
|
+
* and images are left out and named in `warnings`.
|
|
81
|
+
* @param inputs - The SVG text, the unit to read it in and whether hidden elements are read
|
|
82
|
+
* @returns The drawing's parts, unit, view box and warnings
|
|
83
|
+
* @group svg
|
|
84
|
+
* @shortname svg read
|
|
85
|
+
* @drawable false
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const drawing = bitbybit.io.svg.svgRead({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
89
|
+
* const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: drawing.parts, unit: drawing.unit });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
svgRead(inputs) {
|
|
93
|
+
const resolved = resolveDto(Inputs.IO.SvgReadDto, inputs);
|
|
94
|
+
if (typeof resolved.svg !== "string") {
|
|
95
|
+
throw new InputError(`\`svg\` must be the text of an SVG file; it is ${typeof resolved.svg}.`, "svg");
|
|
96
|
+
}
|
|
97
|
+
if (resolved.unit !== undefined) {
|
|
98
|
+
checkedUnitOfLength(resolved.unit, "unit");
|
|
99
|
+
}
|
|
100
|
+
return readSvgDrawing(resolved.svg, { unit: resolved.unit, includeInvisible: resolved.includeInvisible === true });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -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
|
*
|
|
@@ -55,6 +55,7 @@ export declare class MathBitByBit {
|
|
|
55
55
|
/**
|
|
56
56
|
* Rounds a number to a given number of decimal places.
|
|
57
57
|
*
|
|
58
|
+
* A small negative number rounds to 0, never to -0.
|
|
58
59
|
* Example: 1.32156 to 3 places -> 1.322
|
|
59
60
|
* @param inputs - The number and how many decimal places to keep
|
|
60
61
|
* @returns The rounded number
|
|
@@ -654,6 +655,40 @@ export declare class MathBitByBit {
|
|
|
654
655
|
* ```
|
|
655
656
|
*/
|
|
656
657
|
moveTowards(inputs: Inputs.Math.MoveTowardsDto): number;
|
|
658
|
+
/**
|
|
659
|
+
* Gives the angle that `to` names, whole turns aside, nearest to `from`, so going from `from` to
|
|
660
|
+
* it is the short way round.
|
|
661
|
+
*
|
|
662
|
+
* Animating an angle toward the result never spins the long way. `fullTurn` sets the unit.
|
|
663
|
+
* Example: 10 to 350 in degrees -> -10, 350 to 10 -> 370
|
|
664
|
+
* @param inputs - The two angles and the size of a whole turn
|
|
665
|
+
* @returns The angle to arrive at, at most half a turn from `from`
|
|
666
|
+
* @group operations
|
|
667
|
+
* @shortname shortest angle
|
|
668
|
+
* @drawable false
|
|
669
|
+
* @example
|
|
670
|
+
* ```typescript
|
|
671
|
+
* const target = bitbybit.math.shortestAngle({ from: 10, to: 350, fullTurn: 360 });
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
shortestAngle(inputs: Inputs.Math.ShortestAngleDto): number;
|
|
675
|
+
/**
|
|
676
|
+
* Rounds a positive number to a step on the 1, 2, 5 scale - 0.1, 0.2, 0.5, 1, 2, 5, 10 - the
|
|
677
|
+
* sizes a grid, a ruler or a slider reads well in.
|
|
678
|
+
*
|
|
679
|
+
* A number within a billionth of a step counts as that step.
|
|
680
|
+
* Example: 0.37 up -> 0.5, down -> 0.2, nearest -> 0.5
|
|
681
|
+
* @param inputs - The number and which way to round it
|
|
682
|
+
* @returns The step
|
|
683
|
+
* @group operations
|
|
684
|
+
* @shortname nice step
|
|
685
|
+
* @drawable false
|
|
686
|
+
* @example
|
|
687
|
+
* ```typescript
|
|
688
|
+
* const step = bitbybit.math.niceStep({ number: 0.37, direction: Bit.Inputs.Math.niceStepDirectionEnum.up });
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
niceStep(inputs: Inputs.Math.NiceStepDto): number;
|
|
657
692
|
/**
|
|
658
693
|
* Works out a simple arithmetic expression written as text: numbers, +, -, the multiplication
|
|
659
694
|
* sign, /, parentheses and spaces.
|
package/lib/api/services/math.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { resolveDto } from "../kernel-calls";
|
|
3
|
-
import { degreesOf, fractionOf, fractionText, interpolated, radiansOf, roundedTo, smoothstep } from "./helpers/geometry/scalars";
|
|
3
|
+
import { degreesOf, fractionOf, fractionText, interpolated, niceStep, radiansOf, roundedTo, shortestAngle, smoothstep } from "./helpers/geometry/scalars";
|
|
4
4
|
import { InputError } from "../kernel-calls/errors";
|
|
5
5
|
import { checkedUnitOfLength, lengthConverted, millimetresPerUnitOf } from "./helpers/geometry/lengths";
|
|
6
6
|
/**
|
|
@@ -91,6 +91,7 @@ export class MathBitByBit {
|
|
|
91
91
|
/**
|
|
92
92
|
* Rounds a number to a given number of decimal places.
|
|
93
93
|
*
|
|
94
|
+
* A small negative number rounds to 0, never to -0.
|
|
94
95
|
* Example: 1.32156 to 3 places -> 1.322
|
|
95
96
|
* @param inputs - The number and how many decimal places to keep
|
|
96
97
|
* @returns The rounded number
|
|
@@ -917,6 +918,60 @@ export class MathBitByBit {
|
|
|
917
918
|
}
|
|
918
919
|
return resolved.current + Math.sign(delta) * resolved.maxDelta;
|
|
919
920
|
}
|
|
921
|
+
/**
|
|
922
|
+
* Gives the angle that `to` names, whole turns aside, nearest to `from`, so going from `from` to
|
|
923
|
+
* it is the short way round.
|
|
924
|
+
*
|
|
925
|
+
* Animating an angle toward the result never spins the long way. `fullTurn` sets the unit.
|
|
926
|
+
* Example: 10 to 350 in degrees -> -10, 350 to 10 -> 370
|
|
927
|
+
* @param inputs - The two angles and the size of a whole turn
|
|
928
|
+
* @returns The angle to arrive at, at most half a turn from `from`
|
|
929
|
+
* @group operations
|
|
930
|
+
* @shortname shortest angle
|
|
931
|
+
* @drawable false
|
|
932
|
+
* @example
|
|
933
|
+
* ```typescript
|
|
934
|
+
* const target = bitbybit.math.shortestAngle({ from: 10, to: 350, fullTurn: 360 });
|
|
935
|
+
* ```
|
|
936
|
+
*/
|
|
937
|
+
shortestAngle(inputs) {
|
|
938
|
+
const resolved = resolveDto(Inputs.Math.ShortestAngleDto, inputs);
|
|
939
|
+
if (!(resolved.fullTurn > 0 && Number.isFinite(resolved.fullTurn))) {
|
|
940
|
+
throw new InputError(`\`fullTurn\` is ${String(resolved.fullTurn)}, and has to be a positive finite number.`, "fullTurn");
|
|
941
|
+
}
|
|
942
|
+
const notFinite = ["from", "to"].find(name => !Number.isFinite(resolved[name]));
|
|
943
|
+
if (notFinite !== undefined) {
|
|
944
|
+
throw new InputError(`\`${notFinite}\` is ${String(resolved[notFinite])}, not a finite number.`, notFinite);
|
|
945
|
+
}
|
|
946
|
+
return shortestAngle(resolved.from, resolved.to, resolved.fullTurn);
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Rounds a positive number to a step on the 1, 2, 5 scale - 0.1, 0.2, 0.5, 1, 2, 5, 10 - the
|
|
950
|
+
* sizes a grid, a ruler or a slider reads well in.
|
|
951
|
+
*
|
|
952
|
+
* A number within a billionth of a step counts as that step.
|
|
953
|
+
* Example: 0.37 up -> 0.5, down -> 0.2, nearest -> 0.5
|
|
954
|
+
* @param inputs - The number and which way to round it
|
|
955
|
+
* @returns The step
|
|
956
|
+
* @group operations
|
|
957
|
+
* @shortname nice step
|
|
958
|
+
* @drawable false
|
|
959
|
+
* @example
|
|
960
|
+
* ```typescript
|
|
961
|
+
* const step = bitbybit.math.niceStep({ number: 0.37, direction: Bit.Inputs.Math.niceStepDirectionEnum.up });
|
|
962
|
+
* ```
|
|
963
|
+
*/
|
|
964
|
+
niceStep(inputs) {
|
|
965
|
+
const resolved = resolveDto(Inputs.Math.NiceStepDto, inputs);
|
|
966
|
+
if (!(resolved.number > 0 && Number.isFinite(resolved.number))) {
|
|
967
|
+
throw new InputError(`\`number\` is ${String(resolved.number)}, and has to be a positive finite number.`, "number");
|
|
968
|
+
}
|
|
969
|
+
const step = niceStep(resolved.number, resolved.direction);
|
|
970
|
+
if (!Number.isFinite(step)) {
|
|
971
|
+
throw new InputError(`\`number\` is ${String(resolved.number)}, too large to round to a step.`, "number");
|
|
972
|
+
}
|
|
973
|
+
return step;
|
|
974
|
+
}
|
|
920
975
|
/**
|
|
921
976
|
* Works out a simple arithmetic expression written as text: numbers, +, -, the multiplication
|
|
922
977
|
* sign, /, parentheses and spaces.
|
|
@@ -29,6 +29,23 @@ export declare class MeshBitByBit {
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
signedDistanceToPlane(inputs: Inputs.Mesh.SignedDistanceFromPlaneToPointDto): number;
|
|
32
|
+
/**
|
|
33
|
+
* Finds the point of a triangle nearest to another point, with the weight of each corner in it.
|
|
34
|
+
*
|
|
35
|
+
* Each corner times its weight, added up, gives the point; the weights add up to 1. Corners on one
|
|
36
|
+
* line act as the segment they span.
|
|
37
|
+
* Example: point [0.25,0.25,2] and triangle [[0,0,0], [1,0,0], [0,1,0]] -> { point: [0.25,0.25,0], weights: [0.5,0.25,0.25] }
|
|
38
|
+
* @param inputs - The point and the triangle
|
|
39
|
+
* @returns The nearest point and the weight of each corner in it
|
|
40
|
+
* @group traingle
|
|
41
|
+
* @shortname closest point on triangle
|
|
42
|
+
* @drawable false
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const nearest = bitbybit.mesh.closestPointOnTriangle({ point: [0.25, 0.25, 2], triangle: [[0, 0, 0], [1, 0, 0], [0, 1, 0]] });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
closestPointOnTriangle(inputs: Inputs.Mesh.PointTriangleDto): Inputs.Base.TrianglePoint3;
|
|
32
49
|
/**
|
|
33
50
|
* Finds the plane a triangle lies in: its unit normal and its distance from the origin along
|
|
34
51
|
* that normal.
|
package/lib/api/services/mesh.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { InputError, resolveDto } from "../kernel-calls";
|
|
3
3
|
import { signedVolumeOf } from "./helpers/mesh/mesh-measures";
|
|
4
|
-
import { pointInTree, treesNested, treesWithin, triangleTree } from "./helpers/mesh/mesh-proximity";
|
|
4
|
+
import { closestOnTriangle, pointInTree, treesNested, treesWithin, triangleTree } from "./helpers/mesh/mesh-proximity";
|
|
5
5
|
import { triangulateFace } from "./helpers/geometry/triangulation";
|
|
6
6
|
import { frustum, icosphere } from "./helpers/mesh/mesh-primitives";
|
|
7
7
|
import { axesAlong, isTriple, pointToWorld } from "./helpers/geometry/frame-axes";
|
|
@@ -80,6 +80,32 @@ export class MeshBitByBit {
|
|
|
80
80
|
signedDistanceToPlane(inputs) {
|
|
81
81
|
return this.vector.dot({ first: inputs.plane.normal, second: inputs.point }) - inputs.plane.d;
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Finds the point of a triangle nearest to another point, with the weight of each corner in it.
|
|
85
|
+
*
|
|
86
|
+
* Each corner times its weight, added up, gives the point; the weights add up to 1. Corners on one
|
|
87
|
+
* line act as the segment they span.
|
|
88
|
+
* Example: point [0.25,0.25,2] and triangle [[0,0,0], [1,0,0], [0,1,0]] -> { point: [0.25,0.25,0], weights: [0.5,0.25,0.25] }
|
|
89
|
+
* @param inputs - The point and the triangle
|
|
90
|
+
* @returns The nearest point and the weight of each corner in it
|
|
91
|
+
* @group traingle
|
|
92
|
+
* @shortname closest point on triangle
|
|
93
|
+
* @drawable false
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const nearest = bitbybit.mesh.closestPointOnTriangle({ point: [0.25, 0.25, 2], triangle: [[0, 0, 0], [1, 0, 0], [0, 1, 0]] });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
closestPointOnTriangle(inputs) {
|
|
100
|
+
if (!isTriple(inputs.point)) {
|
|
101
|
+
throw new InputError("`point` has to be three finite numbers.", "point");
|
|
102
|
+
}
|
|
103
|
+
if (!Array.isArray(inputs.triangle) || inputs.triangle.length !== TRIANGLE_CORNERS || !inputs.triangle.every(isTriple)) {
|
|
104
|
+
throw new InputError("`triangle` has to be three corners of three finite numbers each.", "triangle");
|
|
105
|
+
}
|
|
106
|
+
const [a, b, c] = inputs.triangle;
|
|
107
|
+
return closestOnTriangle(inputs.point, a, b, c);
|
|
108
|
+
}
|
|
83
109
|
/**
|
|
84
110
|
* Finds the plane a triangle lies in: its unit normal and its distance from the origin along
|
|
85
111
|
* that normal.
|
|
@@ -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
|
*
|