@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,96 @@
|
|
|
1
|
+
import { angleOfCosine } from "./scalars";
|
|
2
|
+
import { cross2 } from "./vectors";
|
|
3
|
+
const FULL_TURN = 2 * Math.PI;
|
|
4
|
+
const turnBetween = (ux, uy, vx, vy) => {
|
|
5
|
+
const angle = angleOfCosine((ux * vx + uy * vy) / Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy)));
|
|
6
|
+
return ux * vy - uy * vx < 0 ? -angle : angle;
|
|
7
|
+
};
|
|
8
|
+
export const ellipseArcOfEndpoints2 = (from, to, radiusX, radiusY, xAxisRotation, largeArc, sweep) => {
|
|
9
|
+
let rx = Math.abs(radiusX);
|
|
10
|
+
let ry = Math.abs(radiusY);
|
|
11
|
+
if ((from[0] === to[0] && from[1] === to[1]) || rx === 0 || ry === 0) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const cosPhi = Math.cos(xAxisRotation);
|
|
15
|
+
const sinPhi = Math.sin(xAxisRotation);
|
|
16
|
+
const dx = (from[0] - to[0]) / 2;
|
|
17
|
+
const dy = (from[1] - to[1]) / 2;
|
|
18
|
+
const x1p = cosPhi * dx + sinPhi * dy;
|
|
19
|
+
const y1p = -sinPhi * dx + cosPhi * dy;
|
|
20
|
+
const lambda = (x1p * x1p) / (rx * rx) + (y1p * y1p) / (ry * ry);
|
|
21
|
+
if (lambda > 1) {
|
|
22
|
+
const s = Math.sqrt(lambda);
|
|
23
|
+
rx *= s;
|
|
24
|
+
ry *= s;
|
|
25
|
+
}
|
|
26
|
+
const rx2 = rx * rx;
|
|
27
|
+
const ry2 = ry * ry;
|
|
28
|
+
const num = rx2 * ry2 - rx2 * y1p * y1p - ry2 * x1p * x1p;
|
|
29
|
+
const den = rx2 * y1p * y1p + ry2 * x1p * x1p;
|
|
30
|
+
const size = den === 0 ? 0 : Math.sqrt(Math.max(0, num / den));
|
|
31
|
+
const factor = largeArc === sweep ? -size : size;
|
|
32
|
+
const cxp = (factor * rx * y1p) / ry;
|
|
33
|
+
const cyp = (-factor * ry * x1p) / rx;
|
|
34
|
+
const startAngle = turnBetween(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
|
|
35
|
+
let deltaAngle = turnBetween((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry);
|
|
36
|
+
if (!sweep && deltaAngle > 0) {
|
|
37
|
+
deltaAngle -= FULL_TURN;
|
|
38
|
+
}
|
|
39
|
+
if (sweep && deltaAngle < 0) {
|
|
40
|
+
deltaAngle += FULL_TURN;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
center: [cosPhi * cxp - sinPhi * cyp + (from[0] + to[0]) / 2, sinPhi * cxp + cosPhi * cyp + (from[1] + to[1]) / 2],
|
|
44
|
+
rx,
|
|
45
|
+
ry,
|
|
46
|
+
xAxisRotation,
|
|
47
|
+
startAngle,
|
|
48
|
+
deltaAngle,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export const affineEllipseArc2 = (matrix, arc) => {
|
|
52
|
+
const [a, b, c, d, tx, ty] = matrix;
|
|
53
|
+
const cosP = Math.cos(arc.xAxisRotation);
|
|
54
|
+
const sinP = Math.sin(arc.xAxisRotation);
|
|
55
|
+
const r00 = cosP * arc.rx;
|
|
56
|
+
const r10 = sinP * arc.rx;
|
|
57
|
+
const r01 = -sinP * arc.ry;
|
|
58
|
+
const r11 = cosP * arc.ry;
|
|
59
|
+
const m00 = a * r00 + c * r10;
|
|
60
|
+
const m10 = b * r00 + d * r10;
|
|
61
|
+
const m01 = a * r01 + c * r11;
|
|
62
|
+
const m11 = b * r01 + d * r11;
|
|
63
|
+
const e = (m00 + m11) / 2;
|
|
64
|
+
const f = (m00 - m11) / 2;
|
|
65
|
+
const g = (m10 + m01) / 2;
|
|
66
|
+
const h = (m10 - m01) / 2;
|
|
67
|
+
const q = Math.hypot(e, h);
|
|
68
|
+
const r = Math.hypot(f, g);
|
|
69
|
+
const sx = q + r;
|
|
70
|
+
const sy = Math.abs(q - r);
|
|
71
|
+
const theta = (Math.atan2(h, e) + Math.atan2(g, f)) / 2;
|
|
72
|
+
const cosT = Math.cos(theta);
|
|
73
|
+
const sinT = Math.sin(theta);
|
|
74
|
+
const imageAngle = (angle) => {
|
|
75
|
+
const px = m00 * Math.cos(angle) + m01 * Math.sin(angle);
|
|
76
|
+
const py = m10 * Math.cos(angle) + m11 * Math.sin(angle);
|
|
77
|
+
return Math.atan2((-sinT * px + cosT * py) / (sy || 1), (cosT * px + sinT * py) / (sx || 1));
|
|
78
|
+
};
|
|
79
|
+
const startAngle = imageAngle(arc.startAngle);
|
|
80
|
+
let deltaAngle = imageAngle(arc.startAngle + arc.deltaAngle) - startAngle;
|
|
81
|
+
const sweepSign = cross2([a, b], [c, d]) < 0 ? -Math.sign(arc.deltaAngle) : Math.sign(arc.deltaAngle);
|
|
82
|
+
if (sweepSign > 0 && deltaAngle < 0) {
|
|
83
|
+
deltaAngle += FULL_TURN;
|
|
84
|
+
}
|
|
85
|
+
if (sweepSign < 0 && deltaAngle > 0) {
|
|
86
|
+
deltaAngle -= FULL_TURN;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
center: [a * arc.center[0] + c * arc.center[1] + tx, b * arc.center[0] + d * arc.center[1] + ty],
|
|
90
|
+
rx: sx,
|
|
91
|
+
ry: sy,
|
|
92
|
+
xAxisRotation: theta,
|
|
93
|
+
startAngle,
|
|
94
|
+
deltaAngle: sweepSign === 0 ? 0 : deltaAngle,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
@@ -7,7 +7,9 @@ type Vec3 = Inputs.Base.Vector3;
|
|
|
7
7
|
export declare const PARALLEL_SINE = 1e-9;
|
|
8
8
|
/**
|
|
9
9
|
* A frame as the four vectors the maths reads: the origin and three unit axes at right angles,
|
|
10
|
-
* with `y` the cross product of `z` and `x`.
|
|
10
|
+
* with `y` the cross product of `z` and `x`. `vectorToWorld`, `pointToWorld` and `composeAxes`
|
|
11
|
+
* also map by axes of any length and angle, such as a scaled block insert's; the `ToLocal`
|
|
12
|
+
* functions and `relativeAxes` undo only unit axes at right angles.
|
|
11
13
|
*/
|
|
12
14
|
export interface FrameAxes {
|
|
13
15
|
readonly origin: Vec3;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const NESTING_BOX_MARGIN = 0.01;
|
|
2
|
+
export declare const INTERIOR_SCANLINES: number[];
|
|
3
|
+
export declare const COINCIDENT_AREA_SHARE = 1e-9;
|
|
4
|
+
export declare const SWEEP_CANDIDATES_PER_PAIR = 1000;
|
|
5
|
+
export declare const SWEEP_STEPS_PER_BOX = 20;
|
|
6
|
+
export declare const SWEEP_STEPS_PER_CANDIDATE = 2;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const NESTING_BOX_MARGIN = 0.01;
|
|
2
|
+
export const INTERIOR_SCANLINES = [0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875];
|
|
3
|
+
export const COINCIDENT_AREA_SHARE = 1e-9;
|
|
4
|
+
export const SWEEP_CANDIDATES_PER_PAIR = 1000;
|
|
5
|
+
export const SWEEP_STEPS_PER_BOX = 20;
|
|
6
|
+
export const SWEEP_STEPS_PER_CANDIDATE = 2;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type * as Inputs from "../../../inputs";
|
|
2
|
+
import { WorkBudget } from "../files/work-budget";
|
|
3
|
+
type Point2 = Inputs.Base.Point2;
|
|
4
|
+
export type FillRule2 = "nonzero" | "evenOdd";
|
|
5
|
+
export interface Box2 {
|
|
6
|
+
min: Point2;
|
|
7
|
+
max: Point2;
|
|
8
|
+
}
|
|
9
|
+
export interface NestingOutline2 {
|
|
10
|
+
points: Point2[];
|
|
11
|
+
area: number;
|
|
12
|
+
box: Box2;
|
|
13
|
+
inner?: Point2;
|
|
14
|
+
}
|
|
15
|
+
export interface FilledRegion2 {
|
|
16
|
+
outer: number;
|
|
17
|
+
holes: number[];
|
|
18
|
+
}
|
|
19
|
+
export declare const boxOf2: (points: readonly Point2[]) => Box2;
|
|
20
|
+
export declare const boxesOverlap2: (a: Box2, b: Box2) => boolean;
|
|
21
|
+
export declare const interiorPoint2: (points: readonly Point2[], box?: Box2) => Point2 | undefined;
|
|
22
|
+
export declare const nestingOutlineOf2: (points: Point2[]) => NestingOutline2;
|
|
23
|
+
export declare function overlappingBoxPairs2(boxes: readonly Box2[]): [number, number][];
|
|
24
|
+
export declare function overlappingBoxPairs2(boxes: readonly Box2[], most: number, budget?: WorkBudget): [number, number][] | undefined;
|
|
25
|
+
export declare const segmentsCross2: (p1: Point2, p2: Point2, q1: Point2, q2: Point2) => boolean;
|
|
26
|
+
export declare function outlinesCross2(outlines: readonly NestingOutline2[], pairs: readonly (readonly [number, number])[]): boolean;
|
|
27
|
+
export declare function outlinesCross2(outlines: readonly NestingOutline2[], pairs: readonly (readonly [number, number])[], budget: WorkBudget): boolean | undefined;
|
|
28
|
+
export declare function nestedOutlines2(outlines: readonly NestingOutline2[], pairs: readonly (readonly [number, number])[]): number[][];
|
|
29
|
+
export declare function nestedOutlines2(outlines: readonly NestingOutline2[], pairs: readonly (readonly [number, number])[], budget: WorkBudget): number[][] | undefined;
|
|
30
|
+
export declare const filledRegions2: (outlines: readonly NestingOutline2[], ancestors: readonly (readonly number[])[], rule: FillRule2) => FilledRegion2[];
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { WorkBudget } from "../files/work-budget";
|
|
2
|
+
import { isInsidePolygon2, signedArea2 } from "./polygons";
|
|
3
|
+
import { cross2, subtract2 } from "./vectors";
|
|
4
|
+
import { COINCIDENT_AREA_SHARE, INTERIOR_SCANLINES, NESTING_BOX_MARGIN, SWEEP_CANDIDATES_PER_PAIR, SWEEP_STEPS_PER_BOX, SWEEP_STEPS_PER_CANDIDATE, } from "./polygon-nesting.constants";
|
|
5
|
+
const SWEEP_AXES = [0, 1];
|
|
6
|
+
export const boxOf2 = (points) => {
|
|
7
|
+
const min = [Infinity, Infinity];
|
|
8
|
+
const max = [-Infinity, -Infinity];
|
|
9
|
+
for (const [x, y] of points) {
|
|
10
|
+
min[0] = Math.min(min[0], x);
|
|
11
|
+
min[1] = Math.min(min[1], y);
|
|
12
|
+
max[0] = Math.max(max[0], x);
|
|
13
|
+
max[1] = Math.max(max[1], y);
|
|
14
|
+
}
|
|
15
|
+
return { min, max };
|
|
16
|
+
};
|
|
17
|
+
export const boxesOverlap2 = (a, b) => a.min[0] <= b.max[0] && b.min[0] <= a.max[0] && a.min[1] <= b.max[1] && b.min[1] <= a.max[1];
|
|
18
|
+
const boxHolds = (outer, inner) => {
|
|
19
|
+
const margin = NESTING_BOX_MARGIN * Math.max(outer.max[0] - outer.min[0], outer.max[1] - outer.min[1]);
|
|
20
|
+
return inner.min[0] >= outer.min[0] - margin && inner.min[1] >= outer.min[1] - margin
|
|
21
|
+
&& inner.max[0] <= outer.max[0] + margin && inner.max[1] <= outer.max[1] + margin;
|
|
22
|
+
};
|
|
23
|
+
const widestSpanAt = (points, y) => {
|
|
24
|
+
const xs = [];
|
|
25
|
+
for (let at = 0, previous = points.length - 1; at < points.length; previous = at++) {
|
|
26
|
+
const [x1, y1] = points[at];
|
|
27
|
+
const [x2, y2] = points[previous];
|
|
28
|
+
if ((y1 > y) !== (y2 > y)) {
|
|
29
|
+
xs.push(x1 + (y - y1) * (x2 - x1) / (y2 - y1));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
xs.sort((a, b) => a - b);
|
|
33
|
+
let best;
|
|
34
|
+
for (let k = 0; k + 1 < xs.length; k += 2) {
|
|
35
|
+
const width = xs[k + 1] - xs[k];
|
|
36
|
+
if (width > 0 && (!best || width > best.width)) {
|
|
37
|
+
best = { width, middle: [(xs[k] + xs[k + 1]) / 2, y] };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return best;
|
|
41
|
+
};
|
|
42
|
+
export const interiorPoint2 = (points, box = boxOf2(points)) => {
|
|
43
|
+
let best;
|
|
44
|
+
for (const share of INTERIOR_SCANLINES) {
|
|
45
|
+
const span = widestSpanAt(points, box.min[1] + (box.max[1] - box.min[1]) * share);
|
|
46
|
+
if (span && (!best || span.width > best.width)) {
|
|
47
|
+
best = span;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return best === null || best === void 0 ? void 0 : best.middle;
|
|
51
|
+
};
|
|
52
|
+
export const nestingOutlineOf2 = (points) => {
|
|
53
|
+
const box = boxOf2(points);
|
|
54
|
+
const area = signedArea2(points);
|
|
55
|
+
const outline = { points, area, box };
|
|
56
|
+
const inner = area === 0 ? undefined : interiorPoint2(points, box);
|
|
57
|
+
if (inner) {
|
|
58
|
+
outline.inner = inner;
|
|
59
|
+
}
|
|
60
|
+
return outline;
|
|
61
|
+
};
|
|
62
|
+
const firstAbove = (sorted, value) => {
|
|
63
|
+
let low = 0;
|
|
64
|
+
let high = sorted.length;
|
|
65
|
+
while (low < high) {
|
|
66
|
+
const middle = (low + high) >> 1;
|
|
67
|
+
if (sorted[middle] > value) {
|
|
68
|
+
high = middle;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
low = middle + 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return low;
|
|
75
|
+
};
|
|
76
|
+
const sweepOrder = (boxes, axis) => boxes.map((_, i) => i).sort((a, b) => boxes[a].min[axis] - boxes[b].min[axis]);
|
|
77
|
+
const sweepCandidates = (boxes, order, axis) => {
|
|
78
|
+
const starts = order.map((i) => boxes[i].min[axis]);
|
|
79
|
+
return order.reduce((sum, i, k) => sum + Math.max(0, firstAbove(starts, boxes[i].max[axis]) - k - 1), 0);
|
|
80
|
+
};
|
|
81
|
+
const sweptPairs = (boxes, order, axis, most) => {
|
|
82
|
+
const pairs = [];
|
|
83
|
+
for (let k = 0; k < order.length; k++) {
|
|
84
|
+
const i = order[k];
|
|
85
|
+
const a = boxes[i];
|
|
86
|
+
for (let m = k + 1; m < order.length; m++) {
|
|
87
|
+
const j = order[m];
|
|
88
|
+
const b = boxes[j];
|
|
89
|
+
if (b.min[axis] > a.max[axis]) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (boxesOverlap2(a, b)) {
|
|
93
|
+
if (pairs.length >= most) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
pairs.push([i, j]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return pairs;
|
|
101
|
+
};
|
|
102
|
+
const unbounded = () => new WorkBudget(Number.POSITIVE_INFINITY);
|
|
103
|
+
export function overlappingBoxPairs2(boxes, most = Number.POSITIVE_INFINITY, budget = unbounded()) {
|
|
104
|
+
const examinable = most * SWEEP_CANDIDATES_PER_PAIR;
|
|
105
|
+
for (const axis of SWEEP_AXES) {
|
|
106
|
+
if (!budget.spend(boxes.length * SWEEP_STEPS_PER_BOX)) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const order = sweepOrder(boxes, axis);
|
|
110
|
+
const candidates = sweepCandidates(boxes, order, axis);
|
|
111
|
+
if (candidates <= examinable) {
|
|
112
|
+
return budget.spend(candidates * SWEEP_STEPS_PER_CANDIDATE) ? sweptPairs(boxes, order, axis, most) : undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
export const segmentsCross2 = (p1, p2, q1, q2) => {
|
|
118
|
+
const d = subtract2(p2, p1);
|
|
119
|
+
const e = subtract2(q2, q1);
|
|
120
|
+
return cross2(d, subtract2(q1, p1)) * cross2(d, subtract2(q2, p1)) < 0 && cross2(e, subtract2(p1, q1)) * cross2(e, subtract2(p2, q1)) < 0;
|
|
121
|
+
};
|
|
122
|
+
const spanMeets = (p, q, low, high) => Math.min(p, q) <= high && low <= Math.max(p, q);
|
|
123
|
+
const edgesNear = (outline, box) => {
|
|
124
|
+
const { points } = outline;
|
|
125
|
+
const near = [];
|
|
126
|
+
for (let k = 0; k < points.length; k++) {
|
|
127
|
+
const p = points[k];
|
|
128
|
+
const q = points[(k + 1) % points.length];
|
|
129
|
+
if (spanMeets(p[0], q[0], box.min[0], box.max[0]) && spanMeets(p[1], q[1], box.min[1], box.max[1])) {
|
|
130
|
+
near.push(k);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return near;
|
|
134
|
+
};
|
|
135
|
+
const edgeBoxesOf = (outline, edges) => {
|
|
136
|
+
const boxes = {
|
|
137
|
+
minX: new Float64Array(edges.length), minY: new Float64Array(edges.length), maxX: new Float64Array(edges.length), maxY: new Float64Array(edges.length),
|
|
138
|
+
};
|
|
139
|
+
edges.forEach((k, at) => {
|
|
140
|
+
const p = outline.points[k];
|
|
141
|
+
const q = outline.points[(k + 1) % outline.points.length];
|
|
142
|
+
boxes.minX[at] = Math.min(p[0], q[0]);
|
|
143
|
+
boxes.minY[at] = Math.min(p[1], q[1]);
|
|
144
|
+
boxes.maxX[at] = Math.max(p[0], q[0]);
|
|
145
|
+
boxes.maxY[at] = Math.max(p[1], q[1]);
|
|
146
|
+
});
|
|
147
|
+
return boxes;
|
|
148
|
+
};
|
|
149
|
+
const edgeCrossesAny = (a, k, b, edges, boxes) => {
|
|
150
|
+
const p1 = a.points[k];
|
|
151
|
+
const p2 = a.points[(k + 1) % a.points.length];
|
|
152
|
+
const minX = Math.min(p1[0], p2[0]);
|
|
153
|
+
const minY = Math.min(p1[1], p2[1]);
|
|
154
|
+
const maxX = Math.max(p1[0], p2[0]);
|
|
155
|
+
const maxY = Math.max(p1[1], p2[1]);
|
|
156
|
+
for (let at = 0; at < edges.length; at++) {
|
|
157
|
+
if (boxes.minX[at] <= maxX && minX <= boxes.maxX[at] && boxes.minY[at] <= maxY && minY <= boxes.maxY[at]
|
|
158
|
+
&& segmentsCross2(p1, p2, b.points[edges[at]], b.points[(edges[at] + 1) % b.points.length])) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
};
|
|
164
|
+
export function outlinesCross2(outlines, pairs, budget = unbounded()) {
|
|
165
|
+
for (const [first, second] of pairs) {
|
|
166
|
+
const a = outlines[first];
|
|
167
|
+
const b = outlines[second];
|
|
168
|
+
if (!budget.spend(a.points.length)) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const ofA = edgesNear(a, b.box);
|
|
172
|
+
if (ofA.length === 0) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (!budget.spend(b.points.length)) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
const ofB = edgesNear(b, a.box);
|
|
179
|
+
const boxesOfB = edgeBoxesOf(b, ofB);
|
|
180
|
+
for (const k of ofA) {
|
|
181
|
+
if (!budget.spend(ofB.length)) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
if (edgeCrossesAny(a, k, b, ofB, boxesOfB)) {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
const sameSize = (a, b) => Math.abs(a - b) <= COINCIDENT_AREA_SHARE * Math.max(a, b);
|
|
192
|
+
export function nestedOutlines2(outlines, pairs, budget = unbounded()) {
|
|
193
|
+
const ancestors = outlines.map(() => []);
|
|
194
|
+
let affordable = true;
|
|
195
|
+
const holds = (outer, inner) => {
|
|
196
|
+
if (inner.inner === undefined || !boxHolds(outer.box, inner.box)) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
affordable = budget.spend(outer.points.length);
|
|
200
|
+
return affordable && isInsidePolygon2(inner.inner, outer.points);
|
|
201
|
+
};
|
|
202
|
+
for (const [first, second] of pairs) {
|
|
203
|
+
const sizeOfFirst = Math.abs(outlines[first].area);
|
|
204
|
+
const sizeOfSecond = Math.abs(outlines[second].area);
|
|
205
|
+
if (sameSize(sizeOfFirst, sizeOfSecond)) {
|
|
206
|
+
if (holds(outlines[first], outlines[second]) && holds(outlines[second], outlines[first])) {
|
|
207
|
+
ancestors[Math.max(first, second)].push(Math.min(first, second));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const [big, small] = sizeOfFirst > sizeOfSecond ? [first, second] : [second, first];
|
|
212
|
+
if (holds(outlines[big], outlines[small])) {
|
|
213
|
+
ancestors[small].push(big);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!affordable) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return ancestors;
|
|
221
|
+
}
|
|
222
|
+
export const filledRegions2 = (outlines, ancestors, rule) => {
|
|
223
|
+
const depth = ancestors.map((a) => a.length);
|
|
224
|
+
const parent = ancestors.map((a) => a.reduce((best, j) => (best === -1 || depth[j] > depth[best] ? j : best), -1));
|
|
225
|
+
const sign = outlines.map((outline) => Math.sign(outline.area));
|
|
226
|
+
const filled = outlines.map((_, i) => rule === "evenOdd"
|
|
227
|
+
? depth[i] % 2 === 0
|
|
228
|
+
: sign[i] + ancestors[i].reduce((sum, j) => sum + sign[j], 0) !== 0);
|
|
229
|
+
const effective = outlines.map((outline, i) => outline.inner !== undefined && filled[i] !== (parent[i] === -1 ? false : filled[parent[i]]));
|
|
230
|
+
const effectiveParent = (i) => {
|
|
231
|
+
let up = parent[i];
|
|
232
|
+
while (up !== -1 && !effective[up]) {
|
|
233
|
+
up = parent[up];
|
|
234
|
+
}
|
|
235
|
+
return up;
|
|
236
|
+
};
|
|
237
|
+
const regions = new Map();
|
|
238
|
+
outlines.forEach((_, i) => {
|
|
239
|
+
if (effective[i] && filled[i]) {
|
|
240
|
+
regions.set(i, { outer: i, holes: [] });
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
outlines.forEach((_, i) => {
|
|
244
|
+
var _a;
|
|
245
|
+
if (effective[i] && !filled[i]) {
|
|
246
|
+
(_a = regions.get(effectiveParent(i))) === null || _a === void 0 ? void 0 : _a.holes.push(i);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
const sizeOf = (i) => Math.abs(outlines[i].area);
|
|
250
|
+
return [...regions.values()].filter((region) => !region.holes.some((hole) => sameSize(sizeOf(hole), sizeOf(region.outer))));
|
|
251
|
+
};
|
|
@@ -22,4 +22,5 @@ export declare const cross3: (a: Vec3, b: Vec3) => Vec3;
|
|
|
22
22
|
export declare const length3: (a: Vec3) => number;
|
|
23
23
|
export declare const between3: (a: Vec3, b: Vec3, share: number) => Vec3;
|
|
24
24
|
export declare const distance3: (a: Vec3, b: Vec3) => number;
|
|
25
|
+
export declare const distanceToSegment3: (point: Vec3, start: Vec3, end: Vec3) => number;
|
|
25
26
|
export {};
|
|
@@ -41,3 +41,9 @@ export const cross3 = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] *
|
|
|
41
41
|
export const length3 = (a) => Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
|
|
42
42
|
export const between3 = (a, b, share) => [a[0] + (b[0] - a[0]) * share, a[1] + (b[1] - a[1]) * share, a[2] + (b[2] - a[2]) * share];
|
|
43
43
|
export const distance3 = (a, b) => length3(subtract3(a, b));
|
|
44
|
+
export const distanceToSegment3 = (point, start, end) => {
|
|
45
|
+
const along = subtract3(end, start);
|
|
46
|
+
const reach = dot3(along, along);
|
|
47
|
+
const share = reach > 0 ? Math.min(Math.max(dot3(subtract3(point, start), along) / reach, 0), 1) : 0;
|
|
48
|
+
return distance3(point, between3(start, end, share));
|
|
49
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as Inputs from "../../inputs";
|
|
2
|
+
import type { Dxf } from "./dxf";
|
|
3
|
+
import type { Svg } from "./svg";
|
|
4
|
+
/**
|
|
5
|
+
* Builds drawings as data, for any file format: segments of every kind, paths joined from segments,
|
|
6
|
+
* and parts that put paths on a layer with a color and a line type. `io.dxf.dxfCreate` writes the
|
|
7
|
+
* parts as DXF and `io.svg.svgCreate` as SVG; `svgToDxf` and `dxfToSvg` convert one file into the
|
|
8
|
+
* other through these parts.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Drawing {
|
|
11
|
+
private readonly dxfOf;
|
|
12
|
+
private readonly svgOf;
|
|
13
|
+
constructor(dxfOf: () => Dxf, svgOf: () => Svg);
|
|
14
|
+
/**
|
|
15
|
+
* Makes a straight segment of a drawing path, from `start` to `end`.
|
|
16
|
+
* @param inputs - The start and the end point
|
|
17
|
+
* @returns The line segment
|
|
18
|
+
* @group drawing
|
|
19
|
+
* @shortname line segment
|
|
20
|
+
* @drawable false
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const edge = bitbybit.io.drawing.lineSegment({ start: [0, 0], end: [40, 0] });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
lineSegment(inputs: Inputs.IO.DrawingLineSegmentDto): Inputs.IO.DrawingLineSegmentDto;
|
|
27
|
+
/**
|
|
28
|
+
* Makes a circular arc of a drawing path, running counterclockwise about its `center` from
|
|
29
|
+
* `startAngle` to `endAngle`, in degrees, in the XY plane unless a `normal` tilts it.
|
|
30
|
+
* @param inputs - The center, the radius, the start and end angles and the plane's normal
|
|
31
|
+
* @returns The arc segment
|
|
32
|
+
* @group drawing
|
|
33
|
+
* @shortname arc segment
|
|
34
|
+
* @drawable false
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const corner = bitbybit.io.drawing.arcSegment({ center: [0, 0], radius: 10, startAngle: 0, endAngle: 90 });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
arcSegment(inputs: Inputs.IO.DrawingArcSegmentDto): Inputs.IO.DrawingArcSegmentDto;
|
|
41
|
+
/**
|
|
42
|
+
* Makes a whole circle of a drawing path from its `center` and `radius`, in the XY plane unless a
|
|
43
|
+
* `normal` tilts it.
|
|
44
|
+
* @param inputs - The center, the radius and the plane's normal
|
|
45
|
+
* @returns The circle segment
|
|
46
|
+
* @group drawing
|
|
47
|
+
* @shortname circle segment
|
|
48
|
+
* @drawable false
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
circleSegment(inputs: Inputs.IO.DrawingCircleSegmentDto): Inputs.IO.DrawingCircleSegmentDto;
|
|
55
|
+
/**
|
|
56
|
+
* Makes connected straight segments through `points`, which `bulges` can bend into arcs;
|
|
57
|
+
* `closed` joins the last point back to the first.
|
|
58
|
+
* @param inputs - The points, whether the polyline is closed, and the bulges
|
|
59
|
+
* @returns The polyline segment
|
|
60
|
+
* @group drawing
|
|
61
|
+
* @shortname polyline segment
|
|
62
|
+
* @drawable false
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
polylineSegment(inputs: Inputs.IO.DrawingPolylineSegmentDto): Inputs.IO.DrawingPolylineSegmentDto;
|
|
69
|
+
/**
|
|
70
|
+
* Makes a B-spline or NURBS curve of a drawing path from its control points and degree, with
|
|
71
|
+
* its knots and weights when they are given.
|
|
72
|
+
* @param inputs - The control points, the degree, whether it is closed, the knots and the weights
|
|
73
|
+
* @returns The spline segment
|
|
74
|
+
* @group drawing
|
|
75
|
+
* @shortname spline segment
|
|
76
|
+
* @drawable false
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const wave = bitbybit.io.drawing.splineSegment({ controlPoints: [[0, 0], [10, 8], [20, -8], [30, 0]], degree: 3 });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
splineSegment(inputs: Inputs.IO.DrawingSplineSegmentDto): Inputs.IO.DrawingSplineSegmentDto;
|
|
83
|
+
/**
|
|
84
|
+
* Makes an ellipse, or an arc of one, for a drawing path.
|
|
85
|
+
*
|
|
86
|
+
* The ellipse is given by its center, the vector to the end of its major axis and the minor to
|
|
87
|
+
* major ratio; parameters in radians pick the arc, running counterclockwise about the normal.
|
|
88
|
+
* @param inputs - The center, the major axis, the ratio, the start and end parameters and the plane's normal
|
|
89
|
+
* @returns The ellipse segment
|
|
90
|
+
* @group drawing
|
|
91
|
+
* @shortname ellipse segment
|
|
92
|
+
* @drawable false
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const lens = bitbybit.io.drawing.ellipseSegment({ center: [0, 0], majorAxis: [20, 0], ratio: 0.5, startParameter: 0, endParameter: Math.PI });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
ellipseSegment(inputs: Inputs.IO.DrawingEllipseSegmentDto): Inputs.IO.DrawingEllipseSegmentDto;
|
|
99
|
+
/**
|
|
100
|
+
* Joins segments into one path, drawn in order like the edges of a wire; segments that meet
|
|
101
|
+
* are drawn as one stroke in SVG.
|
|
102
|
+
* @param inputs - The segments, in order
|
|
103
|
+
* @returns The path
|
|
104
|
+
* @group drawing
|
|
105
|
+
* @shortname path
|
|
106
|
+
* @drawable false
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const edge = bitbybit.io.drawing.lineSegment({ start: [0, 0], end: [40, 0] });
|
|
110
|
+
* const corner = bitbybit.io.drawing.arcSegment({ center: [40, 10], radius: 10, startAngle: 270, endAngle: 360 });
|
|
111
|
+
* const outline = bitbybit.io.drawing.path({ segments: [edge, corner] });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
path(inputs: Inputs.IO.DrawingPathDto): Inputs.IO.DrawingPathDto;
|
|
115
|
+
/**
|
|
116
|
+
* Puts paths on a named layer with a color and a line type, making one part of a drawing.
|
|
117
|
+
*
|
|
118
|
+
* A drawing may hold several parts; `io.dxf.dxfCreate` writes them as DXF and `io.svg.svgCreate`
|
|
119
|
+
* as SVG.
|
|
120
|
+
* @param inputs - The layer name, the color, the paths and the line type
|
|
121
|
+
* @returns The part
|
|
122
|
+
* @group drawing
|
|
123
|
+
* @shortname part
|
|
124
|
+
* @drawable false
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
128
|
+
* const cut = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }] });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
part(inputs: Inputs.IO.DrawingPartDto): Inputs.IO.DrawingPartDto;
|
|
132
|
+
/**
|
|
133
|
+
* Converts an SVG file into a DXF file, reading it as `io.svg.svgRead` does and writing it as
|
|
134
|
+
* `io.dxf.dxfCreate` does.
|
|
135
|
+
*
|
|
136
|
+
* Inkscape layers, stroke colors and dash patterns become DXF layers, colors and line types, and
|
|
137
|
+
* curves stay exact. With `unit` the drawing is read at true size and the DXF states that unit. A
|
|
138
|
+
* drawing too large to write throws.
|
|
139
|
+
* @param inputs - The SVG text, the unit, whether hidden elements are written, and the DXF's color format, version and curve tolerance
|
|
140
|
+
* @returns The DXF text and the reading's warnings
|
|
141
|
+
* @group convert
|
|
142
|
+
* @shortname svg to dxf
|
|
143
|
+
* @drawable false
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const converted = bitbybit.io.drawing.svgToDxf({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
147
|
+
* const drawing = bitbybit.io.dxf.dxfRead({ dxf: converted.dxf });
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
svgToDxf(inputs: Inputs.IO.SvgToDxfDto): Inputs.IO.SvgToDxfResultDto;
|
|
151
|
+
/**
|
|
152
|
+
* Converts a DXF file into an SVG file, reading it as `io.dxf.dxfRead` does and writing it as
|
|
153
|
+
* `io.svg.svgCreate` does.
|
|
154
|
+
*
|
|
155
|
+
* Layers become Inkscape layers and the SVG takes its true size from the unit the DXF states.
|
|
156
|
+
* Splines given only by fit points are left out and named in `warnings`; a drawing too large to
|
|
157
|
+
* write throws.
|
|
158
|
+
* @param inputs - The DXF file as text or bytes, whether hidden layers are written, and the SVG's line width, border and curve tolerance
|
|
159
|
+
* @returns The SVG text and the reading's warnings
|
|
160
|
+
* @group convert
|
|
161
|
+
* @shortname dxf to svg
|
|
162
|
+
* @drawable false
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const converted = bitbybit.io.drawing.dxfToSvg({ dxf: dxfText, includeHiddenLayers: true });
|
|
166
|
+
* const drawing = bitbybit.io.svg.svgRead({ svg: converted.svg });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
dxfToSvg(inputs: Inputs.IO.DxfToSvgDto): Inputs.IO.DxfToSvgResultDto;
|
|
170
|
+
}
|