@bitbybit-dev/base 1.6.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +24 -0
- package/README.md +3 -1
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +40 -7
- package/lib/api/inputs/base-inputs.js +32 -0
- package/lib/api/inputs/io-inputs.d.ts +927 -59
- package/lib/api/inputs/io-inputs.js +769 -40
- package/lib/api/inputs/line-inputs.d.ts +17 -0
- package/lib/api/inputs/line-inputs.js +15 -0
- package/lib/api/inputs/mesh-inputs.d.ts +20 -1
- package/lib/api/inputs/mesh-inputs.js +23 -0
- package/lib/api/inputs/recipes-inputs.d.ts +13 -5
- package/lib/api/inputs/recipes-inputs.js +10 -5
- package/lib/api/kernel-calls/index.d.ts +2 -0
- package/lib/api/kernel-calls/index.js +2 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +3 -1
- package/lib/api/kernel-calls/resolve-dto.js +7 -2
- package/lib/api/kernel-calls/settings.d.ts +101 -0
- package/lib/api/kernel-calls/settings.js +123 -0
- package/lib/api/kernel-calls/up-axis-aliases.d.ts +25 -0
- package/lib/api/kernel-calls/up-axis-aliases.js +70 -0
- package/lib/api/models/simplex.d.ts +2 -0
- package/lib/api/models/simplex.js +10 -1
- package/lib/api/recipes/surface-mesh.d.ts +2 -1
- package/lib/api/recipes/surface-mesh.js +5 -3
- package/lib/api/resolved-inputs/index.d.ts +32 -3
- package/lib/api/services/base-bitbybit.d.ts +12 -0
- package/lib/api/services/base-bitbybit.js +19 -3
- package/lib/api/services/color.js +2 -3
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +3 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +1 -0
- package/lib/api/services/helpers/color/color-forms.js +4 -1
- package/lib/api/services/helpers/color/css-colors.constants.d.ts +9 -0
- package/lib/api/services/helpers/color/css-colors.constants.js +158 -0
- package/lib/api/services/helpers/color/css-colors.d.ts +1 -0
- package/lib/api/services/helpers/color/css-colors.js +61 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.js +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.d.ts +24 -0
- package/lib/api/services/helpers/curves/bezier-pieces.js +149 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.js +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +26 -0
- package/lib/api/services/helpers/curves/conic-arcs.js +87 -0
- package/lib/api/services/helpers/curves/nurbs-forms.d.ts +20 -0
- package/lib/api/services/helpers/curves/nurbs-forms.js +112 -0
- package/lib/api/services/helpers/curves/nurbs.d.ts +4 -0
- package/lib/api/services/helpers/curves/nurbs.js +10 -9
- package/lib/api/services/helpers/files/drawing/drawing-budget.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +34 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.js +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.d.ts +4 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.js +271 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +101 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.js +123 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.js +91 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.js +336 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.d.ts +2 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.js +47 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.d.ts +9 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.js +25 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +117 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.js +1 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +41 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +46 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.js +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.js +45 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +196 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.d.ts +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.js +50 -0
- package/lib/api/services/helpers/files/dxf/dxf-generator.d.ts +2 -36
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +97 -523
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.js +312 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.d.ts +6 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +115 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.js +67 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.js +151 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.js +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +134 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +95 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +446 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +29 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +248 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.d.ts +26 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.js +97 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +11 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +89 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +43 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +47 -1
- package/lib/api/services/helpers/files/file-bytes.d.ts +1 -0
- package/lib/api/services/helpers/files/file-bytes.js +15 -0
- package/lib/api/services/helpers/files/ground-axes.d.ts +2 -0
- package/lib/api/services/helpers/files/ground-axes.js +4 -0
- package/lib/api/services/helpers/files/mesh-file-axes.d.ts +7 -0
- package/lib/api/services/helpers/files/mesh-file-axes.js +17 -0
- package/lib/api/services/helpers/files/stl-axes.d.ts +4 -0
- package/lib/api/services/helpers/files/stl-axes.js +22 -0
- package/lib/api/services/helpers/files/stl-types.d.ts +7 -0
- package/lib/api/services/helpers/files/stl-types.js +1 -0
- package/lib/api/services/helpers/files/stl.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/stl.constants.js +11 -0
- package/lib/api/services/helpers/files/stl.d.ts +3 -0
- package/lib/api/services/helpers/files/stl.js +93 -0
- package/lib/api/services/helpers/files/svg/svg-css.d.ts +48 -0
- package/lib/api/services/helpers/files/svg/svg-css.js +444 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-document.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-document.js +89 -0
- package/lib/api/services/helpers/files/svg/svg-memo.d.ts +1 -0
- package/lib/api/services/helpers/files/svg/svg-memo.js +8 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.js +433 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.d.ts +15 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.js +61 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.d.ts +8 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.js +10 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.js +203 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.d.ts +33 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.d.ts +35 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.js +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-reading.js +233 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.d.ts +54 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.js +102 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +38 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.js +132 -0
- package/lib/api/services/helpers/files/svg/svg-style.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-style.js +211 -0
- package/lib/api/services/helpers/files/svg/svg-transform.d.ts +10 -0
- package/lib/api/services/helpers/files/svg/svg-transform.js +76 -0
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +18 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +230 -0
- package/lib/api/services/helpers/files/svg/svg-xml.d.ts +11 -0
- package/lib/api/services/helpers/files/svg/svg-xml.js +322 -0
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/svg/svg.constants.js +14 -0
- package/lib/api/services/helpers/files/work-budget.d.ts +11 -0
- package/lib/api/services/helpers/files/work-budget.js +26 -0
- package/lib/api/services/helpers/geometry/affine2.d.ts +8 -0
- package/lib/api/services/helpers/geometry/affine2.js +18 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.d.ts +14 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.js +96 -0
- package/lib/api/services/helpers/geometry/frame-axes.d.ts +3 -1
- package/lib/api/services/helpers/geometry/loop-fill.d.ts +2 -0
- package/lib/api/services/helpers/geometry/loop-fill.js +37 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.d.ts +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.js +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.d.ts +31 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.js +251 -0
- package/lib/api/services/helpers/geometry/vectors.d.ts +1 -0
- package/lib/api/services/helpers/geometry/vectors.js +6 -0
- package/lib/api/services/helpers/helper-types.d.ts +33 -0
- package/lib/api/services/helpers/text/stroke-font.d.ts +6 -0
- package/lib/api/services/helpers/text/stroke-font.js +177 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.d.ts +2 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.js +18 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.d.ts +14 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.js +34 -0
- package/lib/api/services/io/drawing.d.ts +368 -0
- package/lib/api/services/io/drawing.js +454 -0
- package/lib/api/services/io/dxf.d.ts +134 -0
- package/lib/api/services/io/dxf.js +167 -0
- package/lib/api/services/io/index.d.ts +4 -0
- package/lib/api/services/io/index.js +4 -0
- package/lib/api/services/io/io.d.ts +14 -0
- package/lib/api/services/io/io.js +15 -0
- package/lib/api/services/io/svg.d.ts +66 -0
- package/lib/api/services/io/svg.js +105 -0
- package/lib/api/services/line.d.ts +17 -0
- package/lib/api/services/line.js +20 -1
- package/lib/api/services/mesh.d.ts +19 -0
- package/lib/api/services/mesh.js +40 -0
- package/lib/api/services/point.d.ts +4 -1
- package/lib/api/services/point.js +9 -4
- package/lib/api/services/recipes.d.ts +3 -0
- package/lib/api/services/recipes.js +6 -2
- package/lib/api/services/text.d.ts +7 -4
- package/lib/api/services/text.js +14 -27
- package/package.json +1 -1
- package/lib/api/services/helpers/files/dxf/dxf.d.ts +0 -87
- package/lib/api/services/helpers/files/dxf/dxf.js +0 -111
- package/lib/api/services/io.d.ts +0 -9
- package/lib/api/services/io.js +0 -10
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type * as Inputs from "../../../../inputs";
|
|
2
|
+
import type { ConicArc } from "../../curves/conic-arcs";
|
|
3
|
+
import type { FrameAxes } from "../../geometry/frame-axes";
|
|
4
|
+
import type { WorkBudget } from "../work-budget";
|
|
5
|
+
import type { DrawingArc, DrawingBounds, DrawingCircle, DrawingEllipse, DrawingPart, DrawingPolyline, DrawingSpline } from "./drawing-types";
|
|
6
|
+
type Point2 = Inputs.Base.Point2;
|
|
7
|
+
type Point3 = Inputs.Base.Point3;
|
|
8
|
+
type Vec3 = Inputs.Base.Vector3;
|
|
9
|
+
export declare const ocsAxesOf: (normal: Vec3) => FrameAxes;
|
|
10
|
+
export declare const circleArcOf: (segment: DrawingCircle | DrawingArc) => ConicArc;
|
|
11
|
+
export declare const ellipseArcOf: (segment: DrawingEllipse) => ConicArc;
|
|
12
|
+
export declare const pointsMeet: (a: Point2 | undefined, b: Point2) => boolean;
|
|
13
|
+
export declare const meetsReversed: (end: Point2 | undefined, start: Point2, finish: Point2) => boolean;
|
|
14
|
+
export declare const polylineSpans: (polyline: DrawingPolyline) => number;
|
|
15
|
+
export declare const polylineSpanEnd: (polyline: DrawingPolyline, span: number) => Point3;
|
|
16
|
+
export declare const bulgeArcOfSpan: (polyline: DrawingPolyline, span: number) => ConicArc | undefined;
|
|
17
|
+
export declare const segmentSamples: (segment: DrawingSpline | DrawingEllipse, tolerance: number, budget?: WorkBudget) => readonly Point3[];
|
|
18
|
+
export declare const drawingBounds: (parts: readonly DrawingPart[], tolerance: number, budget?: WorkBudget) => DrawingBounds | undefined;
|
|
19
|
+
export declare const drawingSize: (bounds: DrawingBounds | undefined, axes?: number) => number;
|
|
20
|
+
export declare const patternUnitOf: (bounds: DrawingBounds | undefined) => number;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { bezierPiecesBounds, samplesOfPiece } from "../../curves/bezier-pieces";
|
|
2
|
+
import { bulgeArcOf, conicArcExtremes, conicArcSamples } from "../../curves/conic-arcs";
|
|
3
|
+
import { bezierPiecesOf } from "../../curves/nurbs-forms";
|
|
4
|
+
import { unitOf } from "../../geometry/frame-axes";
|
|
5
|
+
import { cross3, distance2, length3, scale3 } from "../../geometry/vectors";
|
|
6
|
+
import { textCornersOf, textInked } from "./drawing-text";
|
|
7
|
+
import { ARBITRARY_AXIS_LIMIT, JOIN_DISTANCE, PATTERN_UNIT_SHARE, PLAN_AXES } from "./drawing.constants";
|
|
8
|
+
const WORLD_Y = [0, 1, 0];
|
|
9
|
+
const WORLD_Z = [0, 0, 1];
|
|
10
|
+
export const ocsAxesOf = (normal) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const nearZ = Math.abs(normal[0]) < ARBITRARY_AXIS_LIMIT && Math.abs(normal[1]) < ARBITRARY_AXIS_LIMIT;
|
|
13
|
+
const x = (_a = unitOf(cross3(nearZ ? WORLD_Y : WORLD_Z, normal))) !== null && _a !== void 0 ? _a : [1, 0, 0];
|
|
14
|
+
return { origin: [0, 0, 0], x, y: cross3(normal, x), z: normal };
|
|
15
|
+
};
|
|
16
|
+
export const circleArcOf = (segment) => {
|
|
17
|
+
const axes = ocsAxesOf(segment.normal);
|
|
18
|
+
const frame = { center: segment.center, xAxis: scale3(axes.x, segment.radius), yAxis: scale3(axes.y, segment.radius) };
|
|
19
|
+
return segment.kind === "circle"
|
|
20
|
+
? { frame, start: 0, sweep: 2 * Math.PI }
|
|
21
|
+
: { frame, start: segment.startAngle, sweep: segment.endAngle - segment.startAngle };
|
|
22
|
+
};
|
|
23
|
+
export const ellipseArcOf = (segment) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const minor = (_a = unitOf(cross3(segment.normal, segment.majorAxis))) !== null && _a !== void 0 ? _a : [0, 1, 0];
|
|
26
|
+
return {
|
|
27
|
+
frame: { center: segment.center, xAxis: segment.majorAxis, yAxis: scale3(minor, length3(segment.majorAxis) * segment.ratio) },
|
|
28
|
+
start: segment.start,
|
|
29
|
+
sweep: segment.end - segment.start,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export const pointsMeet = (a, b) => a !== undefined && distance2(a, b) <= JOIN_DISTANCE;
|
|
33
|
+
export const meetsReversed = (end, start, finish) => !pointsMeet(end, start) && pointsMeet(end, finish);
|
|
34
|
+
export const polylineSpans = (polyline) => polyline.closed ? polyline.points.length : polyline.points.length - 1;
|
|
35
|
+
export const polylineSpanEnd = (polyline, span) => polyline.points[(span + 1) % polyline.points.length];
|
|
36
|
+
export const bulgeArcOfSpan = (polyline, span) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const bulge = (_a = polyline.bulges[span]) !== null && _a !== void 0 ? _a : 0;
|
|
39
|
+
return bulge === 0 ? undefined : bulgeArcOf(polyline.points[span], polylineSpanEnd(polyline, span), bulge);
|
|
40
|
+
};
|
|
41
|
+
export const segmentSamples = (segment, tolerance, budget) => segment.kind === "ellipse"
|
|
42
|
+
? conicArcSamples(ellipseArcOf(segment), tolerance, budget)
|
|
43
|
+
: bezierPiecesOf(segment.curve, budget).flatMap((piece, at) => samplesOfPiece(piece, tolerance, budget).slice(at === 0 ? 0 : 1));
|
|
44
|
+
const boundsPointsOf = (segment, tolerance, budget) => {
|
|
45
|
+
switch (segment.kind) {
|
|
46
|
+
case "line":
|
|
47
|
+
return [segment.start, segment.end];
|
|
48
|
+
case "circle":
|
|
49
|
+
case "arc":
|
|
50
|
+
return conicArcExtremes(circleArcOf(segment));
|
|
51
|
+
case "ellipse":
|
|
52
|
+
return conicArcExtremes(ellipseArcOf(segment));
|
|
53
|
+
case "polyline": {
|
|
54
|
+
const arcs = Array.from({ length: polylineSpans(segment) }, (_, span) => bulgeArcOfSpan(segment, span));
|
|
55
|
+
return [...segment.points, ...arcs.flatMap(arc => arc === undefined ? [] : conicArcExtremes(arc))];
|
|
56
|
+
}
|
|
57
|
+
case "spline": {
|
|
58
|
+
const bounds = bezierPiecesBounds(bezierPiecesOf(segment.curve, budget), tolerance, budget);
|
|
59
|
+
return [bounds.min, bounds.max];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export const drawingBounds = (parts, tolerance, budget) => {
|
|
64
|
+
const min = [Infinity, Infinity, Infinity];
|
|
65
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
66
|
+
const grow = (points) => {
|
|
67
|
+
for (const point of points) {
|
|
68
|
+
for (let axis = 0; axis < min.length; axis++) {
|
|
69
|
+
min[axis] = Math.min(min[axis], point[axis]);
|
|
70
|
+
max[axis] = Math.max(max[axis], point[axis]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const growByPaths = (paths) => {
|
|
75
|
+
for (const path of paths) {
|
|
76
|
+
for (const segment of path.segments) {
|
|
77
|
+
grow(boundsPointsOf(segment, tolerance, budget));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
for (const part of parts) {
|
|
82
|
+
growByPaths(part.paths);
|
|
83
|
+
for (const hatch of part.hatches) {
|
|
84
|
+
growByPaths(hatch.boundaries);
|
|
85
|
+
}
|
|
86
|
+
for (const text of part.texts) {
|
|
87
|
+
if (textInked(text)) {
|
|
88
|
+
grow(textCornersOf(text));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return min[0] === Infinity ? undefined : { min, max };
|
|
93
|
+
};
|
|
94
|
+
export const drawingSize = (bounds, axes = PLAN_AXES) => {
|
|
95
|
+
let size = 0;
|
|
96
|
+
for (let axis = 0; axis < axes && bounds !== undefined; axis++) {
|
|
97
|
+
size = Math.max(size, bounds.max[axis] - bounds.min[axis]);
|
|
98
|
+
}
|
|
99
|
+
return size > 0 ? size : 1;
|
|
100
|
+
};
|
|
101
|
+
export const patternUnitOf = (bounds) => drawingSize(bounds) * PATTERN_UNIT_SHARE;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import type { WorkBudget } from "../work-budget";
|
|
3
|
+
import type { DrawingHatch, DrawingHatchFamily } from "./drawing-types";
|
|
4
|
+
type Point2 = Inputs.Base.Point2;
|
|
5
|
+
type Segment2 = Inputs.Base.Segment2;
|
|
6
|
+
export declare const hatchOutlinesOf: (hatch: DrawingHatch, tolerance: number, budget?: WorkBudget) => Point2[][];
|
|
7
|
+
export declare const clippedHatchLinesOf: (hatch: DrawingHatch, tolerance: number, property: string, budget?: WorkBudget) => Segment2[];
|
|
8
|
+
export declare const hatchFamiliesOf: (hatch: DrawingHatch) => DrawingHatchFamily[];
|
|
9
|
+
export declare const hatchLinesOf: (hatch: DrawingHatch, tolerance: number, property: string, budget?: WorkBudget) => Segment2[];
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import { InputError } from "../../../../kernel-calls";
|
|
3
|
+
import { bulgeArcOf, conicArcSamples } from "../../curves/conic-arcs";
|
|
4
|
+
import { radiansOf } from "../../geometry/scalars";
|
|
5
|
+
import { add2, between2, dot2, leftOf2, polar2, scale2 } from "../../geometry/vectors";
|
|
6
|
+
import { drawingBounds } from "./drawing-geometry";
|
|
7
|
+
import { drawingLoopsOf } from "./drawing-loops";
|
|
8
|
+
import { DEFAULT_LAYER, HATCH_FAMILIES, LEAST_LOOP_CORNERS, MOST_HATCH_LINES, SAME_POINT } from "./drawing.constants";
|
|
9
|
+
const flatLoopOf = (loop, tolerance, budget) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const points = [];
|
|
12
|
+
const count = loop.points.length;
|
|
13
|
+
for (let at = 0; at < count; at++) {
|
|
14
|
+
const start = loop.points[at];
|
|
15
|
+
const bulge = (_a = loop.bulges[at]) !== null && _a !== void 0 ? _a : 0;
|
|
16
|
+
points.push([start[0], start[1]]);
|
|
17
|
+
if (bulge === 0) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const end = loop.points[(at + 1) % count];
|
|
21
|
+
const samples = conicArcSamples(bulgeArcOf([start[0], start[1], 0], [end[0], end[1], 0], bulge), tolerance, budget);
|
|
22
|
+
for (let sample = 1; sample < samples.length - 1; sample++) {
|
|
23
|
+
points.push([samples[sample][0], samples[sample][1]]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return points;
|
|
27
|
+
};
|
|
28
|
+
export const hatchOutlinesOf = (hatch, tolerance, budget) => drawingLoopsOf(hatch.boundaries, tolerance, budget)
|
|
29
|
+
.map(loop => flatLoopOf(loop, tolerance, budget))
|
|
30
|
+
.filter(loop => loop.length >= LEAST_LOOP_CORNERS);
|
|
31
|
+
const stepsAcross = (outlines, family, spacing) => {
|
|
32
|
+
let lowest = Infinity;
|
|
33
|
+
let highest = -Infinity;
|
|
34
|
+
for (const outline of outlines) {
|
|
35
|
+
for (const point of outline) {
|
|
36
|
+
const offset = dot2(point, family.across);
|
|
37
|
+
lowest = Math.min(lowest, offset);
|
|
38
|
+
highest = Math.max(highest, offset);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { first: Math.ceil((lowest - family.phase) / spacing), last: Math.floor((highest - family.phase) / spacing) };
|
|
42
|
+
};
|
|
43
|
+
const crossingsOf = (outlines, family, spacing, steps) => {
|
|
44
|
+
const crossings = Array.from({ length: steps.last - steps.first + 1 }, () => []);
|
|
45
|
+
const offsetOf = (step) => family.phase + step * spacing;
|
|
46
|
+
for (const outline of outlines) {
|
|
47
|
+
for (let at = 0; at < outline.length; at++) {
|
|
48
|
+
const start = outline[at];
|
|
49
|
+
const end = outline[(at + 1) % outline.length];
|
|
50
|
+
const from = dot2(start, family.across);
|
|
51
|
+
const to = dot2(end, family.across);
|
|
52
|
+
if (from === to) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const lowest = Math.max(steps.first, Math.floor((Math.min(from, to) - family.phase) / spacing));
|
|
56
|
+
const highest = Math.min(steps.last, Math.ceil((Math.max(from, to) - family.phase) / spacing));
|
|
57
|
+
for (let step = lowest; step <= highest; step++) {
|
|
58
|
+
const offset = offsetOf(step);
|
|
59
|
+
if ((from > offset) !== (to > offset)) {
|
|
60
|
+
crossings[step - steps.first].push(dot2(between2(start, end, (offset - from) / (to - from)), family.direction));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return crossings;
|
|
66
|
+
};
|
|
67
|
+
export const clippedHatchLinesOf = (hatch, tolerance, property, budget) => {
|
|
68
|
+
const outlines = hatchOutlinesOf(hatch, tolerance, budget);
|
|
69
|
+
if (outlines.length === 0) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const lines = [];
|
|
73
|
+
let counted = 0;
|
|
74
|
+
for (const family of hatchFamiliesOf(hatch)) {
|
|
75
|
+
const steps = stepsAcross(outlines, family, hatch.spacing);
|
|
76
|
+
counted += Math.max(0, steps.last - steps.first + 1);
|
|
77
|
+
if (counted > MOST_HATCH_LINES) {
|
|
78
|
+
throw new InputError(`\`${property}\` is ${hatch.spacing} for a region that would take more than ${MOST_HATCH_LINES} lines: widen the spacing.`, property);
|
|
79
|
+
}
|
|
80
|
+
crossingsOf(outlines, family, hatch.spacing, steps).forEach((crossing, at) => {
|
|
81
|
+
const base = scale2(family.across, family.phase + (steps.first + at) * hatch.spacing);
|
|
82
|
+
const sorted = [...crossing].sort((a, b) => a - b);
|
|
83
|
+
for (let pair = 0; pair + 1 < sorted.length; pair += 2) {
|
|
84
|
+
const enter = sorted[pair];
|
|
85
|
+
const leave = sorted[pair + 1];
|
|
86
|
+
if (leave - enter > SAME_POINT) {
|
|
87
|
+
lines.push([add2(base, scale2(family.direction, enter)), add2(base, scale2(family.direction, leave))]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return lines;
|
|
93
|
+
};
|
|
94
|
+
export const hatchFamiliesOf = (hatch) => HATCH_FAMILIES[hatch.pattern].map(([turn, share]) => {
|
|
95
|
+
const angle = hatch.angle + turn;
|
|
96
|
+
const direction = polar2(1, radiansOf(angle));
|
|
97
|
+
return { turn, angle, direction, across: leftOf2(direction), phase: (1 - share) * hatch.spacing };
|
|
98
|
+
});
|
|
99
|
+
export const hatchLinesOf = (hatch, tolerance, property, budget) => {
|
|
100
|
+
const region = { layer: DEFAULT_LAYER, color: "#000000", lineType: Inputs.IO.lineTypeEnum.continuous, lineWeight: undefined, paths: hatch.boundaries, texts: [], hatches: [] };
|
|
101
|
+
const bounds = drawingBounds([region], tolerance, budget);
|
|
102
|
+
if (bounds === undefined) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const corners = [[bounds.min[0], bounds.min[1]], [bounds.max[0], bounds.min[1]], [bounds.max[0], bounds.max[1]], [bounds.min[0], bounds.max[1]]];
|
|
106
|
+
const lines = [];
|
|
107
|
+
for (const family of hatchFamiliesOf(hatch)) {
|
|
108
|
+
const reaches = corners.map(corner => dot2(corner, family.direction));
|
|
109
|
+
const offsets = corners.map(corner => dot2(corner, family.across));
|
|
110
|
+
const from = Math.min(...reaches);
|
|
111
|
+
const to = Math.max(...reaches);
|
|
112
|
+
const first = Math.ceil((Math.min(...offsets) - family.phase) / hatch.spacing);
|
|
113
|
+
const last = Math.floor((Math.max(...offsets) - family.phase) / hatch.spacing);
|
|
114
|
+
if (lines.length + Math.max(0, last - first + 1) > MOST_HATCH_LINES) {
|
|
115
|
+
throw new InputError(`\`${property}\` is ${hatch.spacing} for a region that would take more than ${MOST_HATCH_LINES} lines: widen the spacing.`, property);
|
|
116
|
+
}
|
|
117
|
+
for (let step = first; step <= last; step++) {
|
|
118
|
+
const base = scale2(family.across, family.phase + step * hatch.spacing);
|
|
119
|
+
lines.push([add2(base, scale2(family.direction, from)), add2(base, scale2(family.direction, to))]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return lines;
|
|
123
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { bulgeOfSweep, conicArcSamples, ellipseFramePoint } from "../../curves/conic-arcs";
|
|
2
|
+
import { circleArcOf, meetsReversed, pointsMeet, polylineSpans, segmentSamples } from "./drawing-geometry";
|
|
3
|
+
import { JOIN_DISTANCE } from "./drawing.constants";
|
|
4
|
+
const flat = (point) => [point[0], point[1]];
|
|
5
|
+
const straightRun = (points) => ({ points: points.map(flat), bulges: points.slice(1).map(() => 0) });
|
|
6
|
+
const circularRun = (segment, tolerance, budget) => {
|
|
7
|
+
const arc = circleArcOf(segment);
|
|
8
|
+
if (segment.normal[0] !== 0 || segment.normal[1] !== 0) {
|
|
9
|
+
return straightRun(conicArcSamples(arc, tolerance, budget));
|
|
10
|
+
}
|
|
11
|
+
const spans = Math.max(1, Math.ceil(arc.sweep / Math.PI - JOIN_DISTANCE));
|
|
12
|
+
const step = arc.sweep / spans;
|
|
13
|
+
const bulge = Math.sign(segment.normal[2]) * bulgeOfSweep(step);
|
|
14
|
+
return {
|
|
15
|
+
points: Array.from({ length: spans + 1 }, (_, at) => flat(ellipseFramePoint(arc.frame, arc.start + at * step))),
|
|
16
|
+
bulges: Array.from({ length: spans }, () => bulge),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const runOf = (segment, tolerance, budget) => {
|
|
20
|
+
switch (segment.kind) {
|
|
21
|
+
case "line":
|
|
22
|
+
return straightRun([segment.start, segment.end]);
|
|
23
|
+
case "polyline": {
|
|
24
|
+
const spans = polylineSpans(segment);
|
|
25
|
+
return {
|
|
26
|
+
points: Array.from({ length: spans + 1 }, (_, at) => flat(segment.points[at % segment.points.length])),
|
|
27
|
+
bulges: Array.from({ length: spans }, (_, span) => { var _a; return segment.planar ? (_a = segment.bulges[span]) !== null && _a !== void 0 ? _a : 0 : 0; }),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case "circle":
|
|
31
|
+
case "arc":
|
|
32
|
+
return circularRun(segment, tolerance, budget);
|
|
33
|
+
default:
|
|
34
|
+
return straightRun(segmentSamples(segment, tolerance, budget));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const reversed = (run) => ({ points: [...run.points].reverse(), bulges: [...run.bulges].reverse().map(bulge => -bulge) });
|
|
38
|
+
const appended = (open, run) => {
|
|
39
|
+
for (let at = 1; at < run.points.length; at++) {
|
|
40
|
+
open.points.push(run.points[at]);
|
|
41
|
+
}
|
|
42
|
+
for (const bulge of run.bulges) {
|
|
43
|
+
open.bulges.push(bulge);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export const drawingLoopsOf = (paths, tolerance, budget) => {
|
|
47
|
+
const loops = [];
|
|
48
|
+
let open;
|
|
49
|
+
const close = () => {
|
|
50
|
+
if (open !== undefined && open.points.length > 1) {
|
|
51
|
+
if (pointsMeet(open.points[0], open.points[open.points.length - 1])) {
|
|
52
|
+
open.points.pop();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
open.bulges.push(0);
|
|
56
|
+
}
|
|
57
|
+
if (open.points.length > 2 || open.bulges.some(bulge => bulge !== 0)) {
|
|
58
|
+
loops.push(open);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
open = undefined;
|
|
62
|
+
};
|
|
63
|
+
for (const path of paths) {
|
|
64
|
+
for (const segment of path.segments) {
|
|
65
|
+
let run = runOf(segment, tolerance, budget);
|
|
66
|
+
if (run.points.length < 2) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (open !== undefined) {
|
|
70
|
+
const end = open.points[open.points.length - 1];
|
|
71
|
+
if (meetsReversed(end, run.points[0], run.points[run.points.length - 1])) {
|
|
72
|
+
run = reversed(run);
|
|
73
|
+
}
|
|
74
|
+
if (pointsMeet(end, run.points[0])) {
|
|
75
|
+
appended(open, run);
|
|
76
|
+
if (pointsMeet(open.points[0], open.points[open.points.length - 1])) {
|
|
77
|
+
close();
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
close();
|
|
82
|
+
}
|
|
83
|
+
open = { points: [...run.points], bulges: [...run.bulges] };
|
|
84
|
+
if (pointsMeet(open.points[0], open.points[open.points.length - 1])) {
|
|
85
|
+
close();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
close();
|
|
89
|
+
}
|
|
90
|
+
return loops;
|
|
91
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import type { DrawingHatch, DrawingPart, DrawingPath, DrawingSegment, DrawingText } from "./drawing-types";
|
|
3
|
+
export declare const isDrawable: (value: unknown) => value is number;
|
|
4
|
+
export declare const finiteNumber: (value: unknown, property: string) => number;
|
|
5
|
+
export declare const positiveNumber: (value: unknown, property: string) => number;
|
|
6
|
+
export declare const segmentKindOf: (segment: unknown) => DrawingSegment["kind"] | undefined;
|
|
7
|
+
export declare const drawingPathOf: (path: Inputs.IO.DrawingPathDto | undefined, property: string) => DrawingPath;
|
|
8
|
+
export declare const drawingTextOf: (text: unknown, property: string) => DrawingText;
|
|
9
|
+
export declare const drawingHatchOf: (hatch: unknown, property: string) => DrawingHatch;
|
|
10
|
+
export declare const drawingPartsOf: (parts: readonly unknown[] | undefined, property: string) => DrawingPart[];
|