@bitbybit-dev/base 1.6.2 → 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 +20 -7
- package/lib/api/inputs/base-inputs.js +10 -0
- 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/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 +22 -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.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 +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/vectors.d.ts +1 -0
- package/lib/api/services/helpers/geometry/vectors.js +6 -0
- 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/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/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,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
|
*
|
|
@@ -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
|
|
@@ -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,7 @@ export class Recipes {
|
|
|
71
74
|
*/
|
|
72
75
|
surfaceMeshes(inputs) {
|
|
73
76
|
const resolved = resolveDto(Inputs.Recipes.RecipeSurfaceMeshesDto, inputs);
|
|
74
|
-
return recipeSurfaceMeshes(resolved.recipe, resolved.roots, resolved.adjustZtoY);
|
|
77
|
+
return recipeSurfaceMeshes(resolved.recipe, resolved.roots, resolved.adjustZtoY, this.settings().coordinateSystem);
|
|
75
78
|
}
|
|
76
79
|
/**
|
|
77
80
|
* Follows a node through the transforms that only turn and move to the step it places, folding
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import type * as Models from "../models";
|
|
3
3
|
import type { Point } from "./point";
|
|
4
|
+
import type { BitbybitSettings } from "../kernel-calls/settings";
|
|
4
5
|
/**
|
|
5
6
|
* Working with text: splitting, joining, searching, trimming, padding, changing case, regular
|
|
6
7
|
* expressions and formatting with placeholders. `vectorChar` and `vectorText` turn text into line
|
|
@@ -9,7 +10,8 @@ import type { Point } from "./point";
|
|
|
9
10
|
*/
|
|
10
11
|
export declare class TextBitByBit {
|
|
11
12
|
private readonly point;
|
|
12
|
-
|
|
13
|
+
private readonly settings;
|
|
14
|
+
constructor(point: Point, settings?: () => BitbybitSettings);
|
|
13
15
|
/**
|
|
14
16
|
* Passes a text through unchanged, so a value can be given a name and reused.
|
|
15
17
|
*
|
|
@@ -522,6 +524,7 @@ export declare class TextBitByBit {
|
|
|
522
524
|
* ```
|
|
523
525
|
*/
|
|
524
526
|
vectorText(inputs: Inputs.Text.VectorTextDto): Models.Text.VectorTextData[];
|
|
527
|
+
private onGround;
|
|
525
528
|
private vectorParamsChar;
|
|
526
529
|
private translateLine;
|
|
527
530
|
}
|
package/lib/api/services/text.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { defaultsVectorParams } from "../models/simplex";
|
|
3
3
|
import { resolveDto } from "../kernel-calls";
|
|
4
|
+
import { pointOnGround } from "./helpers/files/ground-axes";
|
|
4
5
|
/**
|
|
5
6
|
* Working with text: splitting, joining, searching, trimming, padding, changing case, regular
|
|
6
7
|
* expressions and formatting with placeholders. `vectorChar` and `vectorText` turn text into line
|
|
@@ -8,8 +9,9 @@ import { resolveDto } from "../kernel-calls";
|
|
|
8
9
|
* 0.
|
|
9
10
|
*/
|
|
10
11
|
export class TextBitByBit {
|
|
11
|
-
constructor(point) {
|
|
12
|
+
constructor(point, settings = () => ({})) {
|
|
12
13
|
this.point = point;
|
|
14
|
+
this.settings = settings;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Passes a text through unchanged, so a value can be given a name and reused.
|
|
@@ -630,7 +632,7 @@ export class TextBitByBit {
|
|
|
630
632
|
const gx = ratio * glyph[i] + xOffset;
|
|
631
633
|
const gy = ratio * glyph[i + 1] + yOffset + extrudeYOffset;
|
|
632
634
|
if (glyph[i] !== undefined) {
|
|
633
|
-
polyline.push(
|
|
635
|
+
polyline.push(this.onGround(gx, gy));
|
|
634
636
|
continue;
|
|
635
637
|
}
|
|
636
638
|
paths.push(polyline);
|
|
@@ -749,6 +751,9 @@ export class TextBitByBit {
|
|
|
749
751
|
}
|
|
750
752
|
return lines;
|
|
751
753
|
}
|
|
754
|
+
onGround(x, y) {
|
|
755
|
+
return pointOnGround(x, y, this.settings().coordinateSystem);
|
|
756
|
+
}
|
|
752
757
|
vectorParamsChar(inputs) {
|
|
753
758
|
const params = Object.assign({}, defaultsVectorParams, inputs);
|
|
754
759
|
params.input = inputs.char || params.char;
|
|
@@ -760,7 +765,7 @@ export class TextBitByBit {
|
|
|
760
765
|
vchar.paths = vchar.paths.map((path) => {
|
|
761
766
|
const pts = this.point.translatePoints({
|
|
762
767
|
points: path,
|
|
763
|
-
translation:
|
|
768
|
+
translation: this.onGround(x, y),
|
|
764
769
|
});
|
|
765
770
|
return pts;
|
|
766
771
|
});
|
package/package.json
CHANGED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import * as Inputs from "../../../../inputs";
|
|
2
|
-
export declare class Dxf {
|
|
3
|
-
private dxfGenerator;
|
|
4
|
-
/**
|
|
5
|
-
* Creates a line segment definition for DXF export (pass-through for validation).
|
|
6
|
-
* Example: start=[0,0], end=[10,5] → DXF line segment from origin to [10,5]
|
|
7
|
-
* @param inputs Line segment definition
|
|
8
|
-
* @returns Line segment DTO
|
|
9
|
-
* @group dxf
|
|
10
|
-
* @shortname line segment
|
|
11
|
-
* @drawable false
|
|
12
|
-
*/
|
|
13
|
-
lineSegment(inputs: Inputs.IO.DxfLineSegmentDto): Inputs.IO.DxfLineSegmentDto;
|
|
14
|
-
/**
|
|
15
|
-
* Creates an arc segment definition for DXF export (curved path between two points).
|
|
16
|
-
* Example: center=[5,5], radius=5, startAngle=0°, endAngle=90° → quarter circle arc
|
|
17
|
-
* @param inputs Arc segment definition
|
|
18
|
-
* @returns Arc segment DTO
|
|
19
|
-
* @group dxf
|
|
20
|
-
* @shortname arc segment
|
|
21
|
-
* @drawable false
|
|
22
|
-
*/
|
|
23
|
-
arcSegment(inputs: Inputs.IO.DxfArcSegmentDto): Inputs.IO.DxfArcSegmentDto;
|
|
24
|
-
/**
|
|
25
|
-
* Creates a circle segment definition for DXF export (closed circular path).
|
|
26
|
-
* Example: center=[10,10], radius=5 → full circle with diameter 10 centered at [10,10]
|
|
27
|
-
* @param inputs Circle segment definition
|
|
28
|
-
* @returns Circle segment DTO
|
|
29
|
-
* @group dxf
|
|
30
|
-
* @shortname circle segment
|
|
31
|
-
* @drawable false
|
|
32
|
-
*/
|
|
33
|
-
circleSegment(inputs: Inputs.IO.DxfCircleSegmentDto): Inputs.IO.DxfCircleSegmentDto;
|
|
34
|
-
/**
|
|
35
|
-
* Creates a polyline segment definition for DXF export (connected line segments through points).
|
|
36
|
-
* Example: points=[[0,0], [5,0], [5,5], [0,5]] → rectangular polyline path
|
|
37
|
-
* @param inputs Polyline segment definition
|
|
38
|
-
* @returns Polyline segment DTO
|
|
39
|
-
* @group dxf
|
|
40
|
-
* @shortname polyline segment
|
|
41
|
-
* @drawable false
|
|
42
|
-
*/
|
|
43
|
-
polylineSegment(inputs: Inputs.IO.DxfPolylineSegmentDto): Inputs.IO.DxfPolylineSegmentDto;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a spline segment definition for DXF export (smooth curve through control points).
|
|
46
|
-
* Example: controlPoints=[[0,0], [5,10], [10,0]] → smooth curved path through points
|
|
47
|
-
* @param inputs Spline segment definition
|
|
48
|
-
* @returns Spline segment DTO
|
|
49
|
-
* @group dxf
|
|
50
|
-
* @shortname spline segment
|
|
51
|
-
* @drawable false
|
|
52
|
-
*/
|
|
53
|
-
splineSegment(inputs: Inputs.IO.DxfSplineSegmentDto): Inputs.IO.DxfSplineSegmentDto;
|
|
54
|
-
/**
|
|
55
|
-
* Creates a path from multiple segments (combines lines, arcs, circles, polylines, splines).
|
|
56
|
-
* Similar to OCCT wires - segments are connected to form a continuous or multi-part path.
|
|
57
|
-
* Example: segments=[lineSegment, arcSegment, polylineSegment] → combined path entity
|
|
58
|
-
* @param inputs Path definition with segments
|
|
59
|
-
* @returns Path DTO
|
|
60
|
-
* @group dxf
|
|
61
|
-
* @shortname path
|
|
62
|
-
* @drawable false
|
|
63
|
-
*/
|
|
64
|
-
path(inputs: Inputs.IO.DxfPathDto): Inputs.IO.DxfPathDto;
|
|
65
|
-
/**
|
|
66
|
-
* Creates a paths part with layer and color assignment for DXF organization.
|
|
67
|
-
* Groups multiple paths into a single layer with consistent styling.
|
|
68
|
-
* Example: paths=[path1, path2], layer="Outlines", color=red → grouped geometry
|
|
69
|
-
* @param inputs Paths part definition
|
|
70
|
-
* @returns Paths part DTO
|
|
71
|
-
* @group dxf
|
|
72
|
-
* @shortname paths part
|
|
73
|
-
* @drawable false
|
|
74
|
-
*/
|
|
75
|
-
pathsPart(inputs: Inputs.IO.DxfPathsPartDto): Inputs.IO.DxfPathsPartDto;
|
|
76
|
-
/**
|
|
77
|
-
* Generates a complete DXF file from paths parts (exports 2D CAD drawing format).
|
|
78
|
-
* Supports lines, arcs, circles, polylines, and splines organized in layered paths.
|
|
79
|
-
* Example: model with 3 parts on different layers → valid DXF file string for CAD software
|
|
80
|
-
* @param inputs DXF model definition
|
|
81
|
-
* @returns DXF file content as string
|
|
82
|
-
* @group dxf
|
|
83
|
-
* @shortname dxf create
|
|
84
|
-
* @drawable false
|
|
85
|
-
*/
|
|
86
|
-
dxfCreate(inputs: Inputs.IO.DxfModelDto): string;
|
|
87
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import * as Inputs from "../../../../inputs";
|
|
2
|
-
import { DxfGenerator } from "./dxf-generator";
|
|
3
|
-
import { resolveDto } from "../../../../kernel-calls";
|
|
4
|
-
export class Dxf {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.dxfGenerator = new DxfGenerator();
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Creates a line segment definition for DXF export (pass-through for validation).
|
|
10
|
-
* Example: start=[0,0], end=[10,5] → DXF line segment from origin to [10,5]
|
|
11
|
-
* @param inputs Line segment definition
|
|
12
|
-
* @returns Line segment DTO
|
|
13
|
-
* @group dxf
|
|
14
|
-
* @shortname line segment
|
|
15
|
-
* @drawable false
|
|
16
|
-
*/
|
|
17
|
-
lineSegment(inputs) {
|
|
18
|
-
return inputs;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Creates an arc segment definition for DXF export (curved path between two points).
|
|
22
|
-
* Example: center=[5,5], radius=5, startAngle=0°, endAngle=90° → quarter circle arc
|
|
23
|
-
* @param inputs Arc segment definition
|
|
24
|
-
* @returns Arc segment DTO
|
|
25
|
-
* @group dxf
|
|
26
|
-
* @shortname arc segment
|
|
27
|
-
* @drawable false
|
|
28
|
-
*/
|
|
29
|
-
arcSegment(inputs) {
|
|
30
|
-
return inputs;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Creates a circle segment definition for DXF export (closed circular path).
|
|
34
|
-
* Example: center=[10,10], radius=5 → full circle with diameter 10 centered at [10,10]
|
|
35
|
-
* @param inputs Circle segment definition
|
|
36
|
-
* @returns Circle segment DTO
|
|
37
|
-
* @group dxf
|
|
38
|
-
* @shortname circle segment
|
|
39
|
-
* @drawable false
|
|
40
|
-
*/
|
|
41
|
-
circleSegment(inputs) {
|
|
42
|
-
return inputs;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates a polyline segment definition for DXF export (connected line segments through points).
|
|
46
|
-
* Example: points=[[0,0], [5,0], [5,5], [0,5]] → rectangular polyline path
|
|
47
|
-
* @param inputs Polyline segment definition
|
|
48
|
-
* @returns Polyline segment DTO
|
|
49
|
-
* @group dxf
|
|
50
|
-
* @shortname polyline segment
|
|
51
|
-
* @drawable false
|
|
52
|
-
*/
|
|
53
|
-
polylineSegment(inputs) {
|
|
54
|
-
const resolved = resolveDto(Inputs.IO.DxfPolylineSegmentDto, inputs);
|
|
55
|
-
return resolved;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Creates a spline segment definition for DXF export (smooth curve through control points).
|
|
59
|
-
* Example: controlPoints=[[0,0], [5,10], [10,0]] → smooth curved path through points
|
|
60
|
-
* @param inputs Spline segment definition
|
|
61
|
-
* @returns Spline segment DTO
|
|
62
|
-
* @group dxf
|
|
63
|
-
* @shortname spline segment
|
|
64
|
-
* @drawable false
|
|
65
|
-
*/
|
|
66
|
-
splineSegment(inputs) {
|
|
67
|
-
const resolved = resolveDto(Inputs.IO.DxfSplineSegmentDto, inputs);
|
|
68
|
-
return resolved;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Creates a path from multiple segments (combines lines, arcs, circles, polylines, splines).
|
|
72
|
-
* Similar to OCCT wires - segments are connected to form a continuous or multi-part path.
|
|
73
|
-
* Example: segments=[lineSegment, arcSegment, polylineSegment] → combined path entity
|
|
74
|
-
* @param inputs Path definition with segments
|
|
75
|
-
* @returns Path DTO
|
|
76
|
-
* @group dxf
|
|
77
|
-
* @shortname path
|
|
78
|
-
* @drawable false
|
|
79
|
-
*/
|
|
80
|
-
path(inputs) {
|
|
81
|
-
return inputs;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Creates a paths part with layer and color assignment for DXF organization.
|
|
85
|
-
* Groups multiple paths into a single layer with consistent styling.
|
|
86
|
-
* Example: paths=[path1, path2], layer="Outlines", color=red → grouped geometry
|
|
87
|
-
* @param inputs Paths part definition
|
|
88
|
-
* @returns Paths part DTO
|
|
89
|
-
* @group dxf
|
|
90
|
-
* @shortname paths part
|
|
91
|
-
* @drawable false
|
|
92
|
-
*/
|
|
93
|
-
pathsPart(inputs) {
|
|
94
|
-
const resolved = resolveDto(Inputs.IO.DxfPathsPartDto, inputs);
|
|
95
|
-
return resolved;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Generates a complete DXF file from paths parts (exports 2D CAD drawing format).
|
|
99
|
-
* Supports lines, arcs, circles, polylines, and splines organized in layered paths.
|
|
100
|
-
* Example: model with 3 parts on different layers → valid DXF file string for CAD software
|
|
101
|
-
* @param inputs DXF model definition
|
|
102
|
-
* @returns DXF file content as string
|
|
103
|
-
* @group dxf
|
|
104
|
-
* @shortname dxf create
|
|
105
|
-
* @drawable false
|
|
106
|
-
*/
|
|
107
|
-
dxfCreate(inputs) {
|
|
108
|
-
const resolved = resolveDto(Inputs.IO.DxfModelDto, inputs);
|
|
109
|
-
return this.dxfGenerator.generateDxf(resolved);
|
|
110
|
-
}
|
|
111
|
-
}
|
package/lib/api/services/io.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Dxf } from "./helpers/files/dxf/dxf";
|
|
2
|
-
/**
|
|
3
|
-
* Reading and writing files: exporting geometry to the supported formats, importing it back, and
|
|
4
|
-
* the download and upload helpers that move files between the browser and the user's machine.
|
|
5
|
-
*/
|
|
6
|
-
export declare class IoBitByBit {
|
|
7
|
-
dxf: Dxf;
|
|
8
|
-
constructor();
|
|
9
|
-
}
|
package/lib/api/services/io.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Dxf } from "./helpers/files/dxf/dxf";
|
|
2
|
-
/**
|
|
3
|
-
* Reading and writing files: exporting geometry to the supported formats, importing it back, and
|
|
4
|
-
* the download and upload helpers that move files between the browser and the user's machine.
|
|
5
|
-
*/
|
|
6
|
-
export class IoBitByBit {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.dxf = new Dxf();
|
|
9
|
-
}
|
|
10
|
-
}
|