@bitbybit-dev/base 1.7.0 → 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 +20 -0
- package/lib/api/inputs/base-inputs.js +22 -0
- package/lib/api/inputs/io-inputs.d.ts +408 -8
- package/lib/api/inputs/io-inputs.js +344 -7
- 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 +1 -0
- package/lib/api/kernel-calls/index.js +1 -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 +19 -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/resolved-inputs/index.d.ts +11 -2
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +3 -1
- package/lib/api/services/helpers/curves/conic-arcs.js +4 -2
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +16 -6
- 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 +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +28 -11
- 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 +6 -1
- package/lib/api/services/helpers/files/drawing/drawing-model.js +97 -13
- 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 +57 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +13 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +17 -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-entities.d.ts +5 -1
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +5 -2
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +26 -10
- 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.js +37 -3
- 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 +27 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +63 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +1 -1
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +71 -181
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +5 -4
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +25 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +13 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +1 -1
- package/lib/api/services/helpers/files/svg/svg-strokes.js +47 -23
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +100 -23
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +2 -1
- package/lib/api/services/helpers/files/svg/svg.constants.js +2 -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/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 +198 -0
- package/lib/api/services/io/drawing.js +242 -0
- package/lib/api/services/io/dxf.d.ts +3 -3
- package/lib/api/services/io/dxf.js +4 -4
- package/lib/api/services/io/svg.d.ts +13 -11
- package/lib/api/services/io/svg.js +15 -12
- package/lib/api/services/mesh.d.ts +19 -0
- package/lib/api/services/mesh.js +40 -0
- package/lib/api/services/recipes.js +3 -2
- package/lib/api/services/text.d.ts +3 -3
- package/lib/api/services/text.js +7 -25
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Base } from "../inputs/base-inputs";
|
|
2
|
+
import { InputError } from "./errors";
|
|
3
|
+
const UP_AXIS = "upAxis";
|
|
4
|
+
const FLAG_TURNS = [
|
|
5
|
+
["adjustZtoY", Base.upAxisConversionEnum.zUpToYUp],
|
|
6
|
+
["adjustYtoZ", Base.upAxisConversionEnum.yUpToZUp],
|
|
7
|
+
];
|
|
8
|
+
const UP_AXIS_VALUES = Object.values(Base.upAxisConversionEnum);
|
|
9
|
+
function refused(by, flag, given) {
|
|
10
|
+
const said = by === UP_AXIS ? "`upAxis` chooses another turn" : `\`${by}\` asks for another turn`;
|
|
11
|
+
return new InputError(`\`${flag}\` is ${String(given)}, but ${said}: give \`upAxis\` alone, since \`${flag}\` is deprecated.`, flag);
|
|
12
|
+
}
|
|
13
|
+
function decidedBy(given, axis, fallback) {
|
|
14
|
+
var _a;
|
|
15
|
+
let decided = { value: axis, by: axis === fallback ? undefined : UP_AXIS };
|
|
16
|
+
for (const [flag, turn] of FLAG_TURNS) {
|
|
17
|
+
const value = given[flag];
|
|
18
|
+
if (typeof value !== "boolean" || value === (turn === fallback)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const asked = value ? turn : Base.upAxisConversionEnum.keep;
|
|
22
|
+
if (decided.by !== undefined && decided.value !== asked) {
|
|
23
|
+
throw refused(decided.by, flag, value);
|
|
24
|
+
}
|
|
25
|
+
decided = { value: asked, by: (_a = decided.by) !== null && _a !== void 0 ? _a : flag };
|
|
26
|
+
}
|
|
27
|
+
return decided;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Lays the deprecated `adjustZtoY` and `adjustYtoZ` flags of a caller's inputs onto the `upAxis`
|
|
31
|
+
* of a DTO whose defaults carry one, and drops them. A flag at its released default (true where the
|
|
32
|
+
* DTO's `upAxis` defaults to the flag's turn, false elsewhere) decides nothing, as an old example or
|
|
33
|
+
* an old positional constructor spells it. Set the other way it decides: true chooses the flag's
|
|
34
|
+
* turn, false `keep`. A deciding flag wins over an `upAxis` equal to its default, since an editor
|
|
35
|
+
* passes every input and an explicit default cannot be told from one laid; it is refused beside an
|
|
36
|
+
* `upAxis` that chooses another turn, or beside the other flag deciding another one. An `upAxis`
|
|
37
|
+
* that is no turn is left for the method to refuse.
|
|
38
|
+
* @param resolved - The inputs over the DTO's defaults, changed in place
|
|
39
|
+
* @param given - The inputs as the caller passed them
|
|
40
|
+
* @param defaults - The DTO's defaults
|
|
41
|
+
* @throws InputError when the flags and `upAxis` ask for different turns, naming both
|
|
42
|
+
*/
|
|
43
|
+
export function layUpAxisFlags(resolved, given, defaults) {
|
|
44
|
+
const fallback = defaults[UP_AXIS];
|
|
45
|
+
if (!UP_AXIS_VALUES.includes(fallback) || !FLAG_TURNS.some(([flag]) => typeof given[flag] === "boolean")) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const axis = resolved[UP_AXIS];
|
|
49
|
+
if (UP_AXIS_VALUES.includes(axis)) {
|
|
50
|
+
resolved[UP_AXIS] = decidedBy(given, axis, fallback).value;
|
|
51
|
+
}
|
|
52
|
+
for (const [flag] of FLAG_TURNS) {
|
|
53
|
+
delete resolved[flag];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The turn an operation was asked for, among the ones it can make: an operation that reads Z-up
|
|
58
|
+
* files takes `keep` and `zUpToYUp`, one that writes for Z-up tools `keep` and `yUpToZUp`.
|
|
59
|
+
* @param value - The `upAxis` the operation received
|
|
60
|
+
* @param accepted - The turns the operation makes
|
|
61
|
+
* @returns The turn, typed
|
|
62
|
+
* @throws InputError when the value is not among `accepted`, naming the turns that are
|
|
63
|
+
*/
|
|
64
|
+
export function checkedUpAxis(value, accepted) {
|
|
65
|
+
if (!accepted.includes(value)) {
|
|
66
|
+
const takes = accepted.map(turn => `\`${turn}\``).join(" or ");
|
|
67
|
+
throw new InputError(`\`${UP_AXIS}\` is \`${String(value)}\`, which this method does not take: it takes ${takes}.`, UP_AXIS);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Keys are code points, not indices, so the map is sparse and reaches past ASCII: 176 is the degree
|
|
13
13
|
* symbol. A code point the font does not carry has no entry, which is why lookups are optional.
|
|
14
|
+
* An accented Latin letter has no entry either: the text service composes it from its letter's
|
|
15
|
+
* entry and a mark it holds for every font.
|
|
14
16
|
*/
|
|
15
17
|
export type VectorFont = {
|
|
16
18
|
height: number;
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Hershey vector font data, taken from http://paulbourke.net/dataformats/hershey/ by way of the
|
|
3
3
|
* OpenJSCAD project (https://github.com/jscad/OpenJSCAD.org), which publishes it under the MIT
|
|
4
|
-
* License. The
|
|
4
|
+
* License. The Hershey Fonts may be used by anyone for any purpose, provided that these
|
|
5
|
+
* acknowledgements are distributed with the font data, and that the data is not converted into the
|
|
6
|
+
* format distributed by the U.S. NTIS:
|
|
7
|
+
*
|
|
8
|
+
* - The Hershey Fonts were originally created by Dr. A. V. Hershey while working at the
|
|
9
|
+
* U. S. National Bureau of Standards.
|
|
10
|
+
* - The format of the Font data in this distribution was originally created by James Hurt,
|
|
11
|
+
* Cognition, Inc., 900 Technology Park Drive, Billerica, MA 01821 (mit-eddie!ci-dandelion!hurt).
|
|
12
|
+
*
|
|
13
|
+
* The package's NOTICE carries the same.
|
|
5
14
|
*/
|
|
6
15
|
export const simplex = {
|
|
7
16
|
height: 21,
|
|
@@ -132,12 +132,20 @@ export declare namespace Frame {
|
|
|
132
132
|
export declare namespace IO {
|
|
133
133
|
type DrawingArcSegmentDto = Inputs.IO.DrawingArcSegmentDto;
|
|
134
134
|
type DrawingCircleSegmentDto = Inputs.IO.DrawingCircleSegmentDto;
|
|
135
|
+
type DrawingDimensionDto = WithDefaults<Inputs.IO.DrawingDimensionDto, "kind" | "offset" | "angle" | "decimalPlaces" | "textHeight">;
|
|
136
|
+
type DrawingDimensionPictureDto = Inputs.IO.DrawingDimensionPictureDto;
|
|
135
137
|
type DrawingEllipseSegmentDto = WithDefaults<Inputs.IO.DrawingEllipseSegmentDto, "startParameter" | "endParameter">;
|
|
138
|
+
type DrawingExtentDto = Inputs.IO.DrawingExtentDto;
|
|
139
|
+
type DrawingHatchDto = WithDefaults<Inputs.IO.DrawingHatchDto, "pattern" | "angle" | "spacing">;
|
|
140
|
+
type DrawingHatchRegionDto = WithDefaults<Inputs.IO.DrawingHatchRegionDto, "pattern" | "angle" | "spacing" | "tolerance">;
|
|
136
141
|
type DrawingLineSegmentDto = Inputs.IO.DrawingLineSegmentDto;
|
|
137
142
|
type DrawingPartDto = WithDefaults<Inputs.IO.DrawingPartDto, "layer" | "color" | "lineType">;
|
|
138
143
|
type DrawingPathDto = Inputs.IO.DrawingPathDto;
|
|
139
144
|
type DrawingPolylineSegmentDto = WithDefaults<Inputs.IO.DrawingPolylineSegmentDto, "closed">;
|
|
145
|
+
type DrawingScalePartsDto = WithDefaults<Inputs.IO.DrawingScalePartsDto, "factor">;
|
|
140
146
|
type DrawingSplineSegmentDto = WithDefaults<Inputs.IO.DrawingSplineSegmentDto, "degree" | "closed">;
|
|
147
|
+
type DrawingTextDto = WithDefaults<Inputs.IO.DrawingTextDto, "height" | "anchor" | "rotation" | "widthFactor">;
|
|
148
|
+
type DrawingTextSizeDto = Inputs.IO.DrawingTextSizeDto;
|
|
141
149
|
type DxfArcSegmentDto = Inputs.IO.DxfArcSegmentDto;
|
|
142
150
|
type DxfCircleSegmentDto = Inputs.IO.DxfCircleSegmentDto;
|
|
143
151
|
type DxfDrawingDto = Inputs.IO.DxfDrawingDto;
|
|
@@ -153,7 +161,7 @@ export declare namespace IO {
|
|
|
153
161
|
type DxfToSvgResultDto = Inputs.IO.DxfToSvgResultDto;
|
|
154
162
|
type SvgDrawingDto = Inputs.IO.SvgDrawingDto;
|
|
155
163
|
type SvgModelDto = WithDefaults<Inputs.IO.SvgModelDto, "tolerance">;
|
|
156
|
-
type SvgPathDataDto = WithDefaults<Inputs.IO.SvgPathDataDto, "flipY" | "tolerance">;
|
|
164
|
+
type SvgPathDataDto = WithDefaults<Inputs.IO.SvgPathDataDto, "flipY" | "tolerance" | "cubicsOnly">;
|
|
157
165
|
type SvgReadDto = WithDefaults<Inputs.IO.SvgReadDto, "includeInvisible">;
|
|
158
166
|
type SvgToDxfDto = WithDefaults<Inputs.IO.SvgToDxfDto, "includeInvisible" | "colorFormat" | "acadVersion" | "curveTolerance">;
|
|
159
167
|
type SvgToDxfResultDto = Inputs.IO.SvgToDxfResultDto;
|
|
@@ -276,6 +284,7 @@ export declare namespace Mesh {
|
|
|
276
284
|
type TriangleDto = Inputs.Mesh.TriangleDto;
|
|
277
285
|
type TriangleToleranceDto = WithDefaults<Inputs.Mesh.TriangleToleranceDto, "tolerance">;
|
|
278
286
|
type TriangleTriangleToleranceDto = WithDefaults<Inputs.Mesh.TriangleTriangleToleranceDto, "tolerance">;
|
|
287
|
+
type TriangulateLoopsDto = WithDefaults<Inputs.Mesh.TriangulateLoopsDto, "fillRule">;
|
|
279
288
|
}
|
|
280
289
|
/**
|
|
281
290
|
* The Point inputs DTOs as their defaults leave them: every property with a default is present,
|
|
@@ -342,7 +351,7 @@ export declare namespace Polyline {
|
|
|
342
351
|
export declare namespace Recipes {
|
|
343
352
|
type RecipeDto = Inputs.Recipes.RecipeDto;
|
|
344
353
|
type RecipeSourceDto = WithDefaults<Inputs.Recipes.RecipeSourceDto, "node">;
|
|
345
|
-
type RecipeSurfaceMeshesDto = WithDefaults<Inputs.Recipes.RecipeSurfaceMeshesDto, "
|
|
354
|
+
type RecipeSurfaceMeshesDto = WithDefaults<Inputs.Recipes.RecipeSurfaceMeshesDto, "upAxis">;
|
|
346
355
|
}
|
|
347
356
|
/**
|
|
348
357
|
* The Text inputs DTOs as their defaults leave them: every property with a default is present,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as Inputs from "../../../inputs";
|
|
2
2
|
import type { NurbsCurveForm } from "./nurbs-forms";
|
|
3
3
|
import type { EllipseArc2 } from "../geometry/ellipse-arcs";
|
|
4
|
+
import type { WorkBudget } from "../files/work-budget";
|
|
4
5
|
type Point3 = Inputs.Base.Point3;
|
|
5
6
|
type Vec3 = Inputs.Base.Vector3;
|
|
6
7
|
export interface EllipseFrame {
|
|
@@ -16,9 +17,10 @@ export interface ConicArc {
|
|
|
16
17
|
export declare const angleWithinTurn: (angle: number, turn: number) => number;
|
|
17
18
|
export declare const ellipseFramePoint: (frame: EllipseFrame, angle: number) => Point3;
|
|
18
19
|
export declare const conicArcOfEllipseArc: (arc: EllipseArc2) => ConicArc;
|
|
19
|
-
export declare const conicArcSamples: (arc: ConicArc, tolerance: number) => Point3[];
|
|
20
|
+
export declare const conicArcSamples: (arc: ConicArc, tolerance: number, budget?: WorkBudget) => Point3[];
|
|
20
21
|
export declare const conicArcAsNurbs: (arc: ConicArc) => NurbsCurveForm;
|
|
21
22
|
export declare const bulgeArcOf: (start: Point3, end: Point3, bulge: number) => ConicArc;
|
|
23
|
+
export declare const bulgeOfSweep: (sweep: number) => number;
|
|
22
24
|
export declare const conicArcExtremes: (arc: ConicArc, axes?: readonly number[]) => Point3[];
|
|
23
25
|
export declare const principalArcOf: (arc: ConicArc) => ConicArc;
|
|
24
26
|
export {};
|
|
@@ -11,11 +11,12 @@ export const conicArcOfEllipseArc = (arc) => {
|
|
|
11
11
|
sweep: arc.deltaAngle,
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
export const conicArcSamples = (arc, tolerance) => {
|
|
14
|
+
export const conicArcSamples = (arc, tolerance, budget) => {
|
|
15
15
|
const radius = Math.max(length3(arc.frame.xAxis), length3(arc.frame.yAxis));
|
|
16
16
|
const relative = Math.max(tolerance / radius, LEAST_RELATIVE_TOLERANCE);
|
|
17
17
|
const step = relative >= 1 ? QUARTER_TURN : Math.min(QUARTER_TURN, 2 * Math.acos(1 - relative));
|
|
18
|
-
const
|
|
18
|
+
const wanted = Math.max(1, Math.ceil(Math.abs(arc.sweep) / step));
|
|
19
|
+
const count = budget === undefined || budget.spend(wanted + 1) ? wanted : 1;
|
|
19
20
|
return Array.from({ length: count + 1 }, (_, at) => ellipseFramePoint(arc.frame, arc.start + (arc.sweep * at) / count));
|
|
20
21
|
};
|
|
21
22
|
export const conicArcAsNurbs = (arc) => {
|
|
@@ -47,6 +48,7 @@ export const bulgeArcOf = (start, end, bulge) => {
|
|
|
47
48
|
sweep: BULGE_TURN_SHARE * Math.atan(bulge),
|
|
48
49
|
};
|
|
49
50
|
};
|
|
51
|
+
export const bulgeOfSweep = (sweep) => Math.tan(sweep / BULGE_TURN_SHARE);
|
|
50
52
|
export const conicArcExtremes = (arc, axes = FRAME_AXES) => {
|
|
51
53
|
const from = Math.min(arc.start, arc.start + arc.sweep);
|
|
52
54
|
const to = Math.min(Math.max(arc.start, arc.start + arc.sweep), from + 2 * Math.PI);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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";
|
|
2
|
+
import { NUMBERS_PER_CHARACTER, NUMBERS_PER_CURVE, NUMBERS_PER_HATCH, NUMBERS_PER_PART, NUMBERS_PER_TEXT, NUMBERS_PER_VERTEX, WRITER_WORK_CEILING, WRITER_WORK_FLOOR, WRITER_WORK_PER_NUMBER } from "./drawing.constants";
|
|
3
3
|
const segmentNumbers = (segment) => {
|
|
4
4
|
switch (segment.kind) {
|
|
5
5
|
case "polyline":
|
|
@@ -10,14 +10,24 @@ const segmentNumbers = (segment) => {
|
|
|
10
10
|
return NUMBERS_PER_CURVE[segment.kind];
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
+
const pathNumbers = (paths) => {
|
|
14
|
+
let numbers = 0;
|
|
15
|
+
for (const path of paths) {
|
|
16
|
+
for (const segment of path.segments) {
|
|
17
|
+
numbers += segmentNumbers(segment);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return numbers;
|
|
21
|
+
};
|
|
13
22
|
export const writerBudgetOf = (parts) => {
|
|
14
23
|
let numbers = 0;
|
|
15
24
|
for (const part of parts) {
|
|
16
|
-
numbers += NUMBERS_PER_PART;
|
|
17
|
-
for (const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
numbers += NUMBERS_PER_PART + pathNumbers(part.paths);
|
|
26
|
+
for (const hatch of part.hatches) {
|
|
27
|
+
numbers += NUMBERS_PER_HATCH + pathNumbers(hatch.boundaries);
|
|
28
|
+
}
|
|
29
|
+
for (const text of part.texts) {
|
|
30
|
+
numbers += NUMBERS_PER_TEXT + text.value.length * NUMBERS_PER_CHARACTER;
|
|
21
31
|
}
|
|
22
32
|
}
|
|
23
33
|
return WorkBudget.forInput(numbers, WRITER_WORK_PER_NUMBER, WRITER_WORK_FLOOR, WRITER_WORK_CEILING);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ARROW_WIDTH_SHARE: number;
|
|
2
|
+
export declare const TEXT_GAP_SHARE: number;
|
|
3
|
+
export declare const EXTENSION_GAP_SHARE: number;
|
|
4
|
+
export declare const EXTENSION_OVERSHOOT_SHARE: number;
|
|
5
|
+
export declare const ARROWS_INSIDE_ROOM: number;
|
|
6
|
+
export declare const ARROW_TAIL_SHARE: number;
|
|
7
|
+
export declare const ARC_TOLERANCE_SHARE: number;
|
|
8
|
+
export declare const MOST_DECIMAL_PLACES = 15;
|
|
9
|
+
export declare const TOLERANCE_DECIMAL_PLACES = 6;
|
|
10
|
+
export declare const UPRIGHT_SLACK = 1e-9;
|
|
11
|
+
export declare const DIAMETER_SIGN = "\u2300";
|
|
12
|
+
export declare const RADIUS_SIGN = "R";
|
|
13
|
+
export declare const DEGREE_SIGN = "\u00B0";
|
|
14
|
+
export declare const PLUS_MINUS_SIGN = "\u00B1";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const ARROW_WIDTH_SHARE = 1 / 3;
|
|
2
|
+
export const TEXT_GAP_SHARE = 1 / 4;
|
|
3
|
+
export const EXTENSION_GAP_SHARE = 1 / 4;
|
|
4
|
+
export const EXTENSION_OVERSHOOT_SHARE = 1 / 2;
|
|
5
|
+
export const ARROWS_INSIDE_ROOM = 5 / 2;
|
|
6
|
+
export const ARROW_TAIL_SHARE = 3 / 2;
|
|
7
|
+
export const ARC_TOLERANCE_SHARE = 1 / 100;
|
|
8
|
+
export const MOST_DECIMAL_PLACES = 15;
|
|
9
|
+
export const TOLERANCE_DECIMAL_PLACES = 6;
|
|
10
|
+
export const UPRIGHT_SLACK = 1e-9;
|
|
11
|
+
export const DIAMETER_SIGN = "⌀";
|
|
12
|
+
export const RADIUS_SIGN = "R";
|
|
13
|
+
export const DEGREE_SIGN = "°";
|
|
14
|
+
export const PLUS_MINUS_SIGN = "±";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import type * as Resolved from "../../../../resolved-inputs";
|
|
3
|
+
export declare const dimensionExtentOf: (dimension: Resolved.IO.DrawingDimensionDto) => Inputs.IO.DrawingExtentDto;
|
|
4
|
+
export declare const dimensionPictureOf: (dimension: Resolved.IO.DrawingDimensionDto) => Inputs.IO.DrawingDimensionPictureDto;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import { InputError } from "../../../../kernel-calls";
|
|
3
|
+
import { simplex } from "../../../../models/simplex";
|
|
4
|
+
import { conicArcSamples } from "../../curves/conic-arcs";
|
|
5
|
+
import { degreesOf, radiansOf, roundedTo } from "../../geometry/scalars";
|
|
6
|
+
import { add2, between2, distance2, dot2, leftOf2, polar2, scale2, subtract2, unit2Of } from "../../geometry/vectors";
|
|
7
|
+
import { strokeTextAdvance, strokeTextStrokes } from "../../text/stroke-font";
|
|
8
|
+
import { drawingTextOf, finiteNumber, isDrawable, positiveNumber } from "./drawing-model";
|
|
9
|
+
import { textCornersOf, textStrokesOf } from "./drawing-text";
|
|
10
|
+
import { FULL_TURN_DEGREES, SAME_POINT } from "./drawing.constants";
|
|
11
|
+
import { ARC_TOLERANCE_SHARE, ARROWS_INSIDE_ROOM, ARROW_TAIL_SHARE, ARROW_WIDTH_SHARE, DEGREE_SIGN, DIAMETER_SIGN, EXTENSION_GAP_SHARE, EXTENSION_OVERSHOOT_SHARE, MOST_DECIMAL_PLACES, PLUS_MINUS_SIGN, RADIUS_SIGN, TEXT_GAP_SHARE, TOLERANCE_DECIMAL_PLACES, UPRIGHT_SLACK, } from "./drawing-dimension.constants";
|
|
12
|
+
const KINDS = new Set(Object.values(Inputs.IO.dimensionKindEnum));
|
|
13
|
+
const DEFAULTS = new Inputs.IO.DrawingDimensionDto();
|
|
14
|
+
const QUARTER_TURN = Math.PI / 2;
|
|
15
|
+
const point2Of = (value, property) => {
|
|
16
|
+
if (!Array.isArray(value) || value.length !== 2 || !value.every(isDrawable)) {
|
|
17
|
+
throw new InputError(`\`${property}\` must be a point of 2 finite numbers.`, property);
|
|
18
|
+
}
|
|
19
|
+
return [value[0], value[1]];
|
|
20
|
+
};
|
|
21
|
+
const amountOf = (value, property) => {
|
|
22
|
+
if (value === undefined) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const amount = finiteNumber(value, property);
|
|
26
|
+
if (amount < 0) {
|
|
27
|
+
throw new InputError(`\`${property}\` is an amount and must not be below 0; it is ${amount}.`, property);
|
|
28
|
+
}
|
|
29
|
+
return amount;
|
|
30
|
+
};
|
|
31
|
+
const decimalPlacesOf = (value) => {
|
|
32
|
+
const places = finiteNumber(value, "decimalPlaces");
|
|
33
|
+
if (!Number.isInteger(places) || places < 0 || places > MOST_DECIMAL_PLACES) {
|
|
34
|
+
throw new InputError(`\`decimalPlaces\` must be a whole number from 0 to ${MOST_DECIMAL_PLACES}; it is ${places}.`, "decimalPlaces");
|
|
35
|
+
}
|
|
36
|
+
return places;
|
|
37
|
+
};
|
|
38
|
+
const writtenNumber = (value, places) => {
|
|
39
|
+
const fixed = roundedTo(value, places).toFixed(places);
|
|
40
|
+
const trimmed = fixed.includes(".") ? fixed.replace(/0+$/, "").replace(/\.$/, "") : fixed;
|
|
41
|
+
return trimmed === "-0" ? "0" : trimmed;
|
|
42
|
+
};
|
|
43
|
+
const toleranceText = (upper, lower) => {
|
|
44
|
+
if (upper === undefined && lower === undefined) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
const above = writtenNumber(upper !== null && upper !== void 0 ? upper : 0, TOLERANCE_DECIMAL_PLACES);
|
|
48
|
+
const below = writtenNumber(lower !== null && lower !== void 0 ? lower : 0, TOLERANCE_DECIMAL_PLACES);
|
|
49
|
+
return above === below ? ` ${PLUS_MINUS_SIGN}${above}` : ` +${above}/-${below}`;
|
|
50
|
+
};
|
|
51
|
+
const radiusOf = (start, end) => {
|
|
52
|
+
const radius = distance2(start, end);
|
|
53
|
+
if (radius <= SAME_POINT) {
|
|
54
|
+
throw new InputError("`end` lies on `start`, so the dimension has no circle or arm to measure.", "end");
|
|
55
|
+
}
|
|
56
|
+
return radius;
|
|
57
|
+
};
|
|
58
|
+
const sweepOf = (value) => {
|
|
59
|
+
const degrees = finiteNumber(value, "angle");
|
|
60
|
+
if (degrees <= 0 || degrees >= FULL_TURN_DEGREES) {
|
|
61
|
+
throw new InputError(`\`angle\` must lie between 0 and ${FULL_TURN_DEGREES} degrees, both left out; it is ${degrees}.`, "angle");
|
|
62
|
+
}
|
|
63
|
+
return radiansOf(degrees);
|
|
64
|
+
};
|
|
65
|
+
const linearMeasureOf = (start, end, direction) => {
|
|
66
|
+
const along = direction !== null && direction !== void 0 ? direction : unit2Of(subtract2(end, start));
|
|
67
|
+
const measured = along === undefined ? 0 : Math.abs(dot2(subtract2(end, start), along));
|
|
68
|
+
if (measured <= SAME_POINT) {
|
|
69
|
+
throw new InputError("`end` lies level with `start` along the measured direction, so the dimension measures no distance.", "end");
|
|
70
|
+
}
|
|
71
|
+
return measured;
|
|
72
|
+
};
|
|
73
|
+
const directionOf = (value) => {
|
|
74
|
+
if (value === undefined) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const direction = unit2Of(point2Of(value, "direction"));
|
|
78
|
+
if (direction === undefined) {
|
|
79
|
+
throw new InputError("`direction` must not be a zero vector.", "direction");
|
|
80
|
+
}
|
|
81
|
+
return direction;
|
|
82
|
+
};
|
|
83
|
+
const dimensionOf = (dimension) => {
|
|
84
|
+
var _a, _b, _c, _d, _e;
|
|
85
|
+
const kind = (_a = dimension.kind) !== null && _a !== void 0 ? _a : DEFAULTS.kind;
|
|
86
|
+
if (typeof kind !== "string" || !KINDS.has(kind)) {
|
|
87
|
+
throw new InputError(`\`kind\` must be one of ${[...KINDS].join(", ")}.`, "kind");
|
|
88
|
+
}
|
|
89
|
+
const start = point2Of(dimension.start, "start");
|
|
90
|
+
const end = point2Of(dimension.end, "end");
|
|
91
|
+
const textHeight = positiveNumber((_b = dimension.textHeight) !== null && _b !== void 0 ? _b : DEFAULTS.textHeight, "textHeight");
|
|
92
|
+
const arrowLength = dimension.arrowLength === undefined ? textHeight : positiveNumber(dimension.arrowLength, "arrowLength");
|
|
93
|
+
const places = decimalPlacesOf((_c = dimension.decimalPlaces) !== null && _c !== void 0 ? _c : DEFAULTS.decimalPlaces);
|
|
94
|
+
const upper = amountOf(dimension.upperTolerance, "upperTolerance");
|
|
95
|
+
const lower = amountOf(dimension.lowerTolerance, "lowerTolerance");
|
|
96
|
+
const given = dimension.value === undefined ? undefined : finiteNumber(dimension.value, "value");
|
|
97
|
+
const direction = kind === Inputs.IO.dimensionKindEnum.linear ? directionOf(dimension.direction) : undefined;
|
|
98
|
+
const offset = finiteNumber((_d = dimension.offset) !== null && _d !== void 0 ? _d : DEFAULTS.offset, "offset");
|
|
99
|
+
const sweep = kind === Inputs.IO.dimensionKindEnum.angular ? sweepOf((_e = dimension.angle) !== null && _e !== void 0 ? _e : DEFAULTS.angle) : 0;
|
|
100
|
+
let measured;
|
|
101
|
+
let prefix = "";
|
|
102
|
+
let suffix = "";
|
|
103
|
+
if (kind === Inputs.IO.dimensionKindEnum.linear) {
|
|
104
|
+
measured = linearMeasureOf(start, end, direction);
|
|
105
|
+
}
|
|
106
|
+
else if (kind === Inputs.IO.dimensionKindEnum.angular) {
|
|
107
|
+
const radius = radiusOf(start, end);
|
|
108
|
+
if (radius < arrowLength) {
|
|
109
|
+
throw new InputError(`\`end\` lies ${radius} from \`start\`, nearer than an arrowhead is long (${arrowLength}), so the arc has no room for its arrows.`, "end");
|
|
110
|
+
}
|
|
111
|
+
measured = degreesOf(sweep);
|
|
112
|
+
suffix = DEGREE_SIGN;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const radius = radiusOf(start, end);
|
|
116
|
+
measured = kind === Inputs.IO.dimensionKindEnum.diameter ? 2 * radius : radius;
|
|
117
|
+
prefix = kind === Inputs.IO.dimensionKindEnum.diameter ? DIAMETER_SIGN : RADIUS_SIGN;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
kind,
|
|
121
|
+
start,
|
|
122
|
+
end,
|
|
123
|
+
direction,
|
|
124
|
+
offset,
|
|
125
|
+
sweep,
|
|
126
|
+
text: `${prefix}${writtenNumber(given !== null && given !== void 0 ? given : measured, places)}${suffix}${toleranceText(upper, lower)}`,
|
|
127
|
+
textHeight,
|
|
128
|
+
arrowLength,
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
const arrowhead = (tip, intoBody, length) => {
|
|
132
|
+
const base = add2(tip, scale2(intoBody, length));
|
|
133
|
+
const side = scale2(leftOf2(intoBody), length * ARROW_WIDTH_SHARE / 2);
|
|
134
|
+
return [tip, subtract2(base, side), add2(base, side)];
|
|
135
|
+
};
|
|
136
|
+
const readableTurn = (along) => {
|
|
137
|
+
const turn = Math.atan2(along[1], along[0]);
|
|
138
|
+
if (turn > QUARTER_TURN + UPRIGHT_SLACK) {
|
|
139
|
+
return turn - Math.PI;
|
|
140
|
+
}
|
|
141
|
+
return turn <= -QUARTER_TURN + UPRIGHT_SLACK ? turn + Math.PI : turn;
|
|
142
|
+
};
|
|
143
|
+
const inkOf = (value) => {
|
|
144
|
+
let low = 0;
|
|
145
|
+
let high = 0;
|
|
146
|
+
for (const stroke of strokeTextStrokes(simplex, value)) {
|
|
147
|
+
for (const point of stroke) {
|
|
148
|
+
low = Math.min(low, point[1]);
|
|
149
|
+
high = Math.max(high, point[1]);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { low, high };
|
|
153
|
+
};
|
|
154
|
+
const textAlong = (dimension, centre, along, outward) => {
|
|
155
|
+
const turn = readableTurn(along);
|
|
156
|
+
const up = leftOf2(polar2(1, turn));
|
|
157
|
+
const ink = inkOf(dimension.text);
|
|
158
|
+
const gap = dimension.textHeight * TEXT_GAP_SHARE;
|
|
159
|
+
const away = outward !== null && outward !== void 0 ? outward : up;
|
|
160
|
+
const clearance = dot2(up, away) >= 0 ? gap - ink.low * dimension.textHeight : gap + ink.high * dimension.textHeight;
|
|
161
|
+
const position = add2(centre, scale2(away, clearance));
|
|
162
|
+
return drawingTextOf({ text: dimension.text, position, height: dimension.textHeight, anchor: "middle", rotation: degreesOf(turn) }, "");
|
|
163
|
+
};
|
|
164
|
+
const textWidthOf = (dimension) => strokeTextAdvance(simplex, dimension.text) * dimension.textHeight;
|
|
165
|
+
const straightLayout = (dimension, line, extensions) => {
|
|
166
|
+
const length = dimension.arrowLength;
|
|
167
|
+
const span = distance2(line.from, line.to);
|
|
168
|
+
const along = scale2(subtract2(line.to, line.from), 1 / span);
|
|
169
|
+
const arrows = line.arrowAtFrom ? 2 : 1;
|
|
170
|
+
const inside = span >= ARROWS_INSIDE_ROOM * length * arrows / 2;
|
|
171
|
+
const tail = inside ? 0 : ARROW_TAIL_SHARE * length;
|
|
172
|
+
const fills = [arrowhead(line.to, scale2(along, inside ? -1 : 1), length)];
|
|
173
|
+
if (line.arrowAtFrom) {
|
|
174
|
+
fills.unshift(arrowhead(line.from, scale2(along, inside ? 1 : -1), length));
|
|
175
|
+
}
|
|
176
|
+
const width = textWidthOf(dimension);
|
|
177
|
+
const gap = dimension.textHeight * TEXT_GAP_SHARE;
|
|
178
|
+
const room = span - (inside ? arrows * length : 0);
|
|
179
|
+
const fits = width + 2 * gap <= room;
|
|
180
|
+
const centre = fits ? between2(line.from, line.to, 1 / 2) : add2(line.to, scale2(along, tail + gap + width / 2));
|
|
181
|
+
const first = line.arrowAtFrom ? subtract2(line.from, scale2(along, tail)) : line.from;
|
|
182
|
+
const last = fits ? add2(line.to, scale2(along, tail)) : add2(centre, scale2(along, width / 2));
|
|
183
|
+
return { lines: [[first, last], ...extensions], fills, text: textAlong(dimension, centre, along, undefined) };
|
|
184
|
+
};
|
|
185
|
+
const extensionLine = (point, foot, side, dimension) => {
|
|
186
|
+
const toward = subtract2(foot, point);
|
|
187
|
+
const reach = distance2(foot, point);
|
|
188
|
+
const along = reach > SAME_POINT ? scale2(toward, 1 / reach) : side;
|
|
189
|
+
const gap = dimension.textHeight * EXTENSION_GAP_SHARE;
|
|
190
|
+
const from = reach > gap ? add2(point, scale2(along, gap)) : point;
|
|
191
|
+
return [from, add2(foot, scale2(along, dimension.textHeight * EXTENSION_OVERSHOOT_SHARE))];
|
|
192
|
+
};
|
|
193
|
+
const linearLayout = (dimension) => {
|
|
194
|
+
var _a;
|
|
195
|
+
const along = (_a = dimension.direction) !== null && _a !== void 0 ? _a : unit2Of(subtract2(dimension.end, dimension.start));
|
|
196
|
+
const side = leftOf2(along);
|
|
197
|
+
const height = dot2(dimension.start, side) + dimension.offset;
|
|
198
|
+
const footOf = (point) => add2(scale2(along, dot2(point, along)), scale2(side, height));
|
|
199
|
+
const firstFoot = footOf(dimension.start);
|
|
200
|
+
const secondFoot = footOf(dimension.end);
|
|
201
|
+
const outward = dimension.offset < 0 ? scale2(side, -1) : side;
|
|
202
|
+
const extensions = [extensionLine(dimension.start, firstFoot, outward, dimension), extensionLine(dimension.end, secondFoot, outward, dimension)];
|
|
203
|
+
return straightLayout(dimension, { from: firstFoot, to: secondFoot, arrowAtFrom: true }, extensions);
|
|
204
|
+
};
|
|
205
|
+
const circleLayout = (dimension) => {
|
|
206
|
+
if (dimension.kind === Inputs.IO.dimensionKindEnum.radius) {
|
|
207
|
+
return straightLayout(dimension, { from: dimension.start, to: dimension.end, arrowAtFrom: false }, []);
|
|
208
|
+
}
|
|
209
|
+
const opposite = subtract2(scale2(dimension.start, 2), dimension.end);
|
|
210
|
+
return straightLayout(dimension, { from: opposite, to: dimension.end, arrowAtFrom: true }, []);
|
|
211
|
+
};
|
|
212
|
+
const angularLayout = (dimension) => {
|
|
213
|
+
const centre = dimension.start;
|
|
214
|
+
const radius = distance2(dimension.start, dimension.end);
|
|
215
|
+
const first = Math.atan2(dimension.end[1] - centre[1], dimension.end[0] - centre[0]);
|
|
216
|
+
const last = first + dimension.sweep;
|
|
217
|
+
const length = dimension.arrowLength;
|
|
218
|
+
const inside = radius * dimension.sweep >= ARROWS_INSIDE_ROOM * length;
|
|
219
|
+
const arrowTurn = length / radius;
|
|
220
|
+
const tailTurn = inside ? 0 : ARROW_TAIL_SHARE * length / radius;
|
|
221
|
+
const onArc = (turn) => add2(centre, polar2(radius, turn));
|
|
222
|
+
const arrowAt = (turn, bodyTurn) => {
|
|
223
|
+
const tip = onArc(turn);
|
|
224
|
+
return arrowhead(tip, unit2Of(subtract2(onArc(bodyTurn), tip)), length);
|
|
225
|
+
};
|
|
226
|
+
const fills = inside
|
|
227
|
+
? [arrowAt(first, first + arrowTurn), arrowAt(last, last - arrowTurn)]
|
|
228
|
+
: [arrowAt(first, first - arrowTurn), arrowAt(last, last + arrowTurn)];
|
|
229
|
+
const arc = conicArcSamples({ frame: { center: [centre[0], centre[1], 0], xAxis: [radius, 0, 0], yAxis: [0, radius, 0] }, start: first - tailTurn, sweep: dimension.sweep + 2 * tailTurn }, dimension.textHeight * ARC_TOLERANCE_SHARE)
|
|
230
|
+
.map((point) => [point[0], point[1]]);
|
|
231
|
+
const gap = dimension.textHeight * EXTENSION_GAP_SHARE;
|
|
232
|
+
const overshoot = dimension.textHeight * EXTENSION_OVERSHOOT_SHARE;
|
|
233
|
+
const arm = (turn) => [add2(centre, polar2(radius > gap ? gap : 0, turn)), add2(centre, polar2(radius + overshoot, turn))];
|
|
234
|
+
const middle = first + dimension.sweep / 2;
|
|
235
|
+
const text = textAlong(dimension, onArc(middle), polar2(1, middle + QUARTER_TURN), polar2(1, middle));
|
|
236
|
+
return { lines: [arc, arm(first), arm(last)], fills, text };
|
|
237
|
+
};
|
|
238
|
+
const layoutOf = (dimension) => {
|
|
239
|
+
if (dimension.kind === Inputs.IO.dimensionKindEnum.linear) {
|
|
240
|
+
return linearLayout(dimension);
|
|
241
|
+
}
|
|
242
|
+
return dimension.kind === Inputs.IO.dimensionKindEnum.angular ? angularLayout(dimension) : circleLayout(dimension);
|
|
243
|
+
};
|
|
244
|
+
const extentOf = (layout) => {
|
|
245
|
+
const min = [Infinity, Infinity];
|
|
246
|
+
const max = [-Infinity, -Infinity];
|
|
247
|
+
const corners = textCornersOf(layout.text).map((corner) => [corner[0], corner[1]]);
|
|
248
|
+
for (const point of [...layout.lines.flat(), ...layout.fills.flat(), ...corners]) {
|
|
249
|
+
min[0] = Math.min(min[0], point[0]);
|
|
250
|
+
min[1] = Math.min(min[1], point[1]);
|
|
251
|
+
max[0] = Math.max(max[0], point[0]);
|
|
252
|
+
max[1] = Math.max(max[1], point[1]);
|
|
253
|
+
}
|
|
254
|
+
return { min, max };
|
|
255
|
+
};
|
|
256
|
+
const withoutRepeats = (strokes) => strokes
|
|
257
|
+
.map(stroke => stroke.filter((point, at) => at === 0 || distance2(point, stroke[at - 1]) > SAME_POINT))
|
|
258
|
+
.filter(stroke => stroke.length > 1);
|
|
259
|
+
export const dimensionExtentOf = (dimension) => extentOf(layoutOf(dimensionOf(dimension)));
|
|
260
|
+
export const dimensionPictureOf = (dimension) => {
|
|
261
|
+
const layout = layoutOf(dimensionOf(dimension));
|
|
262
|
+
const corners = textCornersOf(layout.text);
|
|
263
|
+
return {
|
|
264
|
+
lines: withoutRepeats(layout.lines),
|
|
265
|
+
fills: layout.fills,
|
|
266
|
+
textStrokes: withoutRepeats(textStrokesOf(layout.text).map(stroke => stroke.map((point) => [point[0], point[1]]))),
|
|
267
|
+
text: { text: layout.text.value, position: [layout.text.position[0], layout.text.position[1]], height: layout.text.height, anchor: layout.text.anchor, rotation: layout.text.rotationDegrees, widthFactor: layout.text.widthFactor },
|
|
268
|
+
textPoint: between2([corners[0][0], corners[0][1]], [corners[2][0], corners[2][1]], 1 / 2),
|
|
269
|
+
extent: extentOf(layout),
|
|
270
|
+
};
|
|
271
|
+
};
|
|
@@ -3,11 +3,14 @@ import type { ConicArc } from "../../curves/conic-arcs";
|
|
|
3
3
|
import type { FrameAxes } from "../../geometry/frame-axes";
|
|
4
4
|
import type { WorkBudget } from "../work-budget";
|
|
5
5
|
import type { DrawingArc, DrawingBounds, DrawingCircle, DrawingEllipse, DrawingPart, DrawingPolyline, DrawingSpline } from "./drawing-types";
|
|
6
|
+
type Point2 = Inputs.Base.Point2;
|
|
6
7
|
type Point3 = Inputs.Base.Point3;
|
|
7
8
|
type Vec3 = Inputs.Base.Vector3;
|
|
8
9
|
export declare const ocsAxesOf: (normal: Vec3) => FrameAxes;
|
|
9
10
|
export declare const circleArcOf: (segment: DrawingCircle | DrawingArc) => ConicArc;
|
|
10
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;
|
|
11
14
|
export declare const polylineSpans: (polyline: DrawingPolyline) => number;
|
|
12
15
|
export declare const polylineSpanEnd: (polyline: DrawingPolyline, span: number) => Point3;
|
|
13
16
|
export declare const bulgeArcOfSpan: (polyline: DrawingPolyline, span: number) => ConicArc | undefined;
|
|
@@ -2,8 +2,9 @@ import { bezierPiecesBounds, samplesOfPiece } from "../../curves/bezier-pieces";
|
|
|
2
2
|
import { bulgeArcOf, conicArcExtremes, conicArcSamples } from "../../curves/conic-arcs";
|
|
3
3
|
import { bezierPiecesOf } from "../../curves/nurbs-forms";
|
|
4
4
|
import { unitOf } from "../../geometry/frame-axes";
|
|
5
|
-
import { cross3, length3, scale3 } from "../../geometry/vectors";
|
|
6
|
-
import {
|
|
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";
|
|
7
8
|
const WORLD_Y = [0, 1, 0];
|
|
8
9
|
const WORLD_Z = [0, 0, 1];
|
|
9
10
|
export const ocsAxesOf = (normal) => {
|
|
@@ -28,6 +29,8 @@ export const ellipseArcOf = (segment) => {
|
|
|
28
29
|
sweep: segment.end - segment.start,
|
|
29
30
|
};
|
|
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);
|
|
31
34
|
export const polylineSpans = (polyline) => polyline.closed ? polyline.points.length : polyline.points.length - 1;
|
|
32
35
|
export const polylineSpanEnd = (polyline, span) => polyline.points[(span + 1) % polyline.points.length];
|
|
33
36
|
export const bulgeArcOfSpan = (polyline, span) => {
|
|
@@ -36,7 +39,7 @@ export const bulgeArcOfSpan = (polyline, span) => {
|
|
|
36
39
|
return bulge === 0 ? undefined : bulgeArcOf(polyline.points[span], polylineSpanEnd(polyline, span), bulge);
|
|
37
40
|
};
|
|
38
41
|
export const segmentSamples = (segment, tolerance, budget) => segment.kind === "ellipse"
|
|
39
|
-
? conicArcSamples(ellipseArcOf(segment), tolerance)
|
|
42
|
+
? conicArcSamples(ellipseArcOf(segment), tolerance, budget)
|
|
40
43
|
: bezierPiecesOf(segment.curve, budget).flatMap((piece, at) => samplesOfPiece(piece, tolerance, budget).slice(at === 0 ? 0 : 1));
|
|
41
44
|
const boundsPointsOf = (segment, tolerance, budget) => {
|
|
42
45
|
switch (segment.kind) {
|
|
@@ -60,15 +63,29 @@ const boundsPointsOf = (segment, tolerance, budget) => {
|
|
|
60
63
|
export const drawingBounds = (parts, tolerance, budget) => {
|
|
61
64
|
const min = [Infinity, Infinity, Infinity];
|
|
62
65
|
const max = [-Infinity, -Infinity, -Infinity];
|
|
63
|
-
|
|
64
|
-
for (const
|
|
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) {
|
|
65
76
|
for (const segment of path.segments) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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));
|
|
72
89
|
}
|
|
73
90
|
}
|
|
74
91
|
}
|
|
@@ -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 {};
|