@bitbybit-dev/base 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +36 -7
- package/lib/api/inputs/base-inputs.js +10 -0
- package/lib/api/inputs/color-inputs.d.ts +54 -1
- package/lib/api/inputs/color-inputs.js +73 -1
- package/lib/api/inputs/frame-inputs.d.ts +2 -1
- package/lib/api/inputs/frame-inputs.js +2 -1
- package/lib/api/inputs/io-inputs.d.ts +527 -59
- package/lib/api/inputs/io-inputs.js +432 -40
- package/lib/api/inputs/line-inputs.d.ts +17 -0
- package/lib/api/inputs/line-inputs.js +15 -0
- package/lib/api/inputs/math-inputs.d.ts +62 -0
- package/lib/api/inputs/math-inputs.js +82 -0
- package/lib/api/inputs/mesh-inputs.d.ts +16 -0
- package/lib/api/inputs/mesh-inputs.js +14 -0
- package/lib/api/inputs/transforms-inputs.d.ts +76 -0
- package/lib/api/inputs/transforms-inputs.js +85 -0
- package/lib/api/kernel-calls/index.d.ts +1 -0
- package/lib/api/kernel-calls/index.js +1 -0
- package/lib/api/kernel-calls/settings.d.ts +82 -0
- package/lib/api/kernel-calls/settings.js +123 -0
- package/lib/api/recipes/surface-mesh.d.ts +2 -1
- package/lib/api/recipes/surface-mesh.js +5 -3
- package/lib/api/resolved-inputs/index.d.ts +32 -2
- package/lib/api/services/base-bitbybit.d.ts +12 -0
- package/lib/api/services/base-bitbybit.js +19 -3
- package/lib/api/services/color.d.ts +36 -2
- package/lib/api/services/color.js +60 -11
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +10 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +10 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.js +27 -0
- package/lib/api/services/helpers/color/css-colors.constants.d.ts +9 -0
- package/lib/api/services/helpers/color/css-colors.constants.js +158 -0
- package/lib/api/services/helpers/color/css-colors.d.ts +1 -0
- package/lib/api/services/helpers/color/css-colors.js +61 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.js +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.d.ts +24 -0
- package/lib/api/services/helpers/curves/bezier-pieces.js +149 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.js +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +24 -0
- package/lib/api/services/helpers/curves/conic-arcs.js +85 -0
- package/lib/api/services/helpers/curves/nurbs-forms.d.ts +20 -0
- package/lib/api/services/helpers/curves/nurbs-forms.js +112 -0
- package/lib/api/services/helpers/curves/nurbs.d.ts +4 -0
- package/lib/api/services/helpers/curves/nurbs.js +10 -9
- package/lib/api/services/helpers/files/drawing/drawing-budget.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +24 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +18 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +84 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +5 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.js +252 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +60 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.js +1 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +28 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +29 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.js +45 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +193 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.d.ts +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.js +50 -0
- package/lib/api/services/helpers/files/dxf/dxf-generator.d.ts +2 -36
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +81 -523
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.d.ts +6 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +81 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.js +67 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +69 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.js +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +71 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +78 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +556 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +27 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +247 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.d.ts +26 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.js +97 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +65 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +32 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +34 -1
- package/lib/api/services/helpers/files/file-bytes.d.ts +1 -0
- package/lib/api/services/helpers/files/file-bytes.js +15 -0
- package/lib/api/services/helpers/files/ground-axes.d.ts +2 -0
- package/lib/api/services/helpers/files/ground-axes.js +4 -0
- package/lib/api/services/helpers/files/mesh-file-axes.d.ts +7 -0
- package/lib/api/services/helpers/files/mesh-file-axes.js +17 -0
- package/lib/api/services/helpers/files/stl-axes.d.ts +4 -0
- package/lib/api/services/helpers/files/stl-axes.js +22 -0
- package/lib/api/services/helpers/files/stl-types.d.ts +7 -0
- package/lib/api/services/helpers/files/stl-types.js +1 -0
- package/lib/api/services/helpers/files/stl.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/stl.constants.js +11 -0
- package/lib/api/services/helpers/files/stl.d.ts +3 -0
- package/lib/api/services/helpers/files/stl.js +93 -0
- package/lib/api/services/helpers/files/svg/svg-css.d.ts +48 -0
- package/lib/api/services/helpers/files/svg/svg-css.js +444 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-document.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-document.js +89 -0
- package/lib/api/services/helpers/files/svg/svg-memo.d.ts +1 -0
- package/lib/api/services/helpers/files/svg/svg-memo.js +8 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.js +433 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.d.ts +15 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.js +61 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.d.ts +8 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.js +10 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.js +203 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.d.ts +33 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.d.ts +35 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.js +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-reading.js +233 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.d.ts +54 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.js +102 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +38 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.js +108 -0
- package/lib/api/services/helpers/files/svg/svg-style.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-style.js +211 -0
- package/lib/api/services/helpers/files/svg/svg-transform.d.ts +10 -0
- package/lib/api/services/helpers/files/svg/svg-transform.js +76 -0
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +16 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +153 -0
- package/lib/api/services/helpers/files/svg/svg-xml.d.ts +11 -0
- package/lib/api/services/helpers/files/svg/svg-xml.js +322 -0
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +13 -0
- package/lib/api/services/helpers/files/svg/svg.constants.js +13 -0
- package/lib/api/services/helpers/files/work-budget.d.ts +11 -0
- package/lib/api/services/helpers/files/work-budget.js +26 -0
- package/lib/api/services/helpers/geometry/affine2.d.ts +8 -0
- package/lib/api/services/helpers/geometry/affine2.js +18 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.d.ts +14 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.js +96 -0
- package/lib/api/services/helpers/geometry/frame-axes.d.ts +3 -1
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.d.ts +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.js +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.d.ts +31 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.js +251 -0
- package/lib/api/services/helpers/geometry/quaternions.constants.d.ts +3 -0
- package/lib/api/services/helpers/geometry/quaternions.constants.js +3 -0
- package/lib/api/services/helpers/geometry/quaternions.d.ts +14 -0
- package/lib/api/services/helpers/geometry/quaternions.js +71 -0
- package/lib/api/services/helpers/geometry/scalars.constants.d.ts +1 -0
- package/lib/api/services/helpers/geometry/scalars.constants.js +1 -0
- package/lib/api/services/helpers/geometry/scalars.d.ts +3 -0
- package/lib/api/services/helpers/geometry/scalars.js +29 -1
- package/lib/api/services/helpers/geometry/vectors.d.ts +1 -0
- package/lib/api/services/helpers/geometry/vectors.js +6 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.d.ts +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.js +40 -40
- package/lib/api/services/io/drawing.d.ts +170 -0
- package/lib/api/services/io/drawing.js +212 -0
- package/lib/api/services/io/dxf.d.ts +134 -0
- package/lib/api/services/io/dxf.js +167 -0
- package/lib/api/services/io/index.d.ts +4 -0
- package/lib/api/services/io/index.js +4 -0
- package/lib/api/services/io/io.d.ts +14 -0
- package/lib/api/services/io/io.js +15 -0
- package/lib/api/services/io/svg.d.ts +64 -0
- package/lib/api/services/io/svg.js +102 -0
- package/lib/api/services/line.d.ts +17 -0
- package/lib/api/services/line.js +20 -1
- package/lib/api/services/math.d.ts +35 -0
- package/lib/api/services/math.js +56 -1
- package/lib/api/services/mesh.d.ts +17 -0
- package/lib/api/services/mesh.js +27 -1
- package/lib/api/services/point.d.ts +4 -1
- package/lib/api/services/point.js +9 -4
- package/lib/api/services/recipes.d.ts +3 -0
- package/lib/api/services/recipes.js +4 -1
- package/lib/api/services/text.d.ts +4 -1
- package/lib/api/services/text.js +8 -3
- package/lib/api/services/transforms.d.ts +119 -1
- package/lib/api/services/transforms.js +158 -30
- package/package.json +1 -1
- package/lib/api/services/helpers/files/dxf/dxf.d.ts +0 -87
- package/lib/api/services/helpers/files/dxf/dxf.js +0 -111
- package/lib/api/services/io.d.ts +0 -9
- package/lib/api/services/io.js +0 -10
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { blendedPoint, liftedPoint, projectedPoint } from "./nurbs";
|
|
2
|
+
import { pointOnCubic3 } from "../geometry/arcs";
|
|
3
|
+
import { add3, distance3, distanceToSegment3, scale3, subtract3 } from "../geometry/vectors";
|
|
4
|
+
import { DEEPEST_SPLIT, FIT_SAMPLES, FLATNESS_SHARES, HALF, HERMITE_THIRD } from "./bezier-pieces.constants";
|
|
5
|
+
import { LEAST_RELATIVE_TOLERANCE } from "./conic-arcs.constants";
|
|
6
|
+
const homogeneousOf = (piece) => piece.points.map((point, at) => { var _a; return liftedPoint(point, (_a = piece.weights[at]) !== null && _a !== void 0 ? _a : 1); });
|
|
7
|
+
const blendsOf = (points) => (points.length * (points.length + 1)) / 2;
|
|
8
|
+
const isFinitePoint = (point) => point.every(Number.isFinite);
|
|
9
|
+
const paidFor = (budget, work) => budget === undefined || budget.spend(work);
|
|
10
|
+
export const bezierPointAndTangent = (piece, parameter) => {
|
|
11
|
+
let level = homogeneousOf(piece);
|
|
12
|
+
const degree = level.length - 1;
|
|
13
|
+
while (level.length > 2) {
|
|
14
|
+
level = level.slice(1).map((point, at) => blendedPoint(level[at], point, parameter));
|
|
15
|
+
}
|
|
16
|
+
const [left, right] = [level[0], level[1]];
|
|
17
|
+
const value = blendedPoint(left, right, parameter);
|
|
18
|
+
const point = projectedPoint(value);
|
|
19
|
+
const change = [degree * (right[0] - left[0]), degree * (right[1] - left[1]), degree * (right[2] - left[2]), degree * (right[3] - left[3])];
|
|
20
|
+
const tangent = [
|
|
21
|
+
(change[0] - change[3] * point[0]) / value[3],
|
|
22
|
+
(change[1] - change[3] * point[1]) / value[3],
|
|
23
|
+
(change[2] - change[3] * point[2]) / value[3],
|
|
24
|
+
];
|
|
25
|
+
return { point, tangent };
|
|
26
|
+
};
|
|
27
|
+
export const bezierPoint = (piece, parameter) => bezierPointAndTangent(piece, parameter).point;
|
|
28
|
+
const boundsOf = (points) => {
|
|
29
|
+
const min = [Infinity, Infinity, Infinity];
|
|
30
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
31
|
+
for (const point of points) {
|
|
32
|
+
for (let axis = 0; axis < min.length; axis++) {
|
|
33
|
+
min[axis] = Math.min(min[axis], point[axis]);
|
|
34
|
+
max[axis] = Math.max(max[axis], point[axis]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { min, max };
|
|
38
|
+
};
|
|
39
|
+
const flooredTolerance = (points, tolerance) => {
|
|
40
|
+
const { min, max } = boundsOf(points);
|
|
41
|
+
return Math.max(tolerance, LEAST_RELATIVE_TOLERANCE * Math.max(max[0] - min[0], max[1] - min[1], max[2] - min[2]));
|
|
42
|
+
};
|
|
43
|
+
const hermiteOver = (piece, span) => {
|
|
44
|
+
const length = span.to - span.from;
|
|
45
|
+
const start = bezierPointAndTangent(piece, span.from);
|
|
46
|
+
const end = bezierPointAndTangent(piece, span.to);
|
|
47
|
+
return {
|
|
48
|
+
start: start.point,
|
|
49
|
+
control1: add3(start.point, scale3(start.tangent, length * HERMITE_THIRD)),
|
|
50
|
+
control2: subtract3(end.point, scale3(end.tangent, length * HERMITE_THIRD)),
|
|
51
|
+
end: end.point,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const fitsWithin = (piece, span, cubic, tolerance) => {
|
|
55
|
+
for (let sample = 1; sample < FIT_SAMPLES; sample++) {
|
|
56
|
+
const share = sample / FIT_SAMPLES;
|
|
57
|
+
if (distance3(pointOnCubic3(cubic.start, cubic.control1, cubic.control2, cubic.end, share), bezierPoint(piece, span.from + share * (span.to - span.from))) > tolerance) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
const split = (span) => {
|
|
64
|
+
const middle = (span.from + span.to) / 2;
|
|
65
|
+
return [{ from: span.from, to: middle, depth: span.depth + 1 }, { from: middle, to: span.to, depth: span.depth + 1 }];
|
|
66
|
+
};
|
|
67
|
+
export const cubicsOfPiece = (piece, tolerance, budget) => {
|
|
68
|
+
const floored = flooredTolerance(piece.points, tolerance);
|
|
69
|
+
const spanWork = (FIT_SAMPLES + 1) * blendsOf(piece.points);
|
|
70
|
+
const cubics = [];
|
|
71
|
+
const pending = [{ from: 0, to: 1, depth: 0 }];
|
|
72
|
+
while (pending.length > 0 && paidFor(budget, spanWork)) {
|
|
73
|
+
const span = pending.pop();
|
|
74
|
+
const cubic = hermiteOver(piece, span);
|
|
75
|
+
const finite = [cubic.start, cubic.control1, cubic.control2, cubic.end].every(isFinitePoint);
|
|
76
|
+
if (span.depth >= DEEPEST_SPLIT || !finite || fitsWithin(piece, span, cubic, floored)) {
|
|
77
|
+
cubics.push(cubic);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const [first, second] = split(span);
|
|
81
|
+
pending.push(second, first);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return cubics;
|
|
85
|
+
};
|
|
86
|
+
const isFlat = (piece, span, from, to, tolerance) => FLATNESS_SHARES.every(share => distanceToSegment3(bezierPoint(piece, span.from + share * (span.to - span.from)), from, to) <= tolerance);
|
|
87
|
+
export const samplesOfPiece = (piece, tolerance, budget) => {
|
|
88
|
+
const floored = flooredTolerance(piece.points, tolerance);
|
|
89
|
+
const spanWork = (FLATNESS_SHARES.length + 2) * blendsOf(piece.points);
|
|
90
|
+
const samples = [bezierPoint(piece, 0)];
|
|
91
|
+
const pending = [{ from: 0, to: 1, depth: 0 }];
|
|
92
|
+
while (pending.length > 0 && paidFor(budget, spanWork)) {
|
|
93
|
+
const span = pending.pop();
|
|
94
|
+
const from = bezierPoint(piece, span.from);
|
|
95
|
+
const to = bezierPoint(piece, span.to);
|
|
96
|
+
const finite = isFinitePoint(from) && isFinitePoint(to);
|
|
97
|
+
if (span.depth >= DEEPEST_SPLIT || !finite || (span.depth > 0 && isFlat(piece, span, from, to, floored))) {
|
|
98
|
+
samples.push(to);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const [first, second] = split(span);
|
|
102
|
+
pending.push(second, first);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return samples;
|
|
106
|
+
};
|
|
107
|
+
const halvesOf = (points) => {
|
|
108
|
+
const first = [];
|
|
109
|
+
const second = [];
|
|
110
|
+
let level = points;
|
|
111
|
+
while (level.length > 0) {
|
|
112
|
+
first.push(level[0]);
|
|
113
|
+
second.unshift(level[level.length - 1]);
|
|
114
|
+
level = level.slice(1).map((point, at) => blendedPoint(level[at], point, HALF));
|
|
115
|
+
}
|
|
116
|
+
return [first, second];
|
|
117
|
+
};
|
|
118
|
+
const widened = (bounds, by) => ({
|
|
119
|
+
min: bounds.min.map((value, axis) => Math.min(value, by.min[axis])),
|
|
120
|
+
max: bounds.max.map((value, axis) => Math.max(value, by.max[axis])),
|
|
121
|
+
});
|
|
122
|
+
const liesWithin = (inner, outer, slack) => inner.min.every((value, axis) => value >= outer.min[axis] - slack && inner.max[axis] <= outer.max[axis] + slack);
|
|
123
|
+
export const bezierPiecesBounds = (pieces, tolerance, budget) => {
|
|
124
|
+
const slack = flooredTolerance(pieces.flatMap(piece => piece.points), tolerance);
|
|
125
|
+
let reached = boundsOf(pieces.flatMap(piece => [piece.points[0], piece.points[piece.points.length - 1]]));
|
|
126
|
+
const pending = [];
|
|
127
|
+
for (let next = pieces.length - 1; next >= 0 && (budget === null || budget === void 0 ? void 0 : budget.exhausted) !== true; next--) {
|
|
128
|
+
pending.push({ points: homogeneousOf(pieces[next]), depth: 0 });
|
|
129
|
+
while (pending.length > 0 && paidFor(budget, pending[pending.length - 1].points.length)) {
|
|
130
|
+
const { points, depth } = pending.pop();
|
|
131
|
+
const hull = boundsOf(points.map(projectedPoint));
|
|
132
|
+
if (liesWithin(hull, reached, slack)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (depth >= DEEPEST_SPLIT || !isFinitePoint(hull.min) || !isFinitePoint(hull.max)) {
|
|
136
|
+
reached = widened(reached, hull);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (!paidFor(budget, blendsOf(points))) {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
const [first, second] = halvesOf(points);
|
|
143
|
+
const middle = projectedPoint(second[0]);
|
|
144
|
+
reached = widened(reached, { min: middle, max: middle });
|
|
145
|
+
pending.push({ points: second, depth: depth + 1 }, { points: first, depth: depth + 1 });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { min: reached.min.map(value => value - slack), max: reached.max.map(value => value + slack) };
|
|
149
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type * as Inputs from "../../../inputs";
|
|
2
|
+
import type { NurbsCurveForm } from "./nurbs-forms";
|
|
3
|
+
import type { EllipseArc2 } from "../geometry/ellipse-arcs";
|
|
4
|
+
type Point3 = Inputs.Base.Point3;
|
|
5
|
+
type Vec3 = Inputs.Base.Vector3;
|
|
6
|
+
export interface EllipseFrame {
|
|
7
|
+
readonly center: Point3;
|
|
8
|
+
readonly xAxis: Vec3;
|
|
9
|
+
readonly yAxis: Vec3;
|
|
10
|
+
}
|
|
11
|
+
export interface ConicArc {
|
|
12
|
+
readonly frame: EllipseFrame;
|
|
13
|
+
readonly start: number;
|
|
14
|
+
readonly sweep: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const angleWithinTurn: (angle: number, turn: number) => number;
|
|
17
|
+
export declare const ellipseFramePoint: (frame: EllipseFrame, angle: number) => Point3;
|
|
18
|
+
export declare const conicArcOfEllipseArc: (arc: EllipseArc2) => ConicArc;
|
|
19
|
+
export declare const conicArcSamples: (arc: ConicArc, tolerance: number) => Point3[];
|
|
20
|
+
export declare const conicArcAsNurbs: (arc: ConicArc) => NurbsCurveForm;
|
|
21
|
+
export declare const bulgeArcOf: (start: Point3, end: Point3, bulge: number) => ConicArc;
|
|
22
|
+
export declare const conicArcExtremes: (arc: ConicArc, axes?: readonly number[]) => Point3[];
|
|
23
|
+
export declare const principalArcOf: (arc: ConicArc) => ConicArc;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { add3, distance2, dot3, length3, scale3 } from "../geometry/vectors";
|
|
2
|
+
import { BULGE_TURN_SHARE, FRAME_AXES, LEAST_RELATIVE_TOLERANCE, PIECE_SLACK, QUARTER_TURN } from "./conic-arcs.constants";
|
|
3
|
+
export const angleWithinTurn = (angle, turn) => ((angle % turn) + turn) % turn;
|
|
4
|
+
export const ellipseFramePoint = (frame, angle) => add3(frame.center, add3(scale3(frame.xAxis, Math.cos(angle)), scale3(frame.yAxis, Math.sin(angle))));
|
|
5
|
+
export const conicArcOfEllipseArc = (arc) => {
|
|
6
|
+
const cos = Math.cos(arc.xAxisRotation);
|
|
7
|
+
const sin = Math.sin(arc.xAxisRotation);
|
|
8
|
+
return {
|
|
9
|
+
frame: { center: [arc.center[0], arc.center[1], 0], xAxis: [arc.rx * cos, arc.rx * sin, 0], yAxis: [-arc.ry * sin, arc.ry * cos, 0] },
|
|
10
|
+
start: arc.startAngle,
|
|
11
|
+
sweep: arc.deltaAngle,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export const conicArcSamples = (arc, tolerance) => {
|
|
15
|
+
const radius = Math.max(length3(arc.frame.xAxis), length3(arc.frame.yAxis));
|
|
16
|
+
const relative = Math.max(tolerance / radius, LEAST_RELATIVE_TOLERANCE);
|
|
17
|
+
const step = relative >= 1 ? QUARTER_TURN : Math.min(QUARTER_TURN, 2 * Math.acos(1 - relative));
|
|
18
|
+
const count = Math.max(1, Math.ceil(Math.abs(arc.sweep) / step));
|
|
19
|
+
return Array.from({ length: count + 1 }, (_, at) => ellipseFramePoint(arc.frame, arc.start + (arc.sweep * at) / count));
|
|
20
|
+
};
|
|
21
|
+
export const conicArcAsNurbs = (arc) => {
|
|
22
|
+
const pieces = Math.max(1, Math.ceil(Math.abs(arc.sweep) / QUARTER_TURN - PIECE_SLACK));
|
|
23
|
+
const step = arc.sweep / pieces;
|
|
24
|
+
const middleWeight = Math.cos(step / 2);
|
|
25
|
+
const points = [ellipseFramePoint(arc.frame, arc.start)];
|
|
26
|
+
const weights = [1];
|
|
27
|
+
const knots = [0, 0, 0];
|
|
28
|
+
for (let piece = 0; piece < pieces; piece++) {
|
|
29
|
+
const middle = arc.start + ((2 * piece + 1) * step) / 2;
|
|
30
|
+
points.push(add3(arc.frame.center, scale3(add3(scale3(arc.frame.xAxis, Math.cos(middle)), scale3(arc.frame.yAxis, Math.sin(middle))), 1 / middleWeight)));
|
|
31
|
+
points.push(ellipseFramePoint(arc.frame, arc.start + (piece + 1) * step));
|
|
32
|
+
weights.push(middleWeight, 1);
|
|
33
|
+
knots.push(piece + 1, piece + 1);
|
|
34
|
+
}
|
|
35
|
+
knots.push(pieces);
|
|
36
|
+
return { degree: 2, points, weights, knots };
|
|
37
|
+
};
|
|
38
|
+
export const bulgeArcOf = (start, end, bulge) => {
|
|
39
|
+
const dx = end[0] - start[0];
|
|
40
|
+
const dy = end[1] - start[1];
|
|
41
|
+
const offset = (1 - bulge * bulge) / (BULGE_TURN_SHARE * bulge);
|
|
42
|
+
const center = [(start[0] + end[0]) / 2 - dy * offset, (start[1] + end[1]) / 2 + dx * offset, start[2]];
|
|
43
|
+
const radius = distance2([start[0], start[1]], [center[0], center[1]]);
|
|
44
|
+
return {
|
|
45
|
+
frame: { center, xAxis: [radius, 0, 0], yAxis: [0, radius, 0] },
|
|
46
|
+
start: Math.atan2(start[1] - center[1], start[0] - center[0]),
|
|
47
|
+
sweep: BULGE_TURN_SHARE * Math.atan(bulge),
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export const conicArcExtremes = (arc, axes = FRAME_AXES) => {
|
|
51
|
+
const from = Math.min(arc.start, arc.start + arc.sweep);
|
|
52
|
+
const to = Math.min(Math.max(arc.start, arc.start + arc.sweep), from + 2 * Math.PI);
|
|
53
|
+
const halfTurnsAcross = Math.ceil(Math.min(Math.abs(arc.sweep), 2 * Math.PI) / Math.PI) + 1;
|
|
54
|
+
const turns = [];
|
|
55
|
+
for (const axis of axes) {
|
|
56
|
+
const flat = Math.atan2(arc.frame.yAxis[axis], arc.frame.xAxis[axis]);
|
|
57
|
+
const firstHalfTurn = Math.ceil((from - flat) / Math.PI);
|
|
58
|
+
for (let step = 0; step < halfTurnsAcross; step++) {
|
|
59
|
+
const angle = flat + (firstHalfTurn + step) * Math.PI;
|
|
60
|
+
if (angle > to) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
turns.push(angle);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const along = turns.filter(angle => angle > from && angle < to).sort((first, second) => (first - second) * Math.sign(arc.sweep));
|
|
67
|
+
return [arc.start, ...along, arc.start + arc.sweep].map(angle => ellipseFramePoint(arc.frame, angle));
|
|
68
|
+
};
|
|
69
|
+
export const principalArcOf = (arc) => {
|
|
70
|
+
const { center, xAxis, yAxis } = arc.frame;
|
|
71
|
+
const xx = dot3(xAxis, xAxis);
|
|
72
|
+
const yy = dot3(yAxis, yAxis);
|
|
73
|
+
const xy = dot3(xAxis, yAxis);
|
|
74
|
+
if (Math.abs(xy) <= Number.EPSILON * (xx + yy)) {
|
|
75
|
+
return xx >= yy ? arc : { frame: { center, xAxis: yAxis, yAxis: scale3(xAxis, -1) }, start: arc.start - Math.PI / 2, sweep: arc.sweep };
|
|
76
|
+
}
|
|
77
|
+
const shift = Math.atan2(2 * xy, xx - yy) / 2;
|
|
78
|
+
const cos = Math.cos(shift);
|
|
79
|
+
const sin = Math.sin(shift);
|
|
80
|
+
return {
|
|
81
|
+
frame: { center, xAxis: add3(scale3(xAxis, cos), scale3(yAxis, sin)), yAxis: add3(scale3(xAxis, -sin), scale3(yAxis, cos)) },
|
|
82
|
+
start: arc.start - shift,
|
|
83
|
+
sweep: arc.sweep,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type * as Inputs from "../../../inputs";
|
|
2
|
+
import type { WorkBudget } from "../files/work-budget";
|
|
3
|
+
type Point3 = Inputs.Base.Point3;
|
|
4
|
+
export interface NurbsCurveForm {
|
|
5
|
+
readonly degree: number;
|
|
6
|
+
readonly points: readonly Point3[];
|
|
7
|
+
readonly weights: readonly number[];
|
|
8
|
+
readonly knots: readonly number[];
|
|
9
|
+
}
|
|
10
|
+
export interface BezierPiece {
|
|
11
|
+
readonly points: readonly Point3[];
|
|
12
|
+
readonly weights: readonly number[];
|
|
13
|
+
}
|
|
14
|
+
export declare const clampedUniformKnots: (pointCount: number, degree: number) => number[];
|
|
15
|
+
export declare const periodicUniformForm: (points: readonly Point3[], weights: readonly number[], degree: number) => NurbsCurveForm;
|
|
16
|
+
export declare const insertKnot: (form: NurbsCurveForm, parameter: number, times?: number) => NurbsCurveForm;
|
|
17
|
+
export declare const clampedForm: (form: NurbsCurveForm) => NurbsCurveForm;
|
|
18
|
+
export declare const bezierPiecesOf: (form: NurbsCurveForm, budget?: WorkBudget) => BezierPiece[];
|
|
19
|
+
export declare const isRationalPiece: (piece: BezierPiece) => boolean;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { blendedPoint, knotDomain, liftedPoint, projectedPoint } from "./nurbs";
|
|
2
|
+
const homogeneousOf = (form) => form.points.map((point, at) => { var _a; return liftedPoint(point, (_a = form.weights[at]) !== null && _a !== void 0 ? _a : 1); });
|
|
3
|
+
const pieceOf = (homogeneous) => ({ points: homogeneous.map(projectedPoint), weights: homogeneous.map(point => point[3]) });
|
|
4
|
+
export const clampedUniformKnots = (pointCount, degree) => {
|
|
5
|
+
const spans = pointCount - degree;
|
|
6
|
+
return Array.from({ length: pointCount + degree + 1 }, (_, at) => Math.min(Math.max(at - degree, 0), spans));
|
|
7
|
+
};
|
|
8
|
+
export const periodicUniformForm = (points, weights, degree) => {
|
|
9
|
+
const wrapped = [...points, ...points.slice(0, degree)];
|
|
10
|
+
const wrappedWeights = [...weights, ...weights.slice(0, degree)];
|
|
11
|
+
return { degree, points: wrapped, weights: wrappedWeights, knots: Array.from({ length: wrapped.length + degree + 1 }, (_, at) => at) };
|
|
12
|
+
};
|
|
13
|
+
const insertionSpan = (degree, pointCount, knots, parameter) => {
|
|
14
|
+
let span = degree;
|
|
15
|
+
while (span < pointCount - 1 && knots[span + 1] <= parameter) {
|
|
16
|
+
span++;
|
|
17
|
+
}
|
|
18
|
+
return span;
|
|
19
|
+
};
|
|
20
|
+
const knotAfterRounds = (knots, span, parameter, rounds, at) => {
|
|
21
|
+
if (at <= span) {
|
|
22
|
+
return knots[at];
|
|
23
|
+
}
|
|
24
|
+
return at <= span + rounds ? parameter : knots[at - rounds];
|
|
25
|
+
};
|
|
26
|
+
export const insertKnot = (form, parameter, times = 1) => {
|
|
27
|
+
const { degree, knots, points, weights } = form;
|
|
28
|
+
const span = insertionSpan(degree, points.length, knots, parameter);
|
|
29
|
+
const base = span - degree;
|
|
30
|
+
const window = points.slice(base, span + 1).map((point, at) => { var _a; return liftedPoint(point, (_a = weights[base + at]) !== null && _a !== void 0 ? _a : 1); });
|
|
31
|
+
for (let round = 0; round < times; round++) {
|
|
32
|
+
window.push(window[degree + round]);
|
|
33
|
+
for (let at = degree + round; at > round; at--) {
|
|
34
|
+
const left = knotAfterRounds(knots, span, parameter, round, base + at);
|
|
35
|
+
const reach = knotAfterRounds(knots, span, parameter, round, base + at + degree) - left;
|
|
36
|
+
window[at] = blendedPoint(window[at - 1], window[at], reach > 0 ? (parameter - left) / reach : 0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const inserted = Array.from({ length: Math.max(times, 0) }, () => parameter);
|
|
40
|
+
return {
|
|
41
|
+
degree,
|
|
42
|
+
points: [...points.slice(0, base), ...window.map(projectedPoint), ...points.slice(span + 1)],
|
|
43
|
+
weights: [...weights.slice(0, base), ...window.map(point => point[3]), ...weights.slice(span + 1)],
|
|
44
|
+
knots: [...knots.slice(0, span + 1), ...inserted, ...knots.slice(span + 1)],
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const multiplicityOf = (knots, value) => knots.filter(knot => knot === value).length;
|
|
48
|
+
export const clampedForm = (form) => {
|
|
49
|
+
const [first, last] = knotDomain(form.degree, form.knots);
|
|
50
|
+
let clamped = form;
|
|
51
|
+
for (const end of [first, last]) {
|
|
52
|
+
const missing = form.degree - multiplicityOf(clamped.knots, end);
|
|
53
|
+
if (missing > 0) {
|
|
54
|
+
clamped = insertKnot(clamped, end, missing);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const lastAtStart = clamped.knots.lastIndexOf(first);
|
|
58
|
+
const firstAtEnd = clamped.knots.indexOf(last);
|
|
59
|
+
const from = lastAtStart - form.degree;
|
|
60
|
+
const interior = clamped.knots.slice(lastAtStart + 1, firstAtEnd);
|
|
61
|
+
const ends = Array.from({ length: form.degree + 1 });
|
|
62
|
+
return {
|
|
63
|
+
degree: form.degree,
|
|
64
|
+
points: clamped.points.slice(from, firstAtEnd),
|
|
65
|
+
weights: clamped.weights.slice(from, firstAtEnd),
|
|
66
|
+
knots: [...ends.map(() => first), ...interior, ...ends.map(() => last)],
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
export const bezierPiecesOf = (form, budget) => {
|
|
70
|
+
const clamped = clampedForm(form);
|
|
71
|
+
const { degree, knots } = clamped;
|
|
72
|
+
if (budget !== undefined && !budget.spend(((clamped.points.length - degree) * (degree + 1) * (degree + 2)) / 2)) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const lastKnot = knots.length - 1;
|
|
76
|
+
const control = homogeneousOf(clamped);
|
|
77
|
+
const pieces = [];
|
|
78
|
+
let piece = control.slice(0, degree + 1);
|
|
79
|
+
let spanStart = degree;
|
|
80
|
+
let spanEnd = degree + 1;
|
|
81
|
+
while (spanEnd < lastKnot) {
|
|
82
|
+
const groupStart = spanEnd;
|
|
83
|
+
while (spanEnd < lastKnot && knots[spanEnd + 1] === knots[spanEnd]) {
|
|
84
|
+
spanEnd++;
|
|
85
|
+
}
|
|
86
|
+
const multiplicity = spanEnd - groupStart + 1;
|
|
87
|
+
const next = [];
|
|
88
|
+
if (multiplicity < degree) {
|
|
89
|
+
const reach = knots[spanEnd] - knots[spanStart];
|
|
90
|
+
const shares = Array.from({ length: degree - multiplicity }, (_, at) => reach / (knots[spanStart + multiplicity + 1 + at] - knots[spanStart]));
|
|
91
|
+
const insertions = degree - multiplicity;
|
|
92
|
+
for (let round = 1; round <= insertions; round++) {
|
|
93
|
+
const from = multiplicity + round;
|
|
94
|
+
for (let at = degree; at >= from; at--) {
|
|
95
|
+
piece[at] = blendedPoint(piece[at - 1], piece[at], shares[at - from]);
|
|
96
|
+
}
|
|
97
|
+
next[insertions - round] = piece[degree];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
pieces.push(pieceOf(piece));
|
|
101
|
+
if (spanEnd < lastKnot) {
|
|
102
|
+
for (let at = degree - multiplicity; at <= degree; at++) {
|
|
103
|
+
next[at] = control[spanEnd - degree + at];
|
|
104
|
+
}
|
|
105
|
+
piece = next;
|
|
106
|
+
spanStart = spanEnd;
|
|
107
|
+
spanEnd++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return pieces;
|
|
111
|
+
};
|
|
112
|
+
export const isRationalPiece = (piece) => piece.weights.some(weight => weight !== piece.weights[0]);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type * as Inputs from "../../../inputs";
|
|
2
2
|
type Point3 = Inputs.Base.Point3;
|
|
3
|
+
export type Homogeneous = [number, number, number, number];
|
|
4
|
+
export declare const liftedPoint: (point: Point3, weight: number) => Homogeneous;
|
|
5
|
+
export declare const projectedPoint: (point: Homogeneous) => Point3;
|
|
6
|
+
export declare const blendedPoint: (from: Homogeneous, to: Homogeneous, share: number) => Homogeneous;
|
|
3
7
|
export declare const expandedKnots: (knots: readonly number[], multiplicities: readonly number[]) => number[];
|
|
4
8
|
export declare const knotDomain: (degree: number, knots: readonly number[]) => [number, number];
|
|
5
9
|
export declare const nurbsCurvePoint: (degree: number, points: readonly Point3[], weights: readonly number[] | undefined, knots: readonly number[], t: number) => Point3;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export const liftedPoint = (point, weight) => [point[0] * weight, point[1] * weight, point[2] * weight, weight];
|
|
2
|
+
export const projectedPoint = (point) => [point[0] / point[3], point[1] / point[3], point[2] / point[3]];
|
|
3
|
+
export const blendedPoint = (from, to, share) => {
|
|
4
|
+
const keep = 1 - share;
|
|
5
|
+
return [keep * from[0] + share * to[0], keep * from[1] + share * to[1], keep * from[2] + share * to[2], keep * from[3] + share * to[3]];
|
|
6
|
+
};
|
|
1
7
|
export const expandedKnots = (knots, multiplicities) => knots.flatMap((knot, at) => { var _a; return Array.from({ length: (_a = multiplicities[at]) !== null && _a !== void 0 ? _a : 0 }, () => knot); });
|
|
2
8
|
export const knotDomain = (degree, knots) => [knots[degree], knots[knots.length - degree - 1]];
|
|
3
9
|
const spanOf = (degree, knots, t) => {
|
|
@@ -31,20 +37,15 @@ const deBoor = (degree, knots, parameter, at) => {
|
|
|
31
37
|
const left = knots[span - degree + j];
|
|
32
38
|
const right = knots[span + 1 + j - r];
|
|
33
39
|
const alpha = right === left ? 0 : (t - left) / (right - left);
|
|
34
|
-
|
|
35
|
-
const current = points[j];
|
|
36
|
-
const keep = 1 - alpha;
|
|
37
|
-
points[j] = [keep * previous[0] + alpha * current[0], keep * previous[1] + alpha * current[1], keep * previous[2] + alpha * current[2], keep * previous[3] + alpha * current[3]];
|
|
40
|
+
points[j] = blendedPoint(points[j - 1], points[j], alpha);
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
return points[degree];
|
|
41
44
|
};
|
|
42
|
-
const
|
|
43
|
-
const projected = (point) => [point[0] / point[3], point[1] / point[3], point[2] / point[3]];
|
|
44
|
-
export const nurbsCurvePoint = (degree, points, weights, knots, t) => projected(deBoor(degree, knots, t, (index) => { var _a; return lifted(points[index], (_a = weights === null || weights === void 0 ? void 0 : weights[index]) !== null && _a !== void 0 ? _a : 1); }));
|
|
45
|
+
export const nurbsCurvePoint = (degree, points, weights, knots, t) => projectedPoint(deBoor(degree, knots, t, (index) => { var _a; return liftedPoint(points[index], (_a = weights === null || weights === void 0 ? void 0 : weights[index]) !== null && _a !== void 0 ? _a : 1); }));
|
|
45
46
|
export const nurbsSurfacePoint = (degrees, net, weights, knots, u, v) => {
|
|
46
47
|
const [uDegree, vDegree] = degrees;
|
|
47
48
|
const [uKnots, vKnots] = knots;
|
|
48
|
-
const row = (index) => deBoor(vDegree, vKnots, v, (column) => { var _a, _b; return
|
|
49
|
-
return
|
|
49
|
+
const row = (index) => deBoor(vDegree, vKnots, v, (column) => { var _a, _b; return liftedPoint(net[index][column], (_b = (_a = weights === null || weights === void 0 ? void 0 : weights[index]) === null || _a === void 0 ? void 0 : _a[column]) !== null && _b !== void 0 ? _b : 1); });
|
|
50
|
+
return projectedPoint(deBoor(uDegree, uKnots, u, row));
|
|
50
51
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WorkBudget } from "../work-budget";
|
|
2
|
+
import { NUMBERS_PER_CURVE, NUMBERS_PER_PART, NUMBERS_PER_VERTEX, WRITER_WORK_CEILING, WRITER_WORK_FLOOR, WRITER_WORK_PER_NUMBER } from "./drawing.constants";
|
|
3
|
+
const segmentNumbers = (segment) => {
|
|
4
|
+
switch (segment.kind) {
|
|
5
|
+
case "polyline":
|
|
6
|
+
return segment.points.length * NUMBERS_PER_VERTEX;
|
|
7
|
+
case "spline":
|
|
8
|
+
return segment.curve.points.length * NUMBERS_PER_VERTEX + segment.curve.knots.length;
|
|
9
|
+
default:
|
|
10
|
+
return NUMBERS_PER_CURVE[segment.kind];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const writerBudgetOf = (parts) => {
|
|
14
|
+
let numbers = 0;
|
|
15
|
+
for (const part of parts) {
|
|
16
|
+
numbers += NUMBERS_PER_PART;
|
|
17
|
+
for (const path of part.paths) {
|
|
18
|
+
for (const segment of path.segments) {
|
|
19
|
+
numbers += segmentNumbers(segment);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return WorkBudget.forInput(numbers, WRITER_WORK_PER_NUMBER, WRITER_WORK_FLOOR, WRITER_WORK_CEILING);
|
|
24
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 Point3 = Inputs.Base.Point3;
|
|
7
|
+
type Vec3 = Inputs.Base.Vector3;
|
|
8
|
+
export declare const ocsAxesOf: (normal: Vec3) => FrameAxes;
|
|
9
|
+
export declare const circleArcOf: (segment: DrawingCircle | DrawingArc) => ConicArc;
|
|
10
|
+
export declare const ellipseArcOf: (segment: DrawingEllipse) => ConicArc;
|
|
11
|
+
export declare const polylineSpans: (polyline: DrawingPolyline) => number;
|
|
12
|
+
export declare const polylineSpanEnd: (polyline: DrawingPolyline, span: number) => Point3;
|
|
13
|
+
export declare const bulgeArcOfSpan: (polyline: DrawingPolyline, span: number) => ConicArc | undefined;
|
|
14
|
+
export declare const segmentSamples: (segment: DrawingSpline | DrawingEllipse, tolerance: number, budget?: WorkBudget) => readonly Point3[];
|
|
15
|
+
export declare const drawingBounds: (parts: readonly DrawingPart[], tolerance: number, budget?: WorkBudget) => DrawingBounds | undefined;
|
|
16
|
+
export declare const drawingSize: (bounds: DrawingBounds | undefined, axes?: number) => number;
|
|
17
|
+
export declare const patternUnitOf: (bounds: DrawingBounds | undefined) => number;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
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, length3, scale3 } from "../../geometry/vectors";
|
|
6
|
+
import { ARBITRARY_AXIS_LIMIT, PATTERN_UNIT_SHARE, PLAN_AXES } from "./drawing.constants";
|
|
7
|
+
const WORLD_Y = [0, 1, 0];
|
|
8
|
+
const WORLD_Z = [0, 0, 1];
|
|
9
|
+
export const ocsAxesOf = (normal) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const nearZ = Math.abs(normal[0]) < ARBITRARY_AXIS_LIMIT && Math.abs(normal[1]) < ARBITRARY_AXIS_LIMIT;
|
|
12
|
+
const x = (_a = unitOf(cross3(nearZ ? WORLD_Y : WORLD_Z, normal))) !== null && _a !== void 0 ? _a : [1, 0, 0];
|
|
13
|
+
return { origin: [0, 0, 0], x, y: cross3(normal, x), z: normal };
|
|
14
|
+
};
|
|
15
|
+
export const circleArcOf = (segment) => {
|
|
16
|
+
const axes = ocsAxesOf(segment.normal);
|
|
17
|
+
const frame = { center: segment.center, xAxis: scale3(axes.x, segment.radius), yAxis: scale3(axes.y, segment.radius) };
|
|
18
|
+
return segment.kind === "circle"
|
|
19
|
+
? { frame, start: 0, sweep: 2 * Math.PI }
|
|
20
|
+
: { frame, start: segment.startAngle, sweep: segment.endAngle - segment.startAngle };
|
|
21
|
+
};
|
|
22
|
+
export const ellipseArcOf = (segment) => {
|
|
23
|
+
var _a;
|
|
24
|
+
const minor = (_a = unitOf(cross3(segment.normal, segment.majorAxis))) !== null && _a !== void 0 ? _a : [0, 1, 0];
|
|
25
|
+
return {
|
|
26
|
+
frame: { center: segment.center, xAxis: segment.majorAxis, yAxis: scale3(minor, length3(segment.majorAxis) * segment.ratio) },
|
|
27
|
+
start: segment.start,
|
|
28
|
+
sweep: segment.end - segment.start,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const polylineSpans = (polyline) => polyline.closed ? polyline.points.length : polyline.points.length - 1;
|
|
32
|
+
export const polylineSpanEnd = (polyline, span) => polyline.points[(span + 1) % polyline.points.length];
|
|
33
|
+
export const bulgeArcOfSpan = (polyline, span) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const bulge = (_a = polyline.bulges[span]) !== null && _a !== void 0 ? _a : 0;
|
|
36
|
+
return bulge === 0 ? undefined : bulgeArcOf(polyline.points[span], polylineSpanEnd(polyline, span), bulge);
|
|
37
|
+
};
|
|
38
|
+
export const segmentSamples = (segment, tolerance, budget) => segment.kind === "ellipse"
|
|
39
|
+
? conicArcSamples(ellipseArcOf(segment), tolerance)
|
|
40
|
+
: bezierPiecesOf(segment.curve, budget).flatMap((piece, at) => samplesOfPiece(piece, tolerance, budget).slice(at === 0 ? 0 : 1));
|
|
41
|
+
const boundsPointsOf = (segment, tolerance, budget) => {
|
|
42
|
+
switch (segment.kind) {
|
|
43
|
+
case "line":
|
|
44
|
+
return [segment.start, segment.end];
|
|
45
|
+
case "circle":
|
|
46
|
+
case "arc":
|
|
47
|
+
return conicArcExtremes(circleArcOf(segment));
|
|
48
|
+
case "ellipse":
|
|
49
|
+
return conicArcExtremes(ellipseArcOf(segment));
|
|
50
|
+
case "polyline": {
|
|
51
|
+
const arcs = Array.from({ length: polylineSpans(segment) }, (_, span) => bulgeArcOfSpan(segment, span));
|
|
52
|
+
return [...segment.points, ...arcs.flatMap(arc => arc === undefined ? [] : conicArcExtremes(arc))];
|
|
53
|
+
}
|
|
54
|
+
case "spline": {
|
|
55
|
+
const bounds = bezierPiecesBounds(bezierPiecesOf(segment.curve, budget), tolerance, budget);
|
|
56
|
+
return [bounds.min, bounds.max];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export const drawingBounds = (parts, tolerance, budget) => {
|
|
61
|
+
const min = [Infinity, Infinity, Infinity];
|
|
62
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
63
|
+
for (const part of parts) {
|
|
64
|
+
for (const path of part.paths) {
|
|
65
|
+
for (const segment of path.segments) {
|
|
66
|
+
for (const point of boundsPointsOf(segment, tolerance, budget)) {
|
|
67
|
+
for (let axis = 0; axis < min.length; axis++) {
|
|
68
|
+
min[axis] = Math.min(min[axis], point[axis]);
|
|
69
|
+
max[axis] = Math.max(max[axis], point[axis]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return min[0] === Infinity ? undefined : { min, max };
|
|
76
|
+
};
|
|
77
|
+
export const drawingSize = (bounds, axes = PLAN_AXES) => {
|
|
78
|
+
let size = 0;
|
|
79
|
+
for (let axis = 0; axis < axes && bounds !== undefined; axis++) {
|
|
80
|
+
size = Math.max(size, bounds.max[axis] - bounds.min[axis]);
|
|
81
|
+
}
|
|
82
|
+
return size > 0 ? size : 1;
|
|
83
|
+
};
|
|
84
|
+
export const patternUnitOf = (bounds) => drawingSize(bounds) * PATTERN_UNIT_SHARE;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import type { DrawingPart, DrawingPath } from "./drawing-types";
|
|
3
|
+
export declare const positiveNumber: (value: unknown, property: string) => number;
|
|
4
|
+
export declare const drawingPathOf: (path: Inputs.IO.DrawingPathDto | undefined, property: string) => DrawingPath;
|
|
5
|
+
export declare const drawingPartsOf: (parts: readonly unknown[] | undefined, property: string) => DrawingPart[];
|